LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>
To: Lukas Stockner <lukas@lukasstockner.de>,
	Hari Bathini <hbathini@linux.ibm.com>,
	bpf@vger.kernel.org, linuxppc-dev@lists.ozlabs.org
Cc: Naveen N Rao <naveen@kernel.org>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>
Subject: Re: [PATCH 1/4] powerpc32/bpf: fix argument passing for subprograms
Date: Mon, 23 Nov 2026 08:46:22 +0100	[thread overview]
Message-ID: <91f869ee-8a2f-4016-8b91-893d26692b0f@kernel.org> (raw)
In-Reply-To: <20261122194205.218543-2-lukas@lukasstockner.de>



Le 22/11/2026 à 20:42, Lukas Stockner a écrit :
> [Vous ne recevez pas souvent de courriers de lukas@lukasstockner.de. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ]
> 
> Main programs receive a single 32-bit pointer as the first argument,
> so the current prologue converts it to the 64-bit BPF_REG_1 by moving
> R3 to R4 and zeroing R3.
> 
> However, subprograms are called like helper functions, so there the first
> argument already is 64-bit - but the prologue still does its conversion,
> so the argument ends up with its halves swapped and the upper one zeroed.
> The same problem applies to the return value.
> 
> In particular, in the common case where the first argument is a context
> pointer, the callee ends up with the upper (zeroed) 32 bits, which then
> triggers a kernel panic as soon as it's used.
> 
> Therefore, make JIT emit the appropriate 64-bit prologue/epilogue for
> subprograms.
> 
> Fixes: 51c66ad849a7 ("powerpc/bpf: Implement extended BPF on PPC32")

Take care ctx->is_subprog only exists since commit 2ed2d8f6fb38 
("powerpc64/bpf: Support tailcalls with subprogs") which means automatic 
backport won't work.

> Signed-off-by: Lukas Stockner <lukas@lukasstockner.de>
> ---
>   arch/powerpc/net/bpf_jit_comp32.c | 16 ++++++++++++----
>   1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/powerpc/net/bpf_jit_comp32.c b/arch/powerpc/net/bpf_jit_comp32.c
> index f5b9441cf46a..261ac0646b96 100644
> --- a/arch/powerpc/net/bpf_jit_comp32.c
> +++ b/arch/powerpc/net/bpf_jit_comp32.c
> @@ -179,9 +179,11 @@ void bpf_jit_build_prologue(u32 *image, struct codegen_context *ctx)
>          if (ctx->seen & SEEN_TAILCALL)
>                  EMIT(PPC_RAW_STW(_R4, _R1, bpf_jit_stack_offsetof(ctx, BPF_PPC_TC)));
> 
> -       /* First arg comes in as a 32 bits pointer. */
> -       EMIT(PPC_RAW_MR(bpf_to_ppc(BPF_REG_1), _R3));
> -       EMIT(PPC_RAW_LI(bpf_to_ppc(BPF_REG_1) - 1, 0));
> +       /* Programs receive the first arg as a 32 bits pointer, subprograms don't. */
> +       if (!ctx->is_subprog) {
> +               EMIT(PPC_RAW_MR(bpf_to_ppc(BPF_REG_1), _R3));
> +               EMIT(PPC_RAW_LI(bpf_to_ppc(BPF_REG_1) - 1, 0));
> +       }
> 
>          /*
>           * We need a stack frame, but we don't necessarily need to
> @@ -231,7 +233,13 @@ static void bpf_jit_emit_common_epilogue(u32 *image, struct codegen_context *ctx
> 
>   void bpf_jit_build_epilogue(u32 *image, u32 *fimage, struct codegen_context *ctx)
>   {
> -       EMIT(PPC_RAW_MR(_R3, bpf_to_ppc(BPF_REG_0)));
> +       /* Programs return a 32-bit value, while subprograms return 64 bit. */
> +       if (ctx->is_subprog) {
> +               EMIT(PPC_RAW_MR(_R3, bpf_to_ppc(BPF_REG_0) - 1));
> +               EMIT(PPC_RAW_MR(_R4, bpf_to_ppc(BPF_REG_0)));
> +       } else {
> +               EMIT(PPC_RAW_MR(_R3, bpf_to_ppc(BPF_REG_0)));
> +       }
> 
>          bpf_jit_emit_common_epilogue(image, ctx);
> 
> --
> 2.56.0
> 



  reply	other threads:[~2026-11-23  7:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 19:42 [PATCH 0/4] powerpc32/bpf: fix BPF-to-BPF calls and instruction folding Lukas Stockner
2026-11-22 19:42 ` [PATCH 1/4] powerpc32/bpf: fix argument passing for subprograms Lukas Stockner
2026-11-23  7:46   ` Christophe Leroy (CS GROUP) [this message]
2026-11-22 19:42 ` [PATCH 2/4] powerpc32/bpf: fetch fifth argument in BPF subprograms Lukas Stockner
2026-11-22 19:42 ` [PATCH 3/4] powerpc32/bpf: mark all argument registers seen in function calls Lukas Stockner
2026-11-22 19:42 ` [PATCH 4/4] powerpc32/bpf: don't fold MOV into instructions that use dst_reg Lukas Stockner
2026-11-22 20:14   ` bot+bpf-ci
2026-11-28 18:32   ` Christophe Leroy (CS GROUP)

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=91f869ee-8a2f-4016-8b91-893d26692b0f@kernel.org \
    --to=chleroy@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=hbathini@linux.ibm.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=lukas@lukasstockner.de \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=naveen@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