[PATCH bpf-next] bpf: fix compilation error without CGROUPS

Matthieu Baerts posted 1 patch 5 months, 4 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/multipath-tcp/mptcp_net-next tags/patchew/20231031-bpf-compil-err-css-v1-1-e2244c637835@kernel.org
Maintainers: Yonghong Song <yonghong.song@linux.dev>, Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Andrii Nakryiko <andrii@kernel.org>, Martin KaFai Lau <martin.lau@linux.dev>, Song Liu <song@kernel.org>, John Fastabend <john.fastabend@gmail.com>, KP Singh <kpsingh@kernel.org>, Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>, Jiri Olsa <jolsa@kernel.org>, Tejun Heo <tj@kernel.org>, Chuyi Zhou <zhouchuyi@bytedance.com>
There is a newer version of this series
kernel/bpf/task_iter.c | 4 ++++
1 file changed, 4 insertions(+)
[PATCH bpf-next] bpf: fix compilation error without CGROUPS
Posted by Matthieu Baerts 5 months, 4 weeks ago
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: 9c66dc94b62a ("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>
---
 kernel/bpf/task_iter.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c
index 59e747938bdb..e0d313114a5b 100644
--- a/kernel/bpf/task_iter.c
+++ b/kernel/bpf/task_iter.c
@@ -894,6 +894,8 @@ __bpf_kfunc void bpf_iter_task_vma_destroy(struct bpf_iter_task_vma *it)
 
 __diag_pop();
 
+#ifdef CONFIG_CGROUPS
+
 struct bpf_iter_css_task {
 	__u64 __opaque[1];
 } __attribute__((aligned(8)));
@@ -952,6 +954,8 @@ __bpf_kfunc void bpf_iter_css_task_destroy(struct bpf_iter_css_task *it)
 
 __diag_pop();
 
+#endif /* CONFIG_CGROUPS */
+
 struct bpf_iter_task {
 	__u64 __opaque[3];
 } __attribute__((aligned(8)));

---
base-commit: f1c73396133cb3d913e2075298005644ee8dfade
change-id: 20231031-bpf-compil-err-css-056f3db04860

Best regards,
-- 
Matthieu Baerts <matttbe@kernel.org>
Re: bpf: fix compilation error without CGROUPS: Tests Results
Posted by MPTCP CI 5 months, 4 weeks ago
Hi Matthieu,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal (except selftest_mptcp_join):
  - Success! ✅:
  - Task: https://cirrus-ci.com/task/5146402590818304
  - Summary: https://api.cirrus-ci.com/v1/artifact/task/5146402590818304/summary/summary.txt

- KVM Validation: normal (only selftest_mptcp_join):
  - Success! ✅:
  - Task: https://cirrus-ci.com/task/6272302497660928
  - Summary: https://api.cirrus-ci.com/v1/artifact/task/6272302497660928/summary/summary.txt

- KVM Validation: debug (only selftest_mptcp_join):
  - Success! ✅:
  - Task: https://cirrus-ci.com/task/5990827520950272
  - Summary: https://api.cirrus-ci.com/v1/artifact/task/5990827520950272/summary/summary.txt

- KVM Validation: debug (except selftest_mptcp_join):
  - Success! ✅:
  - Task: https://cirrus-ci.com/task/4864927614107648
  - Summary: https://api.cirrus-ci.com/v1/artifact/task/4864927614107648/summary/summary.txt

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/5a24ddd35f49


If there are some issues, you can reproduce them using the same environment as
the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-debug

For more details:

    https://github.com/multipath-tcp/mptcp-upstream-virtme-docker


Please note that despite all the efforts that have been already done to have a
stable tests suite when executed on a public CI like here, it is possible some
reported issues are not due to your modifications. Still, do not hesitate to
help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (Tessares)
Re: [PATCH bpf-next] bpf: fix compilation error without CGROUPS
Posted by Jiri Olsa 5 months, 4 weeks ago
On Tue, Oct 31, 2023 at 04:49:34PM +0100, Matthieu Baerts wrote:
> 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: 9c66dc94b62a ("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>

Acked/Tested-by: Jiri Olsa <jolsa@kernel.org>

jirka

> ---
>  kernel/bpf/task_iter.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c
> index 59e747938bdb..e0d313114a5b 100644
> --- a/kernel/bpf/task_iter.c
> +++ b/kernel/bpf/task_iter.c
> @@ -894,6 +894,8 @@ __bpf_kfunc void bpf_iter_task_vma_destroy(struct bpf_iter_task_vma *it)
>  
>  __diag_pop();
>  
> +#ifdef CONFIG_CGROUPS
> +
>  struct bpf_iter_css_task {
>  	__u64 __opaque[1];
>  } __attribute__((aligned(8)));
> @@ -952,6 +954,8 @@ __bpf_kfunc void bpf_iter_css_task_destroy(struct bpf_iter_css_task *it)
>  
>  __diag_pop();
>  
> +#endif /* CONFIG_CGROUPS */
> +
>  struct bpf_iter_task {
>  	__u64 __opaque[3];
>  } __attribute__((aligned(8)));
> 
> ---
> base-commit: f1c73396133cb3d913e2075298005644ee8dfade
> change-id: 20231031-bpf-compil-err-css-056f3db04860
> 
> Best regards,
> -- 
> Matthieu Baerts <matttbe@kernel.org>
>
Re: [PATCH bpf-next] bpf: fix compilation error without CGROUPS
Posted by Alexei Starovoitov 5 months, 4 weeks ago
On Tue, Oct 31, 2023 at 10:05 AM Jiri Olsa <olsajiri@gmail.com> wrote:
>
> On Tue, Oct 31, 2023 at 04:49:34PM +0100, Matthieu Baerts wrote:
> > 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: 9c66dc94b62a ("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>
>
> Acked/Tested-by: Jiri Olsa <jolsa@kernel.org>

I believe this patch has the same issue as Arnd's patch:
https://lore.kernel.org/all/CAADnVQL-zoFPPOVu3nM981gKxRu7Q3G3LTRsKstJEeahpoR1RQ@mail.gmail.com/

I'd like to merge the fix asap. Please make it a complete fix.
Re: [PATCH bpf-next] bpf: fix compilation error without CGROUPS
Posted by Jiri Olsa 5 months, 4 weeks ago
On Tue, Oct 31, 2023 at 08:54:56PM -0700, Alexei Starovoitov wrote:
> On Tue, Oct 31, 2023 at 10:05 AM Jiri Olsa <olsajiri@gmail.com> wrote:
> >
> > On Tue, Oct 31, 2023 at 04:49:34PM +0100, Matthieu Baerts wrote:
> > > 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: 9c66dc94b62a ("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>
> >
> > Acked/Tested-by: Jiri Olsa <jolsa@kernel.org>
> 
> I believe this patch has the same issue as Arnd's patch:
> https://lore.kernel.org/all/CAADnVQL-zoFPPOVu3nM981gKxRu7Q3G3LTRsKstJEeahpoR1RQ@mail.gmail.com/
> 
> I'd like to merge the fix asap. Please make it a complete fix.

ugh, it won't fail the build, it just warns.. I think we should
fail the build in that case, I'll check

jirka