Re: [PATCH 0/3] virtio/vringh: kill off ACCESS_ONCE()

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
2016-11-25 18:47:43
Also in
kvm, lkml, netdev
On Fri, Nov 25, 2016 at 10:07 AM, Mark Rutland [off-list ref] wrote:
On Fri, Nov 25, 2016 at 09:52:50AM -0800, Linus Torvalds wrote:
quoted
READ/WRITE_ONCE() are atomic *WHEN*THAT*IS*POSSIBLE*.
quoted
But sometimes it's not going to be atomic.
That's the problem.
It has never really been much of a problem, and quite frankly, the
solution would never be to add _another_ crazy new function that will
just confuse everybody.

If you have code that depends on atomicity of READ_ONCE() and friends,
then you should add the appropriate built-time assert to *your* code.
Not to some random generic function that others care about and that
others do _not_ have problems with.

So if you have a data structure in virtio that is
architecture-dependent and might not be a word size, you add the

   BUILD_BUG_ON(sizeof(mytype) > sizeof(long));

or whatever. With a big comment saying "this needs to actually fit in
a single register so that we can do atomic accesses".

You do not screw it up for everybody else.

                Linus
Thread (1 message) 1 message, 1 author, last reply 2016-11-25
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help