From: Hungyu Lin <dennylin0707@gmail.com>
To: 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,
Hungyu Lin <dennylin0707@gmail.com>
Subject: [PATCH bpf-next v3 0/3] Normalize enum values in libbpf and bpftool
Date: Sun, 1 Nov 2026 10:32:18 +0000 [thread overview]
Message-ID: <20261101103221.51534-1-dennylin0707@gmail.com> (raw)
This series fixes enum signedness problems in libbpf and bpftool data
dumps using the shared btf_enum_value() helper suggested by Alexei.
It also uses the helper when parsing enum-backed map fields, where sign
extension can change the requested map_extra value.
Keep existing enum name matches before considering normalized values.
This matters for eight-byte BTF_KIND_ENUM values in both dumpers and
narrow negative enums in bpftool. libbpf already zero-extends narrow
data without kflag; that behavior is unchanged. bpftool preserves the
original name's priority in one scan, even if another enumerator matches
the normalized value.
For an eight-byte ordinary enum with kflag clear, a stored negative
enumerator can match both its sign- and zero-extended values. This is
a compatibility choice: identical metadata can describe either a legacy
signed enum or an unsigned enum.
Unknown bpftool values follow kflag. With kflag clear, numeric output is
unsigned, including BTF sanitized by libbpf for kernels without enum64
support. This changes unknown negative values whose original signedness
is no longer recorded. libbpf's numeric fallback is unchanged.
CO-RE is left unchanged. Clang 14 and 18 emit a zero-extended immediate
for 0x80000000U, which the current sign-extended orig_val rejects. But
using the helper directly would reject negative enum immediates from
Clang 14 objects without kflag, and would zero-extend negative values
from target BTF without kflag. Those compatibility issues need a
separate change.
This supersedes the pending libbpf patch [1] and bpftool data-dump v2 [2],
as requested in [3]. The already applied bpftool type-JSON fix,
eaae576c34d7, is in the base and is not resubmitted.
Changes in v3:
- Combine libbpf, bpftool and regression tests into one series.
- Add btf_enum_value() and use it for enum-backed map fields and data
name matching.
- Preserve existing legacy names, including eight-byte ordinary enums
and ambiguous narrow names, addressing the review of bpftool v2.
- Add libbpf data-dump tests and kernel-backed bpftool map-dump tests.
Validation on ARM64, GCC 13.3.0, Clang 18.1.3, Linux 6.12.68:
- Complete libbpf and bpftool builds pass, including the libbpf ABI
checks and bpftool built with -Werror.
- With the new tests on the baseline: 38 subtests pass, 8 fail.
- With the fixes: all 46 subtests pass, none fail or skip.
These are the btf_dump and bpftool_map_dump test groups. The bpftool
cases load BTF and maps into the kernel and check both CLI formats.
Run these groups with ./test_progs -t btf_dump,bpftool_map_dump.
- map_extra parsing was checked with a separate local object-open
harness; this series does not include a selftest for that path.
Arena allocation and mmap were not tested.
[1] https://lore.kernel.org/bpf/20261031233219.9362-1-dennylin0707@gmail.com/
[2] https://lore.kernel.org/bpf/20261101001024.9994-1-dennylin0707@gmail.com/
[3] https://lore.kernel.org/bpf/DMJG1R2YIJRK.16CZLV9S5U7Z7@gmail.com/
Thanks,
Hungyu
Hungyu Lin (3):
libbpf: Normalize enum values according to signedness
bpftool: Preserve unsigned enum values in data dumps
selftests/bpf: Cover enum signedness and legacy name matching
tools/bpf/bpftool/btf_dumper.c | 42 ++--
tools/lib/bpf/btf.h | 6 +
tools/lib/bpf/btf_dump.c | 3 +-
tools/lib/bpf/libbpf.c | 2 +-
.../bpf/prog_tests/bpftool_map_dump.c | 180 ++++++++++++++++++
.../selftests/bpf/prog_tests/btf_dump.c | 84 ++++++++
6 files changed, 302 insertions(+), 15 deletions(-)
base-commit: a30c772627b2ef4bc715332b1b04938a914556cd
--
2.43.0
next reply other threads:[~2026-11-01 10:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-01 10:32 Hungyu Lin [this message]
2026-11-01 10:32 ` [PATCH bpf-next v3 1/3] libbpf: Normalize enum values according to signedness Hungyu Lin
2026-11-01 10:32 ` [PATCH bpf-next v3 2/3] bpftool: Preserve unsigned enum values in data dumps Hungyu Lin
2026-11-01 10:32 ` [PATCH bpf-next v3 3/3] selftests/bpf: Cover enum signedness and legacy name matching Hungyu Lin
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=20261101103221.51534-1-dennylin0707@gmail.com \
--to=dennylin0707@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.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®