* [PATCH bpf-next v4 0/3] Add bpf stack arguments support for RV64
@ 2026-09-05 7:04 Pu Lehui
2026-09-05 7:04 ` [PATCH bpf-next v4 1/3] riscv, bpf: Remap BPF_REG_0 and RV_REG_TCC Pu Lehui
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Pu Lehui @ 2026-09-05 7:04 UTC (permalink / raw)
To: bpf, linux-riscv, linux-kernel, Feng Jiang
Cc: Björn Töpel, 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
Implement bpf_jit_supports_stack_args() on RV64 JIT to allow bpf
subprogs and kfuncs to pass and receive more than 5 arguments.
Tested on riscv64 QEMU with LLVM main [1]; BPF-to-BPF and kfunc
selftests pass.
[1] https://github.com/llvm/llvm-project/pull/189060
---
Changes in v4:
- Remap BPF_REG_0 and RV_REG_TCC to align the calling convention of
bpf2bpf and kfunc calls with the riscv abi.
- Adapt the bpf stack arguments implementation based on change 1.
Changes in v3:
- Drop the exceptions.c guard change: the guarded programs use
bpf_throw(), unsupported by the RV64 JIT, so the test is denylisted
on riscv64 and the guard has no effect. (BPF CI)
- Link to v2: https://lore.kernel.org/r/20260813-bpf-riscv-stack-args-v2-0-efea8f9b3fe1@kylinos.cn
Changes in v2:
- Sign-extend 32-bit kfunc arguments passed on the stack (args 9+),
matching the register path and the RISC-V psABI. (Sashiko)
- Restrict the riscv selftest guard to __riscv_xlen == 64 so the
tests are not enabled on RV32. (Sashiko)
- Link to v1: https://lore.kernel.org/r/20260812-bpf-riscv-stack-args-v1-0-67b246806e59@kylinos.cn
Feng Jiang (2):
riscv, bpf: Add BPF stack arguments support for RV64 JIT
selftests/bpf: Enable stack argument tests for RV64
Pu Lehui (1):
riscv, bpf: Remap BPF_REG_0 and RV_REG_TCC
arch/riscv/net/bpf_jit.h | 1 +
arch/riscv/net/bpf_jit_comp64.c | 87 ++++++++++++++++---
arch/riscv/net/bpf_jit_core.c | 6 ++
arch/riscv/net/bpf_timed_may_goto.S | 4 +-
.../bpf/progs/btf__stack_arg_precision.c | 3 +-
.../bpf/progs/btf__verifier_stack_arg_order.c | 3 +-
tools/testing/selftests/bpf/progs/stack_arg.c | 3 +-
.../selftests/bpf/progs/stack_arg_kfunc.c | 3 +-
.../selftests/bpf/progs/stack_arg_precision.c | 3 +-
.../selftests/bpf/progs/verifier_jit_inline.c | 2 +-
.../selftests/bpf/progs/verifier_ldsx.c | 6 +-
.../selftests/bpf/progs/verifier_stack_arg.c | 3 +-
.../bpf/progs/verifier_stack_arg_order.c | 3 +-
13 files changed, 101 insertions(+), 26 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH bpf-next v4 1/3] riscv, bpf: Remap BPF_REG_0 and RV_REG_TCC 2026-09-05 7:04 [PATCH bpf-next v4 0/3] Add bpf stack arguments support for RV64 Pu Lehui @ 2026-09-05 7:04 ` Pu Lehui 2026-09-05 8:00 ` bot+bpf-ci 2026-09-05 7:04 ` [PATCH bpf-next v4 2/3] riscv, bpf: Add BPF stack arguments support for RV64 JIT Pu Lehui 2026-09-05 7:04 ` [PATCH bpf-next v4 3/3] selftests/bpf: Enable stack argument tests for RV64 Pu Lehui 2 siblings, 1 reply; 10+ messages in thread From: Pu Lehui @ 2026-09-05 7:04 UTC (permalink / raw) To: bpf, linux-riscv, linux-kernel, Feng Jiang Cc: Björn Töpel, 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 From: Pu Lehui <pulehui@huawei.com> To prepare for supporting bpf stack arguments and unifying the calling convention between bpf2bpf calls and kfunc calls, remap BPF_REG_0 to t6 and RV_REG_TCC to t5. In the riscv abi, a0-a7 are designated for function argument passing. Freeing a5 and a6 allows bpf2bpf calls to pass extra arguments (6th to 8th) via a5-a7 consistently with kfuncs. Signed-off-by: Pu Lehui <pulehui@huawei.com> --- arch/riscv/net/bpf_jit_comp64.c | 8 ++++---- arch/riscv/net/bpf_timed_may_goto.S | 4 ++-- tools/testing/selftests/bpf/progs/verifier_jit_inline.c | 2 +- tools/testing/selftests/bpf/progs/verifier_ldsx.c | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c index e7378be171a9..aac128b9f0a4 100644 --- a/arch/riscv/net/bpf_jit_comp64.c +++ b/arch/riscv/net/bpf_jit_comp64.c @@ -23,11 +23,11 @@ /* fentry and TCC init insns will be skipped on tailcall */ #define RV_TAILCALL_OFFSET ((RV_FENTRY_NINSNS + 1) * 4) -#define RV_REG_TCC RV_REG_A6 +#define RV_REG_TCC RV_REG_T5 #define RV_REG_ARENA RV_REG_S7 /* For storing arena_vm_start */ static const int regmap[] = { - [BPF_REG_0] = RV_REG_A5, + [BPF_REG_0] = RV_REG_T6, [BPF_REG_1] = RV_REG_A0, [BPF_REG_2] = RV_REG_A1, [BPF_REG_3] = RV_REG_A2, @@ -47,13 +47,13 @@ static const int pt_regmap[] = { [RV_REG_A2] = offsetof(struct pt_regs, a2), [RV_REG_A3] = offsetof(struct pt_regs, a3), [RV_REG_A4] = offsetof(struct pt_regs, a4), - [RV_REG_A5] = offsetof(struct pt_regs, a5), [RV_REG_S1] = offsetof(struct pt_regs, s1), [RV_REG_S2] = offsetof(struct pt_regs, s2), [RV_REG_S3] = offsetof(struct pt_regs, s3), [RV_REG_S4] = offsetof(struct pt_regs, s4), [RV_REG_S5] = offsetof(struct pt_regs, s5), [RV_REG_T0] = offsetof(struct pt_regs, t0), + [RV_REG_T6] = offsetof(struct pt_regs, t6), }; enum { @@ -239,7 +239,7 @@ static void __build_epilogue(bool is_tail_call, struct rv_jit_context *ctx) emit_addi(RV_REG_SP, RV_REG_SP, stack_adjust, ctx); /* Set return value. */ if (!is_tail_call) - emit_addiw(RV_REG_A0, RV_REG_A5, 0, ctx); + emit_addiw(RV_REG_A0, regmap[BPF_REG_0], 0, ctx); emit_jalr(RV_REG_ZERO, is_tail_call ? RV_REG_T3 : RV_REG_RA, is_tail_call ? RV_TAILCALL_OFFSET : 0, ctx); } diff --git a/arch/riscv/net/bpf_timed_may_goto.S b/arch/riscv/net/bpf_timed_may_goto.S index 02c637d87420..ac41bf6dcb3d 100644 --- a/arch/riscv/net/bpf_timed_may_goto.S +++ b/arch/riscv/net/bpf_timed_may_goto.S @@ -21,7 +21,7 @@ SYM_FUNC_START(arch_bpf_timed_may_goto) addi s0, sp, 8*SZREG /* Save BPF registers R0-R5 (a5, a0-a4) */ - REG_S a5, 5*SZREG(sp) + REG_S t6, 5*SZREG(sp) REG_S a0, 4*SZREG(sp) REG_S a1, 3*SZREG(sp) REG_S a2, 2*SZREG(sp) @@ -38,7 +38,7 @@ SYM_FUNC_START(arch_bpf_timed_may_goto) REG_L a2, 2*SZREG(sp) REG_L a1, 3*SZREG(sp) REG_L a0, 4*SZREG(sp) - REG_L a5, 5*SZREG(sp) + REG_L t6, 5*SZREG(sp) REG_L s0, 6*SZREG(sp) REG_L ra, 7*SZREG(sp) diff --git a/tools/testing/selftests/bpf/progs/verifier_jit_inline.c b/tools/testing/selftests/bpf/progs/verifier_jit_inline.c index 02e562f56f9d..5b92da2ab75c 100644 --- a/tools/testing/selftests/bpf/progs/verifier_jit_inline.c +++ b/tools/testing/selftests/bpf/progs/verifier_jit_inline.c @@ -11,7 +11,7 @@ __jited(" addq %gs:{{.*}}, %rax") __arch_arm64 __jited(" mrs x8, SP_EL0") __arch_riscv64 -__jited(" mv a5, tp") +__jited(" mv t6, tp") __arch_loongarch __jited(" move $a5, $tp") int inline_bpf_get_current_task(void) diff --git a/tools/testing/selftests/bpf/progs/verifier_ldsx.c b/tools/testing/selftests/bpf/progs/verifier_ldsx.c index 7e25e1b8cd0b..49e8cd4bb4f9 100644 --- a/tools/testing/selftests/bpf/progs/verifier_ldsx.c +++ b/tools/testing/selftests/bpf/progs/verifier_ldsx.c @@ -289,11 +289,11 @@ __jited("ldrsh x22, [x11, #0x18]") __jited("add x11, x0, x28") __jited("ldrsb x22, [x11, #0x20]") __arch_riscv64 -__jited("add t2, a5, s7") +__jited("add t2, t6, s7") __jited("lw s3, 0x10(t2)") -__jited("add t2, a5, s7") +__jited("add t2, t6, s7") __jited("lh s3, 0x18(t2)") -__jited("add t2, a5, s7") +__jited("add t2, t6, s7") __jited("lb s3, 0x20(t2)") __jited("add t2, a0, s7") __jited("lw s4, 0x10(t2)") -- 2.34.1 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v4 1/3] riscv, bpf: Remap BPF_REG_0 and RV_REG_TCC 2026-09-05 7:04 ` [PATCH bpf-next v4 1/3] riscv, bpf: Remap BPF_REG_0 and RV_REG_TCC Pu Lehui @ 2026-09-05 8:00 ` bot+bpf-ci 2026-09-05 8:11 ` Pu Lehui 0 siblings, 1 reply; 10+ messages in thread From: bot+bpf-ci @ 2026-09-05 8:00 UTC (permalink / raw) To: pulehui, bpf, linux-riscv, linux-kernel, jiangfeng Cc: bjorn, ast, daniel, andrii, eddyz87, memxor, martin.lau, song, yonghong.song, jolsa, emil, ihor.solodrai, puranjay, pjw, palmer, alex, pulehui, ast, andrii, daniel, martin.lau, eddyz87, yonghong.song, mason, ihor.solodrai [-- Attachment #1: Type: text/plain, Size: 1354 bytes --] > diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c > index e7378be171a9..aac128b9f0a4 100644 > --- a/arch/riscv/net/bpf_jit_comp64.c > +++ b/arch/riscv/net/bpf_jit_comp64.c [ ... ] > @@ -1075,7 +1075,7 @@ int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *ro_image, > > save_ret = flags & (BPF_TRAMP_F_CALL_ORIG | BPF_TRAMP_F_RET_FENTRY_RET); > if (save_ret) > - stack_size += 16; /* Save both A5 (BPF R0) and A0 */ > + stack_size += 16; /* Save both T6 (BPF R0) and A0 */ Should the comment read "Save both T6 (BPF R0) and A0"? The patch updates regmap[BPF_REG_0] from RV_REG_A5 to RV_REG_T6, and the stack slot at retval_off - 8 is written via regmap[BPF_REG_0] in the save_ret block (emit_sd(RV_REG_FP, -(retval_off - 8), regmap[BPF_REG_0], ctx)), so the comment still naming "A5" contradicts the new mapping. After this series a5 becomes an argument register (the 6th BPF argument maps to a5 in a later commit), which makes "A5" actively misleading here since a reader could mistake this slot for argument spill space rather than R0/return value storage. --- AI reviewed your patch. Please fix the bug or email reply why it's not a bug. See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md CI run summary: https://github.com/kernel-patches/bpf/actions/runs/33952202002 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v4 1/3] riscv, bpf: Remap BPF_REG_0 and RV_REG_TCC 2026-09-05 8:00 ` bot+bpf-ci @ 2026-09-05 8:11 ` Pu Lehui 0 siblings, 0 replies; 10+ messages in thread From: Pu Lehui @ 2026-09-05 8:11 UTC (permalink / raw) To: bot+bpf-ci, bpf, linux-riscv, linux-kernel, jiangfeng Cc: bjorn, ast, daniel, andrii, eddyz87, memxor, martin.lau, song, yonghong.song, jolsa, emil, ihor.solodrai, puranjay, pjw, palmer, alex, pulehui, martin.lau, mason On 2026/9/5 16:00, bot+bpf-ci@kernel.org wrote: >> diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c >> index e7378be171a9..aac128b9f0a4 100644 >> --- a/arch/riscv/net/bpf_jit_comp64.c >> +++ b/arch/riscv/net/bpf_jit_comp64.c > > [ ... ] > >> @@ -1075,7 +1075,7 @@ int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *ro_image, >> >> save_ret = flags & (BPF_TRAMP_F_CALL_ORIG | BPF_TRAMP_F_RET_FENTRY_RET); >> if (save_ret) >> - stack_size += 16; /* Save both A5 (BPF R0) and A0 */ >> + stack_size += 16; /* Save both T6 (BPF R0) and A0 */ > > Should the comment read "Save both T6 (BPF R0) and A0"? The patch updates > regmap[BPF_REG_0] from RV_REG_A5 to RV_REG_T6, and the stack slot at > retval_off - 8 is written via regmap[BPF_REG_0] in the save_ret block > (emit_sd(RV_REG_FP, -(retval_off - 8), regmap[BPF_REG_0], ctx)), so the > comment still naming "A5" contradicts the new mapping. After this series > a5 becomes an argument register (the 6th BPF argument maps to a5 in a > later commit), which makes "A5" actively misleading here since a reader > could mistake this slot for argument spill space rather than R0/return > value storage. good cache, will update > > > --- > AI reviewed your patch. Please fix the bug or email reply why it's not a bug. > See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md > > CI run summary: https://github.com/kernel-patches/bpf/actions/runs/33952202002 ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH bpf-next v4 2/3] riscv, bpf: Add BPF stack arguments support for RV64 JIT 2026-09-05 7:04 [PATCH bpf-next v4 0/3] Add bpf stack arguments support for RV64 Pu Lehui 2026-09-05 7:04 ` [PATCH bpf-next v4 1/3] riscv, bpf: Remap BPF_REG_0 and RV_REG_TCC Pu Lehui @ 2026-09-05 7:04 ` Pu Lehui 2026-09-05 8:00 ` bot+bpf-ci 2026-09-05 7:04 ` [PATCH bpf-next v4 3/3] selftests/bpf: Enable stack argument tests for RV64 Pu Lehui 2 siblings, 1 reply; 10+ messages in thread From: Pu Lehui @ 2026-09-05 7:04 UTC (permalink / raw) To: bpf, linux-riscv, linux-kernel, Feng Jiang Cc: Björn Töpel, 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 From: Feng Jiang <jiangfeng@kylinos.cn> Implement bpf_jit_supports_stack_args() on RV64 JIT to allow bpf subprogs and kfuncs to pass and receive more than 5 arguments. In the riscv abi, the first 8 arguments are passed in registers a0 to a7, and arguments 9+ reside on the stack. To align bpf stack arguments with this calling convention and unify bpf2bpf calls with kfuncs, map the first 3 bpf stack arguments (6th to 8th) directly to a5 to a7, and store or load the remaining arguments (9th+) at SP or FP. Reserve outgoing stack space in the prologue accordingly when stack_arg_cnt exceeds 3. In addition, update kfunc argument sign extension to handle all 8 register arguments as well as any arguments passed on the stack. Co-developed-by: Pu Lehui <pulehui@huawei.com> Signed-off-by: Feng Jiang <jiangfeng@kylinos.cn> Signed-off-by: Pu Lehui <pulehui@huawei.com> --- arch/riscv/net/bpf_jit.h | 1 + arch/riscv/net/bpf_jit_comp64.c | 79 +++++++++++++++++++++++++++++---- arch/riscv/net/bpf_jit_core.c | 6 +++ 3 files changed, 77 insertions(+), 9 deletions(-) diff --git a/arch/riscv/net/bpf_jit.h b/arch/riscv/net/bpf_jit.h index 419b9d795f2a..039877f286fc 100644 --- a/arch/riscv/net/bpf_jit.h +++ b/arch/riscv/net/bpf_jit.h @@ -82,6 +82,7 @@ struct rv_jit_context { unsigned long flags; int stack_size; int tcc_offset; + int stack_arg_sz; u64 arena_vm_start; u64 user_vm_start; }; diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c index aac128b9f0a4..cda99c1f9ffe 100644 --- a/arch/riscv/net/bpf_jit_comp64.c +++ b/arch/riscv/net/bpf_jit_comp64.c @@ -498,6 +498,18 @@ static void emit_ldx(u8 rd, s16 off, u8 rs, u8 size, bool sign_ext, ctx->ex_jmp_off = ctx->ninsns; } +static void emit_stack_arg_ldx(u8 rd, s16 off, struct rv_jit_context *ctx) +{ + int idx = off / 8 - 1; + + if (idx < 3) { + emit_mv(rd, RV_REG_A5 + idx, ctx); + return; + } + + emit_ldx_insn(rd, (idx - 3) * 8, RV_REG_FP, BPF_DW, false, ctx); +} + static void emit_st(u8 rd, s16 off, s32 imm, u8 size, struct rv_jit_context *ctx) { emit_imm(RV_REG_T1, imm, ctx); @@ -515,6 +527,19 @@ static void emit_st(u8 rd, s16 off, s32 imm, u8 size, struct rv_jit_context *ctx ctx->ex_jmp_off = ctx->ninsns; } +static void emit_stack_arg_st(s16 off, s32 imm, struct rv_jit_context *ctx) +{ + int idx = -off / 8 - 1; + + emit_imm(RV_REG_T1, imm, ctx); + if (idx < 3) { + emit_mv(RV_REG_A5 + idx, RV_REG_T1, ctx); + return; + } + + emit_stx_insn(RV_REG_SP, (idx - 3) * 8, RV_REG_T1, BPF_DW, ctx); +} + static void emit_stx(u8 rd, s16 off, u8 rs, u8 size, struct rv_jit_context *ctx) { if (is_12b_int(off)) { @@ -531,6 +556,18 @@ static void emit_stx(u8 rd, s16 off, u8 rs, u8 size, struct rv_jit_context *ctx) ctx->ex_jmp_off = ctx->ninsns; } +static void emit_stack_arg_stx(s16 off, u8 rs, struct rv_jit_context *ctx) +{ + int idx = -off / 8 - 1; + + if (idx < 3) { + emit_mv(RV_REG_A5 + idx, rs, ctx); + return; + } + + emit_stx_insn(RV_REG_SP, (idx - 3) * 8, rs, BPF_DW, ctx); +} + static int emit_atomic_ld_st(u8 rd, u8 rs, const struct bpf_insn *insn, struct rv_jit_context *ctx) { @@ -1824,11 +1861,21 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx, return -EINVAL; for (idx = 0; idx < fm->nr_args; idx++) { - u8 reg = bpf_to_rv_reg(BPF_REG_1 + idx, ctx); bool sign = fm->arg_flags[idx] & BTF_FMODEL_SIGNED_ARG; - - if (sign_extend(reg, reg, fm->arg_size[idx], sign, ctx)) - return -EINVAL; + u8 arg_sz = fm->arg_size[idx]; + + if (arg_sz == 8 || (arg_sz != 4 && !sign)) + continue; + + if (idx < RV_MAX_REG_ARGS) { + if (sign_extend(RV_REG_A0 + idx, RV_REG_A0 + idx, arg_sz, sign, ctx)) + return -EINVAL; + } else { + emit_ld(RV_REG_T1, (idx - RV_MAX_REG_ARGS) * 8, RV_REG_SP, ctx); + if (sign_extend(RV_REG_T1, RV_REG_T1, arg_sz, sign, ctx)) + return -EINVAL; + emit_sd(RV_REG_SP, (idx - RV_MAX_REG_ARGS) * 8, RV_REG_T1, ctx); + } } } @@ -1927,7 +1974,10 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx, rs = RV_REG_T2; } - emit_ldx(rd, off, rs, BPF_SIZE(code), sign_ext, ctx); + if (is_stack_arg_ldx(insn)) + emit_stack_arg_ldx(rd, off, ctx); + else + emit_ldx(rd, off, rs, BPF_SIZE(code), sign_ext, ctx); ret = add_exception_handler(insn, rd, ctx); if (ret) @@ -1957,7 +2007,10 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx, rd = RV_REG_T3; } - emit_st(rd, off, imm, BPF_SIZE(code), ctx); + if (is_stack_arg_st(insn)) + emit_stack_arg_st(off, imm, ctx); + else + emit_st(rd, off, imm, BPF_SIZE(code), ctx); ret = add_exception_handler(insn, REG_DONT_CLEAR_MARKER, ctx); if (ret) @@ -1979,7 +2032,10 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx, rd = RV_REG_T2; } - emit_stx(rd, off, rs, BPF_SIZE(code), ctx); + if (is_stack_arg_stx(insn)) + emit_stack_arg_stx(off, rs, ctx); + else + emit_stx(rd, off, rs, BPF_SIZE(code), ctx); ret = add_exception_handler(insn, REG_DONT_CLEAR_MARKER, ctx); if (ret) @@ -2029,9 +2085,9 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx, void bpf_jit_build_prologue(struct rv_jit_context *ctx, bool is_subprog) { - int i, stack_adjust = 0, store_offset, bpf_stack_adjust; + int i, stack_adjust = 0, store_offset, bpf_stack_adjust = ctx->stack_arg_sz; - bpf_stack_adjust = round_up(ctx->prog->aux->stack_depth, STACK_ALIGN); + bpf_stack_adjust += round_up(ctx->prog->aux->stack_depth, STACK_ALIGN); if (bpf_stack_adjust) mark_fp(ctx); @@ -2190,3 +2246,8 @@ bool bpf_jit_supports_timed_may_goto(void) { return true; } + +bool bpf_jit_supports_stack_args(void) +{ + return true; +} diff --git a/arch/riscv/net/bpf_jit_core.c b/arch/riscv/net/bpf_jit_core.c index cbfcd287ea16..ed48005568c8 100644 --- a/arch/riscv/net/bpf_jit_core.c +++ b/arch/riscv/net/bpf_jit_core.c @@ -48,6 +48,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr int pass = 0, prev_ninsns = 0, i; struct rv_jit_data *jit_data; struct rv_jit_context *ctx; + u16 stack_arg_cnt; if (!prog->jit_requested) return prog; @@ -71,6 +72,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr ctx->arena_vm_start = bpf_arena_get_kern_vm_start(prog->aux->arena); ctx->user_vm_start = bpf_arena_get_user_vm_start(prog->aux->arena); + + stack_arg_cnt = bpf_out_stack_arg_cnt(env, prog); + /* First 3 stack args in regs, rest on stack */ + ctx->stack_arg_sz = stack_arg_cnt > 3 ? round_up((stack_arg_cnt - 3) * 8, STACK_ALIGN) : 0; + ctx->prog = prog; ctx->offset = kvzalloc_objs(int, prog->len); if (!ctx->offset) -- 2.34.1 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v4 2/3] riscv, bpf: Add BPF stack arguments support for RV64 JIT 2026-09-05 7:04 ` [PATCH bpf-next v4 2/3] riscv, bpf: Add BPF stack arguments support for RV64 JIT Pu Lehui @ 2026-09-05 8:00 ` bot+bpf-ci 2026-09-05 8:15 ` Pu Lehui 0 siblings, 1 reply; 10+ messages in thread From: bot+bpf-ci @ 2026-09-05 8:00 UTC (permalink / raw) To: pulehui, bpf, linux-riscv, linux-kernel, jiangfeng Cc: bjorn, ast, daniel, andrii, eddyz87, memxor, martin.lau, song, yonghong.song, jolsa, emil, ihor.solodrai, puranjay, pjw, palmer, alex, pulehui, ast, andrii, daniel, martin.lau, eddyz87, yonghong.song, mason, ihor.solodrai [-- Attachment #1: Type: text/plain, Size: 4732 bytes --] > diff --git a/arch/riscv/net/bpf_jit.h b/arch/riscv/net/bpf_jit.h > index 419b9d795f2a..039877f286fc 100644 > --- a/arch/riscv/net/bpf_jit.h > +++ b/arch/riscv/net/bpf_jit.h > @@ -82,6 +82,7 @@ struct rv_jit_context { > unsigned long flags; > int stack_size; > int tcc_offset; > + int stack_arg_sz; > u64 arena_vm_start; > u64 user_vm_start; > }; > diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c > index aac128b9f0a4..cda99c1f9ffe 100644 > --- a/arch/riscv/net/bpf_jit_comp64.c > +++ b/arch/riscv/net/bpf_jit_comp64.c > @@ -498,6 +498,18 @@ static void emit_ldx(u8 rd, s16 off, u8 rs, u8 size, bool sign_ext, > ctx->ex_jmp_off = ctx->ninsns; > } > > +static void emit_stack_arg_ldx(u8 rd, s16 off, struct rv_jit_context *ctx) > +{ > + int idx = off / 8 - 1; > + > + if (idx < 3) { > + emit_mv(rd, RV_REG_A5 + idx, ctx); > + return; > + } > + > + emit_ldx_insn(rd, (idx - 3) * 8, RV_REG_FP, BPF_DW, false, ctx); > +} > + This isn't a bug, but the literal 3 appears seven times across this file and bpf_jit_core.c (lines 505, 510, 535, 540, 563, 568, and bpf_jit_core.c line 78). The value really represents RV_MAX_REG_ARGS - MAX_BPF_FUNC_REG_ARGS (8 - 5). The file already defines RV_MAX_REG_ARGS symbolically and uses it in the kfunc fix-up loop (if (idx < RV_MAX_REG_ARGS) / (idx - RV_MAX_REG_ARGS)), but the stack argument helpers use the literal instead. Would a named constant (e.g. NR_STACK_ARG_REGS = RV_MAX_REG_ARGS - MAX_BPF_FUNC_REG_ARGS) placed in bpf_jit.h be worth it here, so the same value in bpf_jit_core.c and the three emit helpers cannot drift apart? arm64 uses NR_STACK_ARG_REGS with an explicit stack_arg_reg[] table. > static void emit_st(u8 rd, s16 off, s32 imm, u8 size, struct rv_jit_context *ctx) > { > emit_imm(RV_REG_T1, imm, ctx); > @@ -515,6 +527,19 @@ static void emit_st(u8 rd, s16 off, s32 imm, u8 size, struct rv_jit_context *ctx > ctx->ex_jmp_off = ctx->ninsns; > } > > +static void emit_stack_arg_st(s16 off, s32 imm, struct rv_jit_context *ctx) > +{ > + int idx = -off / 8 - 1; > + > + emit_imm(RV_REG_T1, imm, ctx); > + if (idx < 3) { > + emit_mv(RV_REG_A5 + idx, RV_REG_T1, ctx); > + return; > + } > + > + emit_stx_insn(RV_REG_SP, (idx - 3) * 8, RV_REG_T1, BPF_DW, ctx); > +} > + This isn't a bug, but for idx < 3 (the common case, covering BPF args 6-8), could this be emit_imm(RV_REG_A5 + idx, imm, ctx) directly, avoiding the RV_REG_T1 round trip and one instruction per store? The emit_imm then emit_mv sequence is carried over from emit_st() where materialising into a scratch register is unavoidable because the destination is memory. Here in the register case the immediate could be materialised straight into the destination. The two sibling helpers (emit_stack_arg_ldx, emit_stack_arg_stx) have no scratch use at all, and arm64's emit_stack_arg_store() writes the immediate path directly into the argument register. > +static void emit_stx(u8 rd, s16 off, u8 rs, u8 size, struct rv_jit_context *ctx) > +{ > + if (is_12b_int(off)) { > @@ -531,6 +556,18 @@ static void emit_stx(u8 rd, s16 off, u8 rs, u8 size, struct rv_jit_context *ctx) > ctx->ex_jmp_off = ctx->ninsns; > } > > +static void emit_stack_arg_stx(s16 off, u8 rs, struct rv_jit_context *ctx) > +{ > + int idx = -off / 8 - 1; > + > + if (idx < 3) { > + emit_mv(RV_REG_A5 + idx, rs, ctx); > + return; > + } > + > + emit_stx_insn(RV_REG_SP, (idx - 3) * 8, rs, BPF_DW, ctx); > +} > + [ ... ] > diff --git a/arch/riscv/net/bpf_jit_core.c b/arch/riscv/net/bpf_jit_core.c > index cbfcd287ea16..ed48005568c8 100644 > --- a/arch/riscv/net/bpf_jit_core.c > +++ b/arch/riscv/net/bpf_jit_core.c > @@ -48,6 +48,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr > int pass = 0, prev_ninsns = 0, i; > struct rv_jit_data *jit_data; > struct rv_jit_context *ctx; > + u16 stack_arg_cnt; > > if (!prog->jit_requested) > return prog; > @@ -71,6 +72,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr > > ctx->arena_vm_start = bpf_arena_get_kern_vm_start(prog->aux->arena); > ctx->user_vm_start = bpf_arena_get_user_vm_start(prog->aux->arena); > + > + stack_arg_cnt = bpf_out_stack_arg_cnt(env, prog); > + /* First 3 stack args in regs, rest on stack */ > + ctx->stack_arg_sz = stack_arg_cnt > 3 ? round_up((stack_arg_cnt - 3) * 8, STACK_ALIGN) : 0; > + > ctx->prog = prog; > ctx->offset = kvzalloc_objs(int, prog->len); > if (!ctx->offset) --- AI reviewed your patch. Please fix the bug or email reply why it's not a bug. See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md CI run summary: https://github.com/kernel-patches/bpf/actions/runs/33952202002 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v4 2/3] riscv, bpf: Add BPF stack arguments support for RV64 JIT 2026-09-05 8:00 ` bot+bpf-ci @ 2026-09-05 8:15 ` Pu Lehui 0 siblings, 0 replies; 10+ messages in thread From: Pu Lehui @ 2026-09-05 8:15 UTC (permalink / raw) To: bot+bpf-ci, bpf, linux-riscv, linux-kernel, jiangfeng Cc: bjorn, ast, daniel, andrii, eddyz87, memxor, martin.lau, song, yonghong.song, jolsa, emil, ihor.solodrai, puranjay, pjw, palmer, alex, pulehui, martin.lau, mason On 2026/9/5 16:00, bot+bpf-ci@kernel.org wrote: >> diff --git a/arch/riscv/net/bpf_jit.h b/arch/riscv/net/bpf_jit.h >> index 419b9d795f2a..039877f286fc 100644 >> --- a/arch/riscv/net/bpf_jit.h >> +++ b/arch/riscv/net/bpf_jit.h >> @@ -82,6 +82,7 @@ struct rv_jit_context { >> unsigned long flags; >> int stack_size; >> int tcc_offset; >> + int stack_arg_sz; >> u64 arena_vm_start; >> u64 user_vm_start; >> }; >> diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c >> index aac128b9f0a4..cda99c1f9ffe 100644 >> --- a/arch/riscv/net/bpf_jit_comp64.c >> +++ b/arch/riscv/net/bpf_jit_comp64.c >> @@ -498,6 +498,18 @@ static void emit_ldx(u8 rd, s16 off, u8 rs, u8 size, bool sign_ext, >> ctx->ex_jmp_off = ctx->ninsns; >> } >> >> +static void emit_stack_arg_ldx(u8 rd, s16 off, struct rv_jit_context *ctx) >> +{ >> + int idx = off / 8 - 1; >> + >> + if (idx < 3) { >> + emit_mv(rd, RV_REG_A5 + idx, ctx); >> + return; >> + } >> + >> + emit_ldx_insn(rd, (idx - 3) * 8, RV_REG_FP, BPF_DW, false, ctx); >> +} >> + > > This isn't a bug, but the literal 3 appears seven times across this file > and bpf_jit_core.c (lines 505, 510, 535, 540, 563, 568, and bpf_jit_core.c > line 78). The value really represents RV_MAX_REG_ARGS - MAX_BPF_FUNC_REG_ARGS > (8 - 5). The file already defines RV_MAX_REG_ARGS symbolically and uses it in > the kfunc fix-up loop (if (idx < RV_MAX_REG_ARGS) / (idx - RV_MAX_REG_ARGS)), > but the stack argument helpers use the literal instead. > > Would a named constant (e.g. NR_STACK_ARG_REGS = RV_MAX_REG_ARGS - > MAX_BPF_FUNC_REG_ARGS) placed in bpf_jit.h be worth it here, so the same > value in bpf_jit_core.c and the three emit helpers cannot drift apart? arm64 > uses NR_STACK_ARG_REGS with an explicit stack_arg_reg[] table. ok > >> static void emit_st(u8 rd, s16 off, s32 imm, u8 size, struct rv_jit_context *ctx) >> { >> emit_imm(RV_REG_T1, imm, ctx); >> @@ -515,6 +527,19 @@ static void emit_st(u8 rd, s16 off, s32 imm, u8 size, struct rv_jit_context *ctx >> ctx->ex_jmp_off = ctx->ninsns; >> } >> >> +static void emit_stack_arg_st(s16 off, s32 imm, struct rv_jit_context *ctx) >> +{ >> + int idx = -off / 8 - 1; >> + >> + emit_imm(RV_REG_T1, imm, ctx); >> + if (idx < 3) { >> + emit_mv(RV_REG_A5 + idx, RV_REG_T1, ctx); >> + return; >> + } >> + >> + emit_stx_insn(RV_REG_SP, (idx - 3) * 8, RV_REG_T1, BPF_DW, ctx); >> +} >> + > > This isn't a bug, but for idx < 3 (the common case, covering BPF args 6-8), > could this be emit_imm(RV_REG_A5 + idx, imm, ctx) directly, avoiding the > RV_REG_T1 round trip and one instruction per store? The emit_imm then emit_mv > sequence is carried over from emit_st() where materialising into a scratch > register is unavoidable because the destination is memory. Here in the > register case the immediate could be materialised straight into the > destination. The two sibling helpers (emit_stack_arg_ldx, emit_stack_arg_stx) > have no scratch use at all, and arm64's emit_stack_arg_store() writes the > immediate path directly into the argument register. very nice > >> +static void emit_stx(u8 rd, s16 off, u8 rs, u8 size, struct rv_jit_context *ctx) >> +{ >> + if (is_12b_int(off)) { >> @@ -531,6 +556,18 @@ static void emit_stx(u8 rd, s16 off, u8 rs, u8 size, struct rv_jit_context *ctx) >> ctx->ex_jmp_off = ctx->ninsns; >> } >> >> +static void emit_stack_arg_stx(s16 off, u8 rs, struct rv_jit_context *ctx) >> +{ >> + int idx = -off / 8 - 1; >> + >> + if (idx < 3) { >> + emit_mv(RV_REG_A5 + idx, rs, ctx); >> + return; >> + } >> + >> + emit_stx_insn(RV_REG_SP, (idx - 3) * 8, rs, BPF_DW, ctx); >> +} >> + > > [ ... ] > >> diff --git a/arch/riscv/net/bpf_jit_core.c b/arch/riscv/net/bpf_jit_core.c >> index cbfcd287ea16..ed48005568c8 100644 >> --- a/arch/riscv/net/bpf_jit_core.c >> +++ b/arch/riscv/net/bpf_jit_core.c >> @@ -48,6 +48,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr >> int pass = 0, prev_ninsns = 0, i; >> struct rv_jit_data *jit_data; >> struct rv_jit_context *ctx; >> + u16 stack_arg_cnt; >> >> if (!prog->jit_requested) >> return prog; >> @@ -71,6 +72,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr >> >> ctx->arena_vm_start = bpf_arena_get_kern_vm_start(prog->aux->arena); >> ctx->user_vm_start = bpf_arena_get_user_vm_start(prog->aux->arena); >> + >> + stack_arg_cnt = bpf_out_stack_arg_cnt(env, prog); >> + /* First 3 stack args in regs, rest on stack */ >> + ctx->stack_arg_sz = stack_arg_cnt > 3 ? round_up((stack_arg_cnt - 3) * 8, STACK_ALIGN) : 0; >> + >> ctx->prog = prog; >> ctx->offset = kvzalloc_objs(int, prog->len); >> if (!ctx->offset) > > > --- > AI reviewed your patch. Please fix the bug or email reply why it's not a bug. > See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md > > CI run summary: https://github.com/kernel-patches/bpf/actions/runs/33952202002 ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH bpf-next v4 3/3] selftests/bpf: Enable stack argument tests for RV64 2026-09-05 7:04 [PATCH bpf-next v4 0/3] Add bpf stack arguments support for RV64 Pu Lehui 2026-09-05 7:04 ` [PATCH bpf-next v4 1/3] riscv, bpf: Remap BPF_REG_0 and RV_REG_TCC Pu Lehui 2026-09-05 7:04 ` [PATCH bpf-next v4 2/3] riscv, bpf: Add BPF stack arguments support for RV64 JIT Pu Lehui @ 2026-09-05 7:04 ` Pu Lehui 2026-09-05 7:45 ` bot+bpf-ci 2 siblings, 1 reply; 10+ messages in thread From: Pu Lehui @ 2026-09-05 7:04 UTC (permalink / raw) To: bpf, linux-riscv, linux-kernel, Feng Jiang Cc: Björn Töpel, 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 From: Feng Jiang <jiangfeng@kylinos.cn> Enable the stack argument selftests for RV64. The riscv guard is restricted to __riscv_xlen == 64 since stack arguments are only supported by the RV64 JIT. Keep the __BPF_FEATURE_STACK_ARGUMENT gate, defined by clang with BPF stack argument support [1]. [1] https://github.com/llvm/llvm-project/pull/189060 Signed-off-by: Feng Jiang <jiangfeng@kylinos.cn> --- tools/testing/selftests/bpf/progs/btf__stack_arg_precision.c | 3 ++- .../selftests/bpf/progs/btf__verifier_stack_arg_order.c | 3 ++- tools/testing/selftests/bpf/progs/stack_arg.c | 3 ++- tools/testing/selftests/bpf/progs/stack_arg_kfunc.c | 3 ++- tools/testing/selftests/bpf/progs/stack_arg_precision.c | 3 ++- tools/testing/selftests/bpf/progs/verifier_stack_arg.c | 3 ++- tools/testing/selftests/bpf/progs/verifier_stack_arg_order.c | 3 ++- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/btf__stack_arg_precision.c b/tools/testing/selftests/bpf/progs/btf__stack_arg_precision.c index 8d38aafe66a2..ab12397a9b52 100644 --- a/tools/testing/selftests/bpf/progs/btf__stack_arg_precision.c +++ b/tools/testing/selftests/bpf/progs/btf__stack_arg_precision.c @@ -4,7 +4,8 @@ #include <bpf/bpf_helpers.h> #include "../test_kmods/bpf_testmod_kfunc.h" -#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64)) && \ +#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64) || \ + (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64)) && \ defined(__BPF_FEATURE_STACK_ARGUMENT) long subprog_call_mem_kfunc(long a, long b, long c, long d, long e, long size) diff --git a/tools/testing/selftests/bpf/progs/btf__verifier_stack_arg_order.c b/tools/testing/selftests/bpf/progs/btf__verifier_stack_arg_order.c index 99bc115f8380..a980a3a399d3 100644 --- a/tools/testing/selftests/bpf/progs/btf__verifier_stack_arg_order.c +++ b/tools/testing/selftests/bpf/progs/btf__verifier_stack_arg_order.c @@ -3,7 +3,8 @@ #include <vmlinux.h> #include <bpf/bpf_helpers.h> -#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64)) && \ +#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64) || \ + (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64)) && \ defined(__BPF_FEATURE_STACK_ARGUMENT) int subprog_bad_order_6args(int a, int b, int c, int d, int e, int f) diff --git a/tools/testing/selftests/bpf/progs/stack_arg.c b/tools/testing/selftests/bpf/progs/stack_arg.c index 944e3bb603e7..3e9ed37c57bb 100644 --- a/tools/testing/selftests/bpf/progs/stack_arg.c +++ b/tools/testing/selftests/bpf/progs/stack_arg.c @@ -21,7 +21,8 @@ struct { int timer_result; -#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64)) && \ +#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64) || \ + (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64)) && \ defined(__BPF_FEATURE_STACK_ARGUMENT) const volatile bool has_stack_arg = true; diff --git a/tools/testing/selftests/bpf/progs/stack_arg_kfunc.c b/tools/testing/selftests/bpf/progs/stack_arg_kfunc.c index 345f2da2e361..b6b1a8aa7f44 100644 --- a/tools/testing/selftests/bpf/progs/stack_arg_kfunc.c +++ b/tools/testing/selftests/bpf/progs/stack_arg_kfunc.c @@ -6,7 +6,8 @@ #include "bpf_kfuncs.h" #include "../test_kmods/bpf_testmod_kfunc.h" -#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64)) && \ +#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64) || \ + (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64)) && \ defined(__BPF_FEATURE_STACK_ARGUMENT) const volatile bool has_stack_arg = true; diff --git a/tools/testing/selftests/bpf/progs/stack_arg_precision.c b/tools/testing/selftests/bpf/progs/stack_arg_precision.c index ce0301a41fa9..7baa9c1c8e31 100644 --- a/tools/testing/selftests/bpf/progs/stack_arg_precision.c +++ b/tools/testing/selftests/bpf/progs/stack_arg_precision.c @@ -6,7 +6,8 @@ #include "../test_kmods/bpf_testmod_kfunc.h" #include "bpf_misc.h" -#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64)) && \ +#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64) || \ + (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64)) && \ defined(__BPF_FEATURE_STACK_ARGUMENT) /* Force kfunc extern BTF generation for inline asm call below. diff --git a/tools/testing/selftests/bpf/progs/verifier_stack_arg.c b/tools/testing/selftests/bpf/progs/verifier_stack_arg.c index 51d22faf4559..f6a4a6aa0e61 100644 --- a/tools/testing/selftests/bpf/progs/verifier_stack_arg.c +++ b/tools/testing/selftests/bpf/progs/verifier_stack_arg.c @@ -12,7 +12,8 @@ struct { __type(value, long long); } map_hash_8b SEC(".maps"); -#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64)) && \ +#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64) || \ + (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64)) && \ defined(__BPF_FEATURE_STACK_ARGUMENT) __noinline __used diff --git a/tools/testing/selftests/bpf/progs/verifier_stack_arg_order.c b/tools/testing/selftests/bpf/progs/verifier_stack_arg_order.c index 8e4325273b3d..57f22691744a 100644 --- a/tools/testing/selftests/bpf/progs/verifier_stack_arg_order.c +++ b/tools/testing/selftests/bpf/progs/verifier_stack_arg_order.c @@ -5,7 +5,8 @@ #include <bpf/bpf_helpers.h> #include "bpf_misc.h" -#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64)) && \ +#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64) || \ + (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64)) && \ defined(__BPF_FEATURE_STACK_ARGUMENT) __noinline __used __naked -- 2.34.1 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v4 3/3] selftests/bpf: Enable stack argument tests for RV64 2026-09-05 7:04 ` [PATCH bpf-next v4 3/3] selftests/bpf: Enable stack argument tests for RV64 Pu Lehui @ 2026-09-05 7:45 ` bot+bpf-ci 2026-09-05 8:05 ` Pu Lehui 0 siblings, 1 reply; 10+ messages in thread From: bot+bpf-ci @ 2026-09-05 7:45 UTC (permalink / raw) To: pulehui, bpf, linux-riscv, linux-kernel, jiangfeng Cc: bjorn, ast, daniel, andrii, eddyz87, memxor, martin.lau, song, yonghong.song, jolsa, emil, ihor.solodrai, puranjay, pjw, palmer, alex, pulehui, ast, andrii, daniel, martin.lau, eddyz87, yonghong.song, mason, ihor.solodrai [-- Attachment #1: Type: text/plain, Size: 2797 bytes --] > Enable the stack argument selftests for RV64. The riscv guard is > restricted to __riscv_xlen == 64 since stack arguments are only > supported by the RV64 JIT. > > Keep the __BPF_FEATURE_STACK_ARGUMENT gate, defined by clang with > BPF stack argument support [1]. > > [1] https://github.com/llvm/llvm-project/pull/189060 > > Signed-off-by: Feng Jiang <jiangfeng@kylinos.cn> The changelog says "Enable the stack argument selftests for RV64", but one arch-gated stack-argument test remains on x86_64/arm64 only. Exhaustive list of every arch-gated stack-argument test in tools/testing/selftests/bpf: progs/btf__stack_arg_precision.c updated by this patch progs/btf__verifier_stack_arg_order.c updated by this patch progs/stack_arg.c updated by this patch progs/stack_arg_kfunc.c updated by this patch progs/stack_arg_precision.c updated by this patch progs/verifier_stack_arg.c updated by this patch progs/verifier_stack_arg_order.c updated by this patch progs/stack_arg_fail.c no arch gate - already runs progs/exceptions.c:383 intentionally left alone progs/arena_kfunc.c:219-230 not updated, not explained progs/exceptions.c is correctly left alone: DENYLIST.riscv64 lists 'exceptions' with the comment "JIT does not support exceptions", and arch/riscv/net/ implements no bpf_jit_supports_exceptions(). progs/arena_kfunc.c is not explained. It gates its stack-argument test with test_loader arch annotations rather than a preprocessor guard: #if defined(__BPF_FEATURE_ADDR_SPACE_CAST) && \ defined(__BPF_FEATURE_STACK_ARGUMENT) SEC("syscall") __arch_x86_64 __arch_arm64 __failure __msg("arena pointer cannot be a stack argument") int arena_arg_stack(void *ctx) test_loader.c skips any test whose arch mask does not contain the running arch, so arena_arg_stack stays skipped on RV64 after this patch. Does anything block it from running on RV64? bpf_jit_supports_arena() returns true on riscv64, DENYLIST.riscv64 contains only 'exceptions', and arena_arg_stack is a __failure test so it only needs the verifier to reach the "arena pointer cannot be a stack argument" check - which now happens on RV64 because the preceding commit makes bpf_jit_supports_stack_args() return true. Should __arch_riscv64 be added to progs/arena_kfunc.c's arena_arg_stack (and the #else dummy_test, which carries the same two annotations), or is there a reason it should stay on x86_64/arm64 only? --- AI reviewed your patch. Please fix the bug or email reply why it's not a bug. See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md CI run summary: https://github.com/kernel-patches/bpf/actions/runs/33952202002 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v4 3/3] selftests/bpf: Enable stack argument tests for RV64 2026-09-05 7:45 ` bot+bpf-ci @ 2026-09-05 8:05 ` Pu Lehui 0 siblings, 0 replies; 10+ messages in thread From: Pu Lehui @ 2026-09-05 8:05 UTC (permalink / raw) To: bot+bpf-ci, bpf, linux-riscv, linux-kernel, jiangfeng Cc: bjorn, ast, daniel, andrii, eddyz87, memxor, martin.lau, song, yonghong.song, jolsa, emil, ihor.solodrai, puranjay, pjw, palmer, alex, pulehui, martin.lau, mason On 2026/9/5 15:45, bot+bpf-ci@kernel.org wrote: >> Enable the stack argument selftests for RV64. The riscv guard is >> restricted to __riscv_xlen == 64 since stack arguments are only >> supported by the RV64 JIT. >> >> Keep the __BPF_FEATURE_STACK_ARGUMENT gate, defined by clang with >> BPF stack argument support [1]. >> >> [1] https://github.com/llvm/llvm-project/pull/189060 >> >> Signed-off-by: Feng Jiang <jiangfeng@kylinos.cn> > > The changelog says "Enable the stack argument selftests for RV64", but > one arch-gated stack-argument test remains on x86_64/arm64 only. > > Exhaustive list of every arch-gated stack-argument test in > tools/testing/selftests/bpf: > > progs/btf__stack_arg_precision.c updated by this patch > progs/btf__verifier_stack_arg_order.c updated by this patch > progs/stack_arg.c updated by this patch > progs/stack_arg_kfunc.c updated by this patch > progs/stack_arg_precision.c updated by this patch > progs/verifier_stack_arg.c updated by this patch > progs/verifier_stack_arg_order.c updated by this patch > progs/stack_arg_fail.c no arch gate - already runs > progs/exceptions.c:383 intentionally left alone > progs/arena_kfunc.c:219-230 not updated, not explained > > progs/exceptions.c is correctly left alone: DENYLIST.riscv64 lists > 'exceptions' with the comment "JIT does not support exceptions", and > arch/riscv/net/ implements no bpf_jit_supports_exceptions(). > > progs/arena_kfunc.c is not explained. It gates its stack-argument test > with test_loader arch annotations rather than a preprocessor guard: > > #if defined(__BPF_FEATURE_ADDR_SPACE_CAST) && \ > defined(__BPF_FEATURE_STACK_ARGUMENT) > SEC("syscall") > __arch_x86_64 > __arch_arm64 > __failure __msg("arena pointer cannot be a stack argument") > int arena_arg_stack(void *ctx) > > test_loader.c skips any test whose arch mask does not contain the running > arch, so arena_arg_stack stays skipped on RV64 after this patch. > > Does anything block it from running on RV64? bpf_jit_supports_arena() > returns true on riscv64, DENYLIST.riscv64 contains only 'exceptions', and > arena_arg_stack is a __failure test so it only needs the verifier to reach > the "arena pointer cannot be a stack argument" check - which now happens > on RV64 because the preceding commit makes bpf_jit_supports_stack_args() > return true. > > Should __arch_riscv64 be added to progs/arena_kfunc.c's arena_arg_stack > (and the #else dummy_test, which carries the same two annotations), or is > there a reason it should stay on x86_64/arm64 only? not yet support bpf_jit_supports_arena_args and Kumar have been worked on this [0]. [0] https://lore.kernel.org/bpf/20260821233516.3426127-4-memxor@gmail.com/ > > > --- > AI reviewed your patch. Please fix the bug or email reply why it's not a bug. > See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md > > CI run summary: https://github.com/kernel-patches/bpf/actions/runs/33952202002 ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-09-05 8:16 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-09-05 7:04 [PATCH bpf-next v4 0/3] Add bpf stack arguments support for RV64 Pu Lehui 2026-09-05 7:04 ` [PATCH bpf-next v4 1/3] riscv, bpf: Remap BPF_REG_0 and RV_REG_TCC Pu Lehui 2026-09-05 8:00 ` bot+bpf-ci 2026-09-05 8:11 ` Pu Lehui 2026-09-05 7:04 ` [PATCH bpf-next v4 2/3] riscv, bpf: Add BPF stack arguments support for RV64 JIT Pu Lehui 2026-09-05 8:00 ` bot+bpf-ci 2026-09-05 8:15 ` Pu Lehui 2026-09-05 7:04 ` [PATCH bpf-next v4 3/3] selftests/bpf: Enable stack argument tests for RV64 Pu Lehui 2026-09-05 7:45 ` bot+bpf-ci 2026-09-05 8:05 ` 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®