bpf: treewide: Annotate BPF kfuncs in BTF
authorDaniel Xu <dxu@dxuuu.xyz>
Mon, 29 Jan 2024 01:24:08 +0000 (18:24 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 1 Feb 2024 04:40:56 +0000 (20:40 -0800)
commit6f3189f38a3e995232e028a4c341164c4aca1b20
treefd932c0339367596adb67fd652849506971fda3f
parenta05e90427ef6706f59188b379ad6366b9d298bc5
bpf: treewide: Annotate BPF kfuncs in BTF

This commit marks kfuncs as such inside the .BTF_ids section. The upshot
of these annotations is that we'll be able to automatically generate
kfunc prototypes for downstream users. The process is as follows:

1. In source, use BTF_KFUNCS_START/END macro pair to mark kfuncs
2. During build, pahole injects into BTF a "bpf_kfunc" BTF_DECL_TAG for
   each function inside BTF_KFUNCS sets
3. At runtime, vmlinux or module BTF is made available in sysfs
4. At runtime, bpftool (or similar) can look at provided BTF and
   generate appropriate prototypes for functions with "bpf_kfunc" tag

To ensure future kfunc are similarly tagged, we now also return error
inside kfunc registration for untagged kfuncs. For vmlinux kfuncs,
we also WARN(), as initcall machinery does not handle errors.

Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
Acked-by: Benjamin Tissoires <bentiss@kernel.org>
Link: https://lore.kernel.org/r/e55150ceecbf0a5d961e608941165c0bee7bc943.1706491398.git.dxu@dxuuu.xyz
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
22 files changed:
Documentation/bpf/kfuncs.rst
drivers/hid/bpf/hid_bpf_dispatch.c
fs/verity/measure.c
kernel/bpf/btf.c
kernel/bpf/cpumask.c
kernel/bpf/helpers.c
kernel/bpf/map_iter.c
kernel/cgroup/rstat.c
kernel/trace/bpf_trace.c
net/bpf/test_run.c
net/core/filter.c
net/core/xdp.c
net/ipv4/bpf_tcp_ca.c
net/ipv4/fou_bpf.c
net/ipv4/tcp_bbr.c
net/ipv4/tcp_cubic.c
net/ipv4/tcp_dctcp.c
net/netfilter/nf_conntrack_bpf.c
net/netfilter/nf_nat_bpf.c
net/xfrm/xfrm_interface_bpf.c
net/xfrm/xfrm_state_bpf.c
tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c