diff mbox series

bpf: hide cgroup functions for configs without cgroups

Message ID 20231020132749.1398012-1-arnd@kernel.org (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series bpf: hide cgroup functions for configs without cgroups | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-0 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-1 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-5 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-6 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-18 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-15 fail Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-19 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-22 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-28 success Logs for veristat

Commit Message

Arnd Bergmann Oct. 20, 2023, 1:27 p.m. UTC
From: Arnd Bergmann <arnd@arndb.de>

When cgroups are disabled, the newly added functions don't build:

kernel/bpf/task_iter.c: In function 'bpf_iter_css_task_new':
kernel/bpf/task_iter.c:917:14: error: 'CSS_TASK_ITER_PROCS' undeclared (first use in this function)
  917 |         case CSS_TASK_ITER_PROCS | CSS_TASK_ITER_THREADED:
      |              ^~~~~~~~~~~~~~~~~~~
kernel/bpf/task_iter.c:925:60: error: invalid application of 'sizeof' to incomplete type 'struct css_task_iter'
  925 |         kit->css_it = bpf_mem_alloc(&bpf_global_ma, sizeof(struct css_task_iter));
      |                                                            ^~~~~~

Hide them in an #ifdef section.

Fixes: 9c66dc94b62ae ("bpf: Introduce css_task open-coded iterator kfuncs")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 kernel/bpf/task_iter.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Alexei Starovoitov Oct. 20, 2023, 5:26 p.m. UTC | #1
On Fri, Oct 20, 2023 at 6:27 AM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> When cgroups are disabled, the newly added functions don't build:
>
> kernel/bpf/task_iter.c: In function 'bpf_iter_css_task_new':
> kernel/bpf/task_iter.c:917:14: error: 'CSS_TASK_ITER_PROCS' undeclared (first use in this function)
>   917 |         case CSS_TASK_ITER_PROCS | CSS_TASK_ITER_THREADED:
>       |              ^~~~~~~~~~~~~~~~~~~
> kernel/bpf/task_iter.c:925:60: error: invalid application of 'sizeof' to incomplete type 'struct css_task_iter'
>   925 |         kit->css_it = bpf_mem_alloc(&bpf_global_ma, sizeof(struct css_task_iter));
>       |                                                            ^~~~~~
>
> Hide them in an #ifdef section.
>
> Fixes: 9c66dc94b62ae ("bpf: Introduce css_task open-coded iterator kfuncs")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  kernel/bpf/task_iter.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c
> index 654601dd6b493..15a184f4f954d 100644
> --- a/kernel/bpf/task_iter.c
> +++ b/kernel/bpf/task_iter.c
> @@ -904,6 +904,7 @@ __diag_push();
>  __diag_ignore_all("-Wmissing-prototypes",
>                   "Global functions as their definitions will be in vmlinux BTF");
>
> +#ifdef CONFIG_CGROUPS
>  __bpf_kfunc int bpf_iter_css_task_new(struct bpf_iter_css_task *it,
>                 struct cgroup_subsys_state *css, unsigned int flags)
>  {
> @@ -947,6 +948,7 @@ __bpf_kfunc void bpf_iter_css_task_destroy(struct bpf_iter_css_task *it)
>         css_task_iter_end(kit->css_it);
>         bpf_mem_free(&bpf_global_ma, kit->css_it);
>  }
> +#endif

Did you actually test build it without cgroups and with bpf+btf?
I suspect the resolve_btfid step should be failing the build.
It needs
#ifdef CONFIG_CGROUPS
around BTF_ID_FLAGS(func, bpf_iter_css_task*
Arnd Bergmann Oct. 20, 2023, 8:06 p.m. UTC | #2
On Fri, Oct 20, 2023, at 19:26, Alexei Starovoitov wrote:
> On Fri, Oct 20, 2023 at 6:27 AM Arnd Bergmann <arnd@kernel.org> wrote:
>> @@ -904,6 +904,7 @@ __diag_push();
>>  __diag_ignore_all("-Wmissing-prototypes",
>>                   "Global functions as their definitions will be in vmlinux BTF");
>>
>> +#ifdef CONFIG_CGROUPS
>>  __bpf_kfunc int bpf_iter_css_task_new(struct bpf_iter_css_task *it,
>>                 struct cgroup_subsys_state *css, unsigned int flags)
>>  {
>> @@ -947,6 +948,7 @@ __bpf_kfunc void bpf_iter_css_task_destroy(struct bpf_iter_css_task *it)
>>         css_task_iter_end(kit->css_it);
>>         bpf_mem_free(&bpf_global_ma, kit->css_it);
>>  }
>> +#endif
>
> Did you actually test build it without cgroups and with bpf+btf?
> I suspect the resolve_btfid step should be failing the build.
> It needs
> #ifdef CONFIG_CGROUPS
> around BTF_ID_FLAGS(func, bpf_iter_css_task*

No, I did test with a few hundred random configurations, but it
looks like CONFIG_DEBUG_INFO_BTF is always disabled
in my builds because I force-disable CONFIG_DEBUG_INFO
to speed up my builds.

I tried reproducing it with CONFIG_DEBUG_INFO_BTF enabled
and it didn't immediately fail but it clearly makes sense that
we'd need another #ifdef.

      Arnd
Chuyi Zhou Oct. 21, 2023, 3:45 a.m. UTC | #3
Hello,

在 2023/10/21 04:06, Arnd Bergmann 写道:
> On Fri, Oct 20, 2023, at 19:26, Alexei Starovoitov wrote:
>> On Fri, Oct 20, 2023 at 6:27 AM Arnd Bergmann <arnd@kernel.org> wrote:
>>> @@ -904,6 +904,7 @@ __diag_push();
>>>   __diag_ignore_all("-Wmissing-prototypes",
>>>                    "Global functions as their definitions will be in vmlinux BTF");
>>>
>>> +#ifdef CONFIG_CGROUPS
>>>   __bpf_kfunc int bpf_iter_css_task_new(struct bpf_iter_css_task *it,
>>>                  struct cgroup_subsys_state *css, unsigned int flags)
>>>   {
>>> @@ -947,6 +948,7 @@ __bpf_kfunc void bpf_iter_css_task_destroy(struct bpf_iter_css_task *it)
>>>          css_task_iter_end(kit->css_it);
>>>          bpf_mem_free(&bpf_global_ma, kit->css_it);
>>>   }
>>> +#endif
>>
>> Did you actually test build it without cgroups and with bpf+btf?
>> I suspect the resolve_btfid step should be failing the build.
>> It needs
>> #ifdef CONFIG_CGROUPS
>> around BTF_ID_FLAGS(func, bpf_iter_css_task*
> 
> No, I did test with a few hundred random configurations, but it
> looks like CONFIG_DEBUG_INFO_BTF is always disabled
> in my builds because I force-disable CONFIG_DEBUG_INFO
> to speed up my builds.
> 
> I tried reproducing it with CONFIG_DEBUG_INFO_BTF enabled
> and it didn't immediately fail but it clearly makes sense that
> we'd need another #ifdef.
> 
>        Arnd

seems the same problem also reported by kernel-robot:

tree: 
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   2030579113a1b1b5bfd7ff24c0852847836d8fd1
commit: 9c66dc94b62aef23300f05f63404afb8990920b4 [13777/13906] bpf: 
Introduce css_task open-coded iterator kfuncs
config: hexagon-randconfig-r003-20230725 
(https://download.01.org/0day-ci/archive/20231021/202310211011.pTzXR2o9-lkp@intel.com/config)
compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git 
ae42196bc493ffe877a7e3dff8be32035dea4d07)
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/20231021/202310211011.pTzXR2o9-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new 
version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: 
https://lore.kernel.org/oe-kbuild-all/202310211011.pTzXR2o9-lkp@intel.com/

All errors (new ones prefixed by >>):

    In file included from kernel/bpf/task_iter.c:9:
    In file included from include/linux/filter.h:9:
    In file included from include/linux/bpf.h:31:
    In file included from include/linux/memcontrol.h:13:
    In file included from include/linux/cgroup.h:26:
    In file included from include/linux/kernel_stat.h:9:
    In file included from include/linux/interrupt.h:11:
    In file included from include/linux/hardirq.h:11:
    In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
    In file included from include/asm-generic/hardirq.h:17:
    In file included from include/linux/irq.h:20:
    In file included from include/linux/io.h:13:
    In file included from arch/hexagon/include/asm/io.h:337:
    include/asm-generic/io.h:547:31: warning: performing pointer 
arithmetic on a null pointer has undefined behavior 
[-Wnull-pointer-arithmetic]
            val = __raw_readb(PCI_IOBASE + addr);
                              ~~~~~~~~~~ ^
    include/asm-generic/io.h:560:61: warning: performing pointer 
arithmetic on a null pointer has undefined behavior 
[-Wnull-pointer-arithmetic]
            val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + 
addr));
                                                            ~~~~~~~~~~ ^
    include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded 
from macro '__le16_to_cpu'
    #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
                                                      ^
    In file included from kernel/bpf/task_iter.c:9:
    In file included from include/linux/filter.h:9:
    In file included from include/linux/bpf.h:31:
    In file included from include/linux/memcontrol.h:13:
    In file included from include/linux/cgroup.h:26:
    In file included from include/linux/kernel_stat.h:9:
    In file included from include/linux/interrupt.h:11:
    In file included from include/linux/hardirq.h:11:
    In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
    In file included from include/asm-generic/hardirq.h:17:
    In file included from include/linux/irq.h:20:
    In file included from include/linux/io.h:13:
    In file included from arch/hexagon/include/asm/io.h:337:
    include/asm-generic/io.h:573:61: warning: performing pointer 
arithmetic on a null pointer has undefined behavior 
[-Wnull-pointer-arithmetic]
            val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + 
addr));
                                                            ~~~~~~~~~~ ^
    include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded 
from macro '__le32_to_cpu'
    #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
                                                      ^
    In file included from kernel/bpf/task_iter.c:9:
    In file included from include/linux/filter.h:9:
    In file included from include/linux/bpf.h:31:
    In file included from include/linux/memcontrol.h:13:
    In file included from include/linux/cgroup.h:26:
    In file included from include/linux/kernel_stat.h:9:
    In file included from include/linux/interrupt.h:11:
    In file included from include/linux/hardirq.h:11:
    In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
    In file included from include/asm-generic/hardirq.h:17:
    In file included from include/linux/irq.h:20:
    In file included from include/linux/io.h:13:
    In file included from arch/hexagon/include/asm/io.h:337:
    include/asm-generic/io.h:584:33: warning: performing pointer 
arithmetic on a null pointer has undefined behavior 
[-Wnull-pointer-arithmetic]
            __raw_writeb(value, PCI_IOBASE + addr);
                                ~~~~~~~~~~ ^
    include/asm-generic/io.h:594:59: warning: performing pointer 
arithmetic on a null pointer has undefined behavior 
[-Wnull-pointer-arithmetic]
            __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + 
addr);
                                                          ~~~~~~~~~~ ^
    include/asm-generic/io.h:604:59: warning: performing pointer 
arithmetic on a null pointer has undefined behavior 
[-Wnull-pointer-arithmetic]
            __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + 
addr);
                                                          ~~~~~~~~~~ ^
 >> kernel/bpf/task_iter.c:919:7: error: use of undeclared identifier 
'CSS_TASK_ITER_PROCS'
            case CSS_TASK_ITER_PROCS | CSS_TASK_ITER_THREADED:
                 ^
 >> kernel/bpf/task_iter.c:919:29: error: use of undeclared identifier 
'CSS_TASK_ITER_THREADED'
            case CSS_TASK_ITER_PROCS | CSS_TASK_ITER_THREADED:
                                       ^
    kernel/bpf/task_iter.c:920:7: error: use of undeclared identifier 
'CSS_TASK_ITER_PROCS'
            case CSS_TASK_ITER_PROCS:
                 ^
 >> kernel/bpf/task_iter.c:927:46: error: invalid application of 
'sizeof' to an incomplete type 'struct css_task_iter'
            kit->css_it = bpf_mem_alloc(&bpf_global_ma, sizeof(struct 
css_task_iter));
                                                        ^ 
~~~~~~~~~~~~~~~~~~~~~~
    kernel/bpf/task_iter.c:902:9: note: forward declaration of 'struct 
css_task_iter'
            struct css_task_iter *css_it;
                   ^
 >> kernel/bpf/task_iter.c:930:2: error: call to undeclared function 
'css_task_iter_start'; ISO C99 and later do not support implicit 
function declarations [-Wimplicit-function-declaration]
            css_task_iter_start(css, flags, kit->css_it);
            ^
    kernel/bpf/task_iter.c:930:2: note: did you mean '__sg_page_iter_start'?
    include/linux/scatterlist.h:573:6: note: '__sg_page_iter_start' 
declared here
    void __sg_page_iter_start(struct sg_page_iter *piter,
         ^
 >> kernel/bpf/task_iter.c:940:9: error: call to undeclared function 
'css_task_iter_next'; ISO C99 and later do not support implicit function 
declarations [-Wimplicit-function-declaration]
            return css_task_iter_next(kit->css_it);
                   ^
 >> kernel/bpf/task_iter.c:940:9: error: incompatible integer to pointer 
conversion returning 'int' from a function with result type 'struct 
task_struct *' [-Wint-conversion]
            return css_task_iter_next(kit->css_it);
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 >> kernel/bpf/task_iter.c:949:2: error: call to undeclared function 
'css_task_iter_end'; ISO C99 and later do not support implicit function 
declarations [-Wimplicit-function-declaration]
            css_task_iter_end(kit->css_it);
            ^
    6 warnings and 8 errors generated.


vim +/CSS_TASK_ITER_PROCS +919 kernel/bpf/task_iter.c

    904	
    905	__diag_push();
    906	__diag_ignore_all("-Wmissing-prototypes",
    907			  "Global functions as their definitions will be in vmlinux BTF");
    908	
    909	__bpf_kfunc int bpf_iter_css_task_new(struct bpf_iter_css_task *it,
    910			struct cgroup_subsys_state *css, unsigned int flags)
    911	{
    912		struct bpf_iter_css_task_kern *kit = (void *)it;
    913	
    914		BUILD_BUG_ON(sizeof(struct bpf_iter_css_task_kern) != 
sizeof(struct bpf_iter_css_task));
    915		BUILD_BUG_ON(__alignof__(struct bpf_iter_css_task_kern) !=
    916						__alignof__(struct bpf_iter_css_task));
    917		kit->css_it = NULL;
    918		switch (flags) {
  > 919		case CSS_TASK_ITER_PROCS | CSS_TASK_ITER_THREADED:
  > 920		case CSS_TASK_ITER_PROCS:
    921		case 0:
    922			break;
    923		default:
    924			return -EINVAL;
    925		}
    926	
  > 927		kit->css_it = bpf_mem_alloc(&bpf_global_ma, sizeof(struct 
css_task_iter));
    928		if (!kit->css_it)
    929			return -ENOMEM;
  > 930		css_task_iter_start(css, flags, kit->css_it);
    931		return 0;
    932	}
    933	
    934	__bpf_kfunc struct task_struct *bpf_iter_css_task_next(struct 
bpf_iter_css_task *it)
    935	{
    936		struct bpf_iter_css_task_kern *kit = (void *)it;
    937	
    938		if (!kit->css_it)
    939			return NULL;
  > 940		return css_task_iter_next(kit->css_it);
    941	}
    942	
    943	__bpf_kfunc void bpf_iter_css_task_destroy(struct 
bpf_iter_css_task *it)
    944	{
    945		struct bpf_iter_css_task_kern *kit = (void *)it;
    946	
    947		if (!kit->css_it)
    948			return;
  > 949		css_task_iter_end(kit->css_it);
    950		bpf_mem_free(&bpf_global_ma, kit->css_it);
    951	}
    952
diff mbox series

Patch

diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c
index 654601dd6b493..15a184f4f954d 100644
--- a/kernel/bpf/task_iter.c
+++ b/kernel/bpf/task_iter.c
@@ -904,6 +904,7 @@  __diag_push();
 __diag_ignore_all("-Wmissing-prototypes",
 		  "Global functions as their definitions will be in vmlinux BTF");
 
+#ifdef CONFIG_CGROUPS
 __bpf_kfunc int bpf_iter_css_task_new(struct bpf_iter_css_task *it,
 		struct cgroup_subsys_state *css, unsigned int flags)
 {
@@ -947,6 +948,7 @@  __bpf_kfunc void bpf_iter_css_task_destroy(struct bpf_iter_css_task *it)
 	css_task_iter_end(kit->css_it);
 	bpf_mem_free(&bpf_global_ma, kit->css_it);
 }
+#endif
 
 __diag_pop();