In order to implement JIT support for the indirect call instruction (BPF_JMP | BPF_CALL | BPF_X), load REG_TCC from the stack (just like a direct bpf2bpf call) first, and emit a jirl instruction to jump to the target subprog address held in dst while saving PC+4 into return address. This is similar to commit 1cec0b70fdc6 ("riscv, bpf: Support indirect calls to bpf subprogs (callx)"). Signed-off-by: Tiezhu Yang --- arch/loongarch/net/bpf_jit.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c index 52da39dce4f6..567729921d6d 100644 --- a/arch/loongarch/net/bpf_jit.c +++ b/arch/loongarch/net/bpf_jit.c @@ -1258,6 +1258,13 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext break; + /* indirect call to a bpf subprog via the address in dst */ + case BPF_JMP | BPF_CALL | BPF_X: + tcc_ptr_off = BPF_TAIL_CALL_CNT_PTR_STACK_OFF(ctx->stack_size); + emit_insn(ctx, ldd, REG_TCC, LOONGARCH_GPR_SP, tcc_ptr_off); + emit_insn(ctx, jirl, LOONGARCH_GPR_RA, dst, 0); + break; + /* tail call */ case BPF_JMP | BPF_TAIL_CALL: if (emit_bpf_tail_call(ctx, i) < 0) @@ -2559,3 +2566,8 @@ bool bpf_jit_inlines_helper_call(s32 imm) return false; } } + +bool bpf_jit_supports_callx(void) +{ + return true; +} -- 2.42.0