All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lukas Stockner" <lukas@lukasstockner.de>, bpf@vger.kernel.org
Subject: Re: [PATCH v2 5/7] powerpc32/bpf: fix MOV folding with in-place operations
Date: Tue, 01 Dec 2026 17:18:54 +0000	[thread overview]
Message-ID: <sashiko-outbox-243804@kernel.org> (raw)
In-Reply-To: <20261201165313.413960-6-lukas@lukasstockner.de>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] powerpc32/bpf: chained MOV folding via in-place MOV loses
  source in bpf_jit_build_body()
--

commit 2571d56115a2072d4ce2b83007a90bba1702c77c
Author: Lukas Stockner <lukas@lukasstockner.de>

powerpc32/bpf: fix MOV folding with in-place operations

This commit updates the 3-operand MOV+ALU folding in bpf_jit_build_body() to
use the MOV source register for both operands when the subsequent ALU
instruction reads from the MOV destination register.

> diff --git a/arch/powerpc/net/bpf_jit_comp32.c b/arch/powerpc/net/bpf_jit_comp32.c
> index c6cc562cf88c8..2c3d94c94ed78 100644
> --- a/arch/powerpc/net/bpf_jit_comp32.c
> +++ b/arch/powerpc/net/bpf_jit_comp32.c
> @@ -371,6 +371,10 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code
>  		    insn[i - 1].off == 0) {
>  			src2_reg = bpf_to_ppc(insn[i - 1].src_reg);
>  			src2_reg_h = src2_reg - 1;
> +			if (BPF_SRC(code) == BPF_X && insn[i].src_reg == insn[i - 1].dst_reg) {
> +				src_reg = src2_reg;
> +				src_reg_h = src2_reg_h;
> +			}
>  			ctx->idx = addrs[i - 1] / 4;
>  		}

[Severity: High]
Can this lose the original MOV source register when an in-place MOV (such as
"w2 = w2" for 32-bit zero-extension) sits between a MOV and a third ALU
instruction on the same destination register?

For a sequence like "r2 = r1; w2 = w2; w2 += w3":

1. At "w2 = w2" (i - 1), the new check folds it with "r2 = r1" (i - 2),
   rewinds ctx->idx to addrs[i - 2] / 4, records addrs[i - 1] = addrs[i - 2],
   and emits the move from r1 into r2.
2. At "w2 += w3" (i), insn[i - 1] is itself a BPF_MOV | BPF_X with
   dst_reg == r2, so it matches the folding check again.  However, src2_reg
   is read from the unmodified insn[i - 1].src_reg (r2 instead of r1), and
   ctx->idx is rewound to addrs[i - 1] / 4 (which equals addrs[i - 2] / 4).

The emitted instruction for "w2 += w3" then overwrites the move from r1 and
computes r2 = r2 + r3 using the stale value of r2 instead of r1.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201165313.413960-1-lukas@lukasstockner.de?part=5

  reply	other threads:[~2026-12-01 17:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 16:53 [PATCH v2 0/7] powerpc32/bpf: fix BPF-to-BPF calls and instruction folding Lukas Stockner
2026-12-01 16:53 ` [PATCH v2 1/7] powerpc32/bpf: fix argument passing for subprograms Lukas Stockner
2026-12-01 16:53 ` [PATCH v2 2/7] powerpc32/bpf: fetch fifth argument in BPF subprograms Lukas Stockner
2026-12-01 16:53 ` [PATCH v2 3/7] powerpc32/bpf: mark all argument registers seen in function calls Lukas Stockner
2026-12-01 17:46   ` bot+bpf-ci
2026-12-01 16:53 ` [PATCH v2 4/7] powerpc32/bpf: don't fold MOVSX into following instruction Lukas Stockner
2026-12-01 16:53 ` [PATCH v2 5/7] powerpc32/bpf: fix MOV folding with in-place operations Lukas Stockner
2026-12-01 17:18   ` sashiko-bot [this message]
2026-12-01 16:53 ` [PATCH v2 6/7] powerpc32/bpf: use src2_reg for all ALU operations Lukas Stockner
2026-12-01 17:13   ` sashiko-bot
2026-12-01 16:53 ` [PATCH v2 7/7] powerpc32/bpf: don't fold MOV into jump targets Lukas Stockner
2026-12-01 17:24   ` sashiko-bot
2026-12-01 17:46   ` bot+bpf-ci

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=sashiko-outbox-243804@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=lukas@lukasstockner.de \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.