LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] powerpc/bpf: Support indirect calls to BPF subprograms
@ 2026-11-30  7:03 Shivani Nittor
  2026-11-30  7:03 ` [PATCH 2/2] selftests/bpf: Add callx tests for PPC64 Shivani Nittor
  0 siblings, 1 reply; 2+ messages in thread
From: Shivani Nittor @ 2026-11-30  7:03 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: maddy, hbathini, chleroy, ast, daniel, andrii, eddyz87, shuah,
	bpf, linux-kselftest, linux-kernel

The BPF callx instruction allows indirect calls to BPF subprograms
through function pointers. Unlike direct calls, where the target
subprogram is known at JIT compilation time, callx requires the
target address to be obtained at runtime.

Add callx instruction support to the PowerPC BPF JIT for PPC64
ELF ABI v2.

Implement handling of BPF_CALL | BPF_X instructions by loading
the target register into the count register (CTR) using mtctr
and invoking the target subprogram using bctrl. Move the return
value from r3 into BPF_REG_0 after the call. Setting SEEN_FUNC
ensures the Link Register (LR) is preserved by the prologue and
epilogue.

Add bpf_jit_supports_callx() in bpf_jit_comp.c to indicate that
CALLX is supported when CONFIG_PPC64_ELF_ABI_V2 is enabled.

Signed-off-by: Shivani Nittor <shivani@linux.ibm.com>
---
 arch/powerpc/net/bpf_jit_comp.c   |  5 +++++
 arch/powerpc/net/bpf_jit_comp64.c | 21 +++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
index ce2966c52ac5..42762dc24198 100644
--- a/arch/powerpc/net/bpf_jit_comp.c
+++ b/arch/powerpc/net/bpf_jit_comp.c
@@ -564,6 +564,11 @@ bool bpf_jit_supports_subprog_tailcalls(void)
 	return IS_ENABLED(CONFIG_PPC64);
 }
 
+bool bpf_jit_supports_callx(void)
+{
+	return IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2);
+}
+
 bool bpf_jit_supports_timed_may_goto(void)
 {
 	return IS_ENABLED(CONFIG_PPC64);
diff --git a/arch/powerpc/net/bpf_jit_comp64.c b/arch/powerpc/net/bpf_jit_comp64.c
index c1e86fe0bd79..e5fda9cbb44b 100644
--- a/arch/powerpc/net/bpf_jit_comp64.c
+++ b/arch/powerpc/net/bpf_jit_comp64.c
@@ -1745,6 +1745,27 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code
 			/* else fall through to the epilogue */
 			break;
 
+		/*
+		 * Indirect call to a BPF subprogram
+		 * Supported only on PPC64 ELF ABI v2 (gated via
+		 * bpf_jit_supports_callx()).
+		 *
+		 * Note: The verifier guarantees that the target is a JITed BPF
+		 * subprog, whose prologue does not depend on r12 (the ELFv2
+		 * global entry point convention): r2 is reloaded from
+		 * paca->kernel_toc, or isn't used with PCREL. So the target
+		 * only needs to be in CTR, and r12 need not be set up.
+		 */
+		case BPF_JMP | BPF_CALL | BPF_X:
+			ctx->seen |= SEEN_FUNC;
+
+			EMIT(PPC_RAW_MTCTR(dst_reg));
+			EMIT(PPC_RAW_BCTRL());
+
+			/* Move return value from r3 to BPF_REG_0 */
+			EMIT(PPC_RAW_MR(bpf_to_ppc(BPF_REG_0), _R3));
+			break;
+
 		/*
 		 * Call kernel helper or bpf function
 		 */
-- 
2.52.0



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

end of thread, other threads:[~2026-11-30  7:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30  7:03 [PATCH 1/2] powerpc/bpf: Support indirect calls to BPF subprograms Shivani Nittor
2026-11-30  7:03 ` [PATCH 2/2] selftests/bpf: Add callx tests for PPC64 Shivani Nittor

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