From: Jesper Dangaard Brouer <jbrouer@redhat.com>
To: Andrii Nakryiko <andrii@kernel.org>,
"andrii.nakryiko@gmail.com" <andrii.nakryiko@gmail.com>
Cc: brouer@redhat.com, Zaremba Larysa <larysa.zaremba@intel.com>,
Alexei Starovoitov <ast@kernel.org>, bpf <bpf@vger.kernel.org>,
"xdp-hints@xdp-project.net" <xdp-hints@xdp-project.net>,
Netdev <netdev@vger.kernel.org>
Subject: [xdp-hints] Re: How to extract BTF object ID from kernel module?
Date: Wed, 31 Aug 2022 19:22:52 +0200 [thread overview]
Message-ID: <f5c47d95-5ff4-3b5b-98db-c69fbf6538b5@redhat.com> (raw)
In-Reply-To: <2c7c8f91-a430-719c-5ef7-174cafa6c0be@redhat.com>
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
prev parent reply other threads:[~2022-08-31 17:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-30 13:17 [xdp-hints] " Jesper Dangaard Brouer
2022-08-31 17:22 ` Jesper Dangaard Brouer [this message]
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
List information: https://lists.xdp-project.net/postorius/lists/xdp-hints.xdp-project.net/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f5c47d95-5ff4-3b5b-98db-c69fbf6538b5@redhat.com \
--to=jbrouer@redhat.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brouer@redhat.com \
--cc=larysa.zaremba@intel.com \
--cc=netdev@vger.kernel.org \
--cc=xdp-hints@xdp-project.net \
/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