bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Xu <dxu@dxuuu.xyz>
To: bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org, qmo@kernel.org
Cc: andrii.nakryiko@gmail.com, antony@phenome.org, toke@kernel.org,
	martin.lau@linux.dev
Subject: [PATCH bpf-next v4 0/4] bpftool: btf: Support dumping a single type from file
Date: Thu, 12 Dec 2024 18:24:12 -0700	[thread overview]
Message-ID: <cover.1734052995.git.dxu@dxuuu.xyz> (raw)

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 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 |  8 ++-
 tools/bpf/bpftool/bash-completion/bpftool     |  7 ++-
 tools/bpf/bpftool/btf.c                       | 51 ++++++++++++++++++-
 3 files changed, 60 insertions(+), 6 deletions(-)

-- 
2.46.0


             reply	other threads:[~2024-12-13  1:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-13  1:24 Daniel Xu [this message]
2024-12-13  1:24 ` [PATCH bpf-next v4 1/4] bpftool: man: Add missing format argument to command description Daniel Xu
2024-12-13 15:15   ` Quentin Monnet
2024-12-13  1:24 ` [PATCH bpf-next v4 2/4] bpftool: btf: Validate root_type_ids early Daniel Xu
2024-12-13 15:15   ` Quentin Monnet
2024-12-13  1:24 ` [PATCH bpf-next v4 3/4] bpftool: btf: Support dumping a specific types from file Daniel Xu
2024-12-13 15:17   ` Quentin Monnet
2024-12-13 16:45     ` Daniel Xu
2024-12-13 16:55       ` Quentin Monnet
2024-12-13 18:01         ` Daniel Xu
2024-12-13  1:24 ` [PATCH bpf-next v4 4/4] bpftool: bash: Add bash completion for root_id argument Daniel Xu
2024-12-13 15:17   ` Quentin Monnet

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=cover.1734052995.git.dxu@dxuuu.xyz \
    --to=dxu@dxuuu.xyz \
    --cc=andrii.nakryiko@gmail.com \
    --cc=antony@phenome.org \
    --cc=bpf@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=qmo@kernel.org \
    --cc=toke@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).