Thread (14 messages) 14 messages, 3 authors, 7d ago

Re: [PATCH bpf-next v1 0/7] Fix timed may_goto with private stacks

From: Siddharth Chintamaneni <hidden>
Date: 2026-09-21 16:25:03
Also in: bpf, linux-riscv, linux-s390

<SNIP>
I think we can keep this fix local to x86. Would be less churn in the end.

The problem is that x86 switches the BPF frame pointer from RBP to R9 for
private stacks, but the trampoline still uses RBP. arm64 and powerpc64 keep
using X25 and R31 respectively for both stack modes, so their trampolines
already use the right frame pointer.

Instead of changing the generic fixup, can we resolve the pointer in the x86 JIT
when emitting the call to arch_bpf_timed_may_goto()? We already know whether
priv_frame_ptr is set there. R10 contains the offset passed through BPF_REG_AX,
so we can emit:

/* Private stack */
leaq (%r9, %r10), %r10

/* Normal stack */
leaq (%rbp, %r10), %r10

Then remove the LEA from the x86 trampoline, as patch 2 already does.
make sense! I thought that the remaining arch's have a similar private
stacks approach to x86. I'll give it a try and re-spin the patch.
This gives bpf_check_timed_may_goto() the same address used by the generated
loads and stores: the BPF frame pointer plus the counter’s stack offset. For
normal stacks, we just move the existing calculation into the JIT. For private
stacks, we use R9 instead of RBP, which fixes the mismatch.

The existing save/restore of R9 around the call should stay. We also leave RBP
alone, since it is still needed for the native frame chain and unwinding.

I haven’t tested this approach, so it still needs checking with both normal and
private stacks.

pw-bot: cr
quoted
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
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help