Skip to content

Normalize enum values in libbpf and bpftool

Hungyu Lin bpf linux-kselftest lkml 3 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest3 patches 0 repliesApplied 3/3
  2. v43 patches 1 replySuperseded
  3. v33 patches 6 repliesSuperseded

Changes in v5 from the cover letter

- Keep patches 1 and 2 and the map_extra test unchanged.
- Adopt the bpftool and libbpf tests posted by Alexei in the v4 review.

Patches in v5 All 3 applied

#Subject and filesSizeRepliesApplied
1/3libbpf: Normalize enum values according to signednesstools/lib/bpf/btf.h tools/lib/bpf/btf_dump.c tools/lib/bpf/libbpf.c+8 -20 repliesApplied
2/3bpftool: Preserve unsigned enum values in data dumpstools/bpf/bpftool/btf_dumper.c+15 -80 repliesApplied
3/3selftests/bpf: Cover enum signedness in data dumps and map fieldstools/testing/selftests/bpf/prog_tests/bpftool_map_dump.c tools/testing/selftests/bpf/prog_tests/btf_dump.c tools/testing/selftests/bpf/prog_tests/map_extra.c +1 more+127 -00 repliesApplied

Reviews trailers per patch

2 of 3 patches have a Reviewed-by or Acked-by.

PatchQuentin Monnet
1/3
2/3A-b
3/3A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v5 thread

Cover letter [PATCH bpf-next v5 0/3] Normalize enum values in libbpf and bpftool

This series fixes enum signedness in libbpf and bpftool data dumps using the shared btf_enum_value() helper suggested by Alexei. It also uses the helper for enum-backed map fields, where sign extension can change the requested map_extra value.

Ordinary enums are interpreted according to kflag. When kflag is clear, values are treated as unsigned, including BTF from producers that did not record signedness.

The helper returns __u64, consistent with btf_enum64_value(). bpftool casts to __s64 at signed numeric output. CO-RE relocation handling is left for a separate change.

Changes in v5:
- Keep patches 1 and 2 and the map_extra test unchanged.
- Adopt the bpftool and libbpf tests posted by Alexei in the v4 review.

Tested on arm64 (Linux 6.12.68, GCC 13.3, Clang 18.1). libbpf and bpftool build with -Werror under both compilers. With patch 3 alone, the new bpftool_map_dump/enum and map_extra/enum32_high subtests and the expanded enum_data subtest in btf_dump fail. With the full series, all 25 subtests pass. The 22 unchanged existing subtests pass in both cases.

v4: https://lore.kernel.org/bpf/[email protected]/
v3: https://lore.kernel.org/bpf/[email protected]/

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 in data dumps and map fields

 tools/bpf/bpftool/btf_dumper.c                | 23 ++++--
 tools/lib/bpf/btf.h                           |  6 ++
 tools/lib/bpf/btf_dump.c                      |  2 +-
 tools/lib/bpf/libbpf.c                        |  2 +-
 .../bpf/prog_tests/bpftool_map_dump.c         | 76 +++++++++++++++++++
 .../selftests/bpf/prog_tests/btf_dump.c       | 20 +++++
 .../selftests/bpf/prog_tests/map_extra.c      | 19 +++++
 .../selftests/bpf/progs/test_map_extra.c      | 12 +++
 8 files changed, 150 insertions(+), 10 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/map_extra.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_map_extra.c

base-commit: 3e18218484126afb9da722080659c038cb2256ab

Signature · 1 line
2.43.0