* [PATCH bpf-next v1 0/7] Fix timed may_goto with private stacks
@ 2026-09-04 19:51 Siddharth Chintamaneni
2026-09-04 19:51 ` [PATCH bpf-next v1 1/7] bpf: Fix timed may_goto stack pointer for " Siddharth Chintamaneni
` (6 more replies)
0 siblings, 7 replies; 18+ messages in thread
From: Siddharth Chintamaneni @ 2026-09-04 19:51 UTC (permalink / raw)
To: bpf
Cc: Siddharth Chintamaneni, Alexei Starovoitov, Daniel Borkmann,
John Fastabend, Andrii Nakryiko, Eduard Zingerman,
Kumar Kartikeya Dwivedi, Martin KaFai Lau, Song Liu,
Yonghong Song, Jiri Olsa, Emil Tsalapatis, Ihor Solodrai,
Anton Protopopov, Puranjay Mohan, linuxppc-dev, linux-s390,
linux-riscv, rlmenge, hargar, apais
Jeremy reported a bug[1] while executing a BPF program containing
timed_may_goto instructions with private stacks.
timed_may_goto[2] is a runtime safety mechanism that allows BPF
programs to execute longer loops[3]. The BPF verifier replaces each
may_goto instruction with a loop counter initialized to 0xffff and a
timestamp check[4] that terminates the loop after 250 ms.
Private stacks[5] allow BPF programs to use per-CPU memory instead of
consuming more of the native kernel stack when BPF programs are deeply
nested.
To make timed may_goto work, the BPF program reserves 16 bytes of stack
space. The first 8 bytes store the loop counter and the next 8 bytes
store the timestamp.
After the loop counter is exhausted, arch_bpf_timed_may_goto() is
called. On x86, it adds the counter's stack offset to RBP to obtain a
pointer to the counter and timestamp[6]. This works when the BPF
program uses the normal stack because RBP is also the BPF frame pointer.
When a private stack is used, the x86 JIT uses R9 as the BPF frame pointer.
The verifier-generated loads and stores therefore access the counter and
timestamp through R9. However, arch_bpf_timed_may_goto() still adds the
offset to RBP and accesses an unrelated location in the native JIT stack
frame. This is the mismatch Jeremy reported.
Fix the mismatch by resolving the address in the generated BPF
instructions:
BPF_REG_AX = BPF_REG_FP
BPF_REG_AX += stack_offset
The JIT can then select the correct BPF frame pointer before calling
arch_bpf_timed_may_goto(). The function receives the resolved pointer
instead of reconstructing it from RBP.
The LoongArch timed may_goto implementation is currently queued through
the loongarch-next tree[7], while its selftests were merged separately
through the bpf-next tree[8]. This series is based on bpf-next and
therefore does not include the LoongArch trampoline update.
[1] https://lore.kernel.org/all/20260824213158.3755932-2-Jeremy.Jean@oss.cyber.gouv.fr/
[2] https://lore.kernel.org/all/20250304003239.2390751-1-memxor@gmail.com/
[3] https://elixir.bootlin.com/linux/v7.2.2/source/tools/testing/selftests/bpf/libarena/include/bpf_may_goto.h#L8
[4] https://elixir.bootlin.com/linux/v7.2.2/source/kernel/bpf/core.c#L3407
[5] https://lore.kernel.org/bpf/20260417034658.2625353-1-yonghong.song@linux.dev/
[6] https://elixir.bootlin.com/linux/v7.2.2/source/arch/x86/net/bpf_timed_may_goto.S#L18
[7] https://lore.kernel.org/loongarch/20260804153938.16129-3-dongtai.guo@linux.dev/
[8] https://lore.kernel.org/bpf/20260813070906.5164-1-yangtiezhu@loongson.cn/
Siddharth Chintamaneni (7):
bpf: Fix timed may_goto stack pointer for private stacks
bpf, x86: Use resolved pointer for timed may_goto
bpf, arm64: Use resolved pointer for timed may_goto
bpf, powerpc64: Use resolved pointer for timed may_goto
bpf, riscv: Use resolved pointer for timed may_goto
bpf, s390: Use resolved pointer for timed may_goto
selftests/bpf: Test timed may_goto with private stacks
arch/arm64/net/bpf_timed_may_goto.S | 12 ++------
arch/powerpc/net/bpf_timed_may_goto.S | 8 ++---
arch/riscv/net/bpf_timed_may_goto.S | 13 ++++----
arch/s390/net/bpf_jit_comp.c | 6 ++--
arch/s390/net/bpf_timed_may_goto.S | 8 ++---
arch/x86/net/bpf_timed_may_goto.S | 6 ----
kernel/bpf/fixups.c | 19 ++++++------
.../bpf/progs/verifier_bpf_fastcall.c | 30 ++++++++++---------
.../selftests/bpf/progs/verifier_may_goto_1.c | 17 ++++++-----
.../bpf/progs/verifier_private_stack.c | 19 ++++++++++++
10 files changed, 75 insertions(+), 63 deletions(-)
base-commit: d761934c9483ecde93fe99d8705282f716dfee50
--
2.43.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH bpf-next v1 1/7] bpf: Fix timed may_goto stack pointer for private stacks
2026-09-04 19:51 [PATCH bpf-next v1 0/7] Fix timed may_goto with private stacks Siddharth Chintamaneni
@ 2026-09-04 19:51 ` Siddharth Chintamaneni
2026-09-04 19:58 ` sashiko-bot
2026-09-04 19:51 ` [PATCH bpf-next v1 2/7] bpf, x86: Use resolved pointer for timed may_goto Siddharth Chintamaneni
` (5 subsequent siblings)
6 siblings, 1 reply; 18+ messages in thread
From: Siddharth Chintamaneni @ 2026-09-04 19:51 UTC (permalink / raw)
To: bpf
Cc: Siddharth Chintamaneni, Jeremy Jean, Alexei Starovoitov,
Daniel Borkmann, John Fastabend, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
Ihor Solodrai, Anton Protopopov, Puranjay Mohan, linuxppc-dev,
linux-s390, linux-riscv, rlmenge, hargar, apais
timed may_goto passes a stack offset to the architecture trampoline,
which reconstructs the counter pointer from its BPF frame pointer. This
breaks when the JIT uses a private stack with a different frame pointer.
Resolve the counter pointer in the fixup using BPF_REG_FP and pass the
pointer through BPF_REG_AX. Account for the extra instruction in the
internal branch offsets.
Fixes: e723608bf428 ("bpf: Add verifier support for timed may_goto")
Reported-by: Jeremy Jean <jeremy.jean@oss.cyber.gouv.fr>
Link: https://lore.kernel.org/all/20260824213158.3755932-2-Jeremy.Jean@oss.cyber.gouv.fr/
Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
---
kernel/bpf/fixups.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
index 65b441e4a351..dc59501a32bb 100644
--- a/kernel/bpf/fixups.c
+++ b/kernel/bpf/fixups.c
@@ -1797,20 +1797,20 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env)
stack_depth_extra = 16;
insn_buf[0] = BPF_LDX_MEM(BPF_DW, BPF_REG_AX, BPF_REG_10, stack_off_cnt);
if (insn->off >= 0)
- insn_buf[1] = BPF_JMP_IMM(BPF_JEQ, BPF_REG_AX, 0, insn->off + 5);
+ insn_buf[1] = BPF_JMP_IMM(BPF_JEQ, BPF_REG_AX, 0, insn->off + 6);
else
insn_buf[1] = BPF_JMP_IMM(BPF_JEQ, BPF_REG_AX, 0, insn->off - 1);
insn_buf[2] = BPF_ALU64_IMM(BPF_SUB, BPF_REG_AX, 1);
- insn_buf[3] = BPF_JMP_IMM(BPF_JNE, BPF_REG_AX, 0, 2);
+ insn_buf[3] = BPF_JMP_IMM(BPF_JNE, BPF_REG_AX, 0, 3);
/*
- * AX is used as an argument to pass in stack_off_cnt
- * (to add to r10/fp), and also as the return value of
- * the call to arch_bpf_timed_may_goto.
+ * AX is used to pass FP + stack_off_cnt as the argument to
+ * arch_bpf_timed_may_goto(), and also holds its return value.
*/
- insn_buf[4] = BPF_MOV64_IMM(BPF_REG_AX, stack_off_cnt);
- insn_buf[5] = BPF_EMIT_CALL(arch_bpf_timed_may_goto);
- insn_buf[6] = BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_AX, stack_off_cnt);
- cnt = 7;
+ insn_buf[4] = BPF_MOV64_REG(BPF_REG_AX, BPF_REG_FP);
+ insn_buf[5] = BPF_ALU64_IMM(BPF_ADD, BPF_REG_AX, stack_off_cnt);
+ insn_buf[6] = BPF_EMIT_CALL(arch_bpf_timed_may_goto);
+ insn_buf[7] = BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_AX, stack_off_cnt);
+ cnt = 8;
new_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);
if (!new_prog)
@@ -2661,4 +2661,3 @@ int bpf_remove_fastcall_spills_fills(struct bpf_verifier_env *env)
return 0;
}
-
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH bpf-next v1 2/7] bpf, x86: Use resolved pointer for timed may_goto
2026-09-04 19:51 [PATCH bpf-next v1 0/7] Fix timed may_goto with private stacks Siddharth Chintamaneni
2026-09-04 19:51 ` [PATCH bpf-next v1 1/7] bpf: Fix timed may_goto stack pointer for " Siddharth Chintamaneni
@ 2026-09-04 19:51 ` Siddharth Chintamaneni
2026-09-04 20:02 ` sashiko-bot
2026-09-04 20:33 ` bot+bpf-ci
2026-09-04 19:51 ` [PATCH bpf-next v1 3/7] bpf, arm64: " Siddharth Chintamaneni
` (4 subsequent siblings)
6 siblings, 2 replies; 18+ messages in thread
From: Siddharth Chintamaneni @ 2026-09-04 19:51 UTC (permalink / raw)
To: bpf
Cc: Siddharth Chintamaneni, Jeremy Jean, Alexei Starovoitov,
Daniel Borkmann, John Fastabend, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
Ihor Solodrai, Anton Protopopov, Puranjay Mohan, linuxppc-dev,
linux-s390, linux-riscv, rlmenge, hargar, apais
The timed may_goto fixup now passes the resolved counter pointer through
BPF_REG_AX instead of a stack offset.
Use the pointer directly rather than adding it to RBP. This preserves the
private-stack address selected by the JIT through R9.
Fixes: 2fb761823ead ("bpf, x86: Add x86 JIT support for timed may_goto")
Reported-by: Jeremy Jean <jeremy.jean@oss.cyber.gouv.fr>
Link: https://lore.kernel.org/all/20260824213158.3755932-2-Jeremy.Jean@oss.cyber.gouv.fr/
Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
---
arch/x86/net/bpf_timed_may_goto.S | 6 ------
1 file changed, 6 deletions(-)
diff --git a/arch/x86/net/bpf_timed_may_goto.S b/arch/x86/net/bpf_timed_may_goto.S
index 54c690cae190..6e9d9e7c2b1d 100644
--- a/arch/x86/net/bpf_timed_may_goto.S
+++ b/arch/x86/net/bpf_timed_may_goto.S
@@ -11,12 +11,6 @@
SYM_FUNC_START(arch_bpf_timed_may_goto)
ANNOTATE_NOENDBR
- /*
- * r10 passes us stack depth, load the pointer to count and timestamp
- * into r10 by adding it to BPF frame pointer.
- */
- leaq (%rbp, %r10, 1), %r10
-
/* Setup frame. */
pushq %rbp
movq %rsp, %rbp
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH bpf-next v1 3/7] bpf, arm64: Use resolved pointer for timed may_goto
2026-09-04 19:51 [PATCH bpf-next v1 0/7] Fix timed may_goto with private stacks Siddharth Chintamaneni
2026-09-04 19:51 ` [PATCH bpf-next v1 1/7] bpf: Fix timed may_goto stack pointer for " Siddharth Chintamaneni
2026-09-04 19:51 ` [PATCH bpf-next v1 2/7] bpf, x86: Use resolved pointer for timed may_goto Siddharth Chintamaneni
@ 2026-09-04 19:51 ` Siddharth Chintamaneni
2026-09-04 20:01 ` sashiko-bot
2026-09-04 19:51 ` [PATCH bpf-next v1 4/7] bpf, powerpc64: " Siddharth Chintamaneni
` (3 subsequent siblings)
6 siblings, 1 reply; 18+ messages in thread
From: Siddharth Chintamaneni @ 2026-09-04 19:51 UTC (permalink / raw)
To: bpf
Cc: Siddharth Chintamaneni, Jeremy Jean, Alexei Starovoitov,
Daniel Borkmann, John Fastabend, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
Ihor Solodrai, Anton Protopopov, Puranjay Mohan, linuxppc-dev,
linux-s390, linux-riscv, rlmenge, hargar, apais
The timed may_goto fixup now passes the resolved counter pointer through
BPF_REG_AX instead of a stack offset.
Copy the pointer directly into the first argument register rather than
adding it to the BPF frame pointer again.
Fixes: 16175375da36 ("bpf, arm64: Add JIT support for timed may_goto")
Reported-by: Jeremy Jean <jeremy.jean@oss.cyber.gouv.fr>
Link: https://lore.kernel.org/all/20260824213158.3755932-2-Jeremy.Jean@oss.cyber.gouv.fr/
Assisted-by: Copilot:gpt-5.6-sol
Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
---
arch/arm64/net/bpf_timed_may_goto.S | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/arch/arm64/net/bpf_timed_may_goto.S b/arch/arm64/net/bpf_timed_may_goto.S
index a9a802711a7f..53148c9a1c58 100644
--- a/arch/arm64/net/bpf_timed_may_goto.S
+++ b/arch/arm64/net/bpf_timed_may_goto.S
@@ -14,16 +14,10 @@ SYM_FUNC_START(arch_bpf_timed_may_goto)
stp x3, x4, [sp, #48]
/*
- * Stack depth was passed in BPF_REG_AX (x9), add it to the BPF_FP
- * (x25) to get the pointer to count and timestamp and pass it as the
- * first argument in x0.
- *
- * Before generating the call to arch_bpf_timed_may_goto, the verifier
- * generates a load instruction using FP, i.e. REG_AX = *(u64 *)(FP -
- * stack_off_cnt), so BPF_REG_FP (x25) is always set up by the arm64
- * jit in this case.
+ * BPF_REG_AX (x9) contains the count and timestamp pointer; pass it as
+ * the first argument in x0.
*/
- add x0, x9, x25
+ mov x0, x9
bl bpf_check_timed_may_goto
/* BPF_REG_AX(x9) will be stored into count, so move return value to it. */
mov x9, x0
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH bpf-next v1 4/7] bpf, powerpc64: Use resolved pointer for timed may_goto
2026-09-04 19:51 [PATCH bpf-next v1 0/7] Fix timed may_goto with private stacks Siddharth Chintamaneni
` (2 preceding siblings ...)
2026-09-04 19:51 ` [PATCH bpf-next v1 3/7] bpf, arm64: " Siddharth Chintamaneni
@ 2026-09-04 19:51 ` Siddharth Chintamaneni
2026-09-04 19:58 ` sashiko-bot
2026-09-04 19:51 ` [PATCH bpf-next v1 5/7] bpf, riscv: " Siddharth Chintamaneni
` (2 subsequent siblings)
6 siblings, 1 reply; 18+ messages in thread
From: Siddharth Chintamaneni @ 2026-09-04 19:51 UTC (permalink / raw)
To: bpf
Cc: Siddharth Chintamaneni, Jeremy Jean, Alexei Starovoitov,
Daniel Borkmann, John Fastabend, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
Ihor Solodrai, Anton Protopopov, Puranjay Mohan, linuxppc-dev,
linux-s390, linux-riscv, rlmenge, hargar, apais
The timed may_goto fixup now passes the resolved counter pointer through
BPF_REG_AX instead of a stack offset.
Copy the pointer directly into the first argument register rather than
adding it to the BPF frame pointer again.
Fixes: b55b6b9ad76c ("powerpc64/bpf: Add powerpc64 JIT support for timed may_goto")
Reported-by: Jeremy Jean <jeremy.jean@oss.cyber.gouv.fr>
Link: https://lore.kernel.org/all/20260824213158.3755932-2-Jeremy.Jean@oss.cyber.gouv.fr/
Assisted-by: Copilot:gpt-5.6-sol
Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
---
arch/powerpc/net/bpf_timed_may_goto.S | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/net/bpf_timed_may_goto.S b/arch/powerpc/net/bpf_timed_may_goto.S
index 84ecf6fa7f5d..d88825dd34fe 100644
--- a/arch/powerpc/net/bpf_timed_may_goto.S
+++ b/arch/powerpc/net/bpf_timed_may_goto.S
@@ -8,7 +8,7 @@
* arch_bpf_timed_may_goto() trampoline for powerpc64
*
* Custom BPF convention (verifier/JIT):
- * - input: stack offset in BPF_REG_AX (r12)
+ * - input: count and timestamp pointer in BPF_REG_AX (r12)
* - output: updated count in BPF_REG_AX (r12)
*
* Call bpf_check_timed_may_goto(ptr) with normal powerpc64 ABI:
@@ -32,10 +32,10 @@ SYM_FUNC_START(arch_bpf_timed_may_goto)
std r8, 72(r1)
/*
- * r3 = BPF_REG_FP + BPF_REG_AX
- * BPF_REG_FP is r31; BPF_REG_AX is r12 (stack offset in bytes).
+ * BPF_REG_AX (r12) contains the count and timestamp pointer; pass it as
+ * the first argument in r3.
*/
- add r3, r31, r12
+ mr r3, r12
bl CFUNC(bpf_check_timed_may_goto)
/* Put return value back into AX */
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH bpf-next v1 5/7] bpf, riscv: Use resolved pointer for timed may_goto
2026-09-04 19:51 [PATCH bpf-next v1 0/7] Fix timed may_goto with private stacks Siddharth Chintamaneni
` (3 preceding siblings ...)
2026-09-04 19:51 ` [PATCH bpf-next v1 4/7] bpf, powerpc64: " Siddharth Chintamaneni
@ 2026-09-04 19:51 ` Siddharth Chintamaneni
2026-09-04 19:57 ` sashiko-bot
2026-09-04 20:33 ` bot+bpf-ci
2026-09-04 19:51 ` [PATCH bpf-next v1 6/7] bpf, s390: " Siddharth Chintamaneni
2026-09-04 19:51 ` [PATCH bpf-next v1 7/7] selftests/bpf: Test timed may_goto with private stacks Siddharth Chintamaneni
6 siblings, 2 replies; 18+ messages in thread
From: Siddharth Chintamaneni @ 2026-09-04 19:51 UTC (permalink / raw)
To: bpf
Cc: Siddharth Chintamaneni, Jeremy Jean, Alexei Starovoitov,
Daniel Borkmann, John Fastabend, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
Ihor Solodrai, Anton Protopopov, Puranjay Mohan, linuxppc-dev,
linux-s390, linux-riscv, rlmenge, hargar, apais
The timed may_goto fixup now passes the resolved counter pointer through
BPF_REG_AX instead of a stack offset.
Copy the pointer directly into the first argument register rather than
adding it to the BPF frame pointer again.
Fixes: 6ef8ff20c30b ("bpf, riscv: Add support for timed may_goto")
Reported-by: Jeremy Jean <jeremy.jean@oss.cyber.gouv.fr>
Link: https://lore.kernel.org/all/20260824213158.3755932-2-Jeremy.Jean@oss.cyber.gouv.fr/
Assisted-by: Copilot:gpt-5.6-sol
Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
---
arch/riscv/net/bpf_timed_may_goto.S | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/arch/riscv/net/bpf_timed_may_goto.S b/arch/riscv/net/bpf_timed_may_goto.S
index 02c637d87420..8c03e272e0bf 100644
--- a/arch/riscv/net/bpf_timed_may_goto.S
+++ b/arch/riscv/net/bpf_timed_may_goto.S
@@ -6,12 +6,11 @@
/*
* Trampoline for the BPF timed may_goto loop bound. Custom calling convention:
- * - input: stack offset in BPF_REG_AX (t0)
+ * - input: count and timestamp pointer in BPF_REG_AX (t0)
* - output: updated count in BPF_REG_AX (t0)
*
- * Calls bpf_check_timed_may_goto(ptr) with the standard RISC-V ABI, where
- * ptr = BPF_REG_FP (s5) + BPF_REG_AX (t0). BPF R0-R5 (a5, a0-a4) are saved
- * across the call; BPF_REG_FP (s5) is callee-saved and needs no saving.
+ * Calls bpf_check_timed_may_goto(ptr) with the standard RISC-V ABI.
+ * BPF R0-R5 (a5, a0-a4) are saved across the call.
*/
SYM_FUNC_START(arch_bpf_timed_may_goto)
@@ -28,7 +27,11 @@ SYM_FUNC_START(arch_bpf_timed_may_goto)
REG_S a3, 1*SZREG(sp)
REG_S a4, 0*SZREG(sp)
- add a0, t0, s5
+ /*
+ * BPF_REG_AX (t0) contains the count and timestamp pointer; pass it as
+ * the first argument in a0.
+ */
+ mv a0, t0
call bpf_check_timed_may_goto
mv t0, a0
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH bpf-next v1 6/7] bpf, s390: Use resolved pointer for timed may_goto
2026-09-04 19:51 [PATCH bpf-next v1 0/7] Fix timed may_goto with private stacks Siddharth Chintamaneni
` (4 preceding siblings ...)
2026-09-04 19:51 ` [PATCH bpf-next v1 5/7] bpf, riscv: " Siddharth Chintamaneni
@ 2026-09-04 19:51 ` Siddharth Chintamaneni
2026-09-04 19:59 ` sashiko-bot
2026-09-04 20:33 ` bot+bpf-ci
2026-09-04 19:51 ` [PATCH bpf-next v1 7/7] selftests/bpf: Test timed may_goto with private stacks Siddharth Chintamaneni
6 siblings, 2 replies; 18+ messages in thread
From: Siddharth Chintamaneni @ 2026-09-04 19:51 UTC (permalink / raw)
To: bpf
Cc: Siddharth Chintamaneni, Jeremy Jean, Alexei Starovoitov,
Daniel Borkmann, John Fastabend, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
Ihor Solodrai, Anton Protopopov, Puranjay Mohan, linuxppc-dev,
linux-s390, linux-riscv, rlmenge, hargar, apais
The timed may_goto fixup now passes the resolved counter pointer through
BPF_REG_AX instead of a stack offset and BPF frame pointer pair.
Copy the pointer directly into the first argument register and update the
special calling convention documentation.
Fixes: b8efa810c1db ("s390/bpf: Add s390 JIT support for timed may_goto")
Reported-by: Jeremy Jean <jeremy.jean@oss.cyber.gouv.fr>
Link: https://lore.kernel.org/all/20260824213158.3755932-2-Jeremy.Jean@oss.cyber.gouv.fr/
Assisted-by: Copilot:gpt-5.6-sol
Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
---
arch/s390/net/bpf_jit_comp.c | 6 +++---
arch/s390/net/bpf_timed_may_goto.S | 8 ++++----
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
index c46872b071ce..4098c3377c21 100644
--- a/arch/s390/net/bpf_jit_comp.c
+++ b/arch/s390/net/bpf_jit_comp.c
@@ -1872,9 +1872,9 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,
if ((void *)func == arch_bpf_timed_may_goto) {
/*
* arch_bpf_timed_may_goto() has a special ABI: the
- * parameters are in BPF_REG_AX and BPF_REG_10; the
- * return value is in BPF_REG_AX; and all GPRs except
- * REG_W0, REG_W1, and BPF_REG_AX are callee-saved.
+ * parameter and return value are in BPF_REG_AX; all
+ * GPRs except REG_W0, REG_W1, and BPF_REG_AX are
+ * callee-saved.
*/
/* brasl %r0,func */
diff --git a/arch/s390/net/bpf_timed_may_goto.S b/arch/s390/net/bpf_timed_may_goto.S
index 06f567a460d7..e34c99982c4a 100644
--- a/arch/s390/net/bpf_timed_may_goto.S
+++ b/arch/s390/net/bpf_timed_may_goto.S
@@ -21,9 +21,9 @@
SYM_FUNC_START(arch_bpf_timed_may_goto)
/*
- * This function has a special ABI: the parameters are in %r12 and
- * %r13; the return value is in %r12; all GPRs except %r0, %r1, and
- * %r12 are callee-saved; and the return address is in %r0.
+ * This function has a special ABI: the parameter and return value are
+ * in %r12; all GPRs except %r0, %r1, and %r12 are callee-saved; and
+ * the return address is in %r0.
*/
stmg %r2,%r5,FRAME_OFF+R2_OFF(%r15)
stg %r14,FRAME_OFF+R14_OFF(%r15)
@@ -33,7 +33,7 @@ SYM_FUNC_START(arch_bpf_timed_may_goto)
lay %r15,-FRAME_SIZE(%r15)
stg %r1,__SF_BACKCHAIN(%r15)
- lay %r2,0(%r12,%r13)
+ lgr %r2,%r12
brasl %r14,bpf_check_timed_may_goto
lgr %r12,%r2
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH bpf-next v1 7/7] selftests/bpf: Test timed may_goto with private stacks
2026-09-04 19:51 [PATCH bpf-next v1 0/7] Fix timed may_goto with private stacks Siddharth Chintamaneni
` (5 preceding siblings ...)
2026-09-04 19:51 ` [PATCH bpf-next v1 6/7] bpf, s390: " Siddharth Chintamaneni
@ 2026-09-04 19:51 ` Siddharth Chintamaneni
2026-09-04 19:58 ` sashiko-bot
6 siblings, 1 reply; 18+ messages in thread
From: Siddharth Chintamaneni @ 2026-09-04 19:51 UTC (permalink / raw)
To: bpf
Cc: Siddharth Chintamaneni, Alexei Starovoitov, Daniel Borkmann,
John Fastabend, Andrii Nakryiko, Eduard Zingerman,
Kumar Kartikeya Dwivedi, Martin KaFai Lau, Song Liu,
Yonghong Song, Jiri Olsa, Emil Tsalapatis, Ihor Solodrai,
Anton Protopopov, Puranjay Mohan, linuxppc-dev, linux-s390,
linux-riscv, rlmenge, hargar, apais
Add private_stack_timed_may_goto() with enough stack usage to select a
private stack. Check that the JIT uses the private-stack frame pointer
when constructing the pointer passed to the architecture trampoline.
Update the translated instruction expectations in may_goto_batch_2(),
may_goto_interaction_x86_64(), and may_goto_interaction() for the
additional pointer construction instruction and adjusted branch offsets.
Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
---
.../bpf/progs/verifier_bpf_fastcall.c | 30 ++++++++++---------
.../selftests/bpf/progs/verifier_may_goto_1.c | 17 ++++++-----
.../bpf/progs/verifier_private_stack.c | 19 ++++++++++++
3 files changed, 44 insertions(+), 22 deletions(-)
diff --git a/tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c b/tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c
index 328cf630210a..c5996d9dc8cc 100644
--- a/tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c
+++ b/tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c
@@ -635,15 +635,16 @@ __xlated("4: r0 = &(void __percpu *)(r0)")
__xlated("...")
/* may_goto expansion starts */
__xlated("6: r12 = *(u64 *)(r10 -24)")
-__xlated("7: if r12 == 0x0 goto pc+6")
+__xlated("7: if r12 == 0x0 goto pc+7")
__xlated("8: r12 -= 1")
-__xlated("9: if r12 != 0x0 goto pc+2")
-__xlated("10: r12 = -24")
-__xlated("11: call unknown")
-__xlated("12: *(u64 *)(r10 -24) = r12")
+__xlated("9: if r12 != 0x0 goto pc+3")
+__xlated("10: r12 = r10")
+__xlated("11: r12 += -24")
+__xlated("12: call unknown")
+__xlated("13: *(u64 *)(r10 -24) = r12")
/* may_goto expansion ends */
-__xlated("13: *(u64 *)(r10 -8) = r1")
-__xlated("14: exit")
+__xlated("14: *(u64 *)(r10 -8) = r1")
+__xlated("15: exit")
__success
__naked void may_goto_interaction_x86_64(void)
{
@@ -676,15 +677,16 @@ __xlated("2: r1 = 1")
__xlated("3: call bpf_get_smp_processor_id")
/* may_goto expansion starts */
__xlated("4: r12 = *(u64 *)(r10 -24)")
-__xlated("5: if r12 == 0x0 goto pc+6")
+__xlated("5: if r12 == 0x0 goto pc+7")
__xlated("6: r12 -= 1")
-__xlated("7: if r12 != 0x0 goto pc+2")
-__xlated("8: r12 = -24")
-__xlated("9: call unknown")
-__xlated("10: *(u64 *)(r10 -24) = r12")
+__xlated("7: if r12 != 0x0 goto pc+3")
+__xlated("8: r12 = r10")
+__xlated("9: r12 += -24")
+__xlated("10: call unknown")
+__xlated("11: *(u64 *)(r10 -24) = r12")
/* may_goto expansion ends */
-__xlated("11: *(u64 *)(r10 -8) = r1")
-__xlated("12: exit")
+__xlated("12: *(u64 *)(r10 -8) = r1")
+__xlated("13: exit")
__success
__naked void may_goto_interaction(void)
{
diff --git a/tools/testing/selftests/bpf/progs/verifier_may_goto_1.c b/tools/testing/selftests/bpf/progs/verifier_may_goto_1.c
index db7e30da234f..1721897160dc 100644
--- a/tools/testing/selftests/bpf/progs/verifier_may_goto_1.c
+++ b/tools/testing/selftests/bpf/progs/verifier_may_goto_1.c
@@ -90,15 +90,16 @@ __arch_loongarch
__xlated("0: *(u64 *)(r10 -16) = 65535")
__xlated("1: *(u64 *)(r10 -8) = 0")
__xlated("2: r12 = *(u64 *)(r10 -16)")
-__xlated("3: if r12 == 0x0 goto pc+6")
+__xlated("3: if r12 == 0x0 goto pc+7")
__xlated("4: r12 -= 1")
-__xlated("5: if r12 != 0x0 goto pc+2")
-__xlated("6: r12 = -16")
-__xlated("7: call unknown")
-__xlated("8: *(u64 *)(r10 -16) = r12")
-__xlated("9: r0 = 1")
-__xlated("10: r0 = 2")
-__xlated("11: exit")
+__xlated("5: if r12 != 0x0 goto pc+3")
+__xlated("6: r12 = r10")
+__xlated("7: r12 += -16")
+__xlated("8: call unknown")
+__xlated("9: *(u64 *)(r10 -16) = r12")
+__xlated("10: r0 = 1")
+__xlated("11: r0 = 2")
+__xlated("12: exit")
__success
__naked void may_goto_batch_2(void)
{
diff --git a/tools/testing/selftests/bpf/progs/verifier_private_stack.c b/tools/testing/selftests/bpf/progs/verifier_private_stack.c
index 3d9994a52464..639b53363c9a 100644
--- a/tools/testing/selftests/bpf/progs/verifier_private_stack.c
+++ b/tools/testing/selftests/bpf/progs/verifier_private_stack.c
@@ -70,6 +70,25 @@ __naked void no_private_stack_nested(void)
" ::: __clobber_all);
}
+SEC("fentry/bpf_fentry_test9")
+__description("Private stack, timed may_goto")
+__success __retval(0)
+__arch_x86_64
+__jited(" movabsq $0x{{.*}}, %r9")
+__jited("...")
+__jited(" movq %r9, %r10")
+__arch_arm64
+__jited(" mov x9, x25")
+int private_stack_timed_may_goto(void)
+{
+ volatile __u64 stack_space[16] = {};
+
+ while (can_loop)
+ ;
+
+ return stack_space[0];
+}
+
__used
__naked static void cumulative_stack_depth_subprog(void)
{
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH bpf-next v1 5/7] bpf, riscv: Use resolved pointer for timed may_goto
2026-09-04 19:51 ` [PATCH bpf-next v1 5/7] bpf, riscv: " Siddharth Chintamaneni
@ 2026-09-04 19:57 ` sashiko-bot
2026-09-04 20:33 ` bot+bpf-ci
1 sibling, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-09-04 19:57 UTC (permalink / raw)
To: Siddharth Chintamaneni
Cc: linux-s390, Vasily Gorbik, Heiko Carstens, Alexander Gordeev,
Christian Borntraeger, bpf
> The timed may_goto fixup now passes the resolved counter pointer through
> BPF_REG_AX instead of a stack offset.
>
> Copy the pointer directly into the first argument register rather than
> adding it to the BPF frame pointer again.
>
> Fixes: 6ef8ff20c30b ("bpf, riscv: Add support for timed may_goto")
> Reported-by: Jeremy Jean <jeremy.jean@oss.cyber.gouv.fr>
> Link: https://lore.kernel.org/all/20260824213158.3755932-2-Jeremy.Jean@oss.cyber.gouv.fr/
> Assisted-by: Copilot:gpt-5.6-sol
> Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260904195132.141068-1-sidchintamaneni@gmail.com?part=5
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH bpf-next v1 1/7] bpf: Fix timed may_goto stack pointer for private stacks
2026-09-04 19:51 ` [PATCH bpf-next v1 1/7] bpf: Fix timed may_goto stack pointer for " Siddharth Chintamaneni
@ 2026-09-04 19:58 ` sashiko-bot
0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-09-04 19:58 UTC (permalink / raw)
To: Siddharth Chintamaneni
Cc: Vasily Gorbik, Heiko Carstens, linux-s390, Christian Borntraeger,
bpf, Alexander Gordeev
> timed may_goto passes a stack offset to the architecture trampoline,
> which reconstructs the counter pointer from its BPF frame pointer. This
> breaks when the JIT uses a private stack with a different frame pointer.
>
> Resolve the counter pointer in the fixup using BPF_REG_FP and pass the
> pointer through BPF_REG_AX. Account for the extra instruction in the
> internal branch offsets.
>
> Fixes: e723608bf428 ("bpf: Add verifier support for timed may_goto")
> Reported-by: Jeremy Jean <jeremy.jean@oss.cyber.gouv.fr>
> Link: https://lore.kernel.org/all/20260824213158.3755932-2-Jeremy.Jean@oss.cyber.gouv.fr/
> Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260904195132.141068-1-sidchintamaneni@gmail.com?part=1
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH bpf-next v1 7/7] selftests/bpf: Test timed may_goto with private stacks
2026-09-04 19:51 ` [PATCH bpf-next v1 7/7] selftests/bpf: Test timed may_goto with private stacks Siddharth Chintamaneni
@ 2026-09-04 19:58 ` sashiko-bot
0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-09-04 19:58 UTC (permalink / raw)
To: Siddharth Chintamaneni
Cc: linux-s390, Heiko Carstens, Vasily Gorbik, bpf,
Christian Borntraeger, Alexander Gordeev
> Add private_stack_timed_may_goto() with enough stack usage to select a
> private stack. Check that the JIT uses the private-stack frame pointer
> when constructing the pointer passed to the architecture trampoline.
>
> Update the translated instruction expectations in may_goto_batch_2(),
> may_goto_interaction_x86_64(), and may_goto_interaction() for the
> additional pointer construction instruction and adjusted branch offsets.
>
> Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260904195132.141068-1-sidchintamaneni@gmail.com?part=7
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH bpf-next v1 4/7] bpf, powerpc64: Use resolved pointer for timed may_goto
2026-09-04 19:51 ` [PATCH bpf-next v1 4/7] bpf, powerpc64: " Siddharth Chintamaneni
@ 2026-09-04 19:58 ` sashiko-bot
0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-09-04 19:58 UTC (permalink / raw)
To: Siddharth Chintamaneni
Cc: Vasily Gorbik, bpf, Heiko Carstens, Christian Borntraeger,
linux-s390, Alexander Gordeev
> The timed may_goto fixup now passes the resolved counter pointer through
> BPF_REG_AX instead of a stack offset.
>
> Copy the pointer directly into the first argument register rather than
> adding it to the BPF frame pointer again.
>
> Fixes: b55b6b9ad76c ("powerpc64/bpf: Add powerpc64 JIT support for timed may_goto")
> Reported-by: Jeremy Jean <jeremy.jean@oss.cyber.gouv.fr>
> Link: https://lore.kernel.org/all/20260824213158.3755932-2-Jeremy.Jean@oss.cyber.gouv.fr/
> Assisted-by: Copilot:gpt-5.6-sol
> Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260904195132.141068-1-sidchintamaneni@gmail.com?part=4
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH bpf-next v1 6/7] bpf, s390: Use resolved pointer for timed may_goto
2026-09-04 19:51 ` [PATCH bpf-next v1 6/7] bpf, s390: " Siddharth Chintamaneni
@ 2026-09-04 19:59 ` sashiko-bot
2026-09-04 20:33 ` bot+bpf-ci
1 sibling, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-09-04 19:59 UTC (permalink / raw)
To: Siddharth Chintamaneni
Cc: linux-s390, Heiko Carstens, bpf, Vasily Gorbik, Alexander Gordeev,
Christian Borntraeger
> The timed may_goto fixup now passes the resolved counter pointer through
> BPF_REG_AX instead of a stack offset and BPF frame pointer pair.
>
> Copy the pointer directly into the first argument register and update the
> special calling convention documentation.
>
> Fixes: b8efa810c1db ("s390/bpf: Add s390 JIT support for timed may_goto")
> Reported-by: Jeremy Jean <jeremy.jean@oss.cyber.gouv.fr>
> Link: https://lore.kernel.org/all/20260824213158.3755932-2-Jeremy.Jean@oss.cyber.gouv.fr/
> Assisted-by: Copilot:gpt-5.6-sol
> Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260904195132.141068-1-sidchintamaneni@gmail.com?part=6
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH bpf-next v1 3/7] bpf, arm64: Use resolved pointer for timed may_goto
2026-09-04 19:51 ` [PATCH bpf-next v1 3/7] bpf, arm64: " Siddharth Chintamaneni
@ 2026-09-04 20:01 ` sashiko-bot
0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-09-04 20:01 UTC (permalink / raw)
To: Siddharth Chintamaneni
Cc: Alexander Gordeev, Christian Borntraeger, Heiko Carstens,
linux-s390, Vasily Gorbik, bpf
> The timed may_goto fixup now passes the resolved counter pointer through
> BPF_REG_AX instead of a stack offset.
>
> Copy the pointer directly into the first argument register rather than
> adding it to the BPF frame pointer again.
>
> Fixes: 16175375da36 ("bpf, arm64: Add JIT support for timed may_goto")
> Reported-by: Jeremy Jean <jeremy.jean@oss.cyber.gouv.fr>
> Link: https://lore.kernel.org/all/20260824213158.3755932-2-Jeremy.Jean@oss.cyber.gouv.fr/
> Assisted-by: Copilot:gpt-5.6-sol
> Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260904195132.141068-1-sidchintamaneni@gmail.com?part=3
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH bpf-next v1 2/7] bpf, x86: Use resolved pointer for timed may_goto
2026-09-04 19:51 ` [PATCH bpf-next v1 2/7] bpf, x86: Use resolved pointer for timed may_goto Siddharth Chintamaneni
@ 2026-09-04 20:02 ` sashiko-bot
2026-09-04 20:33 ` bot+bpf-ci
1 sibling, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-09-04 20:02 UTC (permalink / raw)
To: Siddharth Chintamaneni
Cc: linux-s390, Alexander Gordeev, Christian Borntraeger, bpf,
Vasily Gorbik, Heiko Carstens
> The timed may_goto fixup now passes the resolved counter pointer through
> BPF_REG_AX instead of a stack offset.
>
> Use the pointer directly rather than adding it to RBP. This preserves the
> private-stack address selected by the JIT through R9.
>
> Fixes: 2fb761823ead ("bpf, x86: Add x86 JIT support for timed may_goto")
> Reported-by: Jeremy Jean <jeremy.jean@oss.cyber.gouv.fr>
> Link: https://lore.kernel.org/all/20260824213158.3755932-2-Jeremy.Jean@oss.cyber.gouv.fr/
> Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260904195132.141068-1-sidchintamaneni@gmail.com?part=2
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH bpf-next v1 5/7] bpf, riscv: Use resolved pointer for timed may_goto
2026-09-04 19:51 ` [PATCH bpf-next v1 5/7] bpf, riscv: " Siddharth Chintamaneni
2026-09-04 19:57 ` sashiko-bot
@ 2026-09-04 20:33 ` bot+bpf-ci
1 sibling, 0 replies; 18+ messages in thread
From: bot+bpf-ci @ 2026-09-04 20:33 UTC (permalink / raw)
To: sidchintamaneni, bpf
Cc: sidchintamaneni, jeremy.jean, ast, daniel, john.fastabend, andrii,
eddyz87, memxor, martin.lau, song, yonghong.song, jolsa, emil,
ihor.solodrai, a.s.protopopov, puranjay, linuxppc-dev, linux-s390,
linux-riscv, rlmenge, hargar, apais, ast, andrii, daniel,
martin.lau, eddyz87, yonghong.song, mason, ihor.solodrai
[-- Attachment #1: Type: text/plain, Size: 3625 bytes --]
> bpf, riscv: Use resolved pointer for timed may_goto
>
> The timed may_goto fixup now passes the resolved counter pointer through
> BPF_REG_AX instead of a stack offset.
>
> Copy the pointer directly into the first argument register rather than
> adding it to the BPF frame pointer again.
>
> Fixes: 6ef8ff20c30b ("bpf, riscv: Add support for timed may_goto")
Should the Fixes: tag point to d8319a04dafc ("bpf: Fix timed may_goto
stack pointer for private stacks") instead? That commit changed the
calling convention from passing a stack offset to passing a resolved
pointer through BPF_REG_AX, which is what broke the riscv trampoline.
The original riscv implementation (6ef8ff20c30b) worked correctly with
the original calling convention. riscv64 cannot hit the private-stack bug
that d8319a04dafc targeted: it does not implement
bpf_jit_supports_private_stack(), so the __weak default in
kernel/bpf/core.c returns false, and private stacks are gated on it in
kernel/bpf/verifier.c. On riscv, regmap[BPF_REG_FP] = RV_REG_S5 is the
one and only BPF frame pointer, and the pre-patch 'add a0, t0, s5'
computed exactly the right address.
What this patch actually does on riscv is adapt to the new BPF_REG_AX
calling convention introduced by d8319a04dafc, which is patch 1 of the
same series. If stable/AUTOSEL tooling picks this commit up on the
strength of its Fixes: tag without also taking d8319a04dafc, BPF_REG_AX
still holds the raw immediate from the old fixup (BPF_MOV64_IMM(BPF_REG_AX,
stack_off_cnt), i.e. -stack_depth-16, up to -528):
mv a0, t0 /* a0 = -528, not a pointer */
call bpf_check_timed_may_goto
bpf_check_timed_may_goto() then dereferences p->timestamp
(kernel/bpf/core.c) at 0xfffffffffffffdf0, oopsing on every timed
may_goto loop.
Should the changelog also declare that d8319a04dafc is a prerequisite
for this patch?
Because d8319a04dafc lands first and each architecture is converted in a
later commit, riscv64 (and arm64, powerpc64, s390) BPF timed may_goto is
broken at every intermediate commit of the series. Does the series need to
be structured differently to remain bisectable for those architectures?
> diff --git a/arch/riscv/net/bpf_timed_may_goto.S b/arch/riscv/net/bpf_timed_may_goto.S
> index 02c637d87420..8c03e272e0bf 100644
> --- a/arch/riscv/net/bpf_timed_may_goto.S
> +++ b/arch/riscv/net/bpf_timed_may_goto.S
> @@ -6,12 +6,11 @@
>
> /*
> * Trampoline for the BPF timed may_goto loop bound. Custom calling convention:
> - * - input: stack offset in BPF_REG_AX (t0)
> + * - input: count and timestamp pointer in BPF_REG_AX (t0)
> * - output: updated count in BPF_REG_AX (t0)
> *
> - * Calls bpf_check_timed_may_goto(ptr) with the standard RISC-V ABI, where
> - * ptr = BPF_REG_FP (s5) + BPF_REG_AX (t0). BPF R0-R5 (a5, a0-a4) are saved
> - * across the call; BPF_REG_FP (s5) is callee-saved and needs no saving.
> + * Calls bpf_check_timed_may_goto(ptr) with the standard RISC-V ABI.
> + * BPF R0-R5 (a5, a0-a4) are saved across the call.
> */
>
> SYM_FUNC_START(arch_bpf_timed_may_goto)
> @@ -28,7 +27,11 @@ SYM_FUNC_START(arch_bpf_timed_may_goto)
> REG_S a3, 1*SZREG(sp)
> REG_S a4, 0*SZREG(sp)
>
> - add a0, t0, s5
> + /*
> + * BPF_REG_AX (t0) contains the count and timestamp pointer; pass it as
> + * the first argument in a0.
> + */
> + mv a0, t0
> call bpf_check_timed_may_goto
> mv t0, a0
>
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/33914557238
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH bpf-next v1 2/7] bpf, x86: Use resolved pointer for timed may_goto
2026-09-04 19:51 ` [PATCH bpf-next v1 2/7] bpf, x86: Use resolved pointer for timed may_goto Siddharth Chintamaneni
2026-09-04 20:02 ` sashiko-bot
@ 2026-09-04 20:33 ` bot+bpf-ci
1 sibling, 0 replies; 18+ messages in thread
From: bot+bpf-ci @ 2026-09-04 20:33 UTC (permalink / raw)
To: sidchintamaneni, bpf
Cc: sidchintamaneni, jeremy.jean, ast, daniel, john.fastabend, andrii,
eddyz87, memxor, martin.lau, song, yonghong.song, jolsa, emil,
ihor.solodrai, a.s.protopopov, puranjay, linuxppc-dev, linux-s390,
linux-riscv, rlmenge, hargar, apais, ast, andrii, daniel,
martin.lau, eddyz87, yonghong.song, mason, ihor.solodrai
[-- Attachment #1: Type: text/plain, Size: 4408 bytes --]
> diff --git a/arch/x86/net/bpf_timed_may_goto.S b/arch/x86/net/bpf_timed_may_goto.S
> index 54c690cae190..6e9d9e7c2b1d 100644
> --- a/arch/x86/net/bpf_timed_may_goto.S
> +++ b/arch/x86/net/bpf_timed_may_goto.S
> @@ -11,12 +11,6 @@
> SYM_FUNC_START(arch_bpf_timed_may_goto)
> ANNOTATE_NOENDBR
>
> - /*
> - * r10 passes us stack depth, load the pointer to count and timestamp
> - * into r10 by adding it to BPF frame pointer.
> - */
> - leaq (%rbp, %r10, 1), %r10
> -
A subsystem pattern flags this as potentially concerning: This commit
changes the x86 trampoline to the new 'pointer in BPF_REG_AX' ABI, but the
producer side of that ABI was changed one commit earlier, in d8319a04dafc
("bpf: Fix timed may_goto stack pointer for private stacks"), which
rewrote kernel/bpf/fixups.c to emit:
insn_buf[4] = BPF_MOV64_REG(BPF_REG_AX, BPF_REG_FP);
insn_buf[5] = BPF_ALU64_IMM(BPF_ADD, BPF_REG_AX, stack_off_cnt);
At commit d8319a04dafc (i.e. HEAD~1), does x86 still execute
'leaq (%rbp, %r10, 1), %r10' on a register that already holds a resolved
pointer, producing r10 = rbp + (frame_ptr + stack_off_cnt) -- roughly
2*rbp, a non-canonical address?
bpf_check_timed_may_goto() then reads and writes p->timestamp / p->count
through it (kernel/bpf/core.c:3410). Would any BPF program containing
may_goto oops on x86_64 at that commit?
The same window exists for arm64, riscv, powerpc64 and s390, whose
trampolines are only converted in the four later commits d35642770d98,
7053db7d3c0d, 6e03227c5677 and 20356163d51e. Is the tree bisectable across
the series?
The two halves carry different Fixes: tags (this one 2fb761823ead, the
fixups.c one e723608bf428), which invites a partial stable backport that
reintroduces exactly this wild-pointer write. Would squashing the fixups.c
ABI change with the arch trampoline updates, or ordering all arch updates
before the generic change, address the bisectability concern?
> /* Setup frame. */
> pushq %rbp
> movq %rsp, %rbp
The x86-only __xlated expectations for the timed may_goto expansion in
tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c were never
updated for the new 7-insn -> 8-insn sequence. The test expects:
__xlated("7: if r12 == 0x0 goto pc+6")
__xlated("8: r12 -= 1")
__xlated("9: if r12 != 0x0 goto pc+2")
__xlated("10: r12 = -24")
__xlated("11: call unknown")
__xlated("12: *(u64 *)(r10 -24) = r12")
Does this test fail on x86_64 for the whole series? Every line from index
7 onward is now wrong: the first branch becomes 'goto pc+7' (insn->off + 6
instead of insn->off + 5), the second becomes 'goto pc+3' instead of
'pc+2', 'r12 = -24' is replaced by the pair 'r12 = r10' / 'r12 += -24',
and the trailing indices shift by one ('call unknown' at 12, the store at
13, then 14 and 15).
git log 28bd77eb835b..8dc5c7d5340d shows the only selftest commit in the
series is 8dc5c7d5340d ("selftests/bpf: Test timed may_goto with private
stacks"), which adds new coverage but does not touch
verifier_bpf_fastcall.c. Note the original x86 JIT enablement commit
2fb761823ead -- the commit this patch lists in its Fixes: tag -- adjusted
this very test for the same reason, so the update belongs with the ABI
change.
> commit 28bd77eb835bc1a95190315e93afbc6bb186b9ff
> Author: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
>
> bpf, x86: Use resolved pointer for timed may_goto
>
> The timed may_goto fixup now passes the resolved counter pointer through
> BPF_REG_AX instead of a stack offset.
>
> Use the pointer directly rather than adding it to RBP. This preserves the
> private-stack address selected by the JIT through R9.
>
> Fixes: 2fb761823ead ("bpf, x86: Add x86 JIT support for timed may_goto")
^^^^^^^^^^^
The existing Fixes: tag points to commit 2fb761823ead, which is not an
ancestor of this fix and is on a different branch (bpf-next/res_spin_lock).
The bug was actually introduced by commit 47ab38f3f4d9 in this branch's
history, which added the incorrect code 'leaq (%rbp, %r10, 1), %r10' that
overwrites r10 instead of preserving it.
Should this use:
Fixes: 47ab38f3f4d9 ("adding ci files")
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/33914557238
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH bpf-next v1 6/7] bpf, s390: Use resolved pointer for timed may_goto
2026-09-04 19:51 ` [PATCH bpf-next v1 6/7] bpf, s390: " Siddharth Chintamaneni
2026-09-04 19:59 ` sashiko-bot
@ 2026-09-04 20:33 ` bot+bpf-ci
1 sibling, 0 replies; 18+ messages in thread
From: bot+bpf-ci @ 2026-09-04 20:33 UTC (permalink / raw)
To: sidchintamaneni, bpf
Cc: sidchintamaneni, jeremy.jean, ast, daniel, john.fastabend, andrii,
eddyz87, memxor, martin.lau, song, yonghong.song, jolsa, emil,
ihor.solodrai, a.s.protopopov, puranjay, linuxppc-dev, linux-s390,
linux-riscv, rlmenge, hargar, apais, ast, andrii, daniel,
martin.lau, eddyz87, yonghong.song, mason, ihor.solodrai
[-- Attachment #1: Type: text/plain, Size: 3280 bytes --]
> commit 20356163d51e7b8551f96780e7e969a26767c5c4
> Author: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
> AuthorDate: Fri Sep 4 19:51:31 2026 +0000
> Commit: Kernel Patches Daemon <kernel-patches-bot@fb.com>
> CommitDate: Fri Sep 4 13:03:02 2026 -0700
>
> bpf, s390: Use resolved pointer for timed may_goto
>
> The timed may_goto fixup now passes the resolved counter pointer through
> BPF_REG_AX instead of a stack offset and BPF frame pointer pair.
>
> Copy the pointer directly into the first argument register and update the
> special calling convention documentation.
>
> Fixes: b8efa810c1db ("s390/bpf: Add s390 JIT support for timed may_goto")
> Reported-by: Jeremy Jean <jeremy.jean@oss.cyber.gouv.fr>
> Link: https://lore.kernel.org/all/20260824213158.3755932-2-Jeremy.Jean@oss.cyber.gouv.fr/
> Assisted-by: Copilot:gpt-5.6-sol
> Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
Should the Fixes: tag point at b8efa810c1db?
At that commit the s390 trampoline was correct for the ABI in force at the
time. kernel/bpf/fixups.c emitted `insn_buf[4] = BPF_MOV64_IMM(BPF_REG_AX,
stack_off_cnt)`, so %r12 held a signed byte offset and `lay
%r2,0(%r12,%r13)` correctly resolved it against the s390 BPF frame pointer
%r13. Nothing was wrong with b8efa810c1db.
What makes the old code wrong is the parent commit in this series,
d8319a04dafc ("bpf: Fix timed may_goto stack pointer for private stacks"),
which replaced that with:
insn_buf[4] = BPF_MOV64_REG(BPF_REG_AX, BPF_REG_FP);
insn_buf[5] = BPF_ALU64_IMM(BPF_ADD, BPF_REG_AX, stack_off_cnt)
so that %r12 now carries an already-resolved pointer. Only after that does
`lay %r2,0(%r12,%r13)` double-add the frame pointer.
If a stable maintainer or AUTOSEL picks 20356163d51e on the strength of
its Fixes: tag without also taking d8319a04dafc, s390 is left with `lgr
%r2,%r12` while the fixup still puts a raw offset (stack_off_cnt =
-stack_depth - 16, e.g. -528) in %r12:
bpf_check_timed_may_goto(struct bpf_timed_may_goto *p)
then does `p->count` / `p->timestamp` loads and stores through a small
negative integer treated as a kernel pointer, which would trigger an oops
or memory corruption on every timed may_goto timeout.
The mirror case is equally bad: d8319a04dafc carries `Fixes:
e723608bf428` and will be selected for stable on its own, leaving s390
(and arm64/ppc64/riscv) double-adding the frame pointer.
The generic ABI change and its five arch consumers are not independently
correct, so either they belong in one commit, or the arch patches should
carry the same `Fixes: e723608bf428 ("bpf: Add verifier support for timed
may_goto")` and a `Cc: <stable@vger.kernel.org> # <sha>: <generic
commit>` prerequisite note. No Cc: stable and no prerequisite note is
present today.
Note: the same pattern is used by all four sibling commits (28bd77eb835b
x86, d35642770d98 arm64, 6e03227c5677 ppc64, 7053db7d3c0d riscv), so this
is a series-wide tagging decision rather than an s390-only slip.
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/33914557238
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2026-09-04 20:33 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-04 19:51 [PATCH bpf-next v1 0/7] Fix timed may_goto with private stacks Siddharth Chintamaneni
2026-09-04 19:51 ` [PATCH bpf-next v1 1/7] bpf: Fix timed may_goto stack pointer for " Siddharth Chintamaneni
2026-09-04 19:58 ` sashiko-bot
2026-09-04 19:51 ` [PATCH bpf-next v1 2/7] bpf, x86: Use resolved pointer for timed may_goto Siddharth Chintamaneni
2026-09-04 20:02 ` sashiko-bot
2026-09-04 20:33 ` bot+bpf-ci
2026-09-04 19:51 ` [PATCH bpf-next v1 3/7] bpf, arm64: " Siddharth Chintamaneni
2026-09-04 20:01 ` sashiko-bot
2026-09-04 19:51 ` [PATCH bpf-next v1 4/7] bpf, powerpc64: " Siddharth Chintamaneni
2026-09-04 19:58 ` sashiko-bot
2026-09-04 19:51 ` [PATCH bpf-next v1 5/7] bpf, riscv: " Siddharth Chintamaneni
2026-09-04 19:57 ` sashiko-bot
2026-09-04 20:33 ` bot+bpf-ci
2026-09-04 19:51 ` [PATCH bpf-next v1 6/7] bpf, s390: " Siddharth Chintamaneni
2026-09-04 19:59 ` sashiko-bot
2026-09-04 20:33 ` bot+bpf-ci
2026-09-04 19:51 ` [PATCH bpf-next v1 7/7] selftests/bpf: Test timed may_goto with private stacks Siddharth Chintamaneni
2026-09-04 19:58 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox