]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
genirq: Retain disable depth for managed interrupts across CPU hotplug
authorBrian Norris <briannorris@chromium.org>
Wed, 14 May 2025 20:13:16 +0000 (13:13 -0700)
committerThomas Gleixner <tglx@linutronix.de>
Thu, 15 May 2025 14:44:25 +0000 (16:44 +0200)
Affinity-managed interrupts can be shut down and restarted during CPU
hotunplug/plug. Thereby the interrupt may be left in an unexpected state.
Specifically:

 1. Interrupt is affine to CPU N
 2. disable_irq() -> depth is 1
 3. CPU N goes offline
 4. irq_shutdown() -> depth is set to 1 (again)
 5. CPU N goes online
 6. irq_startup() -> depth is set to 0 (BUG! driver expects that the interrupt
                          still disabled)
 7. enable_irq() -> depth underflow / unbalanced enable_irq() warning

This is only a problem for managed interrupts and CPU hotplug, all other
cases like request()/free()/request() truly needs to reset a possibly stale
disable depth value.

Provide a startup function, which takes the disable depth into account, and
invoked it for the managed interrupts in the CPU hotplug path.

This requires to change irq_shutdown() to do a depth increment instead of
setting it to 1, which allows to retain the disable depth, but is harmless
for the other code paths using irq_startup(), which will still reset the
disable depth unconditionally to keep the original correct behaviour.

A kunit tests will be added separately to cover some of these aspects.

[ tglx: Massaged changelog ]

Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20250514201353.3481400-2-briannorris@chromium.org
kernel/irq/chip.c
kernel/irq/cpuhotplug.c
kernel/irq/internals.h

index 1d45c84d7356b7f3107ea616fd9702fe80637497..b0e0a7332993c77ab9c092f59c87b58c55552fc5 100644 (file)
@@ -202,6 +202,19 @@ __irq_startup_managed(struct irq_desc *desc, const struct cpumask *aff,
                return IRQ_STARTUP_ABORT;
        return IRQ_STARTUP_MANAGED;
 }
+
+void irq_startup_managed(struct irq_desc *desc)
+{
+       /*
+        * Only start it up when the disable depth is 1, so that a disable,
+        * hotunplug, hotplug sequence does not end up enabling it during
+        * hotplug unconditionally.
+        */
+       desc->depth--;
+       if (!desc->depth)
+               irq_startup(desc, IRQ_RESEND, IRQ_START_COND);
+}
+
 #else
 static __always_inline int
 __irq_startup_managed(struct irq_desc *desc, const struct cpumask *aff,
@@ -269,6 +282,7 @@ int irq_startup(struct irq_desc *desc, bool resend, bool force)
                        ret = __irq_startup(desc);
                        break;
                case IRQ_STARTUP_ABORT:
+                       desc->depth = 1;
                        irqd_set_managed_shutdown(d);
                        return 0;
                }
@@ -301,7 +315,13 @@ void irq_shutdown(struct irq_desc *desc)
 {
        if (irqd_is_started(&desc->irq_data)) {
                clear_irq_resend(desc);
-               desc->depth = 1;
+               /*
+                * Increment disable depth, so that a managed shutdown on
+                * CPU hotunplug preserves the actual disabled state when the
+                * CPU comes back online. See irq_startup_managed().
+                */
+               desc->depth++;
+
                if (desc->irq_data.chip->irq_shutdown) {
                        desc->irq_data.chip->irq_shutdown(&desc->irq_data);
                        irq_state_set_disabled(desc);
index e77ca6db5e11ec0bbf67ccf7b99f0c877a52509a..f07529ae489527423b2e758ce61e7f51c46a1013 100644 (file)
@@ -218,7 +218,7 @@ static void irq_restore_affinity_of_irq(struct irq_desc *desc, unsigned int cpu)
                return;
 
        if (irqd_is_managed_and_shutdown(data))
-               irq_startup(desc, IRQ_RESEND, IRQ_START_COND);
+               irq_startup_managed(desc);
 
        /*
         * If the interrupt can only be directed to a single target
index 476a20fd9bfce1f2ae93d18521ebae9a1b087217..aebfe225c9a6d4abceefc6465e55daf4719b149d 100644 (file)
@@ -87,6 +87,7 @@ extern void __enable_irq(struct irq_desc *desc);
 extern int irq_activate(struct irq_desc *desc);
 extern int irq_activate_and_startup(struct irq_desc *desc, bool resend);
 extern int irq_startup(struct irq_desc *desc, bool resend, bool force);
+extern void irq_startup_managed(struct irq_desc *desc);
 
 extern void irq_shutdown(struct irq_desc *desc);
 extern void irq_shutdown_and_deactivate(struct irq_desc *desc);