Re: rcu_read_lock lost its compiler barrier

2019-06-08 Thread Paul E. McKenney
On Sat, Jun 08, 2019 at 11:56:04AM -0400, Alan Stern wrote: > On Sat, 8 Jun 2019, Paul E. McKenney wrote: > > > On Thu, Jun 06, 2019 at 10:19:43AM -0400, Alan Stern wrote: > > > On Thu, 6 Jun 2019, Andrea Parri wrote: > > > > > > > This seems a sensible change to me: looking forward to seeing a

Re: rcu_read_lock lost its compiler barrier

2019-06-08 Thread Alan Stern
On Sat, 8 Jun 2019, Paul E. McKenney wrote: > On Thu, Jun 06, 2019 at 10:19:43AM -0400, Alan Stern wrote: > > On Thu, 6 Jun 2019, Andrea Parri wrote: > > > > > This seems a sensible change to me: looking forward to seeing a patch, > > > on top of -rcu/dev, for further review and testing! > > >

Re: rcu_read_lock lost its compiler barrier

2019-06-08 Thread Paul E. McKenney
On Thu, Jun 06, 2019 at 10:19:43AM -0400, Alan Stern wrote: > On Thu, 6 Jun 2019, Andrea Parri wrote: > > > This seems a sensible change to me: looking forward to seeing a patch, > > on top of -rcu/dev, for further review and testing! > > > > We could also add (to LKMM) the barrier() for

Re: rcu_read_lock lost its compiler barrier

2019-06-06 Thread Alan Stern
On Thu, 6 Jun 2019, Andrea Parri wrote: > This seems a sensible change to me: looking forward to seeing a patch, > on top of -rcu/dev, for further review and testing! > > We could also add (to LKMM) the barrier() for rcu_read_{lock,unlock}() > discussed in this thread (maybe once the RCU code

Re: rcu_read_lock lost its compiler barrier

2019-06-06 Thread Paul E. McKenney
On Thu, Jun 06, 2019 at 09:38:24PM +0800, Herbert Xu wrote: > On Thu, Jun 06, 2019 at 03:58:17AM -0700, Paul E. McKenney wrote: > > > > I cannot immediately think of a way that the compiler could get this > > wrong even in theory, but similar code sequences can be messed up. > > The reason for

Re: rcu_read_lock lost its compiler barrier

2019-06-06 Thread Herbert Xu
On Thu, Jun 06, 2019 at 03:58:17AM -0700, Paul E. McKenney wrote: > > I cannot immediately think of a way that the compiler could get this > wrong even in theory, but similar code sequences can be messed up. > The reason for this is that in theory, the compiler could use the > stored-to location

Re: rcu_read_lock lost its compiler barrier

2019-06-06 Thread Paul E. McKenney
On Thu, Jun 06, 2019 at 05:28:55PM +0800, Herbert Xu wrote: > On Thu, Jun 06, 2019 at 02:06:19AM -0700, Paul E. McKenney wrote: > > > > Or is your point instead that given the initial value of "a" being > > zero and the value stored to "a" being one, there is no way that > > any possible load and

Re: rcu_read_lock lost its compiler barrier

2019-06-06 Thread Herbert Xu
On Thu, Jun 06, 2019 at 10:38:56AM +0200, Andrea Parri wrote: > On Mon, Jun 03, 2019 at 10:46:40AM +0800, Herbert Xu wrote: > > > The case we were discussing is from net/ipv4/inet_fragment.c from > > the net-next tree: > > BTW, thank you for keeping me and other people who intervened in that >

Re: rcu_read_lock lost its compiler barrier

2019-06-06 Thread Herbert Xu
On Thu, Jun 06, 2019 at 02:06:19AM -0700, Paul E. McKenney wrote: > > Or is your point instead that given the initial value of "a" being > zero and the value stored to "a" being one, there is no way that > any possible load and store tearing (your slicing and dicing) could > possibly mess up the

Re: rcu_read_lock lost its compiler barrier

2019-06-06 Thread Paul E. McKenney
On Thu, Jun 06, 2019 at 02:14:38PM +0800, Herbert Xu wrote: > On Wed, Jun 05, 2019 at 11:05:11PM -0700, Paul E. McKenney wrote: > > > > In case you were wondering, the reason that I was giving you such > > a hard time was that from what I could see, you were pushing for no > > {READ,WRITE}_ONCE()

Re: rcu_read_lock lost its compiler barrier

2019-06-06 Thread Andrea Parri
On Mon, Jun 03, 2019 at 10:46:40AM +0800, Herbert Xu wrote: > The case we were discussing is from net/ipv4/inet_fragment.c from > the net-next tree: BTW, thank you for keeping me and other people who intervened in that discussion in Cc:... Andrea > > void fqdir_exit(struct fqdir *fqdir) >

Re: rcu_read_lock lost its compiler barrier

2019-06-06 Thread Andrea Parri
> This example really does point out a weakness in the LKMM's handling of > data races. Herbert's litmus test is a great starting point: > > > C xu > > {} > > P0(int *a, int *b) > { > WRITE_ONCE(*a, 1); > synchronize_rcu(); > *b = 2; > } > > P1(int *a, int *b) > { >

Re: rcu_read_lock lost its compiler barrier

2019-06-06 Thread Herbert Xu
On Wed, Jun 05, 2019 at 11:05:11PM -0700, Paul E. McKenney wrote: > > In case you were wondering, the reason that I was giving you such > a hard time was that from what I could see, you were pushing for no > {READ,WRITE}_ONCE() at all. ;-) Hmm, that's exactly what it should be in

Re: rcu_read_lock lost its compiler barrier

2019-06-06 Thread Paul E. McKenney
On Thu, Jun 06, 2019 at 12:51:09PM +0800, Herbert Xu wrote: > On Tue, Jun 04, 2019 at 10:44:18AM -0400, Alan Stern wrote: > > > > Currently the LKMM says the test is allowed and there is a data race, > > but this answer clearly is wrong since it would violate the RCU > > guarantee. > > Thank

Re: rcu_read_lock lost its compiler barrier

2019-06-05 Thread Herbert Xu
On Tue, Jun 04, 2019 at 10:44:18AM -0400, Alan Stern wrote: > > Currently the LKMM says the test is allowed and there is a data race, > but this answer clearly is wrong since it would violate the RCU > guarantee. Thank you! This is what I tried to say all along in this thread but you expressed

Re: rcu_read_lock lost its compiler barrier

2019-06-05 Thread Herbert Xu
On Tue, Jun 04, 2019 at 08:30:39PM -0700, Paul E. McKenney wrote: > > Understood. Does the patch I sent out a few hours ago cover it? Or is > something else needed? It looks good to me. > Other than updates to the RCU requirements documentation, which is > forthcoming. Thanks Paul. -- Email:

Re: rcu_read_lock lost its compiler barrier

2019-06-04 Thread Paul E. McKenney
On Wed, Jun 05, 2019 at 10:21:17AM +0800, Herbert Xu wrote: > On Tue, Jun 04, 2019 at 02:14:49PM -0700, Paul E. McKenney wrote: > > > > Yeah, I know, even with the "volatile" keyword, it is not entirely clear > > how much reordering the compiler is allowed to do. I was relying on > >

Re: rcu_read_lock lost its compiler barrier

2019-06-04 Thread Herbert Xu
On Tue, Jun 04, 2019 at 02:14:49PM -0700, Paul E. McKenney wrote: > > Yeah, I know, even with the "volatile" keyword, it is not entirely clear > how much reordering the compiler is allowed to do. I was relying on > https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html, which says: The volatile

Re: rcu_read_lock lost its compiler barrier

2019-06-04 Thread Paul E. McKenney
On Mon, Jun 03, 2019 at 01:24:32PM -0700, Linus Torvalds wrote: > On Mon, Jun 3, 2019 at 12:53 PM Paul E. McKenney > wrote: > > > > 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

Re: rcu_read_lock lost its compiler barrier

2019-06-04 Thread Linus Torvalds
On Tue, Jun 4, 2019 at 10:00 AM Alan Stern wrote: > > Which suggests asking whether these higher expectations should be > reflected in the Linux Kernel Memory Model. So far we have largely > avoided doing that sort of thing, although there are a few exceptions. I think they might be hard to

Re: rcu_read_lock lost its compiler barrier

2019-06-04 Thread Alan Stern
On Tue, 4 Jun 2019, Linus Torvalds wrote: > So I don't technically disagree with anything you say, That's good to know! > I just wanted > to point out that as far as the kernel is concerned, we do have higher > quality expectations from the compiler than just "technically valid > according to

Re: rcu_read_lock lost its compiler barrier

2019-06-04 Thread Linus Torvalds
On Tue, Jun 4, 2019 at 7:44 AM Alan Stern wrote: > > Even if you don't think the compiler will ever do this, the C standard > gives compilers the right to invent read accesses if a plain (i.e., > non-atomic and non-volatile) write is present. Note that for the kernel, it's not like we go

Re: rcu_read_lock lost its compiler barrier

2019-06-04 Thread Alan Stern
On Mon, 3 Jun 2019, Paul E. McKenney wrote: > On Mon, Jun 03, 2019 at 02:42:00PM +0800, Boqun Feng wrote: > > On Mon, Jun 03, 2019 at 01:26:26PM +0800, Herbert Xu wrote: > > > On Sun, Jun 02, 2019 at 08:47:07PM -0700, Paul E. McKenney wrote: > > > > > > > > 1. These guarantees are of full

Re: rcu_read_lock lost its compiler barrier

2019-06-03 Thread Linus Torvalds
On Mon, Jun 3, 2019 at 12:53 PM Paul E. McKenney wrote: > > 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,

Re: rcu_read_lock lost its compiler barrier

2019-06-03 Thread Paul E. McKenney
On Mon, Jun 03, 2019 at 02:42:00PM +0800, Boqun Feng wrote: > On Mon, Jun 03, 2019 at 01:26:26PM +0800, Herbert Xu wrote: > > On Sun, Jun 02, 2019 at 08:47:07PM -0700, Paul E. McKenney wrote: > > > > > > 1.These guarantees are of full memory barriers, -not- compiler > > > barriers. > >

Re: rcu_read_lock lost its compiler barrier

2019-06-03 Thread Paul E. McKenney
On Mon, Jun 03, 2019 at 09:07:29AM -0700, Linus Torvalds wrote: > On Mon, Jun 3, 2019 at 8:55 AM Linus Torvalds > 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

Re: rcu_read_lock lost its compiler barrier

2019-06-03 Thread Linus Torvalds
On Mon, Jun 3, 2019 at 8:55 AM Linus Torvalds 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

Re: rcu_read_lock lost its compiler barrier

2019-06-03 Thread Linus Torvalds
On Sun, Jun 2, 2019 at 8:03 PM Herbert Xu wrote: > > In any case, I am now even more certain that compiler barriers are > not needed in the code in question. The reasoning is quite simple. > If you need those compiler barriers then you surely need real memory > barriers. So the above statement

Re: rcu_read_lock lost its compiler barrier

2019-06-03 Thread Linus Torvalds
On Mon, Jun 3, 2019 at 8:26 AM David Laight wrote: > > From: Paul E. McKenney > > > We do > > occasionally use READ_ONCE() to prevent load-fusing optimizations that > > would otherwise cause the compiler to turn while-loops into if-statements > > guarding infinite loops. > > In that case the

RE: rcu_read_lock lost its compiler barrier

2019-06-03 Thread David Laight
From: Paul E. McKenney > Sent: 03 June 2019 09:42 ... > On kissing the kernel goodbye, a reasonable strategy might be to > identify the transformations that are actually occuring (like the > stores of certain constants called out above) and fix those. > We do > occasionally use READ_ONCE() to

Re: rcu_read_lock lost its compiler barrier

2019-06-03 Thread Paul E. McKenney
On Mon, Jun 03, 2019 at 01:26:26PM +0800, Herbert Xu wrote: > On Sun, Jun 02, 2019 at 08:47:07PM -0700, Paul E. McKenney wrote: > > > > 1. These guarantees are of full memory barriers, -not- compiler > > barriers. > > What I'm saying is that wherever they are, they must come with > compiler

Re: rcu_read_lock lost its compiler barrier

2019-06-03 Thread Paul E. McKenney
On Mon, Jun 03, 2019 at 11:03:24AM +0800, Herbert Xu wrote: > On Sun, Jun 02, 2019 at 05:06:17PM -0700, Paul E. McKenney wrote: > > > > Please note that preemptible Tree RCU has lacked the compiler barrier on > > all but the outermost rcu_read_unlock() for years before Boqun's patch. > > Actually

Re: rcu_read_lock lost its compiler barrier

2019-06-03 Thread Paul E. McKenney
On Mon, Jun 03, 2019 at 12:23:39AM -0700, Paul E. McKenney wrote: > On Mon, Jun 03, 2019 at 12:01:14PM +0800, Herbert Xu wrote: > > On Sun, Jun 02, 2019 at 08:47:07PM -0700, Paul E. McKenney wrote: > > > > > > CPU2: if (b != 1) > > > CPU2: b = 1; > > > > Stop right

Re: rcu_read_lock lost its compiler barrier

2019-06-03 Thread Paul E. McKenney
On Mon, Jun 03, 2019 at 12:01:14PM +0800, Herbert Xu wrote: > On Sun, Jun 02, 2019 at 08:47:07PM -0700, Paul E. McKenney wrote: > > > > CPU2: if (b != 1) > > CPU2: b = 1; > > Stop right there. The kernel is full of code that assumes that > assignment to an

Re: rcu_read_lock lost its compiler barrier

2019-06-03 Thread Boqun Feng
On Mon, Jun 03, 2019 at 01:26:26PM +0800, Herbert Xu wrote: > On Sun, Jun 02, 2019 at 08:47:07PM -0700, Paul E. McKenney wrote: > > > > 1. These guarantees are of full memory barriers, -not- compiler > > barriers. > > What I'm saying is that wherever they are, they must come with > compiler

Re: rcu_read_lock lost its compiler barrier

2019-06-02 Thread Herbert Xu
On Sun, Jun 02, 2019 at 08:47:07PM -0700, Paul E. McKenney wrote: > > 1.These guarantees are of full memory barriers, -not- compiler > barriers. What I'm saying is that wherever they are, they must come with compiler barriers. I'm not aware of any synchronisation mechanism in the

Re: rcu_read_lock lost its compiler barrier

2019-06-02 Thread Herbert Xu
On Mon, Jun 03, 2019 at 12:01:14PM +0800, Herbert Xu wrote: > On Sun, Jun 02, 2019 at 08:47:07PM -0700, Paul E. McKenney wrote: > > > > CPU2: if (b != 1) > > CPU2: b = 1; > > Stop right there. The kernel is full of code that assumes that > assignment to an

Re: rcu_read_lock lost its compiler barrier

2019-06-02 Thread Herbert Xu
On Sun, Jun 02, 2019 at 08:47:07PM -0700, Paul E. McKenney wrote: > > CPU2: if (b != 1) > CPU2: b = 1; Stop right there. The kernel is full of code that assumes that assignment to an int/long is atomic. If your compiler breaks this assumption that we can kiss

Re: rcu_read_lock lost its compiler barrier

2019-06-02 Thread Paul E. McKenney
On Mon, Jun 03, 2019 at 10:46:40AM +0800, Herbert Xu wrote: > On Sun, Jun 02, 2019 at 01:54:12PM -0700, Linus Torvalds wrote: > > On Sat, Jun 1, 2019 at 10:56 PM Herbert Xu > > wrote: > > > > > > You can't then go and decide to remove the compiler barrier! To do > > > that you'd need to audit

Re: rcu_read_lock lost its compiler barrier

2019-06-02 Thread Herbert Xu
On Sun, Jun 02, 2019 at 05:06:17PM -0700, Paul E. McKenney wrote: > > Please note that preemptible Tree RCU has lacked the compiler barrier on > all but the outermost rcu_read_unlock() for years before Boqun's patch. Actually this is not true. Boqun's patch (commit bb73c52bad36) does not add a

Re: rcu_read_lock lost its compiler barrier

2019-06-02 Thread Herbert Xu
On Sun, Jun 02, 2019 at 01:54:12PM -0700, Linus Torvalds wrote: > On Sat, Jun 1, 2019 at 10:56 PM Herbert Xu > wrote: > > > > You can't then go and decide to remove the compiler barrier! To do > > that you'd need to audit every single use of rcu_read_lock in the > > kernel to ensure that

Re: rcu_read_lock lost its compiler barrier

2019-06-02 Thread Paul E. McKenney
On Sun, Jun 02, 2019 at 01:56:07PM +0800, Herbert Xu wrote: > Digging up an old email because I was not aware of this previously > but Paul pointed me to it during another discussion. > > On Mon, Sep 21, 2015 at 01:43:27PM -0700, Paul E. McKenney wrote: > > On Mon, Sep 21, 2015 at 09:30:49PM

Re: rcu_read_lock lost its compiler barrier

2019-06-02 Thread Linus Torvalds
On Sat, Jun 1, 2019 at 10:56 PM Herbert Xu wrote: > > You can't then go and decide to remove the compiler barrier! To do > that you'd need to audit every single use of rcu_read_lock in the > kernel to ensure that they're not depending on the compiler barrier. What's the possible case where it

rcu_read_lock lost its compiler barrier

2019-06-01 Thread Herbert Xu
Digging up an old email because I was not aware of this previously but Paul pointed me to it during another discussion. On Mon, Sep 21, 2015 at 01:43:27PM -0700, Paul E. McKenney wrote: > On Mon, Sep 21, 2015 at 09:30:49PM +0200, Frederic Weisbecker wrote: > > > > diff --git