Skip to contentSkip to conversation

powerpc64/bpf: Add powerpc64 JIT support for timed may_goto

PATCH Applied Saket Kumar Bhaskar 2 participants 2 messages Apr 3 – Jun 19

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 powerpc64/bpf: Add powerpc64 JIT support for timed may_goto

When verifier sees a timed may_goto instruction, it emits a call to arch_bpf_timed_may_goto() with a stack offset in BPF_REG_AX (powerpc64 R12) and expects the refreshed count value to be returned in the same register. The verifier doesn't save or restore any registers before emitting this call.

arch_bpf_timed_may_goto() should act as a trampoline to call bpf_check_timed_may_goto() with powerpc64 ELF ABI calling convention.

To support this custom calling convention, implement arch_bpf_timed_may_goto() in assembly and make sure BPF caller saved registers are preserved, then call bpf_check_timed_may_goto with the powerpc64 ABI calling convention where first argument and return value both are in R3. Finally, move the result back into BPF_REG_AX(R12) before returning.

Also, introduce bpf_jit_emit_func_call() that computes the offset from kernel_toc_addr(), validates that the target and emits the ADDIS/ADDI sequence to load the function address before performing the indirect branch via MTCTR/BCTRL. The existing code in bpf_jit_emit_func_call_rel() is refactored to use this function.

---
This patch has been rebased on top of these 3 patches on powerpc-next in the following sequence:
1. https://lore.kernel.org/bpf/[email protected]/
2. https://lore.kernel.org/bpf/[email protected]/
3. https://lore.kernel.org/bpf/[email protected]/

Changes since v1:
- Compile bpf_timed_may_goto.o conditionally for PPC64. (Hari)
- Moved reladdr at the beginning of the function. (Hari)
- Added error check for bpf_jit_emit_func_call() in bpf_jit_build_body(). (Hari)
- Save registers after 32 bytes as MIN_FRAME_SIZE is 32 bytes for powerpc ABIv2. (Hari)

v1: https://lore.kernel.org/bpf/[email protected]/

Changes since v2:
- Removed spurious + that slipped into the patch.

v2: https://lore.kernel.org/bpf/[email protected]/

---
 arch/powerpc/net/Makefile             |  4 ++
 arch/powerpc/net/bpf_jit_comp.c       |  5 +++
 arch/powerpc/net/bpf_jit_comp64.c     | 62 ++++++++++++++++++++++-----
 arch/powerpc/net/bpf_timed_may_goto.S | 57 ++++++++++++++++++++++++
 4 files changed, 117 insertions(+), 11 deletions(-)
 create mode 100644 arch/powerpc/net/bpf_timed_may_goto.S
arch/powerpc/net/Makefile +4 -0
index 8e60af32e51e..7f9339bacef1 100644
@@ -3,3 +3,7 @@
 # Arch-specific network modules
 #
 obj-$(CONFIG_BPF_JIT) += bpf_jit_comp.o bpf_jit_comp$(BITS).o
+
+ifdef CONFIG_PPC64
+obj-$(CONFIG_BPF_JIT) += bpf_timed_may_goto.o
+endif
arch/powerpc/net/bpf_jit_comp.c +5 -0
index 50103b3794fb..9b2b456b0765 100644
@@ -537,6 +537,11 @@ bool bpf_jit_supports_subprog_tailcalls(void)
 	return IS_ENABLED(CONFIG_PPC64);
 }
 
+bool bpf_jit_supports_timed_may_goto(void)
+{
+	return IS_ENABLED(CONFIG_PPC64);
+}
+
 bool bpf_jit_supports_kfunc_call(void)
 {
 	return IS_ENABLED(CONFIG_PPC64);
arch/powerpc/net/bpf_jit_comp64.c +51 -11

83 lines not on this page · raw message

arch/powerpc/net/bpf_timed_may_goto.S new file +57 -0

57 lines not on this page · raw message

Signature · 1 line
2.52.0
maintainer Applied
#1 lore raw
Quoted 10 lines · Saket Kumar Bhaskar

When verifier sees a timed may_goto instruction, it emits a call to arch_bpf_timed_may_goto() with a stack offset in BPF_REG_AX (powerpc64 R12) and expects the refreshed count value to be returned in the same register. The verifier doesn't save or restore any registers before emitting this call.

arch_bpf_timed_may_goto() should act as a trampoline to call bpf_check_timed_may_goto() with powerpc64 ELF ABI calling convention.

[...]

Applied to powerpc/next.

[1/1] powerpc64/bpf: Add powerpc64 JIT support for timed may_goto

      https://git.kernel.org/powerpc/c/b55b6b9ad76cdb82123c62a15c6a4ebe4abb8bfa

cheers