Skip to content

Commit b89ddf4

Browse files
rmk92borkmann
authored andcommitted
arm64/bpf: Remove 128MB limit for BPF JIT programs
Commit 91fc957 ("arm64/bpf: don't allocate BPF JIT programs in module memory") restricts BPF JIT program allocation to a 128MB region to ensure BPF programs are still in branching range of each other. However this restriction should not apply to the aarch64 JIT, since BPF_JMP | BPF_CALL are implemented as a 64-bit move into a register and then a BLR instruction - which has the effect of being able to call anything without proximity limitation. The practical reason to relax this restriction on JIT memory is that 128MB of JIT memory can be quickly exhausted, especially where PAGE_SIZE is 64KB - one page is needed per program. In cases where seccomp filters are applied to multiple VMs on VM launch - such filters are classic BPF but converted to BPF - this can severely limit the number of VMs that can be launched. In a world where we support BPF JIT always on, turning off the JIT isn't always an option either. Fixes: 91fc957 ("arm64/bpf: don't allocate BPF JIT programs in module memory") Suggested-by: Ard Biesheuvel <[email protected]> Signed-off-by: Russell King <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Tested-by: Alan Maguire <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 0cc78dc commit b89ddf4

File tree

5 files changed

+4
-21
lines changed

5 files changed

+4
-21
lines changed

arch/arm64/include/asm/extable.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,6 @@ do { \
3333
(b)->data = (tmp).data; \
3434
} while (0)
3535

36-
static inline bool in_bpf_jit(struct pt_regs *regs)
37-
{
38-
if (!IS_ENABLED(CONFIG_BPF_JIT))
39-
return false;
40-
41-
return regs->pc >= BPF_JIT_REGION_START &&
42-
regs->pc < BPF_JIT_REGION_END;
43-
}
44-
4536
#ifdef CONFIG_BPF_JIT
4637
bool ex_handler_bpf(const struct exception_table_entry *ex,
4738
struct pt_regs *regs);

arch/arm64/include/asm/memory.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,8 @@
4444
#define _PAGE_OFFSET(va) (-(UL(1) << (va)))
4545
#define PAGE_OFFSET (_PAGE_OFFSET(VA_BITS))
4646
#define KIMAGE_VADDR (MODULES_END)
47-
#define BPF_JIT_REGION_START (_PAGE_END(VA_BITS_MIN))
48-
#define BPF_JIT_REGION_SIZE (SZ_128M)
49-
#define BPF_JIT_REGION_END (BPF_JIT_REGION_START + BPF_JIT_REGION_SIZE)
5047
#define MODULES_END (MODULES_VADDR + MODULES_VSIZE)
51-
#define MODULES_VADDR (BPF_JIT_REGION_END)
48+
#define MODULES_VADDR (_PAGE_END(VA_BITS_MIN))
5249
#define MODULES_VSIZE (SZ_128M)
5350
#define VMEMMAP_START (-(UL(1) << (VA_BITS - VMEMMAP_SHIFT)))
5451
#define VMEMMAP_END (VMEMMAP_START + VMEMMAP_SIZE)

arch/arm64/kernel/traps.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ static struct break_hook bug_break_hook = {
994994
static int reserved_fault_handler(struct pt_regs *regs, unsigned int esr)
995995
{
996996
pr_err("%s generated an invalid instruction at %pS!\n",
997-
in_bpf_jit(regs) ? "BPF JIT" : "Kernel text patching",
997+
"Kernel text patching",
998998
(void *)instruction_pointer(regs));
999999

10001000
/* We cannot handle this */

arch/arm64/mm/ptdump.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ static struct addr_marker address_markers[] = {
4141
{ 0 /* KASAN_SHADOW_START */, "Kasan shadow start" },
4242
{ KASAN_SHADOW_END, "Kasan shadow end" },
4343
#endif
44-
{ BPF_JIT_REGION_START, "BPF start" },
45-
{ BPF_JIT_REGION_END, "BPF end" },
4644
{ MODULES_VADDR, "Modules start" },
4745
{ MODULES_END, "Modules end" },
4846
{ VMALLOC_START, "vmalloc() area" },

arch/arm64/net/bpf_jit_comp.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,15 +1141,12 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
11411141

11421142
u64 bpf_jit_alloc_exec_limit(void)
11431143
{
1144-
return BPF_JIT_REGION_SIZE;
1144+
return VMALLOC_END - VMALLOC_START;
11451145
}
11461146

11471147
void *bpf_jit_alloc_exec(unsigned long size)
11481148
{
1149-
return __vmalloc_node_range(size, PAGE_SIZE, BPF_JIT_REGION_START,
1150-
BPF_JIT_REGION_END, GFP_KERNEL,
1151-
PAGE_KERNEL, 0, NUMA_NO_NODE,
1152-
__builtin_return_address(0));
1149+
return vmalloc(size);
11531150
}
11541151

11551152
void bpf_jit_free_exec(void *addr)

0 commit comments

Comments
 (0)