riscv, bpf: Support indirect calls to bpf subprogs (callx)
Subsystems (5)
cover riscv, bpf: Support indirect calls to bpf subprogs (callx)
From: Pu Lehui <[email protected]>
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(-)
Signature · 1 line
2.34.1
PATCH RESEND 1/2 riscv, bpf: Support indirect calls to bpf subprogs (callx)
From: Pu Lehui <[email protected]>
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.
--- arch/riscv/net/bpf_jit_comp64.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
arch/riscv/net/bpf_jit_comp64.c +12 -0
@@ -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; +}
Signature · 1 line
2.34.1
PATCH RESEND 2/2 selftests/bpf: Enable callx related testcases for RV64
In reply to Pu LehuiFrom: Pu Lehui <[email protected]>
Enable callx bpf selftests for RV64 now that the RV64 JIT supports indirect calls to subprogs.
--- 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(-)
tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c +2 -1
@@ -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
tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c +2 -1
@@ -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) {
tools/testing/selftests/bpf/progs/verifier_callx.c +2 -1
@@ -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)
tools/testing/selftests/bpf/progs/verifier_callx_rodata.c +2 -1
@@ -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
Signature · 1 line
2.34.1
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 9 lines · On Wed, 30 Sep 2026 06:49:26 +0000 you wrote:
From: Pu Lehui <[email protected]>
This series implements support for indirect calls to bpf subprogs on riscv64 and enables the corresponding selftests.
Meanwhile, this series also resolves the
test_verifierfailures previously captured by riscv-bpf-daily due to missing callx support [0].[...]
Here is the summary with links:
- [RESEND,bpf-next,1/2] riscv, bpf: Support indirect calls to bpf subprogs (callx)
https://git.kernel.org/bpf/bpf-next/c/1cec0b70fdc6 - [RESEND,bpf-next,2/2] selftests/bpf: Enable callx related testcases for RV64 https://git.kernel.org/bpf/bpf-next/c/530dfafc6107
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
This series was applied to riscv/linux.git (fixes) by Alexei Starovoitov <[email protected]>:
Hello:
This series was applied to riscv/linux.git (fixes) by Alexei Starovoitov <[email protected]>:
Quoted 9 lines · On Wed, 30 Sep 2026 06:49:26 +0000 you wrote:
From: Pu Lehui <[email protected]>
This series implements support for indirect calls to bpf subprogs on riscv64 and enables the corresponding selftests.
Meanwhile, this series also resolves the
test_verifierfailures previously captured by riscv-bpf-daily due to missing callx support [0].[...]
Here is the summary with links:
- [RESEND,bpf-next,1/2] riscv, bpf: Support indirect calls to bpf subprogs (callx)
https://git.kernel.org/riscv/c/1cec0b70fdc6 - [RESEND,bpf-next,2/2] selftests/bpf: Enable callx related testcases for RV64 https://git.kernel.org/riscv/c/530dfafc6107
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html