Re: [PATCH bpf-next v2] bpftool: Use sysfs vmlinux when dumping BTF by ID

From: Andrii Nakryiko
Date: Mon May 09 2022 - 20:24:49 EST


On Thu, May 5, 2022 at 6:17 AM Larysa Zaremba <larysa.zaremba@xxxxxxxxx> wrote:
>
> Currently, dumping almost all BTFs specified by id requires
> using the -B option to pass the base BTF. For kernel module
> BTFs the vmlinux BTF sysfs path should work.
>
> This patch simplifies dumping by ID usage by attempting to
> use vmlinux BTF from sysfs, if the first try of loading BTF by ID
> fails with certain conditions and the ID corresponds to a kernel
> module BTF.

It feels sloppy to first try without base BTF and then fallback to
base BTF. When specified ID of BTF object, let's just get its struct
bpf_btf_info with bpf_obj_get_info_by_fd() and then check that
kernel_btf is set and name isn't "vmlinux". This will mean it's kernel
module, so load base BTF from /sys/kernel/btf/vmlinux. If that fails,
there is no way that kernel module BTF will be successfully loaded, so
there is no point in trying.

>
> Signed-off-by: Larysa Zaremba <larysa.zaremba@xxxxxxxxx>
> Reviewed-by: Alexander Lobakin <alexandr.lobakin@xxxxxxxxx>
> ---
> tools/bpf/bpftool/btf.c | 67 +++++++++++++++++++++++++++++++++++------
> 1 file changed, 58 insertions(+), 9 deletions(-)
>

[...]