[RESEND PATCH bpf-next 1/2] riscv, bpf: Support indirect calls to bpf subprogs (callx)

Pu Lehui pulehui at huaweicloud.com
Tue Sep 29 23:49:27 PDT 2026


From: Pu Lehui <pulehui at huawei.com>

Implement callx by emitting a jalr instruction to jump to the target
subprog address held in rd, and marking the call as it clobbers
RV_REG_RA.

Signed-off-by: Pu Lehui <pulehui at huawei.com>
---
 arch/riscv/net/bpf_jit_comp64.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index ed0a6f871dea..5e6289d1f359 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -1899,6 +1899,13 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
 			emit_mv(bpf_to_rv_reg(BPF_REG_0, ctx), RV_REG_A0, ctx);
 		break;
 	}
+
+	/* indirect call to a bpf subprog via the address in rd */
+	case BPF_JMP | BPF_CALL | BPF_X:
+		mark_call(ctx);
+		emit_jalr(RV_REG_RA, rd, 0, ctx);
+		break;
+
 	/* tail call */
 	case BPF_JMP | BPF_TAIL_CALL:
 		if (emit_bpf_tail_call(i, ctx))
@@ -2258,3 +2265,8 @@ bool bpf_jit_supports_stack_args(void)
 {
 	return true;
 }
+
+bool bpf_jit_supports_callx(void)
+{
+	return true;
+}
-- 
2.34.1




More information about the linux-riscv mailing list