s390/bpf: Use kvcalloc for addrs array
authorIlya Leoshkevich <iii@linux.ibm.com>
Thu, 7 Nov 2019 14:18:38 +0000 (15:18 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 31 Dec 2019 15:45:06 +0000 (16:45 +0100)
[ Upstream commit 166f11d11f6f70439830d09bfa5552ec1b368494 ]

A BPF program may consist of 1m instructions, which means JIT
instruction-address mapping can be as large as 4m. s390 has
FORCE_MAX_ZONEORDER=9 (for memory hotplug reasons), which means maximum
kmalloc size is 1m. This makes it impossible to JIT programs with more
than 256k instructions.

Fix by using kvcalloc, which falls back to vmalloc for larger
allocations. An alternative would be to use a radix tree, but that is
not supported by bpf_prog_fill_jited_linfo.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20191107141838.92202-1-iii@linux.ibm.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/s390/net/bpf_jit_comp.c

index ce88211b9c6cdda55164f82ef00327a98ba11b6d..c8c16b5eed6be180623589a64261ab945bc1c20d 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/filter.h>
 #include <linux/init.h>
 #include <linux/bpf.h>
+#include <linux/mm.h>
 #include <asm/cacheflush.h>
 #include <asm/dis.h>
 #include <asm/facility.h>
@@ -1369,7 +1370,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
        }
 
        memset(&jit, 0, sizeof(jit));
-       jit.addrs = kcalloc(fp->len + 1, sizeof(*jit.addrs), GFP_KERNEL);
+       jit.addrs = kvcalloc(fp->len + 1, sizeof(*jit.addrs), GFP_KERNEL);
        if (jit.addrs == NULL) {
                fp = orig_fp;
                goto out;
@@ -1422,7 +1423,7 @@ skip_init_ctx:
        if (!fp->is_func || extra_pass) {
                bpf_prog_fill_jited_linfo(fp, jit.addrs + 1);
 free_addrs:
-               kfree(jit.addrs);
+               kvfree(jit.addrs);
                kfree(jit_data);
                fp->aux->jit_data = NULL;
        }