Skip to content

Commit 788019e

Browse files
computersforpeaceKAGA-KOKO
authored andcommitted
genirq: Retain disable depth for managed interrupts across CPU hotplug
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
1 parent a4a39c8 commit 788019e

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

kernel/irq/chip.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,19 @@ __irq_startup_managed(struct irq_desc *desc, const struct cpumask *aff,
202202
return IRQ_STARTUP_ABORT;
203203
return IRQ_STARTUP_MANAGED;
204204
}
205+
206+
void irq_startup_managed(struct irq_desc *desc)
207+
{
208+
/*
209+
* Only start it up when the disable depth is 1, so that a disable,
210+
* hotunplug, hotplug sequence does not end up enabling it during
211+
* hotplug unconditionally.
212+
*/
213+
desc->depth--;
214+
if (!desc->depth)
215+
irq_startup(desc, IRQ_RESEND, IRQ_START_COND);
216+
}
217+
205218
#else
206219
static __always_inline int
207220
__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)
269282
ret = __irq_startup(desc);
270283
break;
271284
case IRQ_STARTUP_ABORT:
285+
desc->depth = 1;
272286
irqd_set_managed_shutdown(d);
273287
return 0;
274288
}
@@ -301,7 +315,13 @@ void irq_shutdown(struct irq_desc *desc)
301315
{
302316
if (irqd_is_started(&desc->irq_data)) {
303317
clear_irq_resend(desc);
304-
desc->depth = 1;
318+
/*
319+
* Increment disable depth, so that a managed shutdown on
320+
* CPU hotunplug preserves the actual disabled state when the
321+
* CPU comes back online. See irq_startup_managed().
322+
*/
323+
desc->depth++;
324+
305325
if (desc->irq_data.chip->irq_shutdown) {
306326
desc->irq_data.chip->irq_shutdown(&desc->irq_data);
307327
irq_state_set_disabled(desc);

kernel/irq/cpuhotplug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ static void irq_restore_affinity_of_irq(struct irq_desc *desc, unsigned int cpu)
218218
return;
219219

220220
if (irqd_is_managed_and_shutdown(data))
221-
irq_startup(desc, IRQ_RESEND, IRQ_START_COND);
221+
irq_startup_managed(desc);
222222

223223
/*
224224
* If the interrupt can only be directed to a single target

kernel/irq/internals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ extern void __enable_irq(struct irq_desc *desc);
8787
extern int irq_activate(struct irq_desc *desc);
8888
extern int irq_activate_and_startup(struct irq_desc *desc, bool resend);
8989
extern int irq_startup(struct irq_desc *desc, bool resend, bool force);
90+
extern void irq_startup_managed(struct irq_desc *desc);
9091

9192
extern void irq_shutdown(struct irq_desc *desc);
9293
extern void irq_shutdown_and_deactivate(struct irq_desc *desc);

0 commit comments

Comments
 (0)