Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpftool: add support for split BTF to gen min_core_btf #129

Closed
wants to merge 1 commit into from

Conversation

brycekahle
Copy link

No description provided.

Copy link
Member

@qmonnet qmonnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, and thanks for the patch!

Can you please motivate the change in your commit description? I'm not super familiar with split BTF and minified BTF generation, but unless I'm wrong we need to pass the base BTF on the command line for this to work, don't we? If so, I'd like to have:

  • An example invocation in the commit description, to help with the review
  • Ideally, an example in the relevant docs (Documentation/bpftool-gen.rst)
  • An update of the docs if option -B is required for this to work (so far we only document -B in the bpftool btf man page), along with the update of the help string in gen.c's do_help()

Then I won't merge the commit from this repo, sorry. Instead, you need to submit it to the BPF mailing list (see the relevant docs - I can help if necessary). Please be sure to CC the BPF maintainers and myself, and to prefix your commit title with bpftool: .

src/gen.c Outdated Show resolved Hide resolved
@brycekahle
Copy link
Author

Updated, let me know if it looks good for me to submit to the mailing list.

@brycekahle brycekahle changed the title add support for split BTF to gen min_core_btf bpftool: add support for split BTF to gen min_core_btf Jan 16, 2024
Copy link
Member

@qmonnet qmonnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks better, thanks! A few more nits:

  • Please wrap your commit description (except for the example invocations) on ~72 char-wide lines
  • The second paragraph for the description of the -B option is probably not required for bpftool gen, see below.

After that it looks good from my side, although I've not tested the changes.

I forgot to say it because it seemed obvious to me, but just to be sure, to submit to the BPF mailing list you'll have to port your changes to the Linux git repo (the bpf-next tree). Bpftool sources are under tools/bpf/bpftool/.

docs/bpftool-gen.rst Outdated Show resolved Hide resolved
@brycekahle
Copy link
Author

Updated

Copy link
Member

@qmonnet qmonnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading again the description, I'd recommend adding this note:

A minimized module BTF will still not contain vmlinux BTF types, so you should always minimize the vmlinux file first, and then minimize the kernel module file.

to either the option description, or to your example, in the man page. I suspect that, otherwise, users will try to create a the minimised object in one step by passing the path of both the vmlinux and module BTF paths.

By the way, with your patch, you currently end up with two generated minimised BTF objects, mod-min.btf and vm-min.btf, right? Wouldn't it make sense to look into passing all BTF objects (vmlinux and modules) in one step, and generate a single minimised BTF object from that? Or does it defeat what you're trying to achieve? (Sorry for failing to raise this on the previous review.)

Also, one other nit below.

src/gen.c Show resolved Hide resolved
@brycekahle
Copy link
Author

Wouldn't it make sense to look into passing all BTF objects (vmlinux and modules) in one step, and generate a single minimised BTF object from that? Or does it defeat what you're trying to achieve? (Sorry for failing to raise this on the previous review.)

There may be multiple kernel modules in play for a single eBPF object file, since it can contain multiple programs and they each may probe different modules. Since a kernel module BTF has conflicting type IDs (they all start at max(vmlinux) + 1) with other kernel module BTF, I'm not sure there is a way with libbpf to load them all at the same time.

@brycekahle
Copy link
Author

Updated

Copy link
Member

@qmonnet qmonnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be multiple kernel modules in play...

Might be worth mentioning in your commit description. I don't have a suggestion to address this, but others on the BPF ML may have ideas.

Otherwise, it looks nearly all good from my side (with a last nit below).

Looking forwards to seeing your patch on the ML :)

docs/bpftool-gen.rst Outdated Show resolved Hide resolved
Enables a user to generate minimized kernel module BTF.

If an eBPF program probes a function within a kernel module or uses
types that come from a kernel module, split BTF is required. The split
module BTF contains only the BTF types that are unique to the module.
It will reference the base/vmlinux BTF types and always starts its type
IDs at X+1 where X is the largest type ID in the base BTF.

Minimization allows a user to ship only the types necessary to do
relocations for the program(s) in the provided eBPF object file(s). A
minimized module BTF will still not contain vmlinux BTF types, so you
should always minimize the vmlinux file first, and then minimize the
kernel module file.

Example:

bpftool gen min_core_btf vmlinux.btf vm-min.btf prog.bpf.o
bpftool -B vm-min.btf gen min_core_btf mod.btf mod-min.btf prog.bpf.o

Signed-off-by: Bryce Kahle <[email protected]>
@brycekahle
Copy link
Author

Welp, first ML attempt was a failure. Gmail borked the formatting. I'm looking into my options, but my work email is pretty locked down so I cannot even get an app password.

@qmonnet
Copy link
Member

qmonnet commented Jan 22, 2024

Yeah GMail interface is known to break patch formatting. I'm using git send-email, but yes, it needs an app password to use the SMTP.

Have you looked into using a local client that supports 0Auth2 to connect to GMail (I think Thunderbird at least can)? I don't think you'd need an app password to do that?

If you don't find a solution for your work email, you can always use a personal email to send your patch. git send-email should preserve the From: header and the Signed-off-by, so only your work email would appear in the git logs (your personal email would be on https://lore.kernel.org/bpf/ though).

If none of these work or is convenient, I'm happy to post the patch on your behalf.

@brycekahle
Copy link
Author

Closing because it is on ML now

@brycekahle brycekahle closed this Feb 1, 2024
@qmonnet
Copy link
Member

qmonnet commented Feb 1, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants