]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Factor out fd returning from bpf_btf_find_by_name_kind
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Thu, 17 Mar 2022 11:59:43 +0000 (17:29 +0530)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 18 Mar 2022 23:11:31 +0000 (16:11 -0700)
commit74370cf9920ab09fa5f7bb4a3ff3ab593b2cf429
tree81d4493a97e549028b949cd1460fe7b87321a30a
parente44b4d8361fbcc6881098c8d62b3bbdf61096a2d
bpf: Factor out fd returning from bpf_btf_find_by_name_kind

In next few patches, we need a helper that searches all kernel BTFs
(vmlinux and module BTFs), and finds the type denoted by 'name' and
'kind'. Turns out bpf_btf_find_by_name_kind already does the same thing,
but it instead returns a BTF ID and optionally fd (if module BTF). This
is used for relocating ksyms in BPF loader code (bpftool gen skel -L).

We extract the core code out into a new helper bpf_find_btf_id, which
returns the BTF ID in the return value, and BTF pointer in an out
parameter. The reference for the returned BTF pointer is always raised,
hence user must either transfer it (e.g. to a fd), or release it after
use.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20220317115957.3193097-2-memxor@gmail.com
kernel/bpf/btf.c