summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIdo Yariv <ido@wizery.com>2011-12-01 13:55:08 +0200
committerGreg Kroah-Hartman <gregkh@suse.de>2011-12-09 09:21:50 -0800
commit2a96fb69ba383c2d3923456d1e933ba4950eb4c5 (patch)
tree9b36b48f3a79e70419485ba36dfe292a48700006
parentb669d5d9173f5f8d0e84744bc03e19d7f94f36ed (diff)
genirq: Fix race condition when stopping the irq thread
commit 550acb19269d65f32e9ac4ddb26c2b2070e37f1c 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>
-rw-r--r--kernel/irq/manage.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index d40ecd5822e7..315705ca00f3 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -475,8 +475,9 @@ static irqreturn_t irq_nested_primary_handler(int irq, void *dev_id)
static int irq_wait_for_interrupt(struct irqaction *action)
{
+ set_current_state(TASK_INTERRUPTIBLE);
+
while (!kthread_should_stop()) {
- set_current_state(TASK_INTERRUPTIBLE);
if (test_and_clear_bit(IRQTF_RUNTHREAD,
&action->thread_flags)) {
@@ -484,7 +485,9 @@ static int irq_wait_for_interrupt(struct irqaction *action)
return 0;
}
schedule();
+ set_current_state(TASK_INTERRUPTIBLE);
}
+ __set_current_state(TASK_RUNNING);
return -1;
}