Skip to content

powerpc32/bpf: fix BPF-to-BPF calls and instruction folding

Lukas Stockner bpf linuxppc-dev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4powerpc32/bpf: fix argument passing for subprogramsarch/powerpc/net/bpf_jit_comp32.c+12 -41 reply
2/4powerpc32/bpf: fetch fifth argument in BPF subprogramsarch/powerpc/net/bpf_jit_comp32.c+7 -00 replies
3/4powerpc32/bpf: mark all argument registers seen in function callsarch/powerpc/net/bpf_jit_comp32.c+16 -10 replies
4/4powerpc32/bpf: don't fold MOV into instructions that use dst_regarch/powerpc/net/bpf_jit_comp32.c+2 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/4] powerpc32/bpf: fix BPF-to-BPF calls and instruction folding

This series fixes four 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 is for the 3-operand folding logic. 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 ALU operations.

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 this series to v6.6 and tested it on the WS-AP3715i, and with the fixes applied the CLAT program now works fine. A previous version of this series (before some cleanups) has also been deployed on several APs in production without problems.

Lukas Stockner (4):
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 MOV into instructions that use dst_reg

 arch/powerpc/net/bpf_jit_comp32.c | 43 ++++++++++++++++++++++++++-----
 1 file changed, 37 insertions(+), 6 deletions(-)
Signature · 1 line
2.56.0