Fix up bpf_jit_limit some more
Subsystems (9)
v3 cover Fix up bpf_jit_limit some more
Fix some inconsistencies of bpf_jit_limit on non-x86 platforms. I've dropped exposing bpf_jit_current since we couldn't agree on file modes, correct names, etc.
Lorenz Bauer (3):
bpf: define bpf_jit_alloc_exec_limit for riscv JIT
bpf: define bpf_jit_alloc_exec_limit for arm64 JIT
bpf: prevent increasing bpf_jit_limit above max
arch/arm64/net/bpf_jit_comp.c | 5 +++++ arch/riscv/net/bpf_jit_core.c | 5 +++++ include/linux/filter.h | 1 + kernel/bpf/core.c | 4 +++- net/core/sysctl_net_core.c | 2 +- 5 files changed, 15 insertions(+), 2 deletions(-)
Signature · 1 line
2.30.2
PATCH v3 1/3 bpf: define bpf_jit_alloc_exec_limit for riscv JIT
Expose the maximum amount of useable memory from the riscv JIT.
--- arch/riscv/net/bpf_jit_core.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/riscv/net/bpf_jit_core.c +5 -0
@@ -166,6 +166,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)return prog; } +u64 bpf_jit_alloc_exec_limit (void ) +{ +return BPF_JIT_REGION_SIZE ; +} +void *bpf_jit_alloc_exec (unsigned long size) { return __vmalloc_node_range(size, PAGE_SIZE, BPF_JIT_REGION_START,
Signature · 1 line
2.30.2
Re: [PATCH v3 1/3] bpf: define bpf_jit_alloc_exec_limit for riscv JIT
Quoted 5 lines · Lorenz Bauer
Expose the maximum amount of useable memory from the riscv JIT.
Signed-off-by Lorenz Bauer <[email protected]>Acked-by Luke Nelson <[email protected]>
Quoted 23 lines
--- arch/riscv/net/bpf_jit_core.c | 5 +++++ 1 file changed, 5 insertions(+)arch/riscv/net/bpf_jit_core.c +5
-1@@ -166,6 +166,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)return prog; } +u64 bpf_jit_alloc_exec_limit (void ) +{ +return BPF_JIT_REGION_SIZE ; +} +void *bpf_jit_alloc_exec (unsigned long size) { return __vmalloc_node_range(size, PAGE_SIZE, BPF_JIT_REGION_START, --2.30.2
PATCH v3 2/3 bpf: define bpf_jit_alloc_exec_limit for arm64 JIT
In reply to Lorenz BauerExpose the maximum amount of useable memory from the arm64 JIT.
--- arch/arm64/net/bpf_jit_comp.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm64/net/bpf_jit_comp.c +5 -0
@@ -1136,6 +1136,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)return prog; } +u64 bpf_jit_alloc_exec_limit (void ) +{ +return BPF_JIT_REGION_SIZE ; +} +void *bpf_jit_alloc_exec (unsigned long size) { return __vmalloc_node_range(size, PAGE_SIZE, BPF_JIT_REGION_START,
Signature · 1 line
2.30.2
PATCH v3 3/3 bpf: prevent increasing bpf_jit_limit above max
In reply to Lorenz BauerRestrict bpf_jit_limit to the maximum supported by the arch's JIT.
--- include/linux/filter.h | 1 + kernel/bpf/core.c | 4 +++- net/core/sysctl_net_core.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-)
include/linux/filter.h +1 -0
@@ -1050,6 +1050,7 @@ extern int bpf_jit_enable;extern int bpf_jit_harden;extern int bpf_jit_kallsyms;extern long bpf_jit_limit; +extern long bpf_jit_limit_max;typedef void (*bpf_jit_fill_hole_t )(void *area,unsigned int size);
kernel/bpf/core.c +3 -1
@@ -525,6 +525,7 @@ int bpf_jit_enable __read_mostly = IS_BUILTIN(CONFIG_BPF_JIT_DEFAULT_ON);int bpf_jit_kallsyms__read_mostly =IS_BUILTIN (CONFIG_BPF_JIT_DEFAULT_ON );int bpf_jit_harden__read_mostly ;long bpf_jit_limit__read_mostly ; +long bpf_jit_limit_max__read_mostly ;static void bpf_prog_ksym_set_addr (struct bpf_prog *prog)
@@ -818,7 +819,8 @@ u64 __weak bpf_jit_alloc_exec_limit(void)static int __init bpf_jit_charge_init (void ) {/* Only used as heuristic here to derive limit. */ - bpf_jit_limit =min_t (u64,round_up (bpf_jit_alloc_exec_limit () >>2 , + bpf_jit_limit_max =bpf_jit_alloc_exec_limit (); + bpf_jit_limit =min_t (u64,round_up (bpf_jit_limit_max >>2 ,PAGE_SIZE ),LONG_MAX );return 0 ; }
net/core/sysctl_net_core.c +1 -1
@@ -419,7 +419,7 @@ static struct ctl_table net_core_table[] = { .mode = 0600, .proc_handler = proc_dolongvec_minmax_bpf_restricted, .extra1 = &long_one, - .extra2 = &long_max, + .extra2 = &bpf_jit_limit_max, },#endif {
Signature · 1 line
2.30.2
Alexei Starovoitov
AppliedQuoted 4 lines · Lorenz Bauer
Fix some inconsistencies of
bpf_jit_limiton non-x86 platforms. I've dropped exposingbpf_jit_currentsince we couldn't agree on file modes, correct names, etc.
Applied to bpf tree. Seems more appropriate there.