bpf: Allow fall back to interpreter for programs with stack size <= 512
PATCH 1/1 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 -i mon1 \
"not wlan addr3 3c37121a2b3c and not wlan addr2 184ecbca2a3a \
and not wlan addr2 14130b4d3f47 and not wlan addr2 f0f61cf440b7 \
and not wlan addr3 a84b4dedf471 and not wlan addr3 d022be17e1d7 \
and not wlan addr3 5c497967208b and not wlan addr2 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.
--- kernel/bpf/core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
kernel/bpf/core.c +7 -5
@@ -2366,8 +2366,8 @@ static unsigned int __bpf_prog_ret0_warn(const void *ctx, const struct bpf_insn *insn) {/* If this handler ever gets executed, then BPF_JIT_ALWAYS_ON -* is not working properly, or interpreter is being used when -* prog->jit_requested is not 0, so warn about it! +* or may_goto may cause stack size > 512 is not working properly, +* so warn about it! */ WARN_ON_ONCE (1 );return 0 ;
@@ -2478,10 +2478,10 @@ static void bpf_prog_select_func(struct bpf_prog *fp)* But for non-JITed programs, we don't need bpf_func, so no bounds * check needed. */ -if (!fp->jit_requested && - !WARN_ON_ONCE (idx >=ARRAY_SIZE (interpreters))) { +if (idx <ARRAY_SIZE (interpreters)) { fp->bpf_func = interpreters[idx]; }else { +WARN_ON_ONCE (!fp->jit_requested); fp->bpf_func = __bpf_prog_ret0_warn; }#else
@@ -2505,7 +2505,7 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err)/* In case of BPF to BPF calls, verifier did all the prep * work with regards to JITing, etc. */ -bool jit_needed = fp->jit_requested; +bool jit_needed = false;if (fp->bpf_func) goto finalize;
@@ -2515,6 +2515,8 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err) jit_needed = true;bpf_prog_select_func (fp); +if (fp->bpf_func == __bpf_prog_ret0_warn) + jit_needed = true;/* eBPF JITs can rewrite the program in case constant * blinding is active. However, in case of error during
Signature · 1 line
2.43.0
Yonghong Song
reviewerQuoted 49 lines · KaFai Wan
OpenWRT users reported regression on ARMv6 devices after updating to latest HEAD, where tcpdump filter:
tcpdump -i mon1 \
"not wlan addr33c37121a2b3cand not wlan addr2184ecbca2a3a\
and not wlan addr214130b4d3f47and not wlan addr2f0f61cf440b7\
and not wlan addr3a84b4dedf471and not wlan addr3d022be17e1d7\
and not wlan addr35c497967208band not wlan addr2706655784d5b"fails with warning: "Kernel filter failed: No error information" when using config:
#CONFIG_BPF_JIT_ALWAYS_ONis not setCONFIG_BPF_JIT_DEFAULT_ON=yThe issue arises because commits:
1. "bpf: Fix array bounds error withmay_goto" changed default runtime to__bpf_prog_ret0_warnwhenjit_requested= 1
2. "bpf: Avoid__bpf_prog_ret0_warnwhen jit fails" returns error whenjit_requested= 1 but jit failsThis change restores interpreter fallback capability for BPF programs with stack size <= 512 bytes when jit fails.
Reported-by Felix Fietkau <[email protected]>Fixes 6ebc5030e0c5 ("bpf: Fix array bounds error with may_goto")Fixes 86bc9c742426 ("bpf: Avoid __bpf_prog_ret0_warn when jit fails")Signed-off-by KaFai Wan <[email protected]>--- kernel/bpf/core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)kernel/bpf/core.c +2
-2@@ -2366,8 +2366,8 @@ static unsigned int __bpf_prog_ret0_warn(const void *ctx, const struct bpf_insn *insn) {/* If this handler ever gets executed, then BPF_JIT_ALWAYS_ON -* is not working properly, or interpreter is being used when -* prog->jit_requested is not 0, so warn about it! +* or may_goto may cause stack size > 512 is not working properly, +* so warn about it! */ WARN_ON_ONCE (1 );return 0 ;@@ -2478,10 +2478,10 @@ static void bpf_prog_select_func(struct bpf_prog *fp)* But for non-JITed programs, we don't need bpf_func, so no bounds
kernel/bpf/core.c static void bpf_prog_select_func(struct bpf_prog *fp) · line 2486
Quoted 10 lines
kernel/bpf/core.c +2
-2* check needed. */ -if (!fp->jit_requested && - !WARN_ON_ONCE (idx >=ARRAY_SIZE (interpreters))) { +if (idx <ARRAY_SIZE (interpreters)) { fp->bpf_func = interpreters[idx]; }else { +WARN_ON_ONCE (!fp->jit_requested); fp->bpf_func = __bpf_prog_ret0_warn; }
Your logic here is to do interpreter even if fp->jit_requested is true. This is different from the current implementation.
Also see below code:
static unsigned int __bpf_prog_ret0_warn(const void *ctx,
const struct bpf_insn *insn)
{
/* If this handler ever gets executed, then BPF_JIT_ALWAYS_ON
* is not working properly, or interpreter is being used when
* prog->jit_requested is not 0, so warn about it!
*/
WARN_ON_ONCE(1);
return 0;
}It mentions to warn if the interpreter is being used when prog->jit_requested is not 0.
So if prog->jit_requested is not 0, it is expected not to use interpreter.
Quoted 19 lines
kernel/bpf/core.c +3
-1#else @@ -2505,7 +2505,7 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err)/* In case of BPF to BPF calls, verifier did all the prep * work with regards to JITing, etc. */ -bool jit_needed = fp->jit_requested; +bool jit_needed = false;if (fp->bpf_func) goto finalize;@@ -2515,6 +2515,8 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err) jit_needed = true;bpf_prog_select_func (fp); +if (fp->bpf_func == __bpf_prog_ret0_warn) + jit_needed = true;/* eBPF JITs can rewrite the program in case constant * blinding is active. However, in case of error during
Quoted 97 lines · Yonghong Song
Quoted 70 lines · KaFai Wan
OpenWRT users reported regression on ARMv6 devices after updating to latest
HEAD, where tcpdump filter:tcpdump -i mon1 \
"not wlan addr33c37121a2b3cand not wlan addr2184ecbca2a3a\
and not wlan addr214130b4d3f47and not wlan addr2f0f61cf440b7\
and not wlan addr3a84b4dedf471and not wlan addr3d022be17e1d7\
and not wlan addr35c497967208band not wlan addr2706655784d5b"fails with warning: "Kernel filter failed: No error information" when using config:
#CONFIG_BPF_JIT_ALWAYS_ONis not setCONFIG_BPF_JIT_DEFAULT_ON=yThe issue arises because commits:
1. "bpf: Fix array bounds error withmay_goto" changed default runtime to
__bpf_prog_ret0_warnwhenjit_requested= 1
2. "bpf: Avoid__bpf_prog_ret0_warnwhen jit fails" returns error when
jit_requested= 1 but jit failsThis 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 6ebc5030e0c5 ("bpf: Fix array bounds error with may_goto")Fixes 86bc9c742426 ("bpf: Avoid __bpf_prog_ret0_warn when jitfails")
Signed-off-by KaFai Wan <[email protected]>---
kernel/bpf/core.c| 12 +++++++-----1 file changed, 7 insertions(+), 5 deletions(-)kernel/bpf/core.c +0
-0@@ -2366,8 +2366,8 @@ static unsigned int __bpf_prog_ret0_warn(const void *ctx,const struct
bpf_insn*insn)
{
/* If this handler ever gets executed, thenBPF_JIT_ALWAYS_ONkernel/bpf/core.c +0
-1-* is not working properly, or interpreter is being used when
kernel/bpf/core.c +1
-1-* prog->jit_requested is not 0, so warn about it! +* or may_goto may cause stack size > 512 is not working properly,
kernel/bpf/core.c +1
-0+* so warn about it! */
WARN_ON_ONCE(1);
return 0;kernel/bpf/core.c +0
-0@@ -2478,10 +2478,10 @@ static void bpf_prog_select_func(struct bpf_prog *fp) * But for non-JITed programs, we don't need bpf_func, sono bounds
* check needed.
*/kernel/bpf/core.c +1
-2-if (!fp->jit_requested && - !WARN_ON_ONCE(idx >= ARRAY_SIZE(interpreters))) { +if (idx <ARRAY_SIZE (interpreters)) {
fp->bpf_func= interpreters[idx];
} else {kernel/bpf/core.c +1
-0+WARN_ON_ONCE (!fp->jit_requested);Quoted 2 lines
fp->bpf_func=__bpf_prog_ret0_warn; }Your logic here is to do interpreter even if
fp->jit_requestedis true.
This is different from the current implementation.Also see below code:
static unsigned int
__bpf_prog_ret0_warn(const void *ctx, const struct bpf_insn *insn)
{
/* If this handler ever gets executed, thenBPF_JIT_ALWAYS_ON
* is not working properly, or interpreter is being used when
*prog->jit_requestedis not 0, so warn about it! */
WARN_ON_ONCE(1);
return 0;
}
Quoted 6 lines
It mentions to warn if the interpreter is being used when
prog->jit_requestedis not 0.So if
prog->jit_requestedis not 0, it is expected not to use interpreter.
The commit 6ebc5030e0c5 ("bpf: Fix array bounds error with may_goto")
[1] this patch fix change the code to that, before this commit it was:
static unsigned int __bpf_prog_ret0_warn(const void *ctx,
const struct bpf_insn *insn)
{
/* If this handler ever gets executed, then BPF_JIT_ALWAYS_ON
* is not working properly, so warn about it!
*/
WARN_ON_ONCE(1);
return 0;
}And
static void bpf_prog_select_func(struct bpf_prog *fp) {
#ifndef CONFIG_BPF_JIT_ALWAYS_ON u32 stack_depth = max_t(u32, fp->aux->stack_depth, 1); fp->bpf_func = interpreters[(round_up(stack_depth, 32) / 32) - 1]; #else fp->bpf_func = __bpf_prog_ret0_warn;
#endif
}
so it can fall back to the interpreter when jit fails. And this fit the intent of bpf_prog_select_runtime(), see comment:
/**
* bpf_prog_select_runtime - select exec runtime for BPF program
* @fp: bpf_prog populated with BPF program
* @err: pointer to error variable
*
* Try to JIT eBPF program, if JIT is not available, use interpreter.
* The BPF program will be executed via bpf_prog_run() function. *
* Return: the &fp argument along with &err set to 0 for success or
* a negative errno code on failure
*/
struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err)
And this:
bpf_prog_select_func(fp);
/* eBPF JITs can rewrite the program in case constant
* blinding is active. However, in case of error during
* blinding, bpf_int_jit_compile() must always return a
* valid program, which in this case would simply not
* be JITed, but falls back to the interpreter.
*/
if (!bpf_prog_is_offloaded(fp->aux)) {The commit [1] mismatch the intent of bpf_prog_select_runtime(), so it should be fixed.
[1] https://lore.kernel.org/all/[email protected]/
Quoted 23 lines
Quoted 22 lines
#else
kernel/bpf/core.c +1
-1@@ -2505,7 +2505,7 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err) /* In case of BPF to BPF calls, verifier did all the prep* work with regards to JITing, etc. */ -bool jit_needed = fp->jit_requested; +bool jit_needed = false;
if (fp->bpf_func)
goto finalize;kernel/bpf/core.c +0
-0@@ -2515,6 +2515,8 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err) jit_needed = true;
bpf_prog_select_func(fp);kernel/bpf/core.c +2
-0+if (fp->bpf_func == __bpf_prog_ret0_warn) + jit_needed = true;
/* eBPF JITs can rewrite the program in case constant
* blinding is active. However, in case of error during
Signature · 2 lines
Thanks, KaFai
Yonghong Song
reviewerQuoted 159 lines · KaFai Wan
Quoted 95 lines · Yonghong Song
Quoted 64 lines · KaFai Wan
OpenWRT users reported regression on ARMv6 devices after updating to latest
HEAD, where tcpdump filter:tcpdump -i mon1 \
"not wlan addr33c37121a2b3cand not wlan addr2184ecbca2a3a\
and not wlan addr214130b4d3f47and not wlan addr2f0f61cf440b7\
and not wlan addr3a84b4dedf471and not wlan addr3d022be17e1d7\
and not wlan addr35c497967208band not wlan addr2706655784d5b"fails with warning: "Kernel filter failed: No error information" when using config:
#CONFIG_BPF_JIT_ALWAYS_ONis not setCONFIG_BPF_JIT_DEFAULT_ON=yThe issue arises because commits:
1. "bpf: Fix array bounds error withmay_goto" changed default runtime to
__bpf_prog_ret0_warnwhenjit_requested= 1
2. "bpf: Avoid__bpf_prog_ret0_warnwhen jit fails" returns error when
jit_requested= 1 but jit failsThis 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 6ebc5030e0c5 ("bpf: Fix array bounds error with may_goto")Fixes 86bc9c742426 ("bpf: Avoid __bpf_prog_ret0_warn when jitfails")
Signed-off-by KaFai Wan <[email protected]>--- kernel/bpf/core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)kernel/bpf/core.c +0
-0@@ -2366,8 +2366,8 @@ static unsigned int __bpf_prog_ret0_warn(const void *ctx, const struct bpf_insn *insn) { /* If this handler ever gets executed, then
BPF_JIT_ALWAYS_ONkernel/bpf/core.c +0
-1-* is not working properly, or interpreter is being used when
kernel/bpf/core.c +1
-1-* prog->jit_requested is not 0, so warn about it! +* or may_goto may cause stack size > 512 is not working properly,
kernel/bpf/core.c +1
-0+* so warn about it! */ WARN_ON_ONCE(1); return 0;@@ -2478,10 +2478,10 @@ static void bpf_prog_select_func(struct bpf_prog *fp) * But for non-JITed programs, we don't need bpf_func, sono bounds
* check needed.
*/kernel/bpf/core.c static void bpf_prog_select_func(struct bpf_prog *fp) · line 2486
Quoted 8 lines
kernel/bpf/core.c +2
-2-if (!fp->jit_requested && - !WARN_ON_ONCE(idx >= ARRAY_SIZE(interpreters))) { +if (idx <ARRAY_SIZE (interpreters)) { fp->bpf_func = interpreters[idx]; } else { +WARN_ON_ONCE (!fp->jit_requested); fp->bpf_func = __bpf_prog_ret0_warn; }Your logic here is to do interpreter even if
fp->jit_requestedis true.
This is different from the current implementation.Also see below code:
static unsigned int __bpf_prog_ret0_warn(const void *ctx,
const structbpf_insn
*insn)
{
/* If this handler ever gets executed, thenBPF_JIT_ALWAYS_ON
* is not working properly, or interpreter is being used
when
*prog->jit_requestedis not 0, so warn about it! */
WARN_ON_ONCE(1);
return 0;
}Quoted 6 lines
It mentions to warn if the interpreter is being used when
prog->jit_requestedis not 0.So if
prog->jit_requestedis not 0, it is expected not to use interpreter.The commit
6ebc5030e0c5("bpf: Fix array bounds error withmay_goto")
[1] this patch fix change the code to that, before this commit it was:static unsigned int __bpf_prog_ret0_warn(const void *ctx,
const structbpf_insn*insn){ /* If this handler ever gets executed, then BPF_JIT_ALWAYS_ON * is not working properly, so warn about it! */ WARN_ON_ONCE(1); return 0; }And
static void
bpf_prog_select_func(struct bpf_prog *fp){#ifndef CONFIG_BPF_JIT_ALWAYS_ON u32 stack_depth = max_t(u32, fp->aux->stack_depth, 1); fp->bpf_func = interpreters[(round_up(stack_depth, 32) / 32) - 1]; #else fp->bpf_func = __bpf_prog_ret0_warn;#endif
}so it can fall back to the interpreter when jit fails. And this fit the intent of
bpf_prog_select_runtime(), see comment:/**
*bpf_prog_select_runtime- select exec runtime for BPF program
* @fp:bpf_progpopulated with BPF program
* @err: pointer to error variable
*
* Try to JIT eBPF program, if JIT is not available, use interpreter.
* The BPF program will be executed viabpf_prog_run()function. *
* Return: the &fp argument along with &err set to 0 for success or
* a negative errno code on failure
*/
structbpf_prog*bpf_prog_select_runtime(structbpf_prog*fp, int *err)And this:
bpf_prog_select_func(fp); /* eBPF JITs can rewrite the program in case constant * blinding is active. However, in case of error during * blinding, bpf_int_jit_compile() must always return a * valid program, which in this case would simply not * be JITed, but falls back to the interpreter. */ if (!bpf_prog_is_offloaded(fp->aux)) {
Quoted 5 lines
The commit [1] mismatch the intent of
bpf_prog_select_runtime(), so it should be fixed.
Okay, indeed the above [1] changed the behavior. Maybe Alexei can comment whether we should restore to the behavior before [1].
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
#else
kernel/bpf/core.c +1
-1@@ -2505,7 +2505,7 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err) /* In case of BPF to BPF calls, verifier did all the prep* work with regards to JITing, etc. */ -bool jit_needed = fp->jit_requested; +bool jit_needed = false; if (fp->bpf_func)goto finalize;
kernel/bpf/core.c +2
-0@@ -2515,6 +2515,8 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err) jit_needed = true; bpf_prog_select_func(fp); +if (fp->bpf_func == __bpf_prog_ret0_warn) + jit_needed = true; /* eBPF JITs can rewrite the program in case constant* blinding is active. However, in case of error during
Quoted 21 lines · KaFai Wan
OpenWRT users reported regression on ARMv6 devices after updating to latest HEAD, where tcpdump filter:
tcpdump -i mon1 \
"not wlan addr33c37121a2b3cand not wlan addr2184ecbca2a3a\
and not wlan addr214130b4d3f47and not wlan addr2f0f61cf440b7\
and not wlan addr3a84b4dedf471and not wlan addr3d022be17e1d7\
and not wlan addr35c497967208band not wlan addr2706655784d5b"fails with warning: "Kernel filter failed: No error information" when using config:
#CONFIG_BPF_JIT_ALWAYS_ONis not setCONFIG_BPF_JIT_DEFAULT_ON=yThe issue arises because commits:
1. "bpf: Fix array bounds error withmay_goto" changed default runtime to__bpf_prog_ret0_warnwhenjit_requested= 1
2. "bpf: Avoid__bpf_prog_ret0_warnwhen jit fails" returns error whenjit_requested= 1 but jit fails
Quoted 6 lines
This change restores interpreter fallback capability for BPF programs with stack size <= 512 bytes when jit fails.
Reported-by Felix Fietkau <[email protected]>Fixes 6ebc5030e0c5 ("bpf: Fix array bounds error with may_goto")
This commit looks fine.
Quoted 1 line
Fixes 86bc9c742426 ("bpf: Avoid __bpf_prog_ret0_warn when jit fails")
But this one is indeed problematic.
But before we revert, please provide a selftest that is causing valid classic bpf prog to fail JITing on arm,
because it has to be fixed as well.
Sounds like OpenWRT was suffering performance loss due to the interpreter.
Quoted 10 lines
Signed-off-by KaFai Wan <[email protected]>--- kernel/bpf/core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)kernel/bpf/core.c +0
-0
kernel/bpf/core.c static unsigned int __bpf_prog_ret0_warn(const void *ctx, · line 2370
Quoted 7 lines
kernel/bpf/core.c +2
-2@@ -2366,8 +2366,8 @@ static unsigned int __bpf_prog_ret0_warn(const void *ctx, const struct bpf_insn *insn) {/* If this handler ever gets executed, then BPF_JIT_ALWAYS_ON -* is not working properly, or interpreter is being used when -* prog->jit_requested is not 0, so warn about it! +* or may_goto may cause stack size > 512 is not working properly, +* so warn about it!
We shouldn't have touched this comment. Let's not do it again.
kernel/bpf/core.c static void bpf_prog_select_func(struct bpf_prog *fp) · line 2482
Quoted 11 lines
kernel/bpf/core.c +1
-2*/ WARN_ON_ONCE (1 );return 0 ;@@ -2478,10 +2478,10 @@ static void bpf_prog_select_func(struct bpf_prog *fp)* But for non-JITed programs, we don't need bpf_func, so no bounds * check needed. */ -if (!fp->jit_requested && - !WARN_ON_ONCE (idx >=ARRAY_SIZE (interpreters))) { +if (idx <ARRAY_SIZE (interpreters)) { fp->bpf_func = interpreters[idx];
this is fine.
kernel/bpf/core.c static void bpf_prog_select_func(struct bpf_prog *fp) · line 2484
Quoted 2 lines
kernel/bpf/core.c +1
-0}else { +WARN_ON_ONCE (!fp->jit_requested);
drop it. Let's not give syzbot more opportunities to spam us again with fault injection -like corner cases.
kernel/bpf/core.c struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err) · line 2508
Quoted 9 lines
kernel/bpf/core.c +1
-1fp->bpf_func = __bpf_prog_ret0_warn; }#else @@ -2505,7 +2505,7 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err)/* In case of BPF to BPF calls, verifier did all the prep * work with regards to JITing, etc. */ -bool jit_needed = fp->jit_requested; +bool jit_needed = false;
ok
kernel/bpf/core.c struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err) · line 2519
Quoted 9 lines
kernel/bpf/core.c +2
-0if (fp->bpf_func) goto finalize;@@ -2515,6 +2515,8 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err) jit_needed = true;bpf_prog_select_func (fp); +if (fp->bpf_func == __bpf_prog_ret0_warn) + jit_needed = true;
This is too hacky.
Change bpf_prog_select_func() to return bool and rename it bpf_prog_select_func/bpf_prog_select_interpreter()
true on success, false on when interpreter is impossible.
And target bpf tree.
--
pw-bot: cr
Quoted 6 lines
kernel/bpf/core.c +0
-1/* eBPF JITs can rewrite the program in case constant * blinding is active. However, in case of error during -- 2.43.0
Quoted 36 lines · Alexei Starovoitov
Quoted 24 lines · KaFai Wan
OpenWRT users reported regression on ARMv6 devices after updating to latest
HEAD, where tcpdump filter:tcpdump -i mon1 \
"not wlan addr33c37121a2b3cand not wlan addr2184ecbca2a3a\
and not wlan addr214130b4d3f47and not wlan addr2f0f61cf440b7\
and not wlan addr3a84b4dedf471and not wlan addr3d022be17e1d7\
and not wlan addr35c497967208band not wlan addr2706655784d5b"fails with warning: "Kernel filter failed: No error information" when using config:
#CONFIG_BPF_JIT_ALWAYS_ONis not setCONFIG_BPF_JIT_DEFAULT_ON=yThe issue arises because commits:
1. "bpf: Fix array bounds error withmay_goto" changed default runtime to
__bpf_prog_ret0_warnwhenjit_requested= 1
2. "bpf: Avoid__bpf_prog_ret0_warnwhen jit fails" returns error when
jit_requested= 1 but jit failsQuoted 8 lines
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 6ebc5030e0c5 ("bpf: Fix array bounds error with may_goto")This commit looks fine.
Quoted 8 lines
Quoted 2 lines
Fixes 86bc9c742426 ("bpf: Avoid __bpf_prog_ret0_warn when jitfails")
But this one is indeed problematic.
But before we revert, please provide a selftest that is causing valid classic bpf prog to fail JITing on arm,
because it has to be fixed as well.
OK, I'll add a test for it.
Quoted 19 lines
Sounds like OpenWRT was suffering performance loss due to the interpreter.
Quoted 16 lines
Signed-off-by KaFai Wan <[email protected]>---
kernel/bpf/core.c | 12 +++++++-----1 file changed, 7 insertions(+), 5 deletions(-)kernel/bpf/core.c +0
-0@@ -2366,8 +2366,8 @@ static unsigned int __bpf_prog_ret0_warn(const void *ctx,const struct
bpf_insn*insn)
{
/* If this handler ever gets executed, thenBPF_JIT_ALWAYS_ON
Quoted 9 lines
Quoted 6 lines
- * is not working properly, or interpreter is being used when
- *prog->jit_requestedis not 0, so warn about it! + * ormay_gotomay cause stack size > 512 is not working properly,
+ * so warn about it!We shouldn't have touched this comment. Let's not do it again.
OK.
Quoted 16 lines
Quoted 6 lines
*/
WARN_ON_ONCE(1);
return 0;kernel/bpf/core.c +0
-0@@ -2478,10 +2478,10 @@ static void bpf_prog_select_func(struct bpf_prog *fp) * But for non-JITed programs, we don't need bpf_func, soQuoted 7 lines
no bounds
* check needed.
*/
- if (!fp->jit_requested &&
- !WARN_ON_ONCE(idx >=ARRAY_SIZE(interpreters))) { + if (idx <ARRAY_SIZE(interpreters)) {fp->bpf_func= interpreters[idx];this is fine.
Quoted 6 lines
Quoted 2 lines
} else {
+WARN_ON_ONCE(!fp->jit_requested);drop it. Let's not give syzbot more opportunities to spam us again with fault injection -like corner cases.
OK, will drop it.
Quoted 28 lines
kernel/bpf/core.c struct bpf_prog · line 2509
Quoted 10 lines
fp->bpf_func=__bpf_prog_ret0_warn; }
#elsekernel/bpf/core.c +1
-1@@ -2505,7 +2505,7 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err) /* In case of BPF to BPF calls, verifier did all the prep * work with regards to JITing, etc. */ - bool jit_needed = fp->jit_requested; + bool jit_needed = false;ok
kernel/bpf/core.c struct bpf_prog · line 2520
Quoted 10 lines
kernel/bpf/core.c +2
-0if (fp->bpf_func) goto finalize;@@ -2515,6 +2515,8 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err) jit_needed = true; bpf_prog_select_func(fp); + if (fp->bpf_func == __bpf_prog_ret0_warn) + jit_needed = true;This is too hacky.
Changebpf_prog_select_func()to return bool and rename it bpf_prog_select_func/bpf_prog_select_interpreter()
Quoted 2 lines
true on success, false on when interpreter is impossible.
OK, will change it.
Quoted 2 lines
And target bpf tree.
OK.
Quoted 9 lines
--
pw-bot: crQuoted 6 lines
kernel/bpf/core.c +0
-1/* eBPF JITs can rewrite the program in case constant* blinding is active. However, in case of error during -- 2.43.0
Signature · 2 lines
Thanks, KaFai