Skip to content

Commit 8d39d6e

Browse files
committed
genirq: Prevent migration live lock in handle_edge_irq()
Yicon reported and Liangyan debugged a live lock in handle_edge_irq() related to interrupt migration. If the interrupt affinity is moved to a new target CPU and the interrupt is currently handled on the previous target CPU for edge type interrupts the handler might get stuck on the previous target: CPU 0 (previous target) CPU 1 (new target) handle_edge_irq() repeat: handle_event() handle_edge_irq() if (INPROGESS) { set(PENDING); mask(); return; } if (PENDING) { clear(PENDING); unmask(); goto repeat; } The migration in software never completes and CPU0 continues to handle the pending events forever. This happens when the device raises interrupts with a high rate and always before handle_event() completes and before the CPU0 handler can clear INPROGRESS so that CPU1 sets the PENDING flag over and over. This has been observed in virtual machines. Prevent this by checking whether the CPU which observes the INPROGRESS flag is the new affinity target. If that's the case, do not set the PENDING flag and wait for the INPROGRESS flag to be cleared instead, so that the new interrupt is handled on the new target CPU and the previous CPU is released from the action. This is restricted to the edge type handler and only utilized on systems, which use single CPU targets for interrupt affinity. Reported-by: Yicong Shen <shenyicong.1023@bytedance.com> Reported-by: Liangyan <liangyan.peng@bytedance.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Liangyan <liangyan.peng@bytedance.com> Reviewed-by: Jiri Slaby <jirislaby@kernel.org> Link: https://lore.kernel.org/all/20250701163558.2588435-1-liangyan.peng@bytedance.com Link: https://lore.kernel.org/all/20250718185312.076515034@linutronix.de
1 parent c609045 commit 8d39d6e

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

kernel/irq/chip.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,11 +476,14 @@ static bool irq_wait_on_inprogress(struct irq_desc *desc)
476476

477477
static bool irq_can_handle_pm(struct irq_desc *desc)
478478
{
479+
struct irq_data *irqd = &desc->irq_data;
480+
const struct cpumask *aff;
481+
479482
/*
480483
* If the interrupt is not in progress and is not an armed
481484
* wakeup interrupt, proceed.
482485
*/
483-
if (!irqd_has_set(&desc->irq_data, IRQD_IRQ_INPROGRESS | IRQD_WAKEUP_ARMED))
486+
if (!irqd_has_set(irqd, IRQD_IRQ_INPROGRESS | IRQD_WAKEUP_ARMED))
484487
return true;
485488

486489
/*
@@ -501,7 +504,41 @@ static bool irq_can_handle_pm(struct irq_desc *desc)
501504
return false;
502505
return irq_wait_on_inprogress(desc);
503506
}
504-
return false;
507+
508+
/* The below works only for single target interrupts */
509+
if (!IS_ENABLED(CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK) ||
510+
!irqd_is_single_target(irqd) || desc->handle_irq != handle_edge_irq)
511+
return false;
512+
513+
/*
514+
* If the interrupt affinity was moved to this CPU and the
515+
* interrupt is currently handled on the previous target CPU, then
516+
* busy wait for INPROGRESS to be cleared. Otherwise for edge type
517+
* interrupts the handler might get stuck on the previous target:
518+
*
519+
* CPU 0 CPU 1 (new target)
520+
* handle_edge_irq()
521+
* repeat:
522+
* handle_event() handle_edge_irq()
523+
* if (INPROGESS) {
524+
* set(PENDING);
525+
* mask();
526+
* return;
527+
* }
528+
* if (PENDING) {
529+
* clear(PENDING);
530+
* unmask();
531+
* goto repeat;
532+
* }
533+
*
534+
* This happens when the device raises interrupts with a high rate
535+
* and always before handle_event() completes and the CPU0 handler
536+
* can clear INPROGRESS. This has been observed in virtual machines.
537+
*/
538+
aff = irq_data_get_effective_affinity_mask(irqd);
539+
if (cpumask_first(aff) != smp_processor_id())
540+
return false;
541+
return irq_wait_on_inprogress(desc);
505542
}
506543

507544
static inline bool irq_can_handle_actions(struct irq_desc *desc)

0 commit comments

Comments
 (0)