From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Huang Ying <ying.huang@intel.com>,
Lai Jiangshan <laijs@cn.fujitsu.com>,
Lai Jiangshan <eag0628@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
LKML <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>
Subject: Re: Possible lock-less list race in scheduler_ipi()
Date: Fri, 6 Mar 2015 14:35:23 +0000 (UTC) [thread overview]
Message-ID: <402283060.238174.1425652523685.JavaMail.zimbra@efficios.com> (raw)
In-Reply-To: <CA+55aFzn+ikDZ=Zi6EegH0ji6Wc1o-k6f1DmPGjzaJ+K3udc5g@mail.gmail.com>
----- Original Message -----
> From: "Linus Torvalds" <torvalds@linux-foundation.org>
> To: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>
> Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>, "Huang Ying" <ying.huang@intel.com>, "Lai Jiangshan"
> <laijs@cn.fujitsu.com>, "Lai Jiangshan" <eag0628@gmail.com>, "Peter Zijlstra" <peterz@infradead.org>, "LKML"
> <linux-kernel@vger.kernel.org>, "Ingo Molnar" <mingo@kernel.org>, "Steven Rostedt" <rostedt@goodmis.org>
> Sent: Thursday, March 5, 2015 8:02:06 PM
> Subject: Re: Possible lock-less list race in scheduler_ipi()
>
> On Thu, Mar 5, 2015 at 3:48 PM, Mathieu Desnoyers
> <mathieu.desnoyers@efficios.com> wrote:
> >
> > llist_next() is pretty simple:
> >
> > static inline struct llist_node *llist_next(struct llist_node *node)
> > {
> > return node->next;
> > }
> >
> > It is so simple that I wonder if the compiler would be
> > within its rights to reorder the load of node->next
> > after some operations within ttwu_do_activate(), thus
> > causing corruption of this linked-list due to a
> > concurrent try_to_wake_up() performed by another core.
> >
> > Am I too paranoid about the possible compiler mishaps
> > there, or are my concerns justified ?
>
> I *think* you are too paranoid, because that would be a major compiler
> bug anyway - gcc cannot reorder the load against anything that might
> be changing the value. Which obviously includes calling non-inlined
> functions.
>
> At least the code generation I see doesn't seem to say that gcc gets this
> wrong:
>
> ...
> leaq -32(%rbx), %rsi #, p
> movq (%rbx), %rbx # MEM[(struct llist_node
> *)__mptr_19].next, __mptr
> movq %r12, %rdi # tcp_ptr__,
> call ttwu_do_activate.constprop.85 #
> ...
>
> that "movq (%rbx), %rbx" is the "llist = llist_next(llist);" thing.
Indeed, the compiler should never reorder loads/stores from/to
same memory location from a program order POV. What I had in mind
is a bit more far-fetched though: it would involve having the compiler
reorder this load after a store to another memory location, which
would in turn allow another execution context (interrupt or thread)
to corrupt the list.
The assembly snippet you show above appears to be OK. However, another
compiler may choose to inline ttwu_do_activate, leaving room for
more aggressive optimizations.
But I agree that it is rather far-fetched.
Thanks,
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
next prev parent reply other threads:[~2015-03-06 14:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <995381344.227770.1425597484864.JavaMail.zimbra@efficios.com>
2015-03-05 23:48 ` Possible lock-less list race in scheduler_ipi() Mathieu Desnoyers
2015-03-06 1:02 ` Linus Torvalds
2015-03-06 14:35 ` Mathieu Desnoyers [this message]
2015-03-06 19:03 ` Steven Rostedt
2015-03-06 19:39 ` Mathieu Desnoyers
2015-03-06 20:38 ` Steven Rostedt
2015-03-06 20:39 ` Steven Rostedt
2015-03-06 22:07 ` Mathieu Desnoyers
2015-03-06 17:09 ` 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=402283060.238174.1425652523685.JavaMail.zimbra@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=eag0628@gmail.com \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=torvalds@linux-foundation.org \
--cc=ying.huang@intel.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.