From: Yonghong Song <yonghong.song@linux.dev>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>,
kernel-team@fb.com
Subject: [PATCH bpf-next 2/2] selftests/bpf: Test CO-RE relocations of unsigned 32-bit enum values
Date: Wed, 18 Nov 2026 08:10:58 -0800 [thread overview]
Message-ID: <20261118161058.1769375-1-yonghong.song@linux.dev> (raw)
In-Reply-To: <20261118161053.1768878-1-yonghong.song@linux.dev>
Test the zero extension of unsigned 32-bit enum values in CO-RE
relocations from the previous patch.
test_core_reloc_enumval gets an optional local enum with values out of
the range of int, i.e., an unsigned 4-byte enum, whose values clang
emits zero-extended in the ld_imm64 of the relocations. The enumval
target has the same enum with different values, 0x80000001 and
0xffffffff, which are expected zero-extended in the 64-bit outputs.
Without the fix, the check of the original value fails, and the whole
object is refused:
libbpf: prog 'test_core_enumval': relo #11: unexpected insn #53 (LDIMM64)
value: got 2147483648, exp 18446744071562067968 -> 18446744071562067969
libbpf: prog 'test_core_enumval': relo #11: failed to patch insn #53: -EINVAL
#122/71 core_reloc/enumval:FAIL
Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
---
.../testing/selftests/bpf/prog_tests/core_reloc.c | 2 ++
.../testing/selftests/bpf/progs/core_reloc_types.h | 8 ++++++++
.../selftests/bpf/progs/test_core_reloc_enumval.c | 14 ++++++++++++++
3 files changed, 24 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/core_reloc.c b/tools/testing/selftests/bpf/prog_tests/core_reloc.c
index 80432c4656b5..98b3c5fb1028 100644
--- a/tools/testing/selftests/bpf/prog_tests/core_reloc.c
+++ b/tools/testing/selftests/bpf/prog_tests/core_reloc.c
@@ -904,6 +904,8 @@ static const struct core_reloc_test_case test_cases[] = {
.named_val2 = 2,
.anon_val1 = 0x10,
.anon_val2 = 0x20,
+ .uint_val1 = 0x80000001,
+ .uint_val2 = 0xffffffff,
}),
ENUMVAL_CASE(enumval___diff, {
.named_val1_exists = true,
diff --git a/tools/testing/selftests/bpf/progs/core_reloc_types.h b/tools/testing/selftests/bpf/progs/core_reloc_types.h
index 5760ae015e09..6d758e74bd58 100644
--- a/tools/testing/selftests/bpf/progs/core_reloc_types.h
+++ b/tools/testing/selftests/bpf/progs/core_reloc_types.h
@@ -1215,6 +1215,8 @@ struct core_reloc_enumval_output {
int named_val2;
int anon_val1;
int anon_val2;
+ long uint_val1;
+ long uint_val2;
};
struct core_reloc_enum64val_output {
@@ -1243,9 +1245,15 @@ typedef enum {
ANON_ENUM_VAL3 = 0x30,
} anon_enum;
+enum named_uint_enum {
+ UINT_ENUM_VAL1 = 0x80000001,
+ UINT_ENUM_VAL2 = 0xffffffff,
+};
+
struct core_reloc_enumval {
enum named_enum f1;
anon_enum f2;
+ enum named_uint_enum f3;
};
enum named_unsigned_enum64 {
diff --git a/tools/testing/selftests/bpf/progs/test_core_reloc_enumval.c b/tools/testing/selftests/bpf/progs/test_core_reloc_enumval.c
index e7ef3dada2bf..964297b9bab5 100644
--- a/tools/testing/selftests/bpf/progs/test_core_reloc_enumval.c
+++ b/tools/testing/selftests/bpf/progs/test_core_reloc_enumval.c
@@ -27,6 +27,12 @@ typedef enum {
ANON_ENUM_VAL3 = 0x30,
} anon_enum;
+/* 4-byte enum with values out of the range of int, so it is unsigned */
+enum named_uint_enum {
+ UINT_ENUM_VAL1 = 0x80000000,
+ UINT_ENUM_VAL2 = 0xfffffff0,
+};
+
struct core_reloc_enumval_output {
bool named_val1_exists;
bool named_val2_exists;
@@ -39,6 +45,8 @@ struct core_reloc_enumval_output {
int named_val2;
int anon_val1;
int anon_val2;
+ long uint_val1;
+ long uint_val2;
};
SEC("raw_tracepoint/sys_enter")
@@ -64,6 +72,12 @@ int test_core_enumval(void *ctx)
out->anon_val1 = bpf_core_enum_value(anon, ANON_ENUM_VAL1);
out->anon_val2 = bpf_core_enum_value(anon, ANON_ENUM_VAL2);
/* ANON_ENUM_VAL3 value is optional */
+
+ /* enum named_uint_enum is optional */
+ if (bpf_core_enum_value_exists(enum named_uint_enum, UINT_ENUM_VAL1))
+ out->uint_val1 = bpf_core_enum_value(enum named_uint_enum, UINT_ENUM_VAL1);
+ if (bpf_core_enum_value_exists(enum named_uint_enum, UINT_ENUM_VAL2))
+ out->uint_val2 = bpf_core_enum_value(enum named_uint_enum, UINT_ENUM_VAL2);
#else
data.skip = true;
#endif
--
2.53.1-Meta
next prev parent reply other threads:[~2026-11-18 16:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 16:10 [PATCH bpf-next 1/2] libbpf: Zero-extend unsigned 32-bit enum values in CO-RE relocations Yonghong Song
2026-11-18 16:10 ` Yonghong Song [this message]
2026-11-18 16:59 ` bot+bpf-ci
2026-11-19 1:30 ` Yonghong Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118161058.1769375-1-yonghong.song@linux.dev \
--to=yonghong.song@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=kernel-team@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox