[PATCH v4 3/7] genirq: Implement synchronous disable_nmi()

From: Mayank Rungta

Date: Wed Nov 11 2026 - 22:19:32 EST


Currently, disable_nmi_nosync() is the only interface to disable an NMI
line. Drivers stopping their devices need a synchronous variant that
guarantees any running instance of the NMI handler has completed on other
CPUs before returning.

Implement disable_nmi() by validating the descriptor, disabling the line
via __disable_irq_nosync(), and synchronizing in-flight NMI handlers via
__synchronize_nmi().

Signed-off-by: Mayank Rungta <mrungta@xxxxxxxxxx>
---
include/linux/interrupt.h | 1 +
kernel/irq/manage.c | 24 ++++++++++++++++++++++++
2 files changed, 25 insertions(+)

diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index ee2dd5349697..4a220142e16c 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -245,6 +245,7 @@ DEFINE_LOCK_GUARD_1(disable_irq, int,
disable_irq(*_T->lock), enable_irq(*_T->lock))

extern void disable_nmi_nosync(unsigned int irq);
+void disable_nmi(unsigned int irq);
extern void disable_percpu_nmi(unsigned int irq);
extern void enable_nmi(unsigned int irq);
extern void enable_percpu_nmi(unsigned int irq, unsigned int type);
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index bd7cf91719d7..073fd3595d2c 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -829,6 +829,30 @@ void disable_nmi_nosync(unsigned int irq)
disable_irq_nosync(irq);
}

+/**
+ * disable_nmi - Disable an NMI and wait for any pending handlers
+ * @irq: Interrupt to disable
+ *
+ * Disable the selected interrupt line. Disables and enables are nested.
+ *
+ * The interrupt to disable must have been requested through request_nmi().
+ * This function ensures existing instances of the NMI handler have
+ * completed before returning.
+ *
+ * Cannot be called from NMI context.
+ */
+void disable_nmi(unsigned int irq)
+{
+ struct irq_desc *desc = irq_to_desc(irq);
+
+ if (!desc || WARN_ON(in_nmi()) || WARN_ON(!irq_is_nmi(desc)) ||
+ WARN_ON(irq_settings_is_per_cpu_devid(desc)))
+ return;
+
+ if (!__disable_irq_nosync(irq))
+ __synchronize_nmi(desc, true);
+}
+
void __enable_irq(struct irq_desc *desc)
{
switch (desc->depth) {
--
2.56.0.611.g1030f0b940-goog