From: Shivani Nittor <shivani@linux.ibm.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: maddy@linux.ibm.com, hbathini@linux.ibm.com, chleroy@kernel.org,
ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
eddyz87@gmail.com, shuah@kernel.org, bpf@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] powerpc/bpf: Support indirect calls to BPF subprograms
Date: Mon, 30 Nov 2026 12:33:06 +0530 [thread overview]
Message-ID: <20261130070307.126765-1-shivani@linux.ibm.com> (raw)
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
next reply other threads:[~2026-11-30 7:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 7:03 Shivani Nittor [this message]
2026-11-30 7:03 ` [PATCH 2/2] selftests/bpf: Add callx tests for PPC64 Shivani Nittor
2026-11-30 7:15 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130070307.126765-1-shivani@linux.ibm.com \
--to=shivani@linux.ibm.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chleroy@kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=hbathini@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox