mbox series

[bpf-next,v5,0/4] bpftool: btf: Support dumping a single type from file

Message ID cover.1734119028.git.dxu@dxuuu.xyz (mailing list archive)
Headers show
Series bpftool: btf: Support dumping a single type from file | expand

Message

Daniel Xu Dec. 13, 2024, 7:44 p.m. UTC
Some projects, for example xdp-tools [0], prefer to check in a minimized
vmlinux.h rather than the complete file which can get rather large.

However, when you try to add a minimized version of a complex struct (eg
struct xfrm_state), things can get quite complex if you're trying to
manually untangle and deduplicate the dependencies.

This commit teaches bpftool to do a minimized dump of a single type by
providing an optional root_id argument.

Example usage:

    $ ./bpftool btf dump file ~/dev/linux/vmlinux | rg "STRUCT 'xfrm_state'"
    [12643] STRUCT 'xfrm_state' size=912 vlen=58

    $ ./bpftool btf dump file ~/dev/linux/vmlinux root_id 12643 format c
    #ifndef __VMLINUX_H__
    #define __VMLINUX_H__

    [..]

    struct xfrm_type_offload;

    struct xfrm_sec_ctx;

    struct xfrm_state {
            possible_net_t xs_net;
            union {
                    struct hlist_node gclist;
                    struct hlist_node bydst;
            };
            union {
                    struct hlist_node dev_gclist;
                    struct hlist_node bysrc;
            };
            struct hlist_node byspi;
    [..]

[0]: https://github.com/xdp-project/xdp-tools/blob/master/headers/bpf/vmlinux.h

=== Changelog ===

Changes in v5:
* Update bash-completion to support repeating root_id
* Update man page to mention root_id NAND map key/value/kv/all

Changes in v4:
* Support multiple instances of root_id

Changes in v3:
* Make `root_id` a top level btf-dump argument rather than attached to `file`
* Update bash completion script
* Refactor root_type_ids checking to after btf handle creation
* Update help messages and fix existing man page inconsistency

Changes in v2:
* Add early error check for invalid BTF ID

Daniel Xu (4):
  bpftool: man: Add missing format argument to command description
  bpftool: btf: Validate root_type_ids early
  bpftool: btf: Support dumping a specific types from file
  bpftool: bash: Add bash completion for root_id argument

 .../bpf/bpftool/Documentation/bpftool-btf.rst |  9 +++-
 tools/bpf/bpftool/bash-completion/bpftool     |  7 ++-
 tools/bpf/bpftool/btf.c                       | 51 ++++++++++++++++++-
 3 files changed, 62 insertions(+), 5 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org Dec. 13, 2024, 10:40 p.m. UTC | #1
Hello:

This series was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Fri, 13 Dec 2024 12:44:08 -0700 you wrote:
> Some projects, for example xdp-tools [0], prefer to check in a minimized
> vmlinux.h rather than the complete file which can get rather large.
> 
> However, when you try to add a minimized version of a complex struct (eg
> struct xfrm_state), things can get quite complex if you're trying to
> manually untangle and deduplicate the dependencies.
> 
> [...]

Here is the summary with links:
  - [bpf-next,v5,1/4] bpftool: man: Add missing format argument to command description
    https://git.kernel.org/bpf/bpf-next/c/5e3ad22d8223
  - [bpf-next,v5,2/4] bpftool: btf: Validate root_type_ids early
    https://git.kernel.org/bpf/bpf-next/c/7f5819e1ace8
  - [bpf-next,v5,3/4] bpftool: btf: Support dumping a specific types from file
    https://git.kernel.org/bpf/bpf-next/c/a812d92ed2ae
  - [bpf-next,v5,4/4] bpftool: bash: Add bash completion for root_id argument
    https://git.kernel.org/bpf/bpf-next/c/9d294f698678

You are awesome, thank you!