Le 22/11/2026 à 20:42, Lukas Stockner a écrit :
[Vous ne recevez pas souvent de courriers de [email protected]. Découvrez
pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ]
The PPC32 eBPF JIT folds MOVs followed by an ALU operation to the same
destination into 3-operand PPC instructions by dropping the MOV and
reusing its source as the second operand for the second instruction.
That is wrong when the second instruction also uses the destination
register as its source, since the MOV that would have assigned it
is dropped, so the folded instruction will end up using the previous
content of the register.
For example, "r2 = r1; r2 += r2" gets folded to "r2 = r1 + r2", while
the correct result would be 2 * r1.
You exemple is "r2 = r1; r2 = r2 + r2", it should become "r2 = r1 + r1".
I think you should do that instead:
diff --git a/arch/powerpc/net/bpf_jit_comp32.c
b/arch/powerpc/net/bpf_jit_comp32.c
index bfdc50740da8..a2ec60f2f5da 100644
--- a/arch/powerpc/net/bpf_jit_comp32.c
+++ b/arch/powerpc/net/bpf_jit_comp32.c
@@ -355,6 +355,10 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32
*image, u32 *fimage, struct code
insn[i - 1].dst_reg == insn[i].dst_reg && insn[i - 1].imm
!= 1) {
src2_reg = bpf_to_ppc(insn[i - 1].src_reg);
src2_reg_h = src2_reg - 1;
+ if (src_reg == dst_reg) {
+ src_reg = src2_reg;
+ src_reg_h = src2_reg_h;
+ }
ctx->idx = addrs[i - 1] / 4;
}
In particular, this also happens for zero-extension MOVs inserted by the
verifier, where "r2 = r1; w2 = w2" becomes just "w2 = w2", so the actual
assignment is skipped.
What is w2 ?
Are you talking about the zero extension added by commit 8ecf3c1dab1c
("powerpc/bpf/32: Fix failing test_bpf tests") ? Maybe I missed
something in that commit which was after commit 19daf0aef84f.
Or you are just talking about the /* special mov32 for zext */ ? This
one is normally skipped by insn[i - 1].imm != 1
Fixes: 19daf0aef84f ("powerpc/bpf/32: perform three operands ALU operations")
Signed-off-by: Lukas Stockner <[email protected]>
---
arch/powerpc/net/bpf_jit_comp32.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/net/bpf_jit_comp32.c
b/arch/powerpc/net/bpf_jit_comp32.c
index 7414e350d2d4..3ba50d6696a2 100644
--- a/arch/powerpc/net/bpf_jit_comp32.c
+++ b/arch/powerpc/net/bpf_jit_comp32.c
@@ -367,7 +367,8 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32
*fimage, struct code
if (i && (BPF_CLASS(code) == BPF_ALU64 || BPF_CLASS(code) == BPF_ALU)
&&
(BPF_CLASS(prevcode) == BPF_ALU64 || BPF_CLASS(prevcode) ==
BPF_ALU) &&
BPF_OP(prevcode) == BPF_MOV && BPF_SRC(prevcode) == BPF_X
&&
- insn[i - 1].dst_reg == insn[i].dst_reg && insn[i - 1].imm
!= 1) {
+ insn[i - 1].dst_reg == insn[i].dst_reg && insn[i - 1].imm != 1
&&
+ !(BPF_SRC(code) == BPF_X && insn[i].src_reg ==
insn[i].dst_reg)) {
src2_reg = bpf_to_ppc(insn[i - 1].src_reg);
src2_reg_h = src2_reg - 1;
ctx->idx = addrs[i - 1] / 4;
What about that instead:
diff --git a/arch/powerpc/net/bpf_jit_comp32.c
b/arch/powerpc/net/bpf_jit_comp32.c
index bfdc50740da8..842498efa414 100644
--- a/arch/powerpc/net/bpf_jit_comp32.c
+++ b/arch/powerpc/net/bpf_jit_comp32.c
@@ -352,9 +352,14 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32
*image, u32 *fimage, struct code
if (i && (BPF_CLASS(code) == BPF_ALU64 || BPF_CLASS(code) == BPF_ALU)
&&
(BPF_CLASS(prevcode) == BPF_ALU64 || BPF_CLASS(prevcode) ==
BPF_ALU) &&
BPF_OP(prevcode) == BPF_MOV && BPF_SRC(prevcode) == BPF_X &&
- insn[i - 1].dst_reg == insn[i].dst_reg && insn[i - 1].imm
!= 1) {
+ insn[i - 1].dst_reg == insn[i].dst_reg && insn[i - 1].imm != 1
&&
+ !insn[i - 1].off) {
src2_reg = bpf_to_ppc(insn[i - 1].src_reg);
src2_reg_h = src2_reg - 1;
+ if (src_reg == dst_reg) {
+ src_reg = src2_reg;
+ src_reg_h = src2_reg_h;
+ }
ctx->idx = addrs[i - 1] / 4;
}