Skip to contentSkip to conversation

bpf: fix bpf_prog_pack build for ppc64_defconfig

PATCH Superseded Song Liu 3 participants 3 messages Feb 11, 2022 – Feb 12, 2022

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Song Liu

author reviewer
#0 lore raw

PATCH 1/1 bpf: fix bpf_prog_pack build for ppc64_defconfig

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")
---
 kernel/bpf/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/bpf/core.c +2 -2
index 42d96549a804..44623c9b5bb1 100644
@@ -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);
Signature · 1 line
2.30.2
maintainer
#1 lore raw
Quoted 5 lines · 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...

Quoted 14 lines

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

Fixes 57631054fae6 ("bpf: Introduce bpf_prog_pack allocator")
---
 kernel/bpf/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/bpf/core.c +0 -0
index 42d96549a804..44623c9b5bb1 100644

kernel/bpf/core.c int bpf_jit_add_poke_descriptor(struct bpf_prog *prog, · line 830

Quoted 5 lines
kernel/bpf/core.c +1 -1
@@ -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?

kernel/bpf/core.c static struct bpf_prog_pack *alloc_new_pack(void) · line 843

Quoted 9 lines
kernel/bpf/core.c +1 -1
 };
 
 #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.

Quoted 3 lines
kernel/bpf/core.c +0 -0
 	if (!pack)
 		return NULL;
 	pack->ptr = module_alloc(BPF_PROG_PACK_SIZE);
#2 lore raw
Quoted 12 lines · Jakub Kicinski
Quoted 5 lines · 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.

Quoted 10 lines
Quoted 10 lines

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

Fixes 57631054fae6 ("bpf: Introduce bpf_prog_pack allocator")

---
kernel/bpf/core.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 12 lines

kernel/bpf/core.c int bpf_jit_add_poke_descriptor(struct bpf_prog *prog, · line 830

Quoted 10 lines
kernel/bpf/core.c +1 -1
index 42d96549a804..44623c9b5bb1 100644
@@ -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.

Quoted 8 lines
Quoted 8 lines
kernel/bpf/core.c +0 -0
 };
 
 #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;
 
Quoted 5 lines

kernel/bpf/core.c static struct bpf_prog_pack *alloc_new_pack(void) · line 843

Quoted 2 lines
kernel/bpf/core.c +1 -1
-	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