Re: rcu_read_lock lost its compiler barrier

From: Paul E. McKenney
Date: Thu Jun 06 2019 - 09:53:11 EST

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 this is that in theory, the compiler could use the
> > stored-to location as temporary storage, like this:
> >
> > a = whatever; // Compiler uses "a" as a temporary
> > do_something();
> > whatever = a;
> > a = 1; // Intended store
> Well if the compiler is going to do this then surely it would
> continue to do this even if you used WRITE_ONCE. Remember a is
> not volatile, only the access of a through WRITE_ONCE is volatile.

I disagree. Given a volatile store, the compiler cannot assume that the
stored-to location is normal memory at that point in time, and therefore
cannot assume that it is safe to invent a store to that location (as
shown above). Thus far, the C++ standards committee seems on-board with
this, though time will tell.

Thanx, Paul