From: "Michael S. Tsirkin" <mst@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: tglx@linutronix.de, kvm@vger.kernel.org, fweisbec@gmail.com,
jiangshanlai@gmail.com, linux-kernel@vger.kernel.org,
rostedt@goodmis.org, josh@joshtriplett.org, dhowells@redhat.com,
edumazet@google.com, netdev@vger.kernel.org,
mathieu.desnoyers@efficios.com, oleg@redhat.com,
dipankar@in.ibm.com, akpm@linux-foundation.org,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
virtualization@lists.linux-foundation.org, mingo@kernel.org
Subject: Re: [PATCH tip/core/rcu 21/21] drivers/vhost: Remove now-redundant read_barrier_depends()
Date: Tue, 5 Dec 2017 20:57:46 +0200 [thread overview]
Message-ID: <20171205204928-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20171205183946.GP3165@worktop.lehotels.local>
On Tue, Dec 05, 2017 at 07:39:46PM +0100, Peter Zijlstra wrote:
> On Tue, Dec 05, 2017 at 08:31:20PM +0200, Michael S. Tsirkin wrote:
>
> > Apropos, READ_ONCE is now asymmetrical with WRITE_ONCE.
> >
> > I can read a pointer with READ_ONCE and be sure the value
> > is sane, but only if I also remember to put in smp_wmb before
> > WRITE_ONCE. Otherwise the pointer is ok but no guarantees
> > about the data pointed to.
>
> That was already the case on everything except Alpha. And the canonical
> match do the data dependency is store_release, not wmb.
Oh, interesting
static __always_inline void __write_once_size(volatile void *p, void *res, int size)
{
switch (size) {
case 1: *(volatile __u8 *)p = *(__u8 *)res; break;
case 2: *(volatile __u16 *)p = *(__u16 *)res; break;
case 4: *(volatile __u32 *)p = *(__u32 *)res; break;
case 8: *(volatile __u64 *)p = *(__u64 *)res; break;
default:
barrier();
__builtin_memcpy((void *)p, (const void *)res, size);
barrier();
}
}
#define WRITE_ONCE(x, val) \
({ \
union { typeof(x) __val; char __c[1]; } __u = \
{ .__val = (__force typeof(x)) (val) }; \
__write_once_size(&(x), __u.__c, sizeof(x)); \
__u.__val; \
})
I don't see WRITE_ONCE inserting any barriers, release or
write.
So it seems that on an architecture where writes can be reordered,
if I do
*pointer = 0xa;
WRITE_ONCE(array[x], pointer);
array write might bypass the pointer write,
and readers will read a stale value.
--
MST
next prev parent reply other threads:[~2017-12-05 18:57 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20171201195053.GA23494@linux.vnet.ibm.com>
2017-12-01 19:51 ` [PATCH tip/core/rcu 21/21] drivers/vhost: Remove now-redundant read_barrier_depends() Paul E. McKenney
2017-12-05 18:31 ` Michael S. Tsirkin
[not found] ` <20171205202928-mutt-send-email-mst@kernel.org>
2017-12-05 18:39 ` Peter Zijlstra
2017-12-05 18:57 ` Michael S. Tsirkin [this message]
2017-12-05 19:17 ` Peter Zijlstra
[not found] ` <20171205191733.GQ3165@worktop.lehotels.local>
2017-12-05 19:24 ` Michael S. Tsirkin
2017-12-05 19:33 ` Paul E. McKenney
2017-12-05 19:51 ` Michael S. Tsirkin
[not found] ` <20171205215020-mutt-send-email-mst@kernel.org>
2017-12-05 19:57 ` Peter Zijlstra
2017-12-05 20:28 ` Michael S. Tsirkin
[not found] ` <20171205222757-mutt-send-email-mst@kernel.org>
2017-12-05 21:17 ` Peter Zijlstra
[not found] ` <20171205211735.GT3165@worktop.lehotels.local>
2017-12-05 21:42 ` Michael S. Tsirkin
2017-12-05 20:08 ` Paul E. McKenney
[not found] ` <20171205200801.GR7829@linux.vnet.ibm.com>
2017-12-05 21:24 ` Michael S. Tsirkin
[not found] ` <20171205222857-mutt-send-email-mst@kernel.org>
2017-12-05 21:36 ` Paul E. McKenney
[not found] ` <20171205213644.GU7829@linux.vnet.ibm.com>
2017-12-05 21:43 ` Michael S. Tsirkin
[not found] ` <20171205234308-mutt-send-email-mst@kernel.org>
2017-12-05 22:02 ` Paul E. McKenney
2017-12-05 22:09 ` Peter Zijlstra
2017-12-05 21:57 ` Peter Zijlstra
[not found] ` <20171205215700.GV3165@worktop.lehotels.local>
2017-12-05 22:09 ` Michael S. Tsirkin
[not found] ` <20171206000541-mutt-send-email-mst@kernel.org>
2017-12-05 23:39 ` Paul E. McKenney
2017-12-05 19:55 ` Peter Zijlstra
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=20171205204928-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=dipankar@in.ibm.com \
--cc=edumazet@google.com \
--cc=fweisbec@gmail.com \
--cc=jiangshanlai@gmail.com \
--cc=josh@joshtriplett.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=virtualization@lists.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).