[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wj4pqF9bwjQHNzAKBmbAFTDWi9KwvLznj0HZLAZ+eGFpw@mail.gmail.com>
Date: Mon, 3 Jun 2019 08:40:40 -0700
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: David Laight <David.Laight@...lab.com>
Cc: "paulmck@...ux.ibm.com" <paulmck@...ux.ibm.com>,
Herbert Xu <herbert@...dor.apana.org.au>,
Frederic Weisbecker <fweisbec@...il.com>,
Boqun Feng <boqun.feng@...il.com>,
Fengguang Wu <fengguang.wu@...el.com>, LKP <lkp@...org>,
LKML <linux-kernel@...r.kernel.org>,
Netdev <netdev@...r.kernel.org>,
"David S. Miller" <davem@...emloft.net>
Subject: Re: rcu_read_lock lost its compiler barrier
On Mon, Jun 3, 2019 at 8:26 AM David Laight <David.Laight@...lab.com> 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 variable ought to be volatile...
No.
We do not use volatile on variables.
The C people got the semantics wrong, probably because 'volatile' was
historically for IO, not for access atomicity without locking.
It's not the memory location that is volatile, it is really the
_access_ that is volatile.
The same memory location might be completely stable in other access
situations (ie when done under a lock).
In other words, we should *never* use volatile in the kernel. It's
fundamentally mis-designed for modern use.
(Of course, we then can use volatile in a cast in code, which drives
some compiler people crazy, but that's because said compiler people
don't care about reality, they care about some paperwork).
Linus
Powered by blists - more mailing lists