Re: [PATCH v1] LoongArch: Call fixup_exception() for unaligned accesses

From: George Guo

Date: Wed Dec 02 2026 - 08:22:13 EST


On 2026/12/2 16:11, Tiezhu Yang wrote:
> On LoongArch, atomic memory instructions (AM*) require natural
> alignment and always raise EXCCODE_ALE when given an unaligned
> address, whereas unaligned regular loads and stores are either
> handled in hardware or emulated in software.
>
> Consult fixup_exception() on the failure paths of do_ale() and
> emulate_load_store_insn() so that registered exception handlers
> can catch and recover from unaligned access faults.

I tested this on Loongson-3C6000, with the LoongArch BPF arena atomics
series applied, using a new arena_atomics/unaligned subtest that does
32-bit fetch add and fetch or, 64-bit xchg and cmpxchg one byte off an
aligned arena address.

Without this patch, the kernel panics at the first atomic:

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

With this patch, the test passed 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

Reviewed-by: George Guo <guodongtai@xxxxxxxxxx>
Tested-by: George Guo <guodongtai@xxxxxxxxxx>

I will send the test as a follow-up to this patch.

Thanks,
George