Michal Suchanek 65f660
From d0afd44c05f8f4e4c91487c02d43c87a31552462 Mon Sep 17 00:00:00 2001
Michal Suchanek 65f660
From: Nicholas Piggin <npiggin@gmail.com>
Michal Suchanek 65f660
Date: Tue, 5 Oct 2021 00:56:39 +1000
Michal Suchanek 65f660
Subject: [PATCH] powerpc/traps: do not enable irqs in _exception
Michal Suchanek 65f660
Michal Suchanek 65f660
References: bsc#1065729
Michal Suchanek 65f660
Patch-mainline: v5.15-rc5
Michal Suchanek 65f660
Git-commit: d0afd44c05f8f4e4c91487c02d43c87a31552462
Michal Suchanek 65f660
Michal Suchanek 65f660
_exception can be called by machine check handlers when the MCE hits
Michal Suchanek 65f660
user code (e.g., pseries and powernv). This will enable local irqs
Michal Suchanek 65f660
because, which is a dicey thing to do in NMI or hard irq context.
Michal Suchanek 65f660
Michal Suchanek 65f660
This seemed to worked out okay because a userspace MCE can basically be
Michal Suchanek 65f660
treated like a synchronous interrupt (after async / imprecise MCEs are
Michal Suchanek 65f660
filtered out). Since NMI and hard irq handlers have started growing
Michal Suchanek 65f660
nmi_enter / irq_enter, and more irq state sanity checks, this has
Michal Suchanek 65f660
started to cause problems (or at least trigger warnings).
Michal Suchanek 65f660
Michal Suchanek 65f660
The Fixes tag to the commit which introduced this rather than try to
Michal Suchanek 65f660
work out exactly which commit was the first that could possibly cause a
Michal Suchanek 65f660
problem because that may be difficult to prove.
Michal Suchanek 65f660
Michal Suchanek 65f660
Fixes: 9f2f79e3a3c1 ("powerpc: Disable interrupts in 64-bit kernel FP and vector faults")
Michal Suchanek 65f660
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Michal Suchanek 65f660
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Michal Suchanek 65f660
Link: https://lore.kernel.org/r/20211004145642.1331214-3-npiggin@gmail.com
Michal Suchanek 65f660
Acked-by: Michal Suchanek <msuchanek@suse.de>
Michal Suchanek 65f660
---
Michal Suchanek 65f660
 arch/powerpc/kernel/traps.c | 12 +++++++++---
Michal Suchanek 65f660
 1 file changed, 9 insertions(+), 3 deletions(-)
Michal Suchanek 65f660
Michal Suchanek 65f660
diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
Michal Suchanek 65f660
index aac8c0412ff9..e453b666613b 100644
Michal Suchanek 65f660
--- a/arch/powerpc/kernel/traps.c
Michal Suchanek 65f660
+++ b/arch/powerpc/kernel/traps.c
Michal Suchanek 65f660
@@ -340,10 +340,16 @@ static bool exception_common(int signr, struct pt_regs *regs, int code,
Michal Suchanek 65f660
 		return false;
Michal Suchanek 65f660
 	}
Michal Suchanek 65f660
 
Michal Suchanek 65f660
-	show_signal_msg(signr, regs, code, addr);
Michal Suchanek 65f660
+	/*
Michal Suchanek 65f660
+	 * Must not enable interrupts even for user-mode exception, because
Michal Suchanek 65f660
+	 * this can be called from machine check, which may be a NMI or IRQ
Michal Suchanek 65f660
+	 * which don't like interrupts being enabled. Could check for
Michal Suchanek 65f660
+	 * in_hardirq || in_nmi perhaps, but there doesn't seem to be a good
Michal Suchanek 65f660
+	 * reason why _exception() should enable irqs for an exception handler,
Michal Suchanek 65f660
+	 * the handlers themselves do that directly.
Michal Suchanek 65f660
+	 */
Michal Suchanek 65f660
 
Michal Suchanek 65f660
-	if (arch_irqs_disabled())
Michal Suchanek 65f660
-		interrupt_cond_local_irq_enable(regs);
Michal Suchanek 65f660
+	show_signal_msg(signr, regs, code, addr);
Michal Suchanek 65f660
 
Michal Suchanek 65f660
 	current->thread.trap_nr = code;
Michal Suchanek 65f660
 
Michal Suchanek 65f660
-- 
Michal Suchanek 65f660
2.31.1
Michal Suchanek 65f660