OSDN Git Service

libbpf: Support kernel module function calls
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Sat, 2 Oct 2021 01:17:54 +0000 (06:47 +0530)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 6 Oct 2021 00:07:42 +0000 (17:07 -0700)
commit9dbe6015636c19f929a7f7b742f27f303ff6069d
treefdc16578ed21cc313a0e035468e9c9cfa508d4d9
parent0e32dfc80bae53b05e9eda7eaf259f30ab9ba43a
libbpf: Support kernel module function calls

This patch adds libbpf support for kernel module function call support.
The fd_array parameter is used during BPF program load to pass module
BTFs referenced by the program. insn->off is set to index into this
array, but starts from 1, because insn->off as 0 is reserved for
btf_vmlinux.

We try to use existing insn->off for a module, since the kernel limits
the maximum distinct module BTFs for kfuncs to 256, and also because
index must never exceed the maximum allowed value that can fit in
insn->off (INT16_MAX). In the future, if kernel interprets signed offset
as unsigned for kfunc calls, this limit can be increased to UINT16_MAX.

Also introduce a btf__find_by_name_kind_own helper to start searching
from module BTF's start id when we know that the BTF ID is not present
in vmlinux BTF (in find_ksym_btf_id).

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211002011757.311265-7-memxor@gmail.com
tools/lib/bpf/bpf.c
tools/lib/bpf/btf.c
tools/lib/bpf/libbpf.c
tools/lib/bpf/libbpf_internal.h