Skip to content

Commit 22a1279

Browse files
author
Alexei Starovoitov
committed
Merge branch 'Fix up bpf_jit_limit some more'
Lorenz Bauer says: ==================== 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. ==================== Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2 parents 4225fea + fadb7ff commit 22a1279

5 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎arch/arm64/net/bpf_jit_comp.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
11361136
return prog;
11371137
}
11381138

1139+
u64 bpf_jit_alloc_exec_limit(void)
1140+
{
1141+
return BPF_JIT_REGION_SIZE;
1142+
}
1143+
11391144
void *bpf_jit_alloc_exec(unsigned long size)
11401145
{
11411146
return __vmalloc_node_range(size, PAGE_SIZE, BPF_JIT_REGION_START,

‎arch/riscv/net/bpf_jit_core.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
166166
return prog;
167167
}
168168

169+
u64 bpf_jit_alloc_exec_limit(void)
170+
{
171+
return BPF_JIT_REGION_SIZE;
172+
}
173+
169174
void *bpf_jit_alloc_exec(unsigned long size)
170175
{
171176
return __vmalloc_node_range(size, PAGE_SIZE, BPF_JIT_REGION_START,

‎include/linux/filter.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,7 @@ extern int bpf_jit_enable;
10511051
extern int bpf_jit_harden;
10521052
extern int bpf_jit_kallsyms;
10531053
extern long bpf_jit_limit;
1054+
extern long bpf_jit_limit_max;
10541055

10551056
typedef void (*bpf_jit_fill_hole_t)(void *area, unsigned int size);
10561057

‎kernel/bpf/core.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ int bpf_jit_enable __read_mostly = IS_BUILTIN(CONFIG_BPF_JIT_DEFAULT_ON);
524524
int bpf_jit_kallsyms __read_mostly = IS_BUILTIN(CONFIG_BPF_JIT_DEFAULT_ON);
525525
int bpf_jit_harden __read_mostly;
526526
long bpf_jit_limit __read_mostly;
527+
long bpf_jit_limit_max __read_mostly;
527528

528529
static void
529530
bpf_prog_ksym_set_addr(struct bpf_prog *prog)
@@ -817,7 +818,8 @@ u64 __weak bpf_jit_alloc_exec_limit(void)
817818
static int __init bpf_jit_charge_init(void)
818819
{
819820
/* Only used as heuristic here to derive limit. */
820-
bpf_jit_limit = min_t(u64, round_up(bpf_jit_alloc_exec_limit() >> 2,
821+
bpf_jit_limit_max = bpf_jit_alloc_exec_limit();
822+
bpf_jit_limit = min_t(u64, round_up(bpf_jit_limit_max >> 2,
821823
PAGE_SIZE), LONG_MAX);
822824
return 0;
823825
}

‎net/core/sysctl_net_core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ static struct ctl_table net_core_table[] = {
419419
.mode = 0600,
420420
.proc_handler = proc_dolongvec_minmax_bpf_restricted,
421421
.extra1 = &long_one,
422-
.extra2 = &long_max,
422+
.extra2 = &bpf_jit_limit_max,
423423
},
424424
#endif
425425
{

0 commit comments

Comments
 (0)