mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1] LoongArch: Call fixup_exception() for unaligned accesses
@ 2026-12-02  8:11 Tiezhu Yang
  2026-12-02 13:21 ` George Guo
  2026-12-02 13:40 ` George Guo
  0 siblings, 2 replies; 3+ messages in thread
From: Tiezhu Yang @ 2026-12-02  8:11 UTC (permalink / raw)
  To: Huacai Chen; +Cc: George Guo, loongarch, linux-kernel

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.

Reported-by: sashiko-bot <sashiko@sashiko.dev>
Closes: https://lore.kernel.org/bpf/sashiko-outbox-243049@kernel.org/
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 arch/loongarch/kernel/traps.c     | 12 ++++++++----
 arch/loongarch/kernel/unaligned.c |  4 ++++
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/arch/loongarch/kernel/traps.c b/arch/loongarch/kernel/traps.c
index 20ce2c8d77a1..906ef7a57343 100644
--- a/arch/loongarch/kernel/traps.c
+++ b/arch/loongarch/kernel/traps.c
@@ -564,8 +564,10 @@ asmlinkage void noinstr do_ale(struct pt_regs *regs)
 	irqentry_state_t state = irqentry_enter(regs);
 
 #ifndef CONFIG_ARCH_STRICT_ALIGN
-	die_if_kernel("Kernel ale access", regs);
-	force_sig_fault(SIGBUS, BUS_ADRALN, (void __user *)regs->csr_badvaddr);
+	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 = regs_irqs_disabled(regs);
 	unsigned int *pc;
@@ -594,8 +596,10 @@ asmlinkage void noinstr do_ale(struct pt_regs *regs)
 	goto out;
 
 sigbus:
-	die_if_kernel("Kernel ale access", regs);
-	force_sig_fault(SIGBUS, BUS_ADRALN, (void __user *)regs->csr_badvaddr);
+	if (!fixup_exception(regs)) {
+		die_if_kernel("Kernel ale access", regs);
+		force_sig_fault(SIGBUS, BUS_ADRALN, (void __user *)regs->csr_badvaddr);
+	}
 out:
 	if (!pie)
 		local_irq_disable();
diff --git a/arch/loongarch/kernel/unaligned.c b/arch/loongarch/kernel/unaligned.c
index cc929c9fe7e9..82f53b199f45 100644
--- a/arch/loongarch/kernel/unaligned.c
+++ b/arch/loongarch/kernel/unaligned.c
@@ -491,6 +491,10 @@ void emulate_load_store_insn(struct pt_regs *regs, void __user *addr, unsigned i
 	return;
 
 sigbus:
+	/* Did we have an exception handler installed? */
+	if (fixup_exception(regs))
+		return;
+
 	die_if_kernel("Unhandled kernel unaligned access", regs);
 	force_sig(SIGBUS);
 
-- 
2.42.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-02 13:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02  8:11 [PATCH v1] LoongArch: Call fixup_exception() for unaligned accesses Tiezhu Yang
2026-12-02 13:21 ` George Guo
2026-12-02 13:40 ` George Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®