From: "Dmitry Adamushko" <dmitry.adamushko@gmail.com>
To: "Peter Zijlstra" <a.p.zijlstra@chello.nl>
Cc: "Nick Piggin" <nickpiggin@yahoo.com.au>,
linux-kernel@vger.kernel.org, "Ingo Molnar" <mingo@elte.hu>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Rusty Russel" <rusty@rustcorp.com.au>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: Re: [PATCH, RFC] kthread: (possibly) a missing memory barrier in kthread_stop()
Date: Tue, 19 Feb 2008 10:53:28 +0100 [thread overview]
Message-ID: <b647ffbd0802190153m3c93b500k3773e74fdd5a0f59@mail.gmail.com> (raw)
In-Reply-To: <1203413060.10858.82.camel@lappy>
On 19/02/2008, Peter Zijlstra <a.p.zijlstra@chello.nl> wrote:
> [ ... ]
> > >
> > > From: Dmitry Adamushko <dmitry.adamushko@gmail.com>
> > > Subject: kthread: add a memory barrier to kthread_stop()
> > >
> > > 'kthread' threads do a check in the following order:
> > > - set_current_state(TASK_INTERRUPTIBLE);
> > > - kthread_should_stop();
> > >
> > > and set_current_state() implies an smp_mb().
> > >
> > > on another side (kthread_stop), wake_up_process() is not guaranteed to
> > > act as a full mb.
> > >
> > > 'kthread_stop_info.k' must be visible before wake_up_process() checks
> > > for/modifies a state of the 'kthread' task.
> > >
> > >
> > > Signed-off-by: Dmitry Adamushko <dmitry.adamushko@gmail.com>
> > >
> > >
> > > diff --git a/kernel/kthread.c b/kernel/kthread.c
> > > index 0ac8878..5167110 100644
> > > --- a/kernel/kthread.c
> > > +++ b/kernel/kthread.c
> > > @@ -211,6 +211,10 @@ int kthread_stop(struct task_struct *k)
> > >
> > > /* Now set kthread_should_stop() to true, and wake it up. */
> > > kthread_stop_info.k = k;
> > > +
> > > + /* The previous store operation must not get ahead of the wakeup. */
> > > + smp_mb();
>
> Does this not also imply you need a matching barrier in
> kthread_should_stop() ?
Yes, but only when it's used in combination with something that alters
a state of the task.
So it's rather a question of the interface-design.
We currently impose a requirement on how a main loop of 'kthread'
threads (ok, so it seems to dictate a policy :-) has to be orginized.
Namely, the following sequence must be kept in order:
(1) set_current_task(TASK_INTERRUPTIBLE);
(2) kthread_should_stop()
...
- schedule()
and (1) already provides a mb which becomes a "matching barrier" on
the kthread_should_stop() side.
--
Best regards,
Dmitry Adamushko
next prev parent reply other threads:[~2008-02-19 9:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-18 23:03 Dmitry Adamushko
2008-02-19 6:44 ` Nick Piggin
2008-02-19 9:24 ` Peter Zijlstra
2008-02-19 9:53 ` Dmitry Adamushko [this message]
2008-02-19 13:41 ` Dmitry Adamushko
2008-02-19 22:52 ` Dmitry Adamushko
2008-02-19 13:00 ` Andy Whitcroft
2008-02-19 13:11 ` Dmitry Adamushko
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=b647ffbd0802190153m3c93b500k3773e74fdd5a0f59@mail.gmail.com \
--to=dmitry.adamushko@gmail.com \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=nickpiggin@yahoo.com.au \
--cc=paulmck@linux.vnet.ibm.com \
--cc=rusty@rustcorp.com.au \
/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®