mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/2] riscv, bpf: Support indirect calls to bpf subprogs (callx)
@ 2026-09-29  8:54 Pu Lehui
  2026-09-29  8:54 ` [PATCH bpf-next 1/2] " Pu Lehui
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Pu Lehui @ 2026-09-29  8:54 UTC (permalink / raw)
  To: Björn Töpel, bpf, linux-riscv, linux-kernel
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, Puranjay Mohan, Paul Walmsley, Palmer Dabbelt,
	Alexandre Ghiti, Pu Lehui, Pu Lehui

From: Pu Lehui <pulehui@huawei.com>

This series implements support for indirect calls to bpf subprogs on
riscv64 and enables the corresponding selftests.

Meanwhile, this series also resolves the test_verifier failures
previously captured by riscv-bpf-daily due to missing callx support [0].

[0] https://github.com/pulehui/riscv-bpf-daily/issues/11

Pu Lehui (2):
  riscv, bpf: Support indirect calls to bpf subprogs (callx)
  selftests/bpf: Enable callx related testcases for RV64

 arch/riscv/net/bpf_jit_comp64.c                      | 12 ++++++++++++
 .../selftests/bpf/prog_tests/callx_func_ptr_map.c    |  3 ++-
 .../selftests/bpf/prog_tests/callx_rodata_lskel.c    |  3 ++-
 tools/testing/selftests/bpf/progs/verifier_callx.c   |  3 ++-
 .../selftests/bpf/progs/verifier_callx_rodata.c      |  3 ++-
 5 files changed, 20 insertions(+), 4 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH bpf-next 1/2] riscv, bpf: Support indirect calls to bpf subprogs (callx)
  2026-09-29  8:54 [PATCH bpf-next 0/2] riscv, bpf: Support indirect calls to bpf subprogs (callx) Pu Lehui
@ 2026-09-29  8:54 ` Pu Lehui
  2026-09-29  8:54 ` [PATCH bpf-next 2/2] selftests/bpf: Enable callx related testcases for RV64 Pu Lehui
  2026-09-30  6:47 ` [PATCH bpf-next 0/2] riscv, bpf: Support indirect calls to bpf subprogs (callx) Pu Lehui
  2 siblings, 0 replies; 4+ messages in thread
From: Pu Lehui @ 2026-09-29  8:54 UTC (permalink / raw)
  To: Björn Töpel, bpf, linux-riscv, linux-kernel
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, Puranjay Mohan, Paul Walmsley, Palmer Dabbelt,
	Alexandre Ghiti, Pu Lehui, Pu Lehui

From: Pu Lehui <pulehui@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@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 7ce9f8460c59..88430825f4f5 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -2071,6 +2071,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))
@@ -2397,3 +2404,8 @@ bool bpf_jit_supports_exceptions(void)
 	 */
 	return IS_ENABLED(CONFIG_FRAME_POINTER);
 }
+
+bool bpf_jit_supports_callx(void)
+{
+	return true;
+}
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH bpf-next 2/2] selftests/bpf: Enable callx related testcases for RV64
  2026-09-29  8:54 [PATCH bpf-next 0/2] riscv, bpf: Support indirect calls to bpf subprogs (callx) Pu Lehui
  2026-09-29  8:54 ` [PATCH bpf-next 1/2] " Pu Lehui
@ 2026-09-29  8:54 ` Pu Lehui
  2026-09-30  6:47 ` [PATCH bpf-next 0/2] riscv, bpf: Support indirect calls to bpf subprogs (callx) Pu Lehui
  2 siblings, 0 replies; 4+ messages in thread
From: Pu Lehui @ 2026-09-29  8:54 UTC (permalink / raw)
  To: Björn Töpel, bpf, linux-riscv, linux-kernel
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, Puranjay Mohan, Paul Walmsley, Palmer Dabbelt,
	Alexandre Ghiti, Pu Lehui, Pu Lehui

From: Pu Lehui <pulehui@huawei.com>

Enable callx bpf selftests for RV64 now that the RV64 JIT supports
indirect calls to subprogs.

Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
 tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c | 3 ++-
 tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c | 3 ++-
 tools/testing/selftests/bpf/progs/verifier_callx.c          | 3 ++-
 tools/testing/selftests/bpf/progs/verifier_callx_rodata.c   | 3 ++-
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c b/tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c
index 42b33d5876b1..cc63b84e4d94 100644
--- a/tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c
+++ b/tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c
@@ -8,7 +8,8 @@
 #include <linux/filter.h>
 #include <bpf/btf.h>
 
-#if defined(__x86_64__) || defined(__aarch64__)
+#if defined(__x86_64__) || defined(__aarch64__) || \
+    (defined(__riscv) && __riscv_xlen == 64)
 
 #define CALLEE_INSN	6
 #define DATA		0x1234
diff --git a/tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c b/tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c
index fc5181c5b5ba..f6ef67c3141e 100644
--- a/tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c
+++ b/tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c
@@ -3,7 +3,8 @@
 
 #include "callx_rodata.lskel.h"
 
-#if defined(__x86_64__) || defined(__aarch64__)
+#if defined(__x86_64__) || defined(__aarch64__) || \
+    (defined(__riscv) && __riscv_xlen == 64)
 
 static void run(int prog_fd, int expected, const char *name)
 {
diff --git a/tools/testing/selftests/bpf/progs/verifier_callx.c b/tools/testing/selftests/bpf/progs/verifier_callx.c
index bc31d0221f6a..7e59188d9fca 100644
--- a/tools/testing/selftests/bpf/progs/verifier_callx.c
+++ b/tools/testing/selftests/bpf/progs/verifier_callx.c
@@ -7,7 +7,8 @@
 #include "../../../include/linux/filter.h"
 
 /* gcc doesn't support indirect calls */
-#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64)) && defined(__clang__)
+#if defined(__clang__) && (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64) || \
+    (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64))
 
 #define CALLX_INSN(DST, SRC, OFF, IMM) \
 	BPF_RAW_INSN(BPF_JMP | BPF_CALL | BPF_X, DST, SRC, OFF, IMM)
diff --git a/tools/testing/selftests/bpf/progs/verifier_callx_rodata.c b/tools/testing/selftests/bpf/progs/verifier_callx_rodata.c
index db3169a1ddf6..3ebd50f9c4b6 100644
--- a/tools/testing/selftests/bpf/progs/verifier_callx_rodata.c
+++ b/tools/testing/selftests/bpf/progs/verifier_callx_rodata.c
@@ -7,7 +7,8 @@
 #include "../../../include/linux/filter.h"
 
 /* gcc doesn't support indirect calls */
-#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64)) && defined(__clang__)
+#if defined(__clang__) && (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64) || \
+    (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64))
 
 /*
  * Read-only data with pointers to functions, where the compiler puts tables
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next 0/2] riscv, bpf: Support indirect calls to bpf subprogs (callx)
  2026-09-29  8:54 [PATCH bpf-next 0/2] riscv, bpf: Support indirect calls to bpf subprogs (callx) Pu Lehui
  2026-09-29  8:54 ` [PATCH bpf-next 1/2] " Pu Lehui
  2026-09-29  8:54 ` [PATCH bpf-next 2/2] selftests/bpf: Enable callx related testcases for RV64 Pu Lehui
@ 2026-09-30  6:47 ` Pu Lehui
  2 siblings, 0 replies; 4+ messages in thread
From: Pu Lehui @ 2026-09-30  6:47 UTC (permalink / raw)
  To: Pu Lehui, Björn Töpel, bpf, linux-riscv, linux-kernel
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, Puranjay Mohan, Paul Walmsley, Palmer Dabbelt,
	Alexandre Ghiti

This series fail to apply, I have resent a new one.


https://lore.kernel.org/all/20260930064928.1909085-1-pulehui@huaweicloud.com/T/#t

On 2026/9/29 16:54, Pu Lehui wrote:
> From: Pu Lehui <pulehui@huawei.com>
> 
> This series implements support for indirect calls to bpf subprogs on
> riscv64 and enables the corresponding selftests.
> 
> Meanwhile, this series also resolves the test_verifier failures
> previously captured by riscv-bpf-daily due to missing callx support [0].
> 
> [0] https://github.com/pulehui/riscv-bpf-daily/issues/11
> 
> Pu Lehui (2):
>    riscv, bpf: Support indirect calls to bpf subprogs (callx)
>    selftests/bpf: Enable callx related testcases for RV64
> 
>   arch/riscv/net/bpf_jit_comp64.c                      | 12 ++++++++++++
>   .../selftests/bpf/prog_tests/callx_func_ptr_map.c    |  3 ++-
>   .../selftests/bpf/prog_tests/callx_rodata_lskel.c    |  3 ++-
>   tools/testing/selftests/bpf/progs/verifier_callx.c   |  3 ++-
>   .../selftests/bpf/progs/verifier_callx_rodata.c      |  3 ++-
>   5 files changed, 20 insertions(+), 4 deletions(-)
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-09-30  6:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-29  8:54 [PATCH bpf-next 0/2] riscv, bpf: Support indirect calls to bpf subprogs (callx) Pu Lehui
2026-09-29  8:54 ` [PATCH bpf-next 1/2] " Pu Lehui
2026-09-29  8:54 ` [PATCH bpf-next 2/2] selftests/bpf: Enable callx related testcases for RV64 Pu Lehui
2026-09-30  6:47 ` [PATCH bpf-next 0/2] riscv, bpf: Support indirect calls to bpf subprogs (callx) Pu Lehui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®