[PATCH v4 5/9] x86/nmi: Support NMI stop-machine handler
From: Chang S. Bae
Date: Wed Nov 04 2026 - 14:03:37 EST
From: David Kaplan <david.kaplan@xxxxxxx>
Call the stop-machine handler from the NMI path in order to support the
NMI stop-machine.
Signed-off-by: David Kaplan <david.kaplan@xxxxxxx>
Signed-off-by: Chang S. Bae <chang.seok.bae@xxxxxxxxx>
---
V3 -> V4: Leave a note against coalesced NMI events in theory (Sashiko).
---
arch/x86/kernel/nmi.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
index 3c9f60d6ca5a..0d426e5e74ee 100644
--- a/arch/x86/kernel/nmi.c
+++ b/arch/x86/kernel/nmi.c
@@ -24,6 +24,7 @@
#include <linux/export.h>
#include <linux/atomic.h>
#include <linux/sched/clock.h>
+#include <linux/stop_machine.h>
#include <linux/kvm_types.h>
#include <asm/cpu_entry_area.h>
@@ -382,6 +383,14 @@ static noinstr void default_do_nmi(struct pt_regs *regs)
instrumentation_begin();
+ /*
+ * When an NMI stop-machine runs, the rest of the system should be idle,
+ * so handle the stop-machine NMI first even if other NMIs might get
+ * coalesced with it.
+ */
+ if (stop_machine_nmi_handler())
+ goto out;
+
if (microcode_nmi_handler_enabled() && microcode_nmi_handler())
goto out;
--
2.53.0