Skip to content

Instantly share code, notes, and snippets.

@eddyz87
Created January 15, 2024 15:26
Show Gist options
  • Save eddyz87/4a485573556012ec730c2de0256a79db to your computer and use it in GitHub Desktop.
Save eddyz87/4a485573556012ec730c2de0256a79db to your computer and use it in GitHub Desktop.
cilium-inline-asm-polymorphic-r.patch
diff --git a/bpf/include/bpf/access.h b/bpf/include/bpf/access.h
index 01f4deb6e9..8bc226e0c7 100644
--- a/bpf/include/bpf/access.h
+++ b/bpf/include/bpf/access.h
@@ -10,7 +10,7 @@
static __always_inline __maybe_unused __u32
map_array_get_32(const __u32 *array, __u32 index, const __u32 limit)
{
- __u32 datum = 0;
+ __u64 datum = 0;
if (__builtin_constant_p(index) ||
!__builtin_constant_p(limit))
@@ -26,7 +26,7 @@ map_array_get_32(const __u32 *array, __u32 index, const __u32 limit)
"%[array] += %[index]\n\t"
"%[datum] = *(u32 *)(%[array] + 0)\n\t"
: [datum]"=r"(datum)
- : [limit]"i"(limit), [array]"r"(array), [index]"r"(index)
+ : [limit]"i"(limit), [array]"r"(array), [index]"r"((__u64)index)
: /* no clobbers */ );
return datum;
diff --git a/bpf/include/bpf/ctx/xdp.h b/bpf/include/bpf/ctx/xdp.h
index 0f262ee357..7f912c4b6c 100644
--- a/bpf/include/bpf/ctx/xdp.h
+++ b/bpf/include/bpf/ctx/xdp.h
@@ -37,7 +37,7 @@ static __always_inline __maybe_unused int
xdp_load_bytes(const struct xdp_md *ctx, __u64 off, void *to, const __u64 len)
{
void *from;
- int ret;
+ long ret;
/* LLVM tends to generate code that verifier doesn't understand,
* so force it the way we want it in order to open up a range
* on the reg.
@@ -66,7 +66,7 @@ xdp_store_bytes(const struct xdp_md *ctx, __u64 off, const void *from,
const __u64 len, __u64 flags __maybe_unused)
{
void *to;
- int ret;
+ long ret;
/* See xdp_load_bytes(). */
asm volatile("r1 = *(u32 *)(%[ctx] +0)\n\t"
"r2 = *(u32 *)(%[ctx] +4)\n\t"
@@ -128,7 +128,7 @@ l3_csum_replace(const struct xdp_md *ctx, __u64 off, const __u32 from,
{
__u32 size = flags & BPF_F_HDR_FIELD_MASK;
__sum16 *sum;
- int ret;
+ long ret;
if (unlikely(flags & ~(BPF_F_HDR_FIELD_MASK)))
return -EINVAL;
@@ -164,7 +164,7 @@ l4_csum_replace(const struct xdp_md *ctx, __u64 off, __u32 from, __u32 to,
bool is_mmzero = flags & BPF_F_MARK_MANGLED_0;
__u32 size = flags & BPF_F_HDR_FIELD_MASK;
__sum16 *sum;
- int ret;
+ long ret;
if (unlikely(flags & ~(BPF_F_MARK_MANGLED_0 | BPF_F_PSEUDO_HDR |
BPF_F_HDR_FIELD_MASK)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment