From: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>
To: Shivani Nittor <shivani@linux.ibm.com>, linuxppc-dev@lists.ozlabs.org
Cc: maddy@linux.ibm.com, hbathini@linux.ibm.com, 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: Re: [PATCH 1/2] powerpc/bpf: Support indirect calls to BPF subprograms
Date: Tue, 1 Dec 2026 11:20:41 +0100 [thread overview]
Message-ID: <210531b3-3c45-4bc2-ae94-585a455957bd@kernel.org> (raw)
In-Reply-To: <20261130070307.126765-1-shivani@linux.ibm.com>
Le 30/11/2026 à 08:03, Shivani Nittor a écrit :
> 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.
Can you also add support for PPC32:
diff --git a/arch/powerpc/net/bpf_jit_comp.c
b/arch/powerpc/net/bpf_jit_comp.c
index 233ea7472a15..c2bd925b21f0 100644
--- a/arch/powerpc/net/bpf_jit_comp.c
+++ b/arch/powerpc/net/bpf_jit_comp.c
@@ -566,7 +566,7 @@ bool bpf_jit_supports_subprog_tailcalls(void)
bool bpf_jit_supports_callx(void)
{
- return IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2);
+ return IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2) || IS_ENABLED(CONFIG_PPC32);
}
bool bpf_jit_supports_timed_may_goto(void)
diff --git a/arch/powerpc/net/bpf_jit_comp32.c
b/arch/powerpc/net/bpf_jit_comp32.c
index f5b9441cf46a..2ec64a4e53e1 100644
--- a/arch/powerpc/net/bpf_jit_comp32.c
+++ b/arch/powerpc/net/bpf_jit_comp32.c
@@ -1157,6 +1157,19 @@ 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
+ */
+ case BPF_JMP | BPF_CALL | BPF_X:
+ ctx->seen |= SEEN_FUNC;
+
+ EMIT(PPC_RAW_MTCTR(dst_reg));
+ EMIT(PPC_RAW_BCTRL());
+
+ EMIT(PPC_RAW_MR(bpf_to_ppc(BPF_REG_0) - 1, _R3));
+ EMIT(PPC_RAW_MR(bpf_to_ppc(BPF_REG_0), _R4));
+ break;
+
/*
* Call kernel helper or bpf function
*/
>
> 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
> */
prev parent reply other threads:[~2026-12-01 10:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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
2026-11-30 7:15 ` sashiko-bot
2026-12-01 10:29 ` Christophe Leroy (CS GROUP)
2026-12-01 10:20 ` Christophe Leroy (CS GROUP) [this message]
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=210531b3-3c45-4bc2-ae94-585a455957bd@kernel.org \
--to=chleroy@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.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=shivani@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.