[RFC PATCH 3/3] LoongArch: BPF: Add support for indirect calls

From: Tiezhu Yang

Date: Wed Nov 11 2026 - 04:56:20 EST


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 rd 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 <yangtiezhu@xxxxxxxxxxx>
---
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 64abebd9c950..8191dc5f09b6 100644
--- a/arch/loongarch/net/bpf_jit.c
+++ b/arch/loongarch/net/bpf_jit.c
@@ -1255,6 +1255,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 rd */
+ 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, rd, 0);
+ break;
+
/* tail call */
case BPF_JMP | BPF_TAIL_CALL:
if (emit_bpf_tail_call(ctx, i) < 0)
@@ -2544,3 +2551,8 @@ bool bpf_jit_inlines_helper_call(s32 imm)
return false;
}
}
+
+bool bpf_jit_supports_callx(void)
+{
+ return true;
+}
--
2.42.0