Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arch/riscv/net/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
obj-$(CONFIG_BPF_JIT) += bpf_jit_core.o

ifeq ($(CONFIG_ARCH_RV64I),y)
obj-$(CONFIG_BPF_JIT) += bpf_jit_comp64.o
obj-$(CONFIG_BPF_JIT) += bpf_jit_comp64.o bpf_timed_may_goto.o
else
obj-$(CONFIG_BPF_JIT) += bpf_jit_comp32.o
endif
5 changes: 5 additions & 0 deletions arch/riscv/net/bpf_jit_comp64.c
Original file line number Diff line number Diff line change
Expand Up @@ -2157,3 +2157,8 @@ bool bpf_jit_supports_fsession(void)
{
return true;
}

bool bpf_jit_supports_timed_may_goto(void)
{
return true;
}
44 changes: 44 additions & 0 deletions arch/riscv/net/bpf_timed_may_goto.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (c) 2026 Feng Jiang <jiangfeng@kylinos.cn> */

#include <linux/linkage.h>
#include <asm/asm.h>

/*
* Trampoline for the BPF timed may_goto loop bound. Custom calling convention:
* - input: stack offset in BPF_REG_AX (t0)
* - output: updated count in BPF_REG_AX (t0)
*
* Calls bpf_check_timed_may_goto(ptr) with the standard RISC-V ABI, where
* ptr = BPF_REG_FP (s5) + BPF_REG_AX (t0). BPF R0-R5 (a5, a0-a4) are saved
* across the call; BPF_REG_FP (s5) is callee-saved and needs no saving.
*/

SYM_FUNC_START(arch_bpf_timed_may_goto)
addi sp, sp, -64
sd ra, 56(sp)

/* Save BPF registers R0-R5 (a5, a0-a4) */
sd a5, 48(sp)
sd a0, 40(sp)
sd a1, 32(sp)
sd a2, 24(sp)
sd a3, 16(sp)
sd a4, 8(sp)

add a0, t0, s5
call bpf_check_timed_may_goto
mv t0, a0

/* Restore BPF registers R0-R5 */
ld a4, 8(sp)
ld a3, 16(sp)
ld a2, 24(sp)
ld a1, 32(sp)
ld a0, 40(sp)
ld a5, 48(sp)

ld ra, 56(sp)
addi sp, sp, 64
ret
SYM_FUNC_END(arch_bpf_timed_may_goto)
1 change: 1 addition & 0 deletions tools/testing/selftests/bpf/progs/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ SEC("syscall")
__arch_x86_64
__arch_arm64
__arch_s390x
__arch_riscv64
__success __retval(0)
__stderr("ERROR: Timeout detected for may_goto instruction")
__stderr("CPU: {{[0-9]+}} UID: 0 PID: {{[0-9]+}} Comm: {{.*}}")
Expand Down
4 changes: 4 additions & 0 deletions tools/testing/selftests/bpf/progs/verifier_may_goto_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ __description("may_goto 0")
__arch_x86_64
__arch_s390x
__arch_arm64
__arch_riscv64
__xlated("0: r0 = 1")
__xlated("1: exit")
__success
Expand All @@ -31,6 +32,7 @@ __description("batch 2 of may_goto 0")
__arch_x86_64
__arch_s390x
__arch_arm64
__arch_riscv64
__xlated("0: r0 = 1")
__xlated("1: exit")
__success
Expand All @@ -53,6 +55,7 @@ __description("may_goto batch with offsets 2/1/0")
__arch_x86_64
__arch_s390x
__arch_arm64
__arch_riscv64
__xlated("0: r0 = 1")
__xlated("1: exit")
__success
Expand All @@ -79,6 +82,7 @@ __description("may_goto batch with offsets 2/0")
__arch_x86_64
__arch_s390x
__arch_arm64
__arch_riscv64
__xlated("0: *(u64 *)(r10 -16) = 65535")
__xlated("1: *(u64 *)(r10 -8) = 0")
__xlated("2: r12 = *(u64 *)(r10 -16)")
Expand Down
Loading