bpf: fix missing bpf_base_func_proto in cgroup_base_func_proto for CGROUP_NET=n
Subsystems (5)
PATCH 1/1 bpf: fix missing bpf_base_func_proto in cgroup_base_func_proto for CGROUP_NET=n
linux-next build bot reported compile issue [1] with one of its configs. It looks like when we have CONFIG_NET=n and CONFIG_BPF{,_SYSCALL}=y, we are missing the bpf_base_func_proto definition (from net/core/filter.c) in cgroup_base_func_proto.
I'm reshuffling the code a bit to make it work. The common helpers are moved into kernel/bpf/helpers.c and the bpf_base_func_proto is exported from there.
Also, bpf_get_raw_cpu_id goes into kernel/bpf/core.c akin to existing bpf_user_rnd_u32.
--- include/linux/bpf.h | 8 +++++ include/linux/filter.h | 2 -- kernel/bpf/core.c | 5 +++ kernel/bpf/helpers.c | 73 +++++++++++++++++++++++++++++++++++++++ net/core/filter.c | 78 +----------------------------------------- 5 files changed, 87 insertions(+), 79 deletions(-)
include/linux/bpf.h +8 -0
@@ -1215,6 +1215,7 @@ int btf_check_type_match(struct bpf_verifier_env *env, struct bpf_prog *prog,struct bpf_prog *bpf_prog_by_id (u32 id); +const struct bpf_func_proto *bpf_base_func_proto (enum bpf_func_id func_id);#else /* !CONFIG_BPF_SYSCALL */ static inline struct bpf_prog *bpf_prog_get (u32 ufd) {
@@ -1365,6 +1366,12 @@ static inline struct bpf_prog *bpf_prog_by_id(u32 id) {return ERR_PTR (-ENOTSUPP ); } + +static inline const struct bpf_func_proto * +bpf_base_func_proto (enum bpf_func_id func_id) +{ +return NULL ; +}#endif /* CONFIG_BPF_SYSCALL */ static inline struct bpf_prog *bpf_prog_get_type(u32 ufd,
@@ -1531,6 +1538,7 @@ const struct bpf_func_proto *bpf_tracing_func_proto(/* Shared helpers among cBPF and eBPF. */ void bpf_user_rnd_init_once (void );u64 bpf_user_rnd_u32 (u64 r1,u64 r2,u64 r3,u64 r4,u64 r5); +u64 bpf_get_raw_cpu_id (u64 r1,u64 r2,u64 r3,u64 r4,u64 r5);#if defined(CONFIG_NET ) bool bpf_sock_common_is_valid_access(int off, int size,
include/linux/filter.h +0 -2
@@ -863,8 +863,6 @@ int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog);int bpf_prog_create_from_user (struct bpf_prog **pfp,struct sock_fprog *fprog,bpf_aux_classic_check_t trans,bool save_orig);void bpf_prog_destroy (struct bpf_prog *fp); -const struct bpf_func_proto * -bpf_base_func_proto (enum bpf_func_id func_id);int sk_attach_filter (struct sock_fprog *fprog,struct sock *sk);int sk_attach_bpf (u32 ufd,struct sock *sk);
kernel/bpf/core.c +5 -0
@@ -2136,6 +2136,11 @@ BPF_CALL_0(bpf_user_rnd_u32)return res; } +BPF_CALL_0 (bpf_get_raw_cpu_id) +{ +return raw_smp_processor_id (); +} +/* Weak definitions of helper functions in case we don't have bpf syscall. */ const struct bpf_func_proto bpf_map_lookup_elem_proto__weak ;const struct bpf_func_proto bpf_map_update_elem_proto__weak ;
kernel/bpf/helpers.c +73 -0
76 lines not on this page · raw message
net/core/filter.c +1 -77
96 lines not on this page · raw message
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
Alexei Starovoitov
AppliedQuoted 11 lines · Stanislav Fomichev
linux-next build bot reported compile issue [1] with one of its configs. It looks like when we have
CONFIG_NET=nand CONFIG_BPF{,_SYSCALL}=y, we are missing thebpf_base_func_protodefinition (fromnet/core/filter.c) incgroup_base_func_proto.I'm reshuffling the code a bit to make it work. The common helpers are moved into
kernel/bpf/helpers.cand thebpf_base_func_protois exported from there.
Also,bpf_get_raw_cpu_idgoes intokernel/bpf/core.cakin to existingbpf_user_rnd_u32.
Quoted 5 lines
Fixes 76800cfc27c6 ("bpf: Enable more helpers for BPF_PROG_TYPE_CGROUP_{DEVICE,SYSCTL,SOCKOPT}")Cc Andrii Nakryiko <[email protected]>Signed-off-by Stanislav Fomichev <[email protected]>
Applied, Thanks