From: Thomas Gleixner <tglx@linutronix.de>
To: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kthread: Fix the race condition when kthread is parked
Date: Fri, 27 Jun 2014 01:50:03 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.10.1406270035360.5170@nanos> (raw)
In-Reply-To: <53AC9114.9070106@codeaurora.org>
On Thu, 26 Jun 2014, Subbaraman Narayanamurthy wrote:
> On 06/25/14 17:43, Thomas Gleixner wrote:
> > The kthread park/unpark logic has the following issue:
> >
> > Task CPU 0 CPU 1
> >
> > T1 unplug cpu1
> > kthread_park(T2)
> > set_bit(KTHREAD_SHOULD_PARK);
> > wait_for_completion()
> > T2 parkme(X)
> > __set_current_state(TASK_PARKED);
> > while
> > (test_bit(KTHREAD_SHOULD_PARK)) {
> > if
> > (!test_and_set_bit(KTHREAD_IS_PARKED))
> > complete();
> > schedule();
> > T1 plug cpu1
> >
> > --> premature wakeup of T2, i.e. before unpark, so T2 gets scheduled on
> > CPU 0
> I understood the explanation above. But still I don't understand how this
> premature wakeup of T2 is happening/possible?
Come on. You have a machine which reproduces the issue. So some
moderate tracing should tell you that ...
Without using my lost crystal ball, I bet that it's a premature per
cpu timer interrupt.
> Also, what will happen if the task state is not in TASK_PARKED when
> __kthread_unpark is called? __kthread_bind will fail silently
> causing the same problem.
Right you are, but thinking more about it:
Nothing is supposed to wakeup a parked thread except the unpark
machinery. So the real question is: What causes the premature wakeup?
Darn, I should have thought about that before, but you tricked my
overloaded brain into believing that this is a real issue.
No, it's not.
The parked state is not any different from creating a new kthread,
advertise the thread to possible wakers and then do the bind.
So yes, the code is fine and the BUG_ON() is rightfully asserting
here.
> Thanks for the patch. I've tested (running hotplug tests) it for sometime and
> looks good so far. Can you please submit it?
So you have a legitimate question about the correctness of the patch
and then you ask me to apply it?
Again, we do not apply patches which "fix" an issue just because we do
not observe it anymore. We apply them when the problem at hand is
fully understood and the solution solves all aspects.
Thanks,
tglx
next prev parent reply other threads:[~2014-06-26 23:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-25 19:42 Subbaraman Narayanamurthy
2014-06-26 0:43 ` Thomas Gleixner
2014-06-26 2:00 ` Steven Rostedt
2014-06-26 2:03 ` Steven Rostedt
2014-06-26 21:31 ` Subbaraman Narayanamurthy
2014-06-26 23:50 ` Thomas Gleixner [this message]
2014-11-02 12:01 Daniel J Blueman
2014-11-03 19:44 ` Thomas Gleixner
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.DEB.2.10.1406270035360.5170@nanos \
--to=tglx@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=subbaram@codeaurora.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
all inboxes | Powered by JetHome®