* [xdp-hints] How to extract BTF object ID from kernel module?
@ 2022-08-30 13:17 Jesper Dangaard Brouer
2022-08-31 17:22 ` [xdp-hints] " Jesper Dangaard Brouer
0 siblings, 1 reply; 2+ messages in thread
From: Jesper Dangaard Brouer @ 2022-08-30 13:17 UTC (permalink / raw)
To: Andrii Nakryiko
Cc: brouer, Zaremba Larysa, Alexei Starovoitov, bpf, xdp-hints
Hi Andrii,
When opening a modules BTF file (e.g. /sys/kernel/btf/i40e), can I
somehow get the kernels BTF object ID value (via that FD)?
I think I want the BTF object IDs as displayed by 'btftool btf'.
That code walks all IDs via bpf_btf_get_next_id() and then gets the FD
via bpf_btf_get_fd_by_id(). I'm looking for a more direct way than
having to walk all IDs...
(p.s. Cc. Larysa, I also looked at your code, which like bpftool end-up
walking all BTF IDs and extends libbpf with internal btf_obj_id to keep
track).
--Jesper
^ permalink raw reply [flat|nested] 2+ messages in thread
* [xdp-hints] Re: How to extract BTF object ID from kernel module?
2022-08-30 13:17 [xdp-hints] How to extract BTF object ID from kernel module? Jesper Dangaard Brouer
@ 2022-08-31 17:22 ` Jesper Dangaard Brouer
0 siblings, 0 replies; 2+ messages in thread
From: Jesper Dangaard Brouer @ 2022-08-31 17:22 UTC (permalink / raw)
To: Andrii Nakryiko, andrii.nakryiko
Cc: brouer, Zaremba Larysa, Alexei Starovoitov, bpf, xdp-hints, Netdev
On 30/08/2022 15.17, Jesper Dangaard Brouer wrote:
> Hi Andrii,
>
> When opening a modules BTF file (e.g. /sys/kernel/btf/i40e), can I
> somehow get the kernels BTF object ID value (via that FD)?
I had hoped I could simply open /sys/kernel/btf/module [1]
and use bpf_obj_get_info_by_fd(), but that fails
[1]
https://github.com/xdp-project/bpf-examples/blob/BTF-playground01/BTF-playground/btf_module_read.c#L84
[2]
https://github.com/xdp-project/bpf-examples/blob/BTF-playground01/BTF-playground/btf_module_read.c#L48
> I think I want the BTF object IDs as displayed by 'btftool btf'.
> That code walks all IDs via bpf_btf_get_next_id() and then gets the FD
> via bpf_btf_get_fd_by_id(). I'm looking for a more direct way than
> having to walk all IDs...
>
> (p.s. Cc. Larysa, I also looked at your code, which like bpftool end-up
> walking all BTF IDs and extends libbpf with internal btf_obj_id to keep
> track).
My current approach I end-up walking [3] all the BTF IDs via
bpf_btf_get_next_id() and then use bpf_obj_get_info_by_fd().
And then searching for the module name like this[4].
[3]
https://github.com/xdp-project/bpf-examples/blob/BTF-playground01/BTF-playground/btf_module_ids.c#L144
[4]
https://github.com/xdp-project/bpf-examples/blob/BTF-playground01/BTF-playground/btf_module_ids.c#L187-L256
Is this the only approach?
It seems wasteful that I have to walk all the IDs, when I already knows
what BTF file in /sys/kernel/btf/ I'm interested in...
--Jesper
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-08-31 17:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-30 13:17 [xdp-hints] How to extract BTF object ID from kernel module? Jesper Dangaard Brouer
2022-08-31 17:22 ` [xdp-hints] " Jesper Dangaard Brouer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox