Kfunc parameters marked with BTF_FMODEL_ARENA_ARG carry a 32-bit arena offset in the BPF register, while the native kfunc expects a directly dereferenceable kernel address. Without JIT conversion, moving arena allocation kfuncs from KF_ARENA_ARGS to BTF argument metadata would make LoongArch pass offsets to functions which dereference them. The LoongArch JIT already keeps the arena kernel mapping base in s6 for arena memory accesses. Reuse it while preparing a pseudo-kfunc call: clear the upper 32 bits of each marked argument, preserve a nullable zero by branching over the addition, and otherwise add the base in s6. Keep the existing ABI extension path unchanged for ordinary kfunc arguments. Advertise the kfunc-specific arena argument capability independently of struct_ops trampoline conversion. Cc: Tiezhu Yang Cc: Huacai Chen Signed-off-by: Kumar Kartikeya Dwivedi --- arch/loongarch/net/bpf_jit.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c index d193293a0fd2..33cabaa7353f 100644 --- a/arch/loongarch/net/bpf_jit.c +++ b/arch/loongarch/net/bpf_jit.c @@ -283,6 +283,11 @@ bool bpf_jit_supports_kfunc_call(void) return true; } +bool bpf_jit_supports_arena_kfunc_args(void) +{ + return true; +} + bool bpf_jit_supports_far_kfunc_call(void) { return true; @@ -1195,9 +1200,22 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext for (i = 0; i < m->nr_args; i++) { u8 reg = regmap[BPF_REG_1 + i]; - bool sign = m->arg_flags[i] & BTF_FMODEL_SIGNED_ARG; - - emit_abi_ext(ctx, reg, m->arg_size[i], sign); + u8 flags = m->arg_flags[i]; + + if (flags & BTF_FMODEL_ARENA_ARG) { + if (WARN_ON_ONCE(!ctx->arena_vm_start)) + return -EINVAL; + + /* rN = kern_vm_start + (u32)rN */ + emit_zext_32(ctx, reg, true); + if (flags & BTF_FMODEL_NULLABLE_ARG) + emit_insn(ctx, beq, reg, LOONGARCH_GPR_ZERO, 2); + emit_insn(ctx, addd, reg, reg, REG_ARENA); + continue; + } + + emit_abi_ext(ctx, reg, m->arg_size[i], + flags & BTF_FMODEL_SIGNED_ARG); } } -- 2.53.0