From: Steven Rostedt <rostedt@goodmis.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Paul Gortmaker <paul.gortmaker@windriver.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@kernel.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] wait-simple: Introduce the simple waitqueue implementation
Date: Thu, 12 Dec 2013 11:51:37 -0500 [thread overview]
Message-ID: <20131212115137.4e5d156f@gandalf.local.home> (raw)
In-Reply-To: <20131212160323.GJ21999@twins.programming.kicks-ass.net>
On Thu, 12 Dec 2013 17:03:23 +0100
Peter Zijlstra <peterz@infradead.org> wrote:
> On Thu, Dec 12, 2013 at 09:42:27AM -0500, Steven Rostedt wrote:
> > On Thu, 12 Dec 2013 12:44:47 +0100
> > Peter Zijlstra <peterz@infradead.org> wrote:
> > > Are these two barriers matched or are they both unmatched and thus
> > > probabyl wrong?
> >
> > Nope, the two are unrelated. The the smp_wmb() is to synchronize with
> > the swait_finish() code. When the task wakes up, it checks if w->task
> > is NULL, and if it is it does not grab the head->lock and does not
> > dequeue it, it simply exits, where the caller can then free the swaiter
> > structure.
> >
> > Without the smp_wmb(), the curr->task can be set to NULL before we
> > dequeue it, and if the woken up process sees that NULL, it can jump
> > right to freeing the swaiter structure and cause havoc with this
> > __swait_dequeue().
>
> And yet the swait_finish thing does not have a barrier. Unmatched
> barriers are highly suspect.
Well if it sees the task as NULL then it has nothing to do. The
smp_wmb() on the other end guarantees that. If it sees it not NULL it
then goes into the slow path and the spinlocks synchronize everything
else. That is, we don't care if it sees it as not NULL when it was NULL,
because then the slow path just does duplicate work (under a lock)
(removes itself from the queue with list_del_init() which is fine to
call twice).
Add a comment there discussing this won't hurt.
>
> > The first smp_mb() is about the condition in:
> >
> > +#define __swait_event(wq, condition) \
> > +do { \
> > + DEFINE_SWAITER(__wait); \
> > + \
> > + for (;;) { \
> > + swait_prepare(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
> > + if (condition) \
> > + break; \
> > + schedule(); \
> > + } \
> > + swait_finish(&wq, &__wait); \
> > +} while (0)
> >
> > without the smp_mb(), it is possible that the condition can leak into
> > the critical section of swait_prepare() and have the old condition seen
> > before the task is added to the wait list. My submission of this patch
> > described it in more details:
> >
> > https://lkml.org/lkml/2013/8/19/275
>
> still a fail, barriers should not be described in changelogs but in
> comments.
I agree.
>
> Typically such a barrier comes from set_current_state(), the normal
> pattern is something like:
>
> set_current_state(TASK_UNINTERRUPTIBLE)
> if (!cond)
> schedule();
> __set_current_state(TASK_RUNNING);
>
> vs
>
> cond = true;
> wake_up_process(&foo);
Hmm, that __set_current_state() in swait_prepare() does indeed seem
buggy. I'm surprised that I didn't catch that, as I'm usually a
stickler with set_current_state() (and I'm very paranoid when it comes
to using __set_current_state()).
I'll have to dig deeper to see why I didn't change that.
Thanks,
-- Steve
next prev parent reply other threads:[~2013-12-12 16:51 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-12 1:06 [PATCH 0/3] Introduce simple wait queues Paul Gortmaker
2013-12-12 1:06 ` [PATCH 1/3] wait-simple: Introduce the simple waitqueue implementation Paul Gortmaker
2013-12-12 1:58 ` Steven Rostedt
2013-12-12 2:09 ` Steven Rostedt
2013-12-12 8:03 ` Christoph Hellwig
2013-12-12 10:56 ` Thomas Gleixner
2013-12-12 14:48 ` Paul Gortmaker
2013-12-12 14:55 ` Steven Rostedt
2013-12-12 15:25 ` Thomas Gleixner
2013-12-12 15:44 ` Steven Rostedt
2013-12-12 15:30 ` Paul Gortmaker
2013-12-12 11:18 ` Peter Zijlstra
2013-12-12 11:20 ` Peter Zijlstra
2013-12-12 14:19 ` Paul Gortmaker
2013-12-12 16:17 ` Paul Gortmaker
2013-12-12 11:44 ` Peter Zijlstra
2013-12-12 14:42 ` Steven Rostedt
2013-12-12 16:03 ` Peter Zijlstra
2013-12-12 16:51 ` Steven Rostedt [this message]
2013-12-12 17:10 ` Steven Rostedt
2013-12-12 17:17 ` Peter Zijlstra
2013-12-12 1:06 ` [PATCH 2/3] sched/core: convert completions to use simple wait queues Paul Gortmaker
2013-12-12 1:06 ` [PATCH 3/3] rcu: use simple wait queues where possible in rcutree Paul Gortmaker
2013-12-12 3:42 ` Paul E. McKenney
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=20131212115137.4e5d156f@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=bigeasy@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paul.gortmaker@windriver.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/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®