Re: [PATCH RFC] LoongArch: Enable HAVE_EFFICIENT_UNALIGNED_ACCESS by default
From: Xi Ruoyao
Date: Sun Dec 06 2026 - 01:52:34 EST
On Sat, 2026-12-05 at 18:01 +0800, Tiezhu Yang wrote:
> Currently, CONFIG_ARCH_STRICT_ALIGN is enabled by default in Kconfig
> to prevent unaligned memory accesses on certain LoongArch processors
> without hardware support (such as Loongson-2K0300/2K0500/2K1000).
>
> However, all Loongson-3 series processors and some newer Loongson-2K
> processors (Loongson-2K2000/2K3000) natively support unaligned access
> in hardware. Thus, keeping -mstrict-align enabled by default degrades
> performance and increases code size on mainstream hardware.
>
> Moreover, when ARCH_STRICT_ALIGN is disabled, unaligned.o is not built
> and software emulation is compiled out. As a result, a single generic
> kernel image built without ARCH_STRICT_ALIGN cannot run on processors
> without hardware unaligned access support.
>
> Enable HAVE_EFFICIENT_UNALIGNED_ACCESS by default through disabling
> CONFIG_ARCH_STRICT_ALIGN by default so that modern LoongArch systems
> can fully benefit from hardware unaligned access, allowing subsystems
> such as networking, bpf, and cryptography to perform direct word-size
> unaligned loads/stores instead of falling back to slow byte-by-byte
> accesses or extra alignment padding.
>
> To preserve compatibility so that a single generic kernel image can
> still run on certain processors without hardware UAL support, keep
> software unaligned access emulation always available as a fallback
> (while hot paths like memcpy/memset/copy_user already dynamically
> switch via ALTERNATIVE based on CPU_FEATURE_UAL).
IMO it's easier to just move CONFIG_ARCH_STRICT_ALIGN out of
CONFIG_EXPERT and let the distro maintainer to decide (based on if they
are building a desktop/server distro or a embedded distro).
The desktop/server distros already cannot run on the embedded processors
like 2K0300/2K0500 because the uses of LSX and there's no way to salvage
it. So it does not make sense to be so idealistic and attempt to use
one kernel image for both desktop/server and embedded.
--
Xi Ruoyao <xry111@xxxxxxxxxxx>