From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796466479; b=SO54HlELua1EBHyFD+xwIRnnKj3i+MPQBVL0rrH4CRj7F35Niwj/jOJYQQe52H/hV9g3 lh5qMxIzKzYtdlw6mQdtugmNyzX6P1btn8oa2aMnO6D6QBXgx+X1t5npbXJMr9tNSu1YH fJwBZmmwIXzkn3L0MgkYmzr3NCBuJzBlHlfHzvkj1UzHh5ffmLx1ebcoAppsW1Vdmq0SR g0LXx6gwBXjFIU6NoWQlDJrhrCo3gq0RiAFsDQY2dYG0jpAEabg5pP6pPpEiWZgQTjiMV fEb5aiBCS/DRVvxj/K0pMYzgeG0t3dRUUtqqVUjPanleCvJYM1IPSIAKgJDRR3rf5aQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796466479; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=f/p7c+ia0S0rql9K6IbJZ51y/UZRHm2Lh74tjo/VXUg=; b=MivrGjObr1pZ/lUnPFCEsvEhzceVYOEdgCUL3C7qigupPTBfT8hw38wNGyu6aksgVhPe I8z8N9mnxPmII/inLTKL/ZeXAKLqpqJHnDEaeNpSplcqRna/Kz02CrNFp35FfPo/Gu9K5 2BlArnDt4l1YuKDK7ir2RJ1ik1mG6vZo0vtS2DNK6gqMnyLDROIAIm7CEKTKIBq8Swcx3 btmX8MU5iJvnuKM2z6Ahnt7iJtFsSQY2P4prB6keingZ2x/INfsSxCLnZ0xySyD7/5Afi +oJRkJQXQSEQtpD5tjs1pKWldwyq+flORXXbHM8XdJeilFxKkNfDxeH4ZZNQ9YRK3mg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HIq5aN3l; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5EC40606A322 for ; Sat, 5 Dec 2026 10:27:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HIq5aN3l Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC7D61F0092B; Sat, 5 Dec 2026 10:27:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796466478; bh=f/p7c+ia0S0rql9K6IbJZ51y/UZRHm2Lh74tjo/VXUg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=HIq5aN3ltuLF8wXQiHBVPn2Bdjk5Edxk3U15Z95whcQfbLzGjDaPkLt4BbK4JLI2b HY9LoO3+zUKwO47BOACU9HGBJ1abAlkDnjO2h5LBNOsXYIhvAPdPCnjeaZSrvBI/EA 2gPe7j0pDPBB9q2Oc0tN3wwKaGQGetp5in1wDLobsUGgfz64gO7ZQ9xtbnktO2joyq 6ObPtf2aQmxRM3RcshhHtDLIQn/2W2GhaBOEZY5ceHuleMieZa/a4vMXeSCQAtth21 EcYECo3eyGfZBfTouT5QucMqeGxqbuDaFJ0KtixgF8ytxAsbkABr7lx+32iJJuOZzR Cn/UW7DNpXX3g== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH RFC] LoongArch: Enable HAVE_EFFICIENT_UNALIGNED_ACCESS by default Reply-To: sashiko-reviews@lists.linux.dev To: "Tiezhu Yang" Cc: bpf@vger.kernel.org In-Reply-To: <20261205100121.3605-1-yangtiezhu@loongson.cn> References: <20261205100121.3605-1-yangtiezhu@loongson.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 10:27:58 +0000 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [High] loongarch: disabling ARCH_STRICT_ALIGN breaks early boot on non-UAL CPUs - [High] loongarch: 32-bit ARCH_STRICT_ALIGN=3Dn exposes corrupt unaligned_read() - [Medium] loongarch: unscoped sysctl checks and recursion hazard in do_ale() - [Medium] loongarch: do_ale() drops BUS_ADRALN and si_addr via force_sig(SIGBUS) - [Low] loongarch: ARCH_STRICT_ALIGN gated behind EXPERT despite help text advice -- commit 761f7e330651266d46a18c88be50f6915ae68994 Author: Tiezhu Yang LoongArch: Enable HAVE_EFFICIENT_UNALIGNED_ACCESS by default This commit disables CONFIG_ARCH_STRICT_ALIGN by default to enable HAVE_EFFICIENT_UNALIGNED_ACCESS on LoongArch, while building unaligned.o unconditionally so software unaligned access emulation remains available as a fallback. > diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig > index 2331ecab5f401..09907212ba36f 100644 > --- a/arch/loongarch/Kconfig > +++ b/arch/loongarch/Kconfig > @@ -595,7 +595,7 @@ config ARCH_IOREMAP > =20 > config ARCH_STRICT_ALIGN > bool "Enable -mstrict-align to prevent unaligned accesses" if EXPERT > - default y > + default n [Severity: High] Can disabling CONFIG_ARCH_STRICT_ALIGN by default break early boot on processors without hardware UAL support? handle_ale is not installed until trap_init() runs late in start_kernel(). Before that, per_cpu_trap_init() wires EXCCODE_ALE to handle_reserved, which panics via do_reserved() -> die_if_kernel(). With -mno-strict-align and CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS enabled, early boot code such as cpu_probe_loongson() (which performs a 64-bit store to cpu_full_name[9]) and sized_strscpy() in init_environ() executes unaligned accesses before trap_init() and crashes non-UAL systems like Loongson-2K0300/2K0500/2K1000. The EFI stub and ZBOOT decompressor also inherit -mno-strict-align from KBUILD_CFLAGS in drivers/firmware/efi/libstub/Makefile and execute before kernel_entry when no kernel ALE handler exists. [Severity: High] Will defaulting CONFIG_ARCH_STRICT_ALIGN to n on CONFIG_32BIT expose silent data corruption in unaligned_read() on 32-bit non-UAL hardware? arch/loongarch/lib/unaligned.S:unaligned_read() { ... LONG_ADDI t0, a2, -1 PTR_SLLI t1, t0, LONGLOG ... LONG_ADDI t1, t1, -8 ... } On CONFIG_32BIT, LONGLOG is 2 rather than 3, so t1 starts at (n - 1) * 4 instead of (n - 1) * 8 while the loop still decrements it by 8 each iteration. Every emulated unaligned load on 32-bit non-UAL CPUs shifts bytes to the wrong bit positions and returns corrupted data. Keeping ARCH_STRICT_ALIGN enabled by default on CONFIG_32BIT (or fixing unaligned_read() to shift by 3) would avoid this regression. [ ... ] > + You can enable it manually if you want to optimise for performance > + on systems without h/w unaligned access support to avoid the extra > + overhead of unaligned exception emulation. [Severity: Low] Since ARCH_STRICT_ALIGN is still gated by "if EXPERT", can non-EXPERT users follow this advice? Without CONFIG_EXPERT enabled, the option is hidden in Kconfig and users targeting non-UAL systems cannot enable it. [ ... ] > diff --git a/arch/loongarch/kernel/traps.c b/arch/loongarch/kernel/traps.c > index 790db6c1926e6..30bef19d28fa7 100644 > --- a/arch/loongarch/kernel/traps.c > +++ b/arch/loongarch/kernel/traps.c > @@ -564,13 +564,6 @@ int no_unaligned_warning __read_mostly =3D 1; /* Onl= y 1 warning by default */ > asmlinkage void noinstr do_ale(struct pt_regs *regs) > { > irqentry_state_t state =3D irqentry_enter(regs); > - > -#ifndef CONFIG_ARCH_STRICT_ALIGN > - if (!fixup_exception(regs)) { > - die_if_kernel("Kernel ale access", regs); > - force_sig_fault(SIGBUS, BUS_ADRALN, (void __user *)regs->csr_badvaddr); > - } > -#else > bool pie =3D regs_irqs_disabled(regs); > unsigned int *pc; [Severity: Medium] Does removing the !CONFIG_ARCH_STRICT_ALIGN branch regress siginfo_t reporting for unhandled userspace alignment faults? Previously, CONFIG_ARCH_STRICT_ALIGN=3Dn kernels delivered SIGBUS with BUS_ADRALN and regs->csr_badvaddr via force_sig_fault(). Now userspace traps on unemulated instructions (such as unaligned AM*/ll/sc atomics, which still raise EXCCODE_ALE on UAL-capable CPUs) reach the sigbus label in emulate_load_store_insn(), which calls force_sig(SIGBUS) and reports si_code =3D SI_KERNEL and si_addr =3D NULL. emulate_load_store_insn() also ignores the return value of __get_inst(), so an instruction-fetch fault on an execute-only page likewise falls through to force_sig(SIGBUS). [Severity: Medium] Are the unaligned_enabled and no_unaligned_warning checks in do_ale() safe for kernel-mode traps now that non-UAL CPUs rely on emulation for normal kernel code? Neither check is restricted to user_mode(regs). Setting kernel.unaligned-trap to 0 sends the next routine kernel unaligned access to sigbus and panics in die_if_kernel(). Setting kernel.ignore-unaligned-usertrap to 0 calls show_registers() without a recursion guard, which can recurse indefinitely through printk() and string helpers into do_ale() until the kernel stack overflows. In addition, arch/loongarch/kernel/Makefile builds unaligned.o with -mno-strict-align and leaves ftrace and KASAN enabled on it, which can trigger recursive EXCCODE_ALE faults inside emulate_load_store_insn() on non-UAL CPUs. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205100121.3605= -1-yangtiezhu@loongson.cn?part=3D1