[PATCH bpf-next v5 0/3] Add bpf stack arguments support for RV64

Pu Lehui posted 3 patches 2 weeks, 6 days ago
arch/riscv/net/bpf_jit.h                      |  4 +
arch/riscv/net/bpf_jit_comp64.c               | 90 +++++++++++++++----
arch/riscv/net/bpf_jit_core.c                 |  7 ++
arch/riscv/net/bpf_timed_may_goto.S           |  8 +-
.../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, 108 insertions(+), 30 deletions(-)
[PATCH bpf-next v5 0/3] Add bpf stack arguments support for RV64
Posted by Pu Lehui 2 weeks, 6 days ago
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 v5:
- Add RV_EXTRA_STK_ARGS macro to represent the exceeding stack args
  passed in riscv arg regs. (BPF CI)
- Optimize emit_stack_arg_st() by materializing immediates directly
  into destination registers. (BPF CI)
- Update stale comments. (BPF CI and sashiko)

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                      |  4 +
 arch/riscv/net/bpf_jit_comp64.c               | 90 +++++++++++++++----
 arch/riscv/net/bpf_jit_core.c                 |  7 ++
 arch/riscv/net/bpf_timed_may_goto.S           |  8 +-
 .../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, 108 insertions(+), 30 deletions(-)

-- 
2.34.1
Re: [PATCH bpf-next v5 0/3] Add bpf stack arguments support for RV64
Posted by Björn Töpel 2 weeks, 5 days ago
Pu Lehui <pulehui@huaweicloud.com> writes:

> 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 v5:
> - Add RV_EXTRA_STK_ARGS macro to represent the exceeding stack args
>   passed in riscv arg regs. (BPF CI)
> - Optimize emit_stack_arg_st() by materializing immediates directly
>   into destination registers. (BPF CI)
> - Update stale comments. (BPF CI and sashiko)
>
> 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

Thanks!

For the series:

Acked-by: Björn Töpel <bjorn@kernel.org>