Re: [PATCH bpf-next v4] bpftool: add support for split BTF to gen min_core_btf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Feb 26, 2024 at 1:48 PM Bryce Kahle <bryce.kahle@xxxxxxxxxxxxx> wrote:
>
> On Fri, Feb 2, 2024, at 2:10 PM, Andrii Nakryiko wrote:
> > But yes, you'd have to specify both vmlinux and all the module
> > BTFs at the same time (which bpftool allows you to do easily with its
> > CLI interface, so not really a problem)
>
> I didn't see a way to specify a directory for vmlinux and all the
> modules BTFs. Are you suggesting I specify the path to each
> individually? I didn't see a way to do that with the current CLI api.
> It assumes that the input is only a single path.

so right now we have

bpftool min_core_btf <input-btf> <output-btf> <input1.bpf.o> ... <inputN.bpf.o>

so we'd have to either add a flag and do

bpftool min_core_btf <input-btf> -E <extra-btf1> -E <extra-btf2>
<output-btf> ...

or define special key/value pair (we do that for other commands to
specify extra options):

bpftool min_core_btf <input-btf> extra <extra-btf-1> extra
<extra-btf-2> <output-btf> ....

This has a tiny chance that user used "extra" as a name of one of
input object file (we can probably disregard).

Yet another option is to introduce new command, something like
`bpftool min_core_btf_multi ...` and define new convention.


OR. We can pivot and say that we do what you want as two steps:

1) generate one large combined BTF from multiple BTFs, something along
the lines of `bpftool btf merge <btf1> ... <btfN>`. We'd need to
specify how split BTF should be handled.

2) then use existing min_core_btf command with this merged BTF

I don't know what's best.

>
> On Mon, Feb 5, 2024 at 10:21 AM Andrii Nakryiko
> <andrii.nakryiko@xxxxxxxxx> wrote:
> > 2) append each module BTF to that instance (we have btf__add_btf() API
> > already for that). This will rewrite type IDs for each module
> > (shifting them by some constant number)
>
> It looks like btf__add_btf() doesn't support split BTF, which the
> module BTF has to be in order for it to parse correctly. Any
> suggestions for how to proceed? Do I need to add support for split BTF
> to btf__add_btf() to libbpf? If so, any thoughts on how that should
> work would be appreciated.

Yep, seems like it is explicitly not supported. I think one of the
problems with split BTF is that you don't want to append shared types
from base BTF, because that would be a waste. So you need a variant of
btf__add_btf() that allows you to specify a range of types to append.
But at that point what to do if some of the added types reference
types that were not appended? A bunch of unpleasant issues to be dealt
with.

So perhaps instead of using btf__add_btf(), bpftool can just do
btf__add_type() API, which remaps strings properly, but doesn't touch
type IDs. Libbpf has internal btf_type_visit_type_ids() function that
calls provided callback for each field that contains type ID. bpftool
can do its own remapping.

If we assume that we are merging vmlinux BTF and a bunch of module
BTFs, then this remapping is actually pretty straightforward: if type
ID belongs to base BTF, don't touch it. Otherwise shift it by some
amount, common for each type within the module's BTF.





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux