Skip to content

libbpf/bpftool: support merging split BTFs

Josef Bacik bpf 6 versions – Applied

Status from this message: pushed to bpf-next

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v6 Latest3 patches 4 repliesApplied 1/3
  2. v53 patches 3 repliesSuperseded
  3. v43 patches 8 repliesSuperseded
Earlier versions · 3
VersionPostedPatchesRepliesStatus
v33 patches0 repliesSuperseded
v23 patches0 repliesSuperseded
v13 patches0 repliesSuperseded

Changes in v6 from the cover letter

- Fixed the missed is_prefix comment.
- Fixed the removed warning about skipping vmlinux.

Patches in v6 Applied · 1/3

#Subject and filesSizeRepliesApplied
1/3libbpf: support appending split BTF in btf__add_btf()tools/lib/bpf/btf.c+29 -82 replies
2/3bpftool: support merging multiple module BTFs in btf dumptools/bpf/bpftool/Documentation/bpftool-btf.rst tools/bpf/bpftool/bash-completion/bpftool tools/bpf/bpftool/btf.c+132 -172 replies
3/3selftests/bpf: add test for btf__add_btf() with split BTF sourcestools/testing/selftests/bpf/prog_tests/btf_write.c+111 -00 repliesApplied

Reviews trailers per patch

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

PatchAlan Maguire
1/3R-b
2/3R-b
3/3R-b

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

Read the v6 thread

Cover letter [PATCH v6 0/3] libbpf/bpftool: support merging split BTFs

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

v1->v2:
- Added a btf__dedup() call to btf__add_btf() to ensure that we don't have duplicate types in the merged BTF.
v2->v3:
- AI review got confused about the UAF comment, so the comment was expanded to clarify the UAF potential.
- Fixed potential clobbering of errno in the error path.
v3->v4:
- Fixed a potential silent corruption pointed out by the AI review bot. v4->v5:
- Addressed Andrii's comments for 1/3.
- Addressed Alan and Quentin's comments for 2/3.
- Addressed Alan's comments for 3/3.
- Added my Signed-off-by for the third patch.
- Made sure to validate everything still worked.
v5->v6:
- Fixed the missed is_prefix comment.
- Fixed the removed warning about skipping vmlinux.

--- Original email ---

Hello,

I'm extending systing to do introspection on vfio devices, which requires having the structs I need from the kernel available in userspace. Normally these are loadable modules, but in the case of vfio there's multiple structs across multiple modules. Normally you'd do the following to generate your vmlinux.h with a module

bpftool btf dump file /sys/kernel/btf/<module> format c \
--base /sys/kernel/btf/vmlinux > vmlinux.h

but if you need multiple modules you have to hack together multiple dumps and merge them together. This patch series adds support for merging multiple BTF sources together, so you can do

bpftool btf dump file /sys/kernel/btf/<module1> \
	file /sys/kernel/btf/<module2> format c \
	--base /sys/kernel/btf/vmlinux > vmlinux.h

I tested this with my usecase and it works. Thanks,

Josef

Josef Bacik (3):
libbpf: support appending split BTF in btf__add_btf()
bpftool: support merging multiple module BTFs in btf dump selftests/bpf: add test for btf__add_btf() with split BTF sources

 .../bpf/bpftool/Documentation/bpftool-btf.rst |  11 +-
 tools/bpf/bpftool/bash-completion/bpftool     |   6 +-
 tools/bpf/bpftool/btf.c                       | 132 ++++++++++++++++--
 tools/lib/bpf/btf.c                           |  37 +++--
 .../selftests/bpf/prog_tests/btf_write.c      | 111 +++++++++++++++
 5 files changed, 272 insertions(+), 25 deletions(-)
Signature · 1 line
2.53.0