Merge branch 'riscv-bpf-support-indirect-calls-to-bpf-subprogs-callx'

Pu Lehui says:

====================
riscv, bpf: Support indirect calls to bpf subprogs (callx)

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
====================

Link: https://patch.msgid.link/20260930064928.1909085-1-pulehui@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
Alexei Starovoitov 2026-10-11 13:35:13 +00:00
commit 0184613039
No known key found for this signature in database
5 changed files with 20 additions and 4 deletions

View File

@ -1921,6 +1921,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))
@ -2280,3 +2287,8 @@ bool bpf_jit_supports_stack_args(void)
{
return true;
}
bool bpf_jit_supports_callx(void)
{
return true;
}

View File

@ -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

View File

@ -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)
{

View File

@ -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)

View File

@ -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