From: bot+bpf-ci@kernel.org
To: dennylin0707@gmail.com,ast@kernel.org,bpf@vger.kernel.org
Cc: andrii@kernel.org,qmo@kernel.org,daniel@iogearbox.net,yonghong.song@linux.dev,eddyz87@gmail.com,ihor.solodrai@linux.dev,shuah@kernel.org,linux-kselftest@vger.kernel.org,linux-kernel@vger.kernel.org,dennylin0707@gmail.com,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v4 3/3] selftests/bpf: Cover enum signedness in data dumps and map fields
Date: Sat, 7 Nov 2026 02:47:40 +0000 (UTC) [thread overview]
Message-ID: <d190f90d01988652195bf5ced90396d7ad07425705bd274d73140016d6a6c129@mail.kernel.org> (raw)
In-Reply-To: <20261107020725.36675-4-dennylin0707@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2879 bytes --]
> selftests/bpf: Cover enum signedness in data dumps and map fields
TL;DR: The wide_unknown btf_dump test only checks for digits, so it may pass
even when libbpf prints a truncated 32-bit value; a possible crash on 32-bit
hosts is also raised.
> diff --git a/tools/testing/selftests/bpf/prog_tests/btf_dump.c b/tools/testing/selftests/bpf/prog_tests/btf_dump.c
> --- a/tools/testing/selftests/bpf/prog_tests/btf_dump.c
> +++ b/tools/testing/selftests/bpf/prog_tests/btf_dump.c
[ ... ]
> +static void test_btf_dump_enum_values(void)
> +{
[ ... ]
> + /*
> + * Wider data must not match an enumerator through its low 32 bits.
> + * Check numeric output without requiring an exact value.
> + */
> + { "wide_unknown", 8, 0xffffffffLL,
> + { .u64 = 0x1ffffffffULL }, NULL },
> + };
[ ... ]
> + if (cases[i].expected) {
> + ASSERT_STREQ(str, cases[i].expected, cases[i].name);
> + } else {
> + ASSERT_NEQ(str[0], '\0', cases[i].name);
> + ASSERT_EQ(strspn(str, "0123456789"), strlen(str),
> + cases[i].name);
> + }
Does the wide_unknown case actually guard against the low 32 bits being
shown?
The check only requires the output to consist of digits, which also
passes when libbpf prints the truncated value. In btf_dump_enum_data()
the fallback for an unmatched BTF_KIND_ENUM value is:
__s64 value;
...
btf_dump_type_values(d, is_signed ? "%d" : "%u", value);
The value is an __s64 but the format is %d or %u. For an 8-byte enum
holding 0x1ffffffff, x86-64 would print "4294967295", which is the low 32
bits and equals the VALUE enumerator (0xffffffff). That is the situation
the comment and the commit message say this case guards against, yet the
test passes.
The bpftool counterpart (enum_wide_unknown in bpftool_map_dump.c) requires
"8589934591", and passes because btf_dumper_enum() uses jsonw_uint() with
a __u64.
On 32-bit hosts the 64-bit argument takes two vararg slots, so the high
word would be consumed as the char * for the "%s" appended by
btf_dump_type_values(). Could that crash test_progs in this subtest?
Related, in existing code: the macro expands to
is_signed ? "%d" : "%u" "%s%s"
so string literal concatenation applies only to the unsigned branch, and
signed unmatched values (and the ENUM64 "%lldLL" branch) are printed
without the delimiter and newline. This was not introduced here; it
dates from d90ec262b35b ("libbpf: Add enum64 support for btf_dump").
Would it make sense to have the libbpf fallback print a 64-bit value (for
example separate %lld/%llu calls with a long long cast) so that this case
can require "8589934591" as the bpftool test does?
---
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/42329238242
next prev parent reply other threads:[~2026-11-07 2:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 2:07 [PATCH bpf-next v4 0/3] Normalize enum values in libbpf and bpftool Hungyu Lin
2026-11-07 2:07 ` [PATCH bpf-next v4 1/3] libbpf: Normalize enum values according to signedness Hungyu Lin
2026-11-07 2:07 ` [PATCH bpf-next v4 2/3] bpftool: Preserve unsigned enum values in data dumps Hungyu Lin
2026-11-07 2:07 ` [PATCH bpf-next v4 3/3] selftests/bpf: Cover enum signedness in data dumps and map fields Hungyu Lin
2026-11-07 2:47 ` bot+bpf-ci [this message]
2026-11-07 3:46 ` [PATCH bpf-next v4 0/3] Normalize enum values in libbpf and bpftool Alexei Starovoitov
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=d190f90d01988652195bf5ced90396d7ad07425705bd274d73140016d6a6c129@mail.kernel.org \
--to=bot+bpf-ci@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dennylin0707@gmail.com \
--cc=eddyz87@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=mason@kernel.org \
--cc=qmo@kernel.org \
--cc=shuah@kernel.org \
--cc=yonghong.song@linux.dev \
/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
all inboxes | Powered by JetHome®