From: "Paul E. McKenney" <paulmck@linux.ibm.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
Frederic Weisbecker <fweisbec@gmail.com>,
Boqun Feng <boqun.feng@gmail.com>,
Fengguang Wu <fengguang.wu@intel.com>, LKP <lkp@01.org>,
LKML <linux-kernel@vger.kernel.org>,
Netdev <netdev@vger.kernel.org>,
"David S. Miller" <davem@davemloft.net>
Subject: Re: rcu_read_lock lost its compiler barrier
Date: Mon, 3 Jun 2019 12:53:04 -0700 [thread overview]
Message-ID: <20190603195304.GK28207@linux.ibm.com> (raw)
In-Reply-To: <CAHk-=wgZcrb_vQi5rwpv+=wwG+68SRDY16HcqcMtgPFL_kdfyQ@mail.gmail.com>
On Mon, Jun 03, 2019 at 09:07:29AM -0700, Linus Torvalds wrote:
> On Mon, Jun 3, 2019 at 8:55 AM Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
> >
> > I don't believe that it would necessarily help to turn a
> > rcu_read_lock() into a compiler barrier, because for the non-preempt
> > case rcu_read_lock() doesn't need to actually _do_ anything, and
> > anything that matters for the RCU read lock will already be a compiler
> > barrier for other reasons (ie a function call that can schedule).
>
> Actually, thinking a bit more about this, and trying to come up with
> special cases, I'm not at all convinced.
>
> Even if we don't have preemption enabled, it turns out that we *do*
> have things that can cause scheduling without being compiler barriers.
>
> In particular, user accesses are not necessarily full compiler
> barriers. One common pattern (x86) is
>
> asm volatile("call __get_user_%P4"
>
> which explicitly has a "asm volaile" so that it doesn't re-order wrt
> other asms (and thus other user accesses), but it does *not* have a
> "memory" clobber, because the user access doesn't actually change
> kernel memory. Not even if it's a "put_user()".
>
> So we've made those fairly relaxed on purpose. And they might be
> relaxed enough that they'd allow re-ordering wrt something that does a
> rcu read lock, unless the rcu read lock has some compiler barrier in
> it.
>
> IOW, imagine completely made up code like
>
> get_user(val, ptr)
> rcu_read_lock();
> WRITE_ONCE(state, 1);
>
> and unless the rcu lock has a barrier in it, I actually think that
> write to 'state' could migrate to *before* the get_user().
>
> I'm not convinced we have anything that remotely looks like the above,
> but I'm actually starting to think that yes, all RCU barriers had
> better be compiler barriers.
>
> Because this is very much an example of something where you don't
> necessarily need a memory barrier, but there's a code generation
> barrier needed because of local ordering requirements. The possible
> faulting behavior of "get_user()" must not migrate into the RCU
> critical region.
>
> Paul?
I agree that !PREEMPT rcu_read_lock() would not affect compiler code
generation, but given that get_user() is a volatile asm, isn't the
compiler already forbidden from reordering it with the volatile-casted
WRITE_ONCE() access, even if there was nothing at all between them?
Or are asms an exception to the rule that volatile executions cannot
be reordered?
> So I think the rule really should be: every single form of locking
> that has any semantic meaning at all, absolutely needs to be at least
> a compiler barrier.
>
> (That "any semantic meaning" weaselwording is because I suspect that
> we have locking that truly and intentionally becomes no-ops because
> it's based on things that aren't relevant in some configurations. But
> generally compiler barriers are really pretty damn cheap, even from a
> code generation standpoint, and can help make the resulting code more
> legible, so I think we should not try to aggressively remove them
> without _very_ good reasons)
We can of course put them back in, but this won't help in the typical
rcu_assign_pointer(), rcu_dereference(), and synchronize_rcu() situation
(nor do I see how it helps in Hubert's example). And in other RCU
use cases, the accesses analogous to the rcu_assign_pointer() and
rcu_dereference() (in Hubert's example, the accesses to variable "a")
really need to be READ_ONCE()/WRITE_ONCE() or stronger, correct?
Thanx, Paul
next prev parent reply other threads:[~2019-06-03 19:53 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-10 0:57 [rcu] kernel BUG at include/linux/pagemap.h:149! Fengguang Wu
2015-09-10 10:25 ` Boqun Feng
2015-09-10 17:16 ` Paul E. McKenney
2015-09-11 2:19 ` Boqun Feng
[not found] ` <CAJzB8QG=1iZW3dQEie6ZSTLv8GZ3YSut0aL1VU7LLmiHQ1B1DQ@mail.gmail.com>
2015-09-11 21:59 ` Paul E. McKenney
2015-09-12 5:46 ` Boqun Feng
2015-09-21 19:30 ` Frederic Weisbecker
2015-09-21 20:43 ` Paul E. McKenney
2019-06-02 5:56 ` rcu_read_lock lost its compiler barrier Herbert Xu
2019-06-02 20:54 ` Linus Torvalds
2019-06-03 2:46 ` Herbert Xu
2019-06-03 3:47 ` Paul E. McKenney
2019-06-03 4:01 ` Herbert Xu
2019-06-03 4:17 ` Herbert Xu
2019-06-03 7:23 ` Paul E. McKenney
2019-06-03 8:42 ` Paul E. McKenney
2019-06-03 15:26 ` David Laight
2019-06-03 15:40 ` Linus Torvalds
2019-06-03 5:26 ` Herbert Xu
2019-06-03 6:42 ` Boqun Feng
2019-06-03 20:03 ` Paul E. McKenney
2019-06-04 14:44 ` Alan Stern
2019-06-04 16:04 ` Linus Torvalds
2019-06-04 17:00 ` Alan Stern
2019-06-04 17:29 ` Linus Torvalds
2019-06-07 14:09 ` inet: frags: Turn fqdir->dead into an int for old Alphas Herbert Xu
2019-06-07 15:26 ` Eric Dumazet
2019-06-07 15:32 ` Herbert Xu
2019-06-07 16:13 ` Eric Dumazet
2019-06-07 16:19 ` Linus Torvalds
2019-06-08 15:27 ` Paul E. McKenney
2019-06-08 17:42 ` Linus Torvalds
2019-06-08 17:50 ` Linus Torvalds
2019-06-08 18:50 ` Paul E. McKenney
2019-06-08 18:14 ` Paul E. McKenney
2019-06-06 4:51 ` rcu_read_lock lost its compiler barrier Herbert Xu
2019-06-06 6:05 ` Paul E. McKenney
2019-06-06 6:14 ` Herbert Xu
2019-06-06 9:06 ` Paul E. McKenney
2019-06-06 9:28 ` Herbert Xu
2019-06-06 10:58 ` Paul E. McKenney
2019-06-06 13:38 ` Herbert Xu
2019-06-06 13:48 ` Paul E. McKenney
2019-06-06 8:16 ` Andrea Parri
2019-06-06 14:19 ` Alan Stern
2019-06-08 15:19 ` Paul E. McKenney
2019-06-08 15:56 ` Alan Stern
2019-06-08 16:31 ` Paul E. McKenney
2019-06-03 9:35 ` Paul E. McKenney
2019-06-06 8:38 ` Andrea Parri
2019-06-06 9:32 ` Herbert Xu
2019-06-03 0:06 ` Paul E. McKenney
2019-06-03 3:03 ` Herbert Xu
2019-06-03 9:27 ` Paul E. McKenney
2019-06-03 15:55 ` Linus Torvalds
2019-06-03 16:07 ` Linus Torvalds
2019-06-03 19:53 ` Paul E. McKenney [this message]
2019-06-03 20:24 ` Linus Torvalds
2019-06-04 21:14 ` Paul E. McKenney
2019-06-05 2:21 ` Herbert Xu
2019-06-05 3:30 ` Paul E. McKenney
2019-06-06 4:37 ` Herbert Xu
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=20190603195304.GK28207@linux.ibm.com \
--to=paulmck@linux.ibm.com \
--cc=boqun.feng@gmail.com \
--cc=davem@davemloft.net \
--cc=fengguang.wu@intel.com \
--cc=fweisbec@gmail.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@01.org \
--cc=netdev@vger.kernel.org \
--cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).