Skip to content

Commit 7be4ce7

Browse files
mannkafaiKernel Patches Daemon
authored andcommitted
bpf: Allow fall back to interpreter for programs with stack size <= 512
OpenWRT users reported regression on ARMv6 devices after updating to latest HEAD, where tcpdump filter: tcpdump "not ether host 3c37121a2b3c and not ether host 184ecbca2a3a \ and not ether host 14130b4d3f47 and not ether host f0f61cf440b7 \ and not ether host a84b4dedf471 and not ether host d022be17e1d7 \ and not ether host 5c497967208b and not ether host 706655784d5b" fails with warning: "Kernel filter failed: No error information" when using config: # CONFIG_BPF_JIT_ALWAYS_ON is not set CONFIG_BPF_JIT_DEFAULT_ON=y The issue arises because commits: 1. "bpf: Fix array bounds error with may_goto" changed default runtime to __bpf_prog_ret0_warn when jit_requested = 1 2. "bpf: Avoid __bpf_prog_ret0_warn when jit fails" returns error when jit_requested = 1 but jit fails This change restores interpreter fallback capability for BPF programs with stack size <= 512 bytes when jit fails. Reported-by: Felix Fietkau <[email protected]> Closes: https://lore.kernel.org/bpf/[email protected]/ Fixes: 6ebc503 ("bpf: Fix array bounds error with may_goto") Signed-off-by: KaFai Wan <[email protected]>
1 parent e1e69b8 commit 7be4ce7

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

kernel/bpf/core.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,8 +2366,7 @@ static unsigned int __bpf_prog_ret0_warn(const void *ctx,
23662366
const struct bpf_insn *insn)
23672367
{
23682368
/* If this handler ever gets executed, then BPF_JIT_ALWAYS_ON
2369-
* is not working properly, or interpreter is being used when
2370-
* prog->jit_requested is not 0, so warn about it!
2369+
* is not working properly, so warn about it!
23712370
*/
23722371
WARN_ON_ONCE(1);
23732372
return 0;
@@ -2468,8 +2467,9 @@ static int bpf_check_tail_call(const struct bpf_prog *fp)
24682467
return ret;
24692468
}
24702469

2471-
static void bpf_prog_select_func(struct bpf_prog *fp)
2470+
static bool bpf_prog_select_interpreter(struct bpf_prog *fp)
24722471
{
2472+
bool select_interpreter = false;
24732473
#ifndef CONFIG_BPF_JIT_ALWAYS_ON
24742474
u32 stack_depth = max_t(u32, fp->aux->stack_depth, 1);
24752475
u32 idx = (round_up(stack_depth, 32) / 32) - 1;
@@ -2478,15 +2478,16 @@ static void bpf_prog_select_func(struct bpf_prog *fp)
24782478
* But for non-JITed programs, we don't need bpf_func, so no bounds
24792479
* check needed.
24802480
*/
2481-
if (!fp->jit_requested &&
2482-
!WARN_ON_ONCE(idx >= ARRAY_SIZE(interpreters))) {
2481+
if (idx < ARRAY_SIZE(interpreters)) {
24832482
fp->bpf_func = interpreters[idx];
2483+
select_interpreter = true;
24842484
} else {
24852485
fp->bpf_func = __bpf_prog_ret0_warn;
24862486
}
24872487
#else
24882488
fp->bpf_func = __bpf_prog_ret0_warn;
24892489
#endif
2490+
return select_interpreter;
24902491
}
24912492

24922493
/**
@@ -2505,7 +2506,7 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err)
25052506
/* In case of BPF to BPF calls, verifier did all the prep
25062507
* work with regards to JITing, etc.
25072508
*/
2508-
bool jit_needed = fp->jit_requested;
2509+
bool jit_needed = false;
25092510

25102511
if (fp->bpf_func)
25112512
goto finalize;
@@ -2514,7 +2515,8 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err)
25142515
bpf_prog_has_kfunc_call(fp))
25152516
jit_needed = true;
25162517

2517-
bpf_prog_select_func(fp);
2518+
if (!bpf_prog_select_interpreter(fp))
2519+
jit_needed = true;
25182520

25192521
/* eBPF JITs can rewrite the program in case constant
25202522
* blinding is active. However, in case of error during

0 commit comments

Comments
 (0)