BPF List
 help / color / mirror / Atom feed
* [PATCH v2 0/7] powerpc32/bpf: fix BPF-to-BPF calls and instruction folding
@ 2026-12-01 16:53 Lukas Stockner
  2026-12-01 16:53 ` [PATCH v2 1/7] powerpc32/bpf: fix argument passing for subprograms Lukas Stockner
                   ` (6 more replies)
  0 siblings, 7 replies; 13+ messages in thread
From: Lukas Stockner @ 2026-12-01 16:53 UTC (permalink / raw)
  To: Hari Bathini, Christophe Leroy, Naveen N Rao, bpf, linuxppc-dev
  Cc: Madhavan Srinivasan, Michael Ellerman, Alexei Starovoitov,
	Daniel Borkmann, Andrii Nakryiko, Lukas Stockner

This series fixes several bugs in the 32-bit PowerPC eBPF JIT.

The current function prologue/epilogue assumes the calling convention for
main programs, while generated calls follow helper calling convention.
Therefore, patch 1 makes it generate a helper-style prologue/epilogue for
subprograms instead.

Patch 2 and 3 are needed to fix the additional arguments in subprograms.
Currently, the fifth argument is not being loaded in the prologue, and
all of them may be overwritten by register reallocation logic when they're
only passed on to another call.

Patch 4-7 are for the 3-operand folding logic.
First, the code wasn't updated when MOVSX was added, so it currently gets
folded away as if it was a regular MOV. Patch 4 adds a check for this.
When the second instruction uses the same source and destination register,
the current folding doesn't work because it will end up using the previous
value of the register, even though it should have been written by the
first instruction. We encountered this for the case of verifier-inserted
zero-extension MOVs, but it also affects other ops. Patch 5 fixes this.
Additionally, several ALU operations currently don't handle the folded
second operand correctly, so Patch 6 fixes them.
Finally, Patch 7 prevents the JIT from folding instructions if the second
one is a jump target, since the jump would otherwise target the folded
result and incorrectly also execute the MOV.

Testing:
We found these bugs in an eBPF-based CLAT program on various WiFi APs,
where it would trigger kernels panics on PPC32 hardware (e.g. Enterasys
WS-AP3715i with Freescale P1010 CPU).
While working on the fixes, I tested in QEMU on g3beige using small
reproducers (generated by GLM 5.3 Flash).
Afterwards, we backported v1 of this series to v6.6 and tested it on the
WS-AP3715i, and with the fixes applied the CLAT program now works fine.
A WIP version of this series has also been deployed on several APs in
production without problems.

Lukas Stockner (7):
  powerpc32/bpf: fix argument passing for subprograms
  powerpc32/bpf: fetch fifth argument in BPF subprograms
  powerpc32/bpf: mark all argument registers seen in function calls
  powerpc32/bpf: don't fold MOVSX into following instruction
  powerpc32/bpf: fix MOV folding with in-place operations
  powerpc32/bpf: use src2_reg for all ALU operations
  powerpc32/bpf: don't fold MOV into jump targets

---
v1 -> v2: Reworked MOV folding patch to fix additional issues
v1: https://lore.kernel.org/bpf/20261122194205.218543-1-lukas@lukasstockner.de/

 arch/powerpc/net/bpf_jit.h        |  4 +-
 arch/powerpc/net/bpf_jit_comp.c   |  8 +--
 arch/powerpc/net/bpf_jit_comp32.c | 83 ++++++++++++++++++++++++++-----
 arch/powerpc/net/bpf_jit_comp64.c |  5 +-
 include/linux/bpf.h               |  2 +
 kernel/bpf/core.c                 |  9 ++++
 6 files changed, 90 insertions(+), 21 deletions(-)

-- 
2.56.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-12-01 17:46 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 16:53 [PATCH v2 0/7] powerpc32/bpf: fix BPF-to-BPF calls and instruction folding Lukas Stockner
2026-12-01 16:53 ` [PATCH v2 1/7] powerpc32/bpf: fix argument passing for subprograms Lukas Stockner
2026-12-01 16:53 ` [PATCH v2 2/7] powerpc32/bpf: fetch fifth argument in BPF subprograms Lukas Stockner
2026-12-01 16:53 ` [PATCH v2 3/7] powerpc32/bpf: mark all argument registers seen in function calls Lukas Stockner
2026-12-01 17:46   ` bot+bpf-ci
2026-12-01 16:53 ` [PATCH v2 4/7] powerpc32/bpf: don't fold MOVSX into following instruction Lukas Stockner
2026-12-01 16:53 ` [PATCH v2 5/7] powerpc32/bpf: fix MOV folding with in-place operations Lukas Stockner
2026-12-01 17:18   ` sashiko-bot
2026-12-01 16:53 ` [PATCH v2 6/7] powerpc32/bpf: use src2_reg for all ALU operations Lukas Stockner
2026-12-01 17:13   ` sashiko-bot
2026-12-01 16:53 ` [PATCH v2 7/7] powerpc32/bpf: don't fold MOV into jump targets Lukas Stockner
2026-12-01 17:24   ` sashiko-bot
2026-12-01 17:46   ` bot+bpf-ci

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox