bpf, riscv: Make arena support depend on ZACAS
Subsystems (4)
PATCH 1/1 bpf, riscv: Make arena support depend on ZACAS
The arena range tree allocates its nodes with kmalloc_nolock() since commit f8c67d8550ee ("bpf: Use kmalloc_nolock() in range tree"). kmalloc_nolock() requires slab caches with cmpxchg128 support (__CMPXCHG_DOUBLE); on riscv cmpxchg128 is provided by the ZACAS extension. On systems without ZACAS every arena map creation fails with a misleading -ENOMEM.
Report the missing support instead: make bpf_jit_supports_arena() return system_has_cmpxchg128(), so arena map creation fails with -EOPNOTSUPP on systems without ZACAS. This matches how arena BPF_CMPXCHG instructions are already gated on ZACAS in bpf_jit_supports_insn().
---
This issue was reported by sashiko-bot:
https://sashiko.dev/#/patchset/[email protected]?part=1
Question for reviewers: should the arena selftests gate on ZACAS, e.g. probing it via riscv_hwprobe() (RISCV_ISA_EXT_ZACAS) and SKIPping cleanly on systems without the extension?
arch/riscv/net/bpf_jit_comp64.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
arch/riscv/net/bpf_jit_comp64.c +5 -1
@@ -2128,7 +2128,11 @@ bool bpf_jit_supports_ptr_xchg(void)bool bpf_jit_supports_arena (void ) { -return true; +/* +* The arena range tree uses kmalloc_nolock(), which needs +* cmpxchg128, provided by ZACAS on riscv. +*/ +return system_has_cmpxchg128 (); }bool bpf_jit_supports_insn (struct bpf_insn *insn,bool in_arena)
Signature · 1 line
2.50.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The unconditional use of `system_has_cmpxchg128()` in `bpf_jit_supports_arena()` causes a build…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The unconditional use of system_has_cmpxchg128() in bpf_jit_supports_arena() causes a build failure when CONFIG_RISCV_ISA_ZACAS or CONFIG_TOOLCHAIN_HAS_ZACAS is disabled. --
commit c73d679b84188e98d5cff0171b751fa3f4ce5627
Author: Chen Pei <[email protected]>
bpf, riscv: Make arena support depend on ZACAS
This patch updates bpf_jit_supports_arena() to return the result of system_has_cmpxchg128(). This ensures that BPF arena map creation fails with -EOPNOTSUPP on RISC-V systems that do not have the ZACAS extension.
Quoted 5 lines
arch/riscv/net/bpf_jit_comp64.c +0
-0
arch/riscv/net/bpf_jit_comp64.c bool bpf_jit_supports_ptr_xchg(void) · line 2148
Quoted 9 lines
arch/riscv/net/bpf_jit_comp64.c +5
-1@@ -2141,7 +2141,11 @@ bool bpf_jit_supports_ptr_xchg(void)bool bpf_jit_supports_arena (void ) { -return true; +/* +* The arena range tree uses kmalloc_nolock(), which needs +* cmpxchg128, provided by ZACAS on riscv. +*/ +return system_has_cmpxchg128 ();
[Severity: Low]
Does this code cause a build regression when compiling without ZACAS support?
Looking at arch/riscv/include/asm/cmpxchg.h, system_has_cmpxchg128() is conditionally defined without a fallback:
#if defined(CONFIG_64BIT) && defined(CONFIG_RISCV_ISA_ZACAS) && defined(CONFIG_TOOLCHAIN_HAS_ZACAS)
#define system_has_cmpxchg128() riscv_has_extension_unlikely(...)
...
#endif
If a kernel is built with CONFIG_BPF_JIT=y but CONFIG_RISCV_ISA_ZACAS=n (or CONFIG_TOOLCHAIN_HAS_ZACAS=n), will the unconditional use of system_has_cmpxchg128() in bpf_jit_supports_arena() result in an implicit declaration error?
Quoted 1 line
arch/riscv/net/bpf_jit_comp64.c +0
-0}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1