From 89d8e19811f2b18c273fe4056d193e82afaa6e1a Mon Sep 17 00:00:00 2001 From: Johan Almbladh Date: Sat, 26 Sep 2026 01:19:31 +0200 Subject: [PATCH 1/2] bpf, mips: Add JIT support for unconditional BSWAP The unconditional BSWAP instruction from the eBPF v4 ISA was not implemented. This caused programs using the instruction to fall back to the interpreter. Implement the unconditional BSWAP instruction. Signed-off-by: Johan Almbladh Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20260925231932.1063678-2-johan.almbladh@anyfinetworks.com --- arch/mips/net/bpf_jit_comp32.c | 4 ++++ arch/mips/net/bpf_jit_comp64.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/arch/mips/net/bpf_jit_comp32.c b/arch/mips/net/bpf_jit_comp32.c index bbbe4a737825..158e69718c09 100644 --- a/arch/mips/net/bpf_jit_comp32.c +++ b/arch/mips/net/bpf_jit_comp32.c @@ -1701,6 +1701,10 @@ int build_insn(const struct bpf_insn *insn, struct jit_context *ctx) case BPF_ALU64 | BPF_MOD | BPF_X: emit_divmod_r64(ctx, dst, src, BPF_OP(code), off); break; + /* dst = bswap(dst) */ + case BPF_ALU64 | BPF_END: + emit_bswap_r64(ctx, dst, imm); + break; /* dst = htole(dst) */ /* dst = htobe(dst) */ case BPF_ALU | BPF_END | BPF_FROM_LE: diff --git a/arch/mips/net/bpf_jit_comp64.c b/arch/mips/net/bpf_jit_comp64.c index b04b68fa5ace..8359ad3f6992 100644 --- a/arch/mips/net/bpf_jit_comp64.c +++ b/arch/mips/net/bpf_jit_comp64.c @@ -876,6 +876,10 @@ int build_insn(const struct bpf_insn *insn, struct jit_context *ctx) case BPF_ALU64 | BPF_MOD | BPF_X: emit_alu_r64(ctx, dst, src, BPF_OP(code), off); break; + /* dst = bswap(dst) */ + case BPF_ALU64 | BPF_END: + emit_bswap_r64(ctx, dst, imm); + break; /* dst = htole(dst) */ /* dst = htobe(dst) */ case BPF_ALU | BPF_END | BPF_FROM_LE: From f4f496decae188ab1621023fecb3d2c191e6e43a Mon Sep 17 00:00:00 2001 From: Johan Almbladh Date: Sat, 26 Sep 2026 01:19:32 +0200 Subject: [PATCH 2/2] bpf, mips: Add JIT support for JMP32_JA The JMP32_JA instruction from the eBPF v4 ISA was not implemented. This caused programs using the instruction to fall back to the interpreter. Implement the JMP32_JA instruction. Signed-off-by: Johan Almbladh Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20260925231932.1063678-3-johan.almbladh@anyfinetworks.com --- arch/mips/net/bpf_jit_comp.c | 2 +- arch/mips/net/bpf_jit_comp.h | 2 +- arch/mips/net/bpf_jit_comp32.c | 7 +++++++ arch/mips/net/bpf_jit_comp64.c | 7 +++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/arch/mips/net/bpf_jit_comp.c b/arch/mips/net/bpf_jit_comp.c index f14de6d73122..4682dbb3a059 100644 --- a/arch/mips/net/bpf_jit_comp.c +++ b/arch/mips/net/bpf_jit_comp.c @@ -850,7 +850,7 @@ void emit_jmp_r(struct jit_context *ctx, u8 dst, u8 src, s32 off, u8 op) } /* Jump always */ -int emit_ja(struct jit_context *ctx, s16 off) +int emit_ja(struct jit_context *ctx, s32 off) { int target = get_target(ctx, ctx->bpf_index + off + 1); diff --git a/arch/mips/net/bpf_jit_comp.h b/arch/mips/net/bpf_jit_comp.h index 0ddedb733dd1..d0ab5c9a0c46 100644 --- a/arch/mips/net/bpf_jit_comp.h +++ b/arch/mips/net/bpf_jit_comp.h @@ -204,7 +204,7 @@ void emit_jmp_i(struct jit_context *ctx, u8 dst, s32 imm, s32 off, u8 op); void emit_jmp_r(struct jit_context *ctx, u8 dst, u8 src, s32 off, u8 op); /* Jump always */ -int emit_ja(struct jit_context *ctx, s16 off); +int emit_ja(struct jit_context *ctx, s32 off); /* Jump to epilogue */ int emit_exit(struct jit_context *ctx); diff --git a/arch/mips/net/bpf_jit_comp32.c b/arch/mips/net/bpf_jit_comp32.c index 158e69718c09..84d9c7036e4f 100644 --- a/arch/mips/net/bpf_jit_comp32.c +++ b/arch/mips/net/bpf_jit_comp32.c @@ -1877,6 +1877,13 @@ int build_insn(const struct bpf_insn *insn, struct jit_context *ctx) if (finish_jmp(ctx, jmp, off) < 0) goto toofar; break; + /* PC += imm */ + case BPF_JMP32 | BPF_JA: + if (imm == 0) + break; + if (emit_ja(ctx, imm) < 0) + goto toofar; + break; /* PC += off if dst == src */ /* PC += off if dst != src */ /* PC += off if dst & src */ diff --git a/arch/mips/net/bpf_jit_comp64.c b/arch/mips/net/bpf_jit_comp64.c index 8359ad3f6992..994589c3de46 100644 --- a/arch/mips/net/bpf_jit_comp64.c +++ b/arch/mips/net/bpf_jit_comp64.c @@ -1041,6 +1041,13 @@ int build_insn(const struct bpf_insn *insn, struct jit_context *ctx) if (finish_jmp(ctx, jmp, off) < 0) goto toofar; break; + /* PC += imm */ + case BPF_JMP32 | BPF_JA: + if (imm == 0) + break; + if (emit_ja(ctx, imm) < 0) + goto toofar; + break; /* PC += off if dst == src */ /* PC += off if dst != src */ /* PC += off if dst & src */