From: George Guo Currently, the verifier rejects sign-extending loads from arena on LoongArch with "sign extending loads from arena are not supported yet", because the JIT does not implement bpf_jit_supports_insn() and the weak default returns false. In order to support them, implement bpf_jit_supports_insn() and handle BPF_PROBE_MEM32SX like BPF_PROBE_MEM32: add the arena base held in REG_ARENA to the address, use sign-extending load instructions, and add an exception table entry for the load. This is similar to commit b4757714cc63 ("bpf, riscv: Add support for signed arena loads"). Signed-off-by: George Guo --- arch/loongarch/net/bpf_jit.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c index 20f29ea01bda..03c88cd9c96a 100644 --- a/arch/loongarch/net/bpf_jit.c +++ b/arch/loongarch/net/bpf_jit.c @@ -709,7 +709,8 @@ static int add_exception_handler(const struct bpf_insn *insn, if (BPF_MODE(insn->code) != BPF_PROBE_MEM && BPF_MODE(insn->code) != BPF_PROBE_MEMSX && - BPF_MODE(insn->code) != BPF_PROBE_MEM32) + BPF_MODE(insn->code) != BPF_PROBE_MEM32 && + BPF_MODE(insn->code) != BPF_PROBE_MEM32SX) return 0; if (WARN_ON_ONCE(ctx->num_exentries >= ctx->prog->aux->num_exentries)) @@ -1389,10 +1390,16 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext case BPF_LDX | BPF_PROBE_MEM32 | BPF_H: case BPF_LDX | BPF_PROBE_MEM32 | BPF_W: case BPF_LDX | BPF_PROBE_MEM32 | BPF_DW: + /* LDX | PROBE_MEM32SX: dst = *(signed size *)(src + REG_ARENA + off) */ + case BPF_LDX | BPF_PROBE_MEM32SX | BPF_B: + case BPF_LDX | BPF_PROBE_MEM32SX | BPF_H: + case BPF_LDX | BPF_PROBE_MEM32SX | BPF_W: sign_extend = BPF_MODE(code) == BPF_MEMSX || - BPF_MODE(code) == BPF_PROBE_MEMSX; + BPF_MODE(code) == BPF_PROBE_MEMSX || + BPF_MODE(code) == BPF_PROBE_MEM32SX; - if (BPF_MODE(code) == BPF_PROBE_MEM32) { + if (BPF_MODE(code) == BPF_PROBE_MEM32 || + BPF_MODE(code) == BPF_PROBE_MEM32SX) { emit_insn(ctx, addd, t2, src, REG_ARENA); src = t2; } @@ -2676,6 +2683,11 @@ bool bpf_jit_supports_arena(void) #endif } +bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena) +{ + return true; +} + bool bpf_jit_supports_fsession(void) { return true; -- 2.53.0