On 2026/7/22 18:18, Pu Lehui wrote: > > On 2026/7/22 12:21, Feng Jiang wrote: >> Implement arch_bpf_timed_may_goto() for the RV64 JIT. The argument and >> return value are carried in BPF_REG_AX, and BPF R0-R5 are preserved >> across the call to the generic bpf_check_timed_may_goto(). >> >> Enable bpf_jit_supports_timed_may_goto() so the verifier uses the timed >> expansion path. >> >> Signed-off-by: Feng Jiang <[email protected]>
[ ...] >> diff --git a/arch/riscv/net/bpf_timed_may_goto.S >> b/arch/riscv/net/bpf_timed_may_goto.S >> new file mode 100644 >> index 000000000000..f4bf2cd10586 >> --- /dev/null >> +++ b/arch/riscv/net/bpf_timed_may_goto.S >> @@ -0,0 +1,47 @@ >> +/* SPDX-License-Identifier: GPL-2.0 */ >> +/* Copyright (c) 2026 Feng Jiang <[email protected]> */ >> + >> +#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) >> + sd s0, 48(sp) >> + addi s0, sp, 64 >> + >> + /* Save BPF registers R0-R5 (a5, a0-a4) */ >> + sd a5, 40(sp) >> + sd a0, 32(sp) >> + sd a1, 24(sp) >> + sd a2, 16(sp) >> + sd a3, 8(sp) >> + sd a4, 0(sp) >> + >> + add a0, t0, s5 >> + call bpf_check_timed_may_goto >> + mv t0, a0 >> + >> + /* Restore BPF registers R0-R5 */ >> + ld a4, 0(sp) >> + ld a3, 8(sp) >> + ld a2, 16(sp) >> + ld a1, 24(sp) >> + ld a0, 32(sp) >> + ld a5, 40(sp) >> + >> + ld s0, 48(sp) >> + ld ra, 56(sp) >> + addi sp, sp, 64 >> + ret >> +SYM_FUNC_END(arch_bpf_timed_may_goto) > > I think we should use REG_S/REG_L/SZREG like in arch/riscv ([0]) – it keeps > us in sync with upstream and will make it easier if we may later port > timed_may_goto to RV32. > > [0] arch/riscv/kernel/mcount.S Agreed, will switch to REG_S/REG_L/SZREG in v5. -- With Best Regards, Feng Jiang

