[PATCH bpf-next 5/5] bpf, x86: Add unconditional byte swap to the i386 JIT

From: Nicholas Dudar

Date: Mon Sep 14 2026 - 22:22:30 EST


The i386 JIT rejects unconditional BPF byte-swap instructions, which use
BPF_ALU64 | BPF_END.

Route them through the existing big-endian conversion emitter. On
little-endian i386, it provides the same 16-, 32- and 64-bit byte swaps.
The verifier treats sub-64-bit BPF_END results as 32-bit definitions and
inserts zero extension where the upper word is used. The emitter clears
that word itself when verifier_zext is disabled.

Assisted-by: Codex:gpt-6
Signed-off-by: Nicholas Dudar <main.kalliope@xxxxxxxxx>
---
arch/x86/net/bpf_jit_comp32.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/x86/net/bpf_jit_comp32.c b/arch/x86/net/bpf_jit_comp32.c
index 2d8a3a961e91..bdba05b72ef3 100644
--- a/arch/x86/net/bpf_jit_comp32.c
+++ b/arch/x86/net/bpf_jit_comp32.c
@@ -2037,6 +2037,8 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image,
break;
/* dst = htobe(dst) */
case BPF_ALU | BPF_END | BPF_FROM_BE:
+ /* dst = bswap(dst) */
+ case BPF_ALU64 | BPF_END | BPF_FROM_LE:
emit_ia32_to_be_r64(dst, imm32, dstk, &prog,
bpf_prog->aux);
break;