Skip to content

bpf: btf: fix struct/union/fwd types with kind_flag

Yonghong Song netdev 3 versions – Applied

Status from this message: Applied to bpf-next, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest8 patches 1 replyApplied
  2. v28 patches 21 repliesSuperseded
  3. v17 patches 0 repliesSuperseded

Changes in v3 from the cover letter

. Relocated comments about bitfield_size/bit_offset interpretation
of the "offset" field right before the "offset" struct member.
. Added missing byte alignment checking for non-bitfield enum
member of a struct with kind_flag set.
. Added two test cases in unit tests for struct type, kind_flag set,
non-bitfield int/enum member, not-byte aligned bit offsets.
. Added comments to help understand there is no overflow for
total_bits_offset in bpftool function btf_dumper_int_bits().
. Added explanation of typedef type dumping fix in Patch #8 commit
message.

Patches in v3 Applied

#Subject and filesSizeRepliesApplied
1/8bpf: btf: refactor btf_int_bits_seq_show()kernel/bpf/btf.c+21 -140 replies
2/8bpf: btf: fix struct/union/fwd types with kind_flaginclude/uapi/linux/btf.h kernel/bpf/btf.c+278 -220 replies
3/8bpf: enable cgroup local storage map pretty print with kind_flaginclude/linux/btf.h kernel/bpf/btf.c kernel/bpf/local_storage.c+36 -230 replies
4/8tools/bpf: sync btf.h header from kernel to toolstools/include/uapi/linux/btf.h+18 -20 replies
5/8tools/bpf: add test_btf unit tests for kind_flagtools/testing/selftests/bpf/test_btf.c+494 -20 replies
6/8tools/bpf: test kernel bpffs map pretty print with struct kind_flagtools/testing/selftests/bpf/test_btf.c+154 -140 replies
7/8tools: bpftool: refactor btf_dumper_int_bits()tools/bpf/bpftool/btf_dumper.c+19 -60 replies
8/8tools: bpftool: support pretty print with kind_flag settools/bpf/bpftool/btf_dumper.c+27 -90 replies

Reviews trailers per patch

All 8 patches have a Reviewed-by or Acked-by.

PatchMartin KaFai Lau
1/8A-b
2/8A-b
3/8A-b
4/8A-b
5/8A-b
6/8A-b
7/8A-b
8/8A-b

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

Read the v3 thread

Cover letter [PATCH bpf-next v3 0/8] bpf: btf: fix struct/union/fwd types with kind_flag

Commit 69b693f0aefa ("bpf: btf: Introduce BPF Type Format (BTF)") introduced BTF, a debug info format for BTF.

The original design has a couple of issues though.
First, the bitfield size is only encoded in int type.
If the struct member bitfield type is enum, pahole ([1])
or llvm is forced to replace enum with int type. As a result, the original type information gets lost.

Second, the original BTF design does not envision the possibility of BTF=>header_file conversion ([2]), hence does not encode "struct" or "union" info for a forward type. Such information is necessary to convert BTF to a header file.

This patch set fixed the issue by introducing kind_flag, using one bit in type->info. When kind_flag, the struct/union btf_member->offset will encode both bitfield_size and bit_offset, covering both int and enum base types. The kind_flag is also used to indicate whether the forward type is a union (when set) or a struct.

Patch #1 refactors function btf_int_bits_seq_show() so Patch #2 can reuse part of the function.
Patch #2 implemented kind_flag support for struct/union/fwd types. Patch #3 added kind_flag support for cgroup local storage map pretty print. Patch #4 syncs kernel uapi btf.h to tools directory.
Patch #5 added unit tests for kind_flag.
Patch #6 added tests for kernel bpffs based pretty print with kind_flag. Patch #7 refactors function btf_dumper_int_bits() so Patch #8 can reuse part of the function.
Patch #8 added bpftool support of pretty print with kind_flag set.

[1] https://git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?id=b18354f64cc215368c3bc0df4a7e5341c55c378c
[2] https://lwn.net/SubscriberLink/773198/fe3074838f5c3f26/

Change logs:
v2 -> v3:
. Relocated comments about bitfield_size/bit_offset interpretation
of the "offset" field right before the "offset" struct member.
. Added missing byte alignment checking for non-bitfield enum
member of a struct with kind_flag set.
. Added two test cases in unit tests for struct type, kind_flag set,
non-bitfield int/enum member, not-byte aligned bit offsets.
. Added comments to help understand there is no overflow for
total_bits_offset in bpftool function btf_dumper_int_bits().
. Added explanation of typedef type dumping fix in Patch #8 commit
message.

v1 -> v2:
. If kind_flag is set for a structure, ensure an int member,
whether it is a bitfield or not, is a regular int type.
. Added support so cgroup local storage map pretty print
works with kind_flag.

Yonghong Song (8):
bpf: btf: refactor btf_int_bits_seq_show()
bpf: btf: fix struct/union/fwd types with kind_flag
bpf: enable cgroup local storage map pretty print with kind_flag tools/bpf: sync btf.h header from kernel to tools tools/bpf: add test_btf unit tests for kind_flag tools/bpf: test kernel bpffs map pretty print with struct kind_flag
tools: bpftool: refactor btf_dumper_int_bits()
tools: bpftool: support pretty print with kind_flag set

 include/linux/btf.h                    |   5 +-
 include/uapi/linux/btf.h               |  20 +-
 kernel/bpf/btf.c                       | 352 +++++++++++--
 kernel/bpf/local_storage.c             |  17 +-
 tools/bpf/bpftool/btf_dumper.c         |  61 ++-
 tools/include/uapi/linux/btf.h         |  20 +-
 tools/testing/selftests/bpf/test_btf.c | 664 ++++++++++++++++++++++++-
 7 files changed, 1047 insertions(+), 92 deletions(-)
Signature · 1 line
2.17.1