[PW_SID:1148451] bpf, riscv: Add support for signed arena loads - #2498
[PW_SID:1148451] bpf, riscv: Add support for signed arena loads#2498linux-riscv-bot wants to merge 5 commits into
Conversation
…_RWX When CONFIG_STRICT_MODULE_RWX is not set, execmem cannot create temporary writable mappings for read-only executable pages. In this case, the execmem ranges must already have writable permissions. Currently EXECMEM_KPROBES unconditionally uses PAGE_KERNEL_READ_EXEC, which causes kprobe instruction slot writes to trigger page faults on systems where CONFIG_STRICT_MODULE_RWX is not enabled. Fix this by using PAGE_KERNEL_EXEC when CONFIG_STRICT_MODULE_RWX is not available. Signed-off-by: Xiaofeng Yuan <xiaofengmian@163.com> Tested-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Reviewed-by: Nam Cao <namcao@linutronix.de> Link: https://patch.msgid.link/20260814082742.148403-2-xiaofengmian@163.com Signed-off-by: Paul Walmsley <pjw@kernel.org>
patch_map() always creates a temporary writable mapping via fixmap for kernel text addresses, even when CONFIG_STRICT_KERNEL_RWX is disabled and the kernel text is already mapped with _PAGE_WRITE. This is unnecessary overhead at best, and on minimal configurations it can cause page faults. Skip the fixmap path for kernel text when CONFIG_STRICT_KERNEL_RWX is not enabled, since the text pages are already writable in that case. The module text path is already gated on CONFIG_STRICT_MODULE_RWX and is kept unchanged. Reported-by: Klara Modin <klara@kasm.eu> Closes: https://lore.kernel.org/all/ant_8TaBbov_GS4i@soda.int.kasm.eu/ Reported-by: Lad Prabhakar <prabhakar.csengg@gmail.com> Closes: https://lore.kernel.org/all/CA+V-a8tQK8rih9SGGTyqrEBGpNkx4H0eX2YccCRrgkVAPr+EBg@mail.gmail.com/ Tested-by: Klara Modin <klarasmodin@gmail.com> Tested-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Link: https://patch.msgid.link/20260814082742.148403-3-xiaofengmian@163.com Signed-off-by: Paul Walmsley <pjw@kernel.org>
Signed loads from arena memory are currently rejected on riscv64, as bpf_jit_supports_insn() refuses BPF_MEMSX loads when in_arena is set, while x86 and arm64 gained support for them in v6.18. Compilers such as GCC-14 are free to generate signed loads into arena memory, which breaks loading of otherwise valid BPF programs on riscv64. Implement BPF_PROBE_MEM32SX support in the RV64 JIT by reusing 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). Add BPF_PROBE_MEM32SX to the add_exception_handler() mode gate so that faulting loads get an exception table entry which clears the destination register and resumes execution. Since BPF_PROBE_MEM32SX shares its mode value (0xc0) with BPF_ATOMIC, the gate accepts it only for LDX class instructions so that plain atomic instructions do not register exception table entries. Verified by running the arena LDSX selftests (arena_ldsx_disasm, arena_ldsx_exception, arena_ldsx_s8/s16/s32) and the full arena_atomics test suite on riscv64 QEMU, all passing. Signed-off-by: Chen Pei <cp0613@linux.alibaba.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Now that the riscv64 JIT supports signed arena loads (BPF_PROBE_MEM32SX), enable the arena LDSX tests on riscv64: add JIT disassembly assertions for arena_ldsx_disasm (arena base in s7, add into t2, sign-extending lw/lh/lb loads) and run arena_ldsx_exception and arena_ldsx_s8/s16/s32 on riscv64. Reviewed-by: Pu Lehui <pulehui@huawei.com> Signed-off-by: Chen Pei <cp0613@linux.alibaba.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
|
Patch 1: "[bpf-next,v3,1/2] bpf, riscv: Add support for signed arena loads" |
|
Patch 1: "[bpf-next,v3,1/2] bpf, riscv: Add support for signed arena loads" |
|
Patch 1: "[bpf-next,v3,1/2] bpf, riscv: Add support for signed arena loads" |
|
Patch 1: "[bpf-next,v3,1/2] bpf, riscv: Add support for signed arena loads" |
|
Patch 1: "[bpf-next,v3,1/2] bpf, riscv: Add support for signed arena loads" |
|
Patch 1: "[bpf-next,v3,1/2] bpf, riscv: Add support for signed arena loads" |
|
Patch 1: "[bpf-next,v3,1/2] bpf, riscv: Add support for signed arena loads" |
|
Patch 1: "[bpf-next,v3,1/2] bpf, riscv: Add support for signed arena loads" |
|
Patch 1: "[bpf-next,v3,1/2] bpf, riscv: Add support for signed arena loads" |
|
Patch 1: "[bpf-next,v3,1/2] bpf, riscv: Add support for signed arena loads" |
|
Patch 1: "[bpf-next,v3,1/2] bpf, riscv: Add support for signed arena loads" |
|
Patch 1: "[bpf-next,v3,1/2] bpf, riscv: Add support for signed arena loads" |
|
Patch 2: "[bpf-next,v3,2/2] selftests/bpf: Enable arena LDSX tests for riscv64" |
|
Patch 2: "[bpf-next,v3,2/2] selftests/bpf: Enable arena LDSX tests for riscv64" |
|
Patch 2: "[bpf-next,v3,2/2] selftests/bpf: Enable arena LDSX tests for riscv64" |
|
Patch 2: "[bpf-next,v3,2/2] selftests/bpf: Enable arena LDSX tests for riscv64" |
|
Patch 2: "[bpf-next,v3,2/2] selftests/bpf: Enable arena LDSX tests for riscv64" |
|
Patch 2: "[bpf-next,v3,2/2] selftests/bpf: Enable arena LDSX tests for riscv64" |
|
Patch 2: "[bpf-next,v3,2/2] selftests/bpf: Enable arena LDSX tests for riscv64" |
|
Patch 2: "[bpf-next,v3,2/2] selftests/bpf: Enable arena LDSX tests for riscv64" |
|
Patch 2: "[bpf-next,v3,2/2] selftests/bpf: Enable arena LDSX tests for riscv64" |
|
Patch 2: "[bpf-next,v3,2/2] selftests/bpf: Enable arena LDSX tests for riscv64" |
|
Patch 2: "[bpf-next,v3,2/2] selftests/bpf: Enable arena LDSX tests for riscv64" |
|
Patch 2: "[bpf-next,v3,2/2] selftests/bpf: Enable arena LDSX tests for riscv64" |
492cc66 to
bb1a926
Compare
bb1a926 to
6f6f7c0
Compare
PR for series 1148451 applied to workflow__riscv__fixes
Name: bpf, riscv: Add support for signed arena loads
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1148451
Version: 3