From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796120448; b=bwcx62a/Xp1OiJWhcojXpA8JeNrV35605WEne88fxPpZEHbzwev7GoVnMgIuieezrBRW TQvbLunRsvsAhEl7MLudGdKr4SEEzgUqfgqdweEBO5u1Iev2Q8GyCy+6zhwh0+vFDyQKC Ye/Ui4V9MHMccKIiD0w/dleFxuzOf3BDuD3nWegFnshZUyPUvxp8z6j3KWDdHuTBdQfO4 egvF/E3NVToa1uebh5pR3jjg0xgKaXmtR5/hDIpAdrpN1yhlU0j3nfnW8ZMItdNVQjSdN OBskpdDMoTmUr/ocrgQnnb7NR7rcdgW4RB1dGDs6RNTHAOasB8yxgOuc8sHRULgFFog== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796120448; h=Received:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=YzToTHgXqSTtGvFpeZieabWJRRGRa42FKF51rGD34kY=; b=QIVzv/ac4mzRXqnfZgZJUPZIbLHzChsUSpenqHyRf7V4jigR+AL/M7niFG7PWqaPXFt5 SuQdFd+tEj1IjOMosagO9UM7SUSxtorS7bf2jg4qOMto+oiUUtvv5zxSqIBHmWkdbA4c2 2gBLo9rH0Md+4fXHrckGR7tCbfTzRmgGuepLBPC2DAzgmNb7FugcdL3bmTxgSNQwNmOrx GaaMP/NmqJTOMYU5rJdp3MsV+lxZVLSby8JJfbUWHBQ/ju/4sXPwxymSYa7OH8b2+HTjb 7C2uV6CEFzlcToUEk/heN/tl7/N4tOrKdXRcvwtw/j1h1QwIw4UttnZnpelkZivpgcg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bUSvtLfz; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A91E606A320; Tue, 1 Dec 2026 10:20:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bUSvtLfz Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9DD71F0089C; Tue, 1 Dec 2026 10:20:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796120447; bh=YzToTHgXqSTtGvFpeZieabWJRRGRa42FKF51rGD34kY=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=bUSvtLfzDEXS1JiZN7t3D6XT4rmQL13fpGJfain8WmC5ruW6UDzdIPRr5x3rfg5S+ NeMyDEGDkkAA1ywqVgHXGjIUiGYYzySRmGqZfpVmo8BmrcjC65ieBg5JVvMNV4ux6W JqPl+v29UTV5/6jhqvy7JoK+xEX6jvIDTlxDLjeVNL3+p3gG9DzROCHeYCENEOTlzd WH15HqnzbV5EGNiLZyxpyoWMY/4Cbo/0e1XnN8WLGvk7PeBX5uFBuLjOlCQTrwvowo z66qrWskcOrHqmvdhlvz31b4IV2muAU5DywA1D4czGHiDX00FgsccRDGb3P1crPWg/ CRbwD3i2z2JpQ== Message-ID: <210531b3-3c45-4bc2-ae94-585a455957bd@kernel.org> Date: Tue, 1 Dec 2026 11:20:41 +0100 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] powerpc/bpf: Support indirect calls to BPF subprograms To: Shivani Nittor , 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 References: <20261130070307.126765-1-shivani@linux.ibm.com> Content-Language: fr-FR From: "Christophe Leroy (CS GROUP)" In-Reply-To: <20261130070307.126765-1-shivani@linux.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 > --- > 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 > */