From: Thomas Gleixner <tglx@linutronix.de>
To: Ido Yariv <ido@wizery.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] irq: Fix race condition when stopping the irq thread
Date: Thu, 1 Dec 2011 22:23:22 +0100 (CET) [thread overview]
Message-ID: <alpine.LFD.2.02.1112012221380.2735@ionos> (raw)
In-Reply-To: <1322740508-22640-1-git-send-email-ido@wizery.com>
On Thu, 1 Dec 2011, Ido Yariv wrote:
> 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.
Good catch! I restructure it to:
--- tip.orig/kernel/irq/manage.c
+++ tip/kernel/irq/manage.c
@@ -623,8 +623,9 @@ static irqreturn_t irq_nested_primary_ha
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)) {
@@ -632,7 +633,9 @@ static int irq_wait_for_interrupt(struct
return 0;
}
schedule();
+ set_current_state(TASK_INTERRUPTIBLE);
}
+ __set_current_state(TASK_RUNNING);
return -1;
}
That saves us the extra conditional in the loop.
Thanks,
tglx
next prev parent reply other threads:[~2011-12-01 21:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-01 11:55 Ido Yariv
2011-12-01 21:23 ` Thomas Gleixner [this message]
2011-12-02 10:59 ` [tip:irq/urgent] genirq: " tip-bot for Ido Yariv
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LFD.2.02.1112012221380.2735@ionos \
--to=tglx@linutronix.de \
--cc=ido@wizery.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome