Skip to content

Commit 05670f8

Browse files
matttbeAlexei Starovoitov
authored andcommitted
bpf: fix compilation error without CGROUPS
Our MPTCP CI complained [1] -- and KBuild too -- that it was no longer possible to build the kernel without CONFIG_CGROUPS: kernel/bpf/task_iter.c: In function 'bpf_iter_css_task_new': kernel/bpf/task_iter.c:919:14: error: 'CSS_TASK_ITER_PROCS' undeclared (first use in this function) 919 | case CSS_TASK_ITER_PROCS | CSS_TASK_ITER_THREADED: | ^~~~~~~~~~~~~~~~~~~ kernel/bpf/task_iter.c:919:14: note: each undeclared identifier is reported only once for each function it appears in kernel/bpf/task_iter.c:919:36: error: 'CSS_TASK_ITER_THREADED' undeclared (first use in this function) 919 | case CSS_TASK_ITER_PROCS | CSS_TASK_ITER_THREADED: | ^~~~~~~~~~~~~~~~~~~~~~ kernel/bpf/task_iter.c:927:60: error: invalid application of 'sizeof' to incomplete type 'struct css_task_iter' 927 | kit->css_it = bpf_mem_alloc(&bpf_global_ma, sizeof(struct css_task_iter)); | ^~~~~~ kernel/bpf/task_iter.c:930:9: error: implicit declaration of function 'css_task_iter_start'; did you mean 'task_seq_start'? [-Werror=implicit-function-declaration] 930 | css_task_iter_start(css, flags, kit->css_it); | ^~~~~~~~~~~~~~~~~~~ | task_seq_start kernel/bpf/task_iter.c: In function 'bpf_iter_css_task_next': kernel/bpf/task_iter.c:940:16: error: implicit declaration of function 'css_task_iter_next'; did you mean 'class_dev_iter_next'? [-Werror=implicit-function-declaration] 940 | return css_task_iter_next(kit->css_it); | ^~~~~~~~~~~~~~~~~~ | class_dev_iter_next kernel/bpf/task_iter.c:940:16: error: returning 'int' from a function with return type 'struct task_struct *' makes pointer from integer without a cast [-Werror=int-conversion] 940 | return css_task_iter_next(kit->css_it); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ kernel/bpf/task_iter.c: In function 'bpf_iter_css_task_destroy': kernel/bpf/task_iter.c:949:9: error: implicit declaration of function 'css_task_iter_end' [-Werror=implicit-function-declaration] 949 | css_task_iter_end(kit->css_it); | ^~~~~~~~~~~~~~~~~ This patch simply surrounds with a #ifdef the new code requiring CGroups support. It seems enough for the compiler and this is similar to bpf_iter_css_{new,next,destroy}() functions where no other #ifdef have been added in kernel/bpf/helpers.c and in the selftests. Fixes: 9c66dc9 ("bpf: Introduce css_task open-coded iterator kfuncs") Link: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/6665206927 Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202310260528.aHWgVFqq-lkp@intel.com/ Signed-off-by: Matthieu Baerts <matttbe@kernel.org> [ added missing ifdefs for BTF_ID cgroup definitions ] Signed-off-by: Jiri Olsa <jolsa@kernel.org> Link: https://lore.kernel.org/r/20231101181601.1493271-1-jolsa@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 2b7ac0c commit 05670f8

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

kernel/bpf/helpers.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,15 +2564,17 @@ BTF_ID_FLAGS(func, bpf_iter_num_destroy, KF_ITER_DESTROY)
25642564
BTF_ID_FLAGS(func, bpf_iter_task_vma_new, KF_ITER_NEW | KF_RCU)
25652565
BTF_ID_FLAGS(func, bpf_iter_task_vma_next, KF_ITER_NEXT | KF_RET_NULL)
25662566
BTF_ID_FLAGS(func, bpf_iter_task_vma_destroy, KF_ITER_DESTROY)
2567+
#ifdef CONFIG_CGROUPS
25672568
BTF_ID_FLAGS(func, bpf_iter_css_task_new, KF_ITER_NEW | KF_TRUSTED_ARGS)
25682569
BTF_ID_FLAGS(func, bpf_iter_css_task_next, KF_ITER_NEXT | KF_RET_NULL)
25692570
BTF_ID_FLAGS(func, bpf_iter_css_task_destroy, KF_ITER_DESTROY)
2570-
BTF_ID_FLAGS(func, bpf_iter_task_new, KF_ITER_NEW | KF_TRUSTED_ARGS | KF_RCU_PROTECTED)
2571-
BTF_ID_FLAGS(func, bpf_iter_task_next, KF_ITER_NEXT | KF_RET_NULL)
2572-
BTF_ID_FLAGS(func, bpf_iter_task_destroy, KF_ITER_DESTROY)
25732571
BTF_ID_FLAGS(func, bpf_iter_css_new, KF_ITER_NEW | KF_TRUSTED_ARGS | KF_RCU_PROTECTED)
25742572
BTF_ID_FLAGS(func, bpf_iter_css_next, KF_ITER_NEXT | KF_RET_NULL)
25752573
BTF_ID_FLAGS(func, bpf_iter_css_destroy, KF_ITER_DESTROY)
2574+
#endif
2575+
BTF_ID_FLAGS(func, bpf_iter_task_new, KF_ITER_NEW | KF_TRUSTED_ARGS | KF_RCU_PROTECTED)
2576+
BTF_ID_FLAGS(func, bpf_iter_task_next, KF_ITER_NEXT | KF_RET_NULL)
2577+
BTF_ID_FLAGS(func, bpf_iter_task_destroy, KF_ITER_DESTROY)
25762578
BTF_ID_FLAGS(func, bpf_dynptr_adjust)
25772579
BTF_ID_FLAGS(func, bpf_dynptr_is_null)
25782580
BTF_ID_FLAGS(func, bpf_dynptr_is_rdonly)

kernel/bpf/task_iter.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,8 @@ __bpf_kfunc void bpf_iter_task_vma_destroy(struct bpf_iter_task_vma *it)
892892

893893
__diag_pop();
894894

895+
#ifdef CONFIG_CGROUPS
896+
895897
struct bpf_iter_css_task {
896898
__u64 __opaque[1];
897899
} __attribute__((aligned(8)));
@@ -950,6 +952,8 @@ __bpf_kfunc void bpf_iter_css_task_destroy(struct bpf_iter_css_task *it)
950952

951953
__diag_pop();
952954

955+
#endif /* CONFIG_CGROUPS */
956+
953957
struct bpf_iter_task {
954958
__u64 __opaque[3];
955959
} __attribute__((aligned(8)));

kernel/bpf/verifier.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5388,7 +5388,9 @@ static bool in_rcu_cs(struct bpf_verifier_env *env)
53885388
/* Once GCC supports btf_type_tag the following mechanism will be replaced with tag check */
53895389
BTF_SET_START(rcu_protected_types)
53905390
BTF_ID(struct, prog_test_ref_kfunc)
5391+
#ifdef CONFIG_CGROUPS
53915392
BTF_ID(struct, cgroup)
5393+
#endif
53925394
BTF_ID(struct, bpf_cpumask)
53935395
BTF_ID(struct, task_struct)
53945396
BTF_SET_END(rcu_protected_types)
@@ -10835,7 +10837,9 @@ BTF_ID(func, bpf_dynptr_clone)
1083510837
BTF_ID(func, bpf_percpu_obj_new_impl)
1083610838
BTF_ID(func, bpf_percpu_obj_drop_impl)
1083710839
BTF_ID(func, bpf_throw)
10840+
#ifdef CONFIG_CGROUPS
1083810841
BTF_ID(func, bpf_iter_css_task_new)
10842+
#endif
1083910843
BTF_SET_END(special_kfunc_set)
1084010844

1084110845
BTF_ID_LIST(special_kfunc_list)
@@ -10861,7 +10865,11 @@ BTF_ID(func, bpf_dynptr_clone)
1086110865
BTF_ID(func, bpf_percpu_obj_new_impl)
1086210866
BTF_ID(func, bpf_percpu_obj_drop_impl)
1086310867
BTF_ID(func, bpf_throw)
10868+
#ifdef CONFIG_CGROUPS
1086410869
BTF_ID(func, bpf_iter_css_task_new)
10870+
#else
10871+
BTF_ID_UNUSED
10872+
#endif
1086510873

1086610874
static bool is_kfunc_ret_null(struct bpf_kfunc_call_arg_meta *meta)
1086710875
{

0 commit comments

Comments
 (0)