From: Yonghong Song <yonghong.song@linux.dev>
To: bot+bpf-ci@kernel.org, bpf@vger.kernel.org
Cc: ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net,
eddyz87@gmail.com, kernel-team@fb.com, martin.lau@kernel.org,
mason@kernel.org, ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v2 2/4] selftests/bpf: Test CO-RE relocations of unsigned 32-bit enum values
Date: Thu, 19 Nov 2026 07:57:42 -0800 [thread overview]
Message-ID: <473a226d-311a-43f4-a494-b0ce25862c75@linux.dev> (raw)
In-Reply-To: <4b1c106f8c17afddbdacf8814838a3c0aca16456e7655da2be23bad0bc40405f@mail.kernel.org>
On 11/18/26 9:54 PM, bot+bpf-ci@kernel.org wrote:
>> selftests/bpf: Test CO-RE relocations of unsigned 32-bit enum values
> TL;DR: The new enum test likely fails core_reloc/enumval on the GCC-BPF flavor
> at this commit, since GCC sign-extends the value; fixes come later in the
> series, so it isn't bisectable.
>
>> diff --git a/tools/testing/selftests/bpf/progs/test_core_reloc_enumval.c b/tools/testing/selftests/bpf/progs/test_core_reloc_enumval.c
>> --- a/tools/testing/selftests/bpf/progs/test_core_reloc_enumval.c
>> +++ b/tools/testing/selftests/bpf/progs/test_core_reloc_enumval.c
> [ ... ]
>
>> @@ -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);
> Will this pass for the GCC-BPF flavor of the object (test_progs-bpf_gcc)?
>
> Under !__clang__, bpf_core_enum_value() expands to
> __builtin_preserve_enum_value(), which returns int, so GCC emits the
> ld_imm64 sign-extended (for example lddw %r1,-2147483648 for 0x80000000).
>
> With f3507c4b38e8 applied, bpf_core_calc_enumval_relo() gets orig_val from
> btf_enum_value(), which is (__u32)e->val for a kflag 0 enum, and
> bpf_core_patch_insn() then validates it against the instruction:
>
> imm = (__u32)insn[0].imm | ((__u64)insn[1].imm << 32);
> if (res->validate && imm != orig_val) {
> pr_warn("... unexpected insn #%d (LDIMM64) value: ...");
> return -EINVAL;
> }
>
> For the GCC-built object imm is 0xffffffff80000000 while orig_val is
> 0x80000000, so bpf_object__load() should fail and ASSERT_OK(err,
> "obj_load") would fail core_reloc/enumval, and core_reloc_btfgen/enumval
> the same way. ENUMVAL_CASE(enumval) does not set .fails, neither subtest
> is in ci/vmtest/configs/DENYLIST.test_progs-bpf_gcc, and the gcc-bpf job
> (KERNEL_TEST: test_progs-bpf_gcc) runs on x86_64.
>
> Even with only the libbpf fix, the int result stored into the new long
> uint_val1/uint_val2 fields would read back as 0xffffffff80000001, while
> core_reloc.c expects 0x80000001 and 0xffffffff.
>
> This looks to be fixed later in the series, and both are needed for GCC:
>
> aa93e7e947e0 ("libbpf: Accept sign-extended 32-bit enum values in CO-RE
> relocations") makes libbpf accept the sign-extended form.
>
> ec81091d83f1 ("selftests/bpf: Take unsigned enum values as unsigned int
> for GCC") adds UINT_ENUM_VALUE(), which casts to unsigned int under
> !__clang__.
>
> Until both land, test_progs-bpf_gcc fails at this commit, so the series is
> not bisectable for that flavor. Could those changes be folded into this
> commit and f3507c4b38e8, or the series reordered?
>
> The commit message also describes only the clang behaviour ("whose values
> clang emits zero-extended in the ld_imm64 of the relocations").
You are correct. this will still have gcc test failure.
So in the next revision, I will merge 1/3 as the first commit
and 2/4 as the second commit. This way, we can avoid the selftest failure
during bisecting.
>
>
> ---
> AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
> See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
>
> CI run summary: https://github.com/kernel-patches/bpf/actions/runs/44465301903
next prev parent reply other threads:[~2026-11-19 15:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 5:14 [PATCH bpf-next v2 0/4] libbpf: Fix CO-RE relocations of unsigned 32-bit enum values Yonghong Song
2026-11-19 5:14 ` [PATCH bpf-next v2 1/4] libbpf: Zero-extend unsigned 32-bit enum values in CO-RE relocations Yonghong Song
2026-11-19 5:54 ` bot+bpf-ci
2026-11-19 15:55 ` Yonghong Song
2026-11-19 5:14 ` [PATCH bpf-next v2 2/4] selftests/bpf: Test CO-RE relocations of unsigned 32-bit enum values Yonghong Song
2026-11-19 5:54 ` bot+bpf-ci
2026-11-19 15:57 ` Yonghong Song [this message]
2026-11-19 5:14 ` [PATCH bpf-next v2 3/4] libbpf: Accept sign-extended 32-bit enum values in CO-RE relocations Yonghong Song
2026-11-19 5:21 ` sashiko-bot
2026-11-19 5:15 ` [PATCH bpf-next v2 4/4] selftests/bpf: Take unsigned enum values as unsigned int for GCC 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=473a226d-311a-43f4-a494-b0ce25862c75@linux.dev \
--to=yonghong.song@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=kernel-team@fb.com \
--cc=martin.lau@kernel.org \
--cc=mason@kernel.org \
/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