Skip to content

Commit a4b63ef

Browse files
Ido Yarivgregkh
authored andcommitted
genirq: Fix race condition when stopping the irq thread
commit 550acb1 upstream. In irq_wait_for_interrupt(), the should_stop member is verified before setting the task's state to TASK_INTERRUPTIBLE and calling schedule(). In case kthread_stop sets should_stop and wakes up the process after should_stop is checked by the irq thread but before the task's state is changed, the irq thread might never exit: kthread_stop irq_wait_for_interrupt ------------ ---------------------- ... ... while (!kthread_should_stop()) { kthread->should_stop = 1; wake_up_process(k); wait_for_completion(&kthread->exited); ... set_current_state(TASK_INTERRUPTIBLE); ... schedule(); } Fix this by checking if the thread should stop after modifying the task's state. [ tglx: Simplified it a bit ] Signed-off-by: Ido Yariv <ido@wizery.com> Link: http://lkml.kernel.org/r/1322740508-22640-1-git-send-email-ido@wizery.com Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent aedebb8 commit a4b63ef

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎kernel/irq/manage.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,16 +620,19 @@ static irqreturn_t irq_nested_primary_handler(int irq, void *dev_id)
620620

621621
static int irq_wait_for_interrupt(struct irqaction *action)
622622
{
623+
set_current_state(TASK_INTERRUPTIBLE);
624+
623625
while (!kthread_should_stop()) {
624-
set_current_state(TASK_INTERRUPTIBLE);
625626

626627
if (test_and_clear_bit(IRQTF_RUNTHREAD,
627628
&action->thread_flags)) {
628629
__set_current_state(TASK_RUNNING);
629630
return 0;
630631
}
631632
schedule();
633+
set_current_state(TASK_INTERRUPTIBLE);
632634
}
635+
__set_current_state(TASK_RUNNING);
633636
return -1;
634637
}
635638

0 commit comments

Comments
 (0)