Skip to content

bpf, riscv: Add support for signed arena loads

Chen Pei bpf linux-kselftest linux-riscv lkml 3 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest2 patches 3 repliesApplied 2/2
  2. v22 patches 1 replySuperseded
  3. v12 patches 5 repliesSuperseded

Changes in v3 from the cover letter

- Restore the pseudo-code form of the PROBE_MEM32SX case comment.

Patches in v3 All 2 applied

#Subject and filesSizeRepliesApplied
1/2bpf, riscv: Add support for signed arena loadsarch/riscv/net/bpf_jit_comp64.c+10 -61 replyApplied
2/2selftests/bpf: Enable arena LDSX tests for riscv64tools/testing/selftests/bpf/progs/verifier_ldsx.c+17 -01 replyApplied

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchPu LehuiBjörn Töpel
SeriesA-b
1/2R-b T-b
2/2R-b T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH bpf-next v3 0/2] bpf, riscv: Add support for signed arena loads

Hi,

Signed loads from arena memory are currently unsupported on riscv64:
bpf_jit_supports_insn() rejects BPF_MEMSX loads when in_arena is set, so the verifier fails such programs with "sign extending loads from arena are not supported yet". The x86 and arm64 JITs gained support for them in v6.18 (a91ae3c89311, eab2a71f3a6a). Since compilers are free to generate signed loads into arena memory (e.g. GCC-14 was reported to do so), otherwise valid BPF programs fail to load on riscv64.

This series adds BPF_PROBE_MEM32SX support to the RV64 JIT and enables the corresponding selftests on riscv64:

1 implements signed arena loads in the RV64 JIT. The verifier
already converts MEMSX loads from PTR_TO_ARENA to BPF_PROBE_MEM32SX once bpf_jit_supports_insn() allows them, so the JIT reuses the existing arena handling: the arena base (RV_REG_ARENA) is added to the source register and the load is emitted with sign extension (lb/lh/lw). BPF_PROBE_MEM32SX is also added to the add_exception_handler() mode gate so faulting loads register an exception table entry that clears the destination register and resumes execution.

2 enables the arena LDSX tests on riscv64: JIT disassembly
assertions are added to arena_ldsx_disasm, and arena_ldsx_exception/s8/s16/s32 are now run on riscv64.

The series was verified on riscv64 with QEMU (-M virt): all five arena_ldsx tests pass, including the exception path (load from unallocated arena memory returns 0) and the sign-extension values (s8/s16/s32 tests return -1 as expected). The arena_atomics test suite also loads and runs cleanly.

Changes in v3:
- Restore the pseudo-code form of the PROBE_MEM32SX case comment.

Changes in v2:
- Fix an extable entry overflow breaking the arena_atomics load.
- Collect Reviewed-by on patch 2.

Note: the __jited assertions in patch 2 were derived from the JIT register allocation (R0->a5, R1->a0, R8->s3, R9->s4, arena base in s7) and the emit_ldx() code paths; happy to adjust them if a disassembler output detail differs.

Thanks,
Pei

Chen Pei (2):
bpf, riscv: Add support for signed arena loads selftests/bpf: Enable arena LDSX tests for riscv64

 arch/riscv/net/bpf_jit_comp64.c                 | 16 ++++++++++------
 .../testing/selftests/bpf/progs/verifier_ldsx.c | 17 +++++++++++++++++
 2 files changed, 27 insertions(+), 6 deletions(-)
Signature · 1 line
2.50.1