Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: mark dynptr kfuncs __weak to make them optional on old kernels

Mark dynptr kfuncs as __weak to allow
verifier_global_subprogs/arg_ctx_{perf,kprobe,raw_tp} subtests to be
loadable on old kernels. Because bpf_dynptr_from_xdp() kfunc is used
from arg_tag_dynptr BPF program in progs/verifier_global_subprogs.c
*and* is not marked as __weak, loading any subtest from
verifier_global_subprogs fails on old kernels that don't have
bpf_dynptr_from_xdp() kfunc defined. Even if arg_tag_dynptr program
itself is not loaded, libbpf bails out on non-weak reference to
bpf_dynptr_from_xdp (that can't be resolved), which shared across all
programs in progs/verifier_global_subprogs.c.

So mark all dynptr-related kfuncs as __weak to unblock libbpf CI ([0]).
In the upcoming "kfunc in vmlinux.h" work we should make sure that
kfuncs are always declared __weak as well.

[0] https://github.com/libbpf/libbpf/actions/runs/7792673215/job/21251250831?pr=776#step:4:7961

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20240206004008.1541513-1-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Andrii Nakryiko and committed by
Alexei Starovoitov
c7dcb6c9 d7bc416a

+9 -9
+9 -9
tools/testing/selftests/bpf/bpf_kfuncs.h
··· 9 9 * Error code 10 10 */ 11 11 extern int bpf_dynptr_from_skb(struct __sk_buff *skb, __u64 flags, 12 - struct bpf_dynptr *ptr__uninit) __ksym; 12 + struct bpf_dynptr *ptr__uninit) __ksym __weak; 13 13 14 14 /* Description 15 15 * Initializes an xdp-type dynptr ··· 17 17 * Error code 18 18 */ 19 19 extern int bpf_dynptr_from_xdp(struct xdp_md *xdp, __u64 flags, 20 - struct bpf_dynptr *ptr__uninit) __ksym; 20 + struct bpf_dynptr *ptr__uninit) __ksym __weak; 21 21 22 22 /* Description 23 23 * Obtain a read-only pointer to the dynptr's data ··· 26 26 * buffer if unable to obtain a direct pointer 27 27 */ 28 28 extern void *bpf_dynptr_slice(const struct bpf_dynptr *ptr, __u32 offset, 29 - void *buffer, __u32 buffer__szk) __ksym; 29 + void *buffer, __u32 buffer__szk) __ksym __weak; 30 30 31 31 /* Description 32 32 * Obtain a read-write pointer to the dynptr's data ··· 35 35 * buffer if unable to obtain a direct pointer 36 36 */ 37 37 extern void *bpf_dynptr_slice_rdwr(const struct bpf_dynptr *ptr, __u32 offset, 38 - void *buffer, __u32 buffer__szk) __ksym; 38 + void *buffer, __u32 buffer__szk) __ksym __weak; 39 39 40 - extern int bpf_dynptr_adjust(const struct bpf_dynptr *ptr, __u32 start, __u32 end) __ksym; 41 - extern bool bpf_dynptr_is_null(const struct bpf_dynptr *ptr) __ksym; 42 - extern bool bpf_dynptr_is_rdonly(const struct bpf_dynptr *ptr) __ksym; 43 - extern __u32 bpf_dynptr_size(const struct bpf_dynptr *ptr) __ksym; 44 - extern int bpf_dynptr_clone(const struct bpf_dynptr *ptr, struct bpf_dynptr *clone__init) __ksym; 40 + extern int bpf_dynptr_adjust(const struct bpf_dynptr *ptr, __u32 start, __u32 end) __ksym __weak; 41 + extern bool bpf_dynptr_is_null(const struct bpf_dynptr *ptr) __ksym __weak; 42 + extern bool bpf_dynptr_is_rdonly(const struct bpf_dynptr *ptr) __ksym __weak; 43 + extern __u32 bpf_dynptr_size(const struct bpf_dynptr *ptr) __ksym __weak; 44 + extern int bpf_dynptr_clone(const struct bpf_dynptr *ptr, struct bpf_dynptr *clone__init) __ksym __weak; 45 45 46 46 /* Description 47 47 * Modify the address of a AF_UNIX sockaddr.