diff mbox series

[bpf-next] bpf: fix bpf_prog_pack build for ppc64_defconfig

Message ID 20220211014915.2403508-1-song@kernel.org (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next] bpf: fix bpf_prog_pack build for ppc64_defconfig | expand

Checks

Context Check Description
bpf/vmtest-bpf-next success VM_Test
bpf/vmtest-bpf-next-PR success PR summary
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
netdev/cc_maintainers fail 1 blamed authors not CCed: songliubraving@fb.com; 5 maintainers not CCed: kpsingh@kernel.org john.fastabend@gmail.com kafai@fb.com songliubraving@fb.com yhs@fb.com
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 14 this patch: 14
netdev/checkpatch warning WARNING: line length of 88 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Song Liu Feb. 11, 2022, 1:49 a.m. UTC
bpf_prog_pack causes build error with powerpc ppc64_defconfig:

kernel/bpf/core.c:830:23: error: variably modified 'bitmap' at file scope
  830 |         unsigned long bitmap[BITS_TO_LONGS(BPF_PROG_CHUNK_COUNT)];
      |                       ^~~~~~

Fix it by turning bitmap into a 0-length array.

Fixes: 57631054fae6 ("bpf: Introduce bpf_prog_pack allocator")
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Song Liu <song@kernel.org>
---
 kernel/bpf/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Jakub Kicinski Feb. 11, 2022, 11:54 p.m. UTC | #1
On Thu, 10 Feb 2022 17:49:15 -0800 Song Liu wrote:
> bpf_prog_pack causes build error with powerpc ppc64_defconfig:
> 
> kernel/bpf/core.c:830:23: error: variably modified 'bitmap' at file scope
>   830 |         unsigned long bitmap[BITS_TO_LONGS(BPF_PROG_CHUNK_COUNT)];
>       |                       ^~~~~~

No idea what this error means but...

> Fix it by turning bitmap into a 0-length array.
> 
> Fixes: 57631054fae6 ("bpf: Introduce bpf_prog_pack allocator")
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Signed-off-by: Song Liu <song@kernel.org>
> ---
>  kernel/bpf/core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index 42d96549a804..44623c9b5bb1 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
> @@ -827,7 +827,7 @@ int bpf_jit_add_poke_descriptor(struct bpf_prog *prog,
>  struct bpf_prog_pack {
>  	struct list_head list;
>  	void *ptr;
> -	unsigned long bitmap[BITS_TO_LONGS(BPF_PROG_CHUNK_COUNT)];
> +	unsigned long bitmap[];

This is really asking to be DECLARE_BITMAP(), does that fix the issue?

>  };
>  
>  #define BPF_PROG_MAX_PACK_PROG_SIZE	BPF_PROG_PACK_SIZE
> @@ -840,7 +840,7 @@ static struct bpf_prog_pack *alloc_new_pack(void)
>  {
>  	struct bpf_prog_pack *pack;
>  
> -	pack = kzalloc(sizeof(*pack), GFP_KERNEL);
> +	pack = kzalloc(sizeof(*pack) + BITS_TO_BYTES(BPF_PROG_CHUNK_COUNT), GFP_KERNEL);

Otherwise you may want to use struct_size(pack, bitmap, BITS...).
One of the bots will soon send us a patch to do that.

>  	if (!pack)
>  		return NULL;
>  	pack->ptr = module_alloc(BPF_PROG_PACK_SIZE);
Song Liu Feb. 12, 2022, 1:23 a.m. UTC | #2
> On Feb 11, 2022, at 3:54 PM, Jakub Kicinski <kuba@kernel.org> wrote:
> 
> On Thu, 10 Feb 2022 17:49:15 -0800 Song Liu wrote:
>> bpf_prog_pack causes build error with powerpc ppc64_defconfig:
>> 
>> kernel/bpf/core.c:830:23: error: variably modified 'bitmap' at file scope
>>  830 |         unsigned long bitmap[BITS_TO_LONGS(BPF_PROG_CHUNK_COUNT)];
>>      |                       ^~~~~~
> 
> No idea what this error means but...
v2 (which has applied to bpf-next) has more information about this. 
Basically, BPF_PROG_CHUNK_COUNT contains a global variable for ppc. 

> 
>> Fix it by turning bitmap into a 0-length array.
>> 
>> Fixes: 57631054fae6 ("bpf: Introduce bpf_prog_pack allocator")
>> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
>> Signed-off-by: Song Liu <song@kernel.org>
>> ---
>> kernel/bpf/core.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>> 
>> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
>> index 42d96549a804..44623c9b5bb1 100644
>> --- a/kernel/bpf/core.c
>> +++ b/kernel/bpf/core.c
>> @@ -827,7 +827,7 @@ int bpf_jit_add_poke_descriptor(struct bpf_prog *prog,
>> struct bpf_prog_pack {
>> 	struct list_head list;
>> 	void *ptr;
>> -	unsigned long bitmap[BITS_TO_LONGS(BPF_PROG_CHUNK_COUNT)];
>> +	unsigned long bitmap[];
> 
> This is really asking to be DECLARE_BITMAP(), does that fix the issue?

I am afraid DECLARE_BITMAP() will hit the same error here. 

> 
>> };
>> 
>> #define BPF_PROG_MAX_PACK_PROG_SIZE	BPF_PROG_PACK_SIZE
>> @@ -840,7 +840,7 @@ static struct bpf_prog_pack *alloc_new_pack(void)
>> {
>> 	struct bpf_prog_pack *pack;
>> 
>> -	pack = kzalloc(sizeof(*pack), GFP_KERNEL);
>> +	pack = kzalloc(sizeof(*pack) + BITS_TO_BYTES(BPF_PROG_CHUNK_COUNT), GFP_KERNEL);
> 
> Otherwise you may want to use struct_size(pack, bitmap, BITS...).
> One of the bots will soon send us a patch to do that.

Since v2 has applied to bpf-next, I will send another follow-up patch to
use struct_size, unless some bot get it first. 

Thanks,
Song
diff mbox series

Patch

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 42d96549a804..44623c9b5bb1 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -827,7 +827,7 @@  int bpf_jit_add_poke_descriptor(struct bpf_prog *prog,
 struct bpf_prog_pack {
 	struct list_head list;
 	void *ptr;
-	unsigned long bitmap[BITS_TO_LONGS(BPF_PROG_CHUNK_COUNT)];
+	unsigned long bitmap[];
 };
 
 #define BPF_PROG_MAX_PACK_PROG_SIZE	BPF_PROG_PACK_SIZE
@@ -840,7 +840,7 @@  static struct bpf_prog_pack *alloc_new_pack(void)
 {
 	struct bpf_prog_pack *pack;
 
-	pack = kzalloc(sizeof(*pack), GFP_KERNEL);
+	pack = kzalloc(sizeof(*pack) + BITS_TO_BYTES(BPF_PROG_CHUNK_COUNT), GFP_KERNEL);
 	if (!pack)
 		return NULL;
 	pack->ptr = module_alloc(BPF_PROG_PACK_SIZE);