Re: [PATCH v4 6/6] LoongArch: BPF: Add support for arena atomics
From: George Guo
Date: Wed Dec 02 2026 - 20:42:00 EST
On 2026/12/1 10:11, sashiko-bot@xxxxxxxxxx wrote:
> Can an unaligned BPF_PROBE_ATOMIC read-modify-write access trigger a kernel
> Oops in do_ale() instead of recovering through ex_handler_bpf()?
>
> check_ptr_alignment() returns 0 unconditionally for PTR_TO_ARENA, so the
> verifier allows unaligned arena addresses to reach the atomic instructions
> emitted by emit_atomic_rmw(). On LoongArch, AM* atomic instructions require
> natural alignment and raise EXCCODE_ALE when unaligned.
>
> However, neither do_ale() nor emulate_load_store_insn() consults
> fixup_exception(regs) on kernel alignment faults:
Yes, this is a real issue. I reproduced it with an atomic one byte off
an aligned arena address, the kernel panics at the first amadd_db.w:
Kernel ale access[#1]:
...
ERA: ffff8000020136f4 bpf_prog_53d40cccca5faaf3_unaligned+0x10c/0x284
ESTAT: 00090000 [ALE] (IS= ECode=9 EsubCode=0)
BADV: ffff80008d600001
...
Kernel panic - not syncing: Fatal exception
The exception table entry added by this patch is fine, the problem is
that the trap code never looks it up for ALE. This is fixed by Tiezhu's
patch "LoongArch: Call fixup_exception() for unaligned accesses", which
calls fixup_exception() on the failure paths of do_ale() and
emulate_load_store_insn():
https://lore.kernel.org/loongarch/20261203012908.27076-1-yangtiezhu@xxxxxxxxxxx/
With that patch, a new arena_atomics/unaligned subtest (32-bit fetch
add and fetch or, 64-bit xchg and cmpxchg, all one byte off) passed on
Loongson-3C6000, with both CONFIG_ARCH_STRICT_ALIGN=y and
CONFIG_ARCH_STRICT_ALIGN=n:
$ sudo ./test_progs -a arena_atomics/unaligned
#3/10 arena_atomics/unaligned:OK
#3 arena_atomics:OK
Summary: 1/1 PASSED, 0 SKIPPED, 0/0 FAILED
The test is archived in the v1 thread of that patch:
https://lore.kernel.org/loongarch/20261202134056.40836-1-dongtai.guo@xxxxxxxxx/
I will send it formally after the LoongArch BPF JIT support is merged.
Thanks,
George