From: "Michael S. Tsirkin" <mst@redhat.com>
To: Paul Brook <paul@codesourcery.com>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH] qemu/virtio: make wmb compiler barrier + comments
Date: Wed, 11 Nov 2009 15:12:53 +0200 [thread overview]
Message-ID: <20091111131253.GC23036@redhat.com> (raw)
In-Reply-To: <200911111301.03427.paul@codesourcery.com>
On Wed, Nov 11, 2009 at 01:01:03PM +0000, Paul Brook wrote:
> On Wednesday 11 November 2009, Michael S. Tsirkin wrote:
> > On Wed, Nov 11, 2009 at 01:34:12AM +0000, Paul Brook wrote:
> > > On Monday 26 October 2009, Michael S. Tsirkin wrote:
> > > > wmb must be at least a compiler barrier, even without SMP.
> > >
> > > Why?
> >
> > Because virtio code might run on a separate thread from guest.
> > If compiler reorders writes, guest might see inconsistent data.
>
> If you've got threads running in parallel (which may be running on separate
> CPUs)
Yes, but you asked what happens without SMP (single CPU).
> then you need an actual memory barrier to prevent the hardware
> reordering things behind your back.
>
> If you've already used locking to avoid simultaneous execution then the
> locking routines already include memory barriers.
You can not share a lock with guest.
> A "compiler memory barrier" provides absolutely no guarantees in a
> multithreaded environment. They are sometimes useful in a single threaded
> interruptable system (i.e. UNIX signals), but that's definitely not the case
> here.
>
> Paul
"absolutely no guarantees" is surely wrong. On intel CPUs, regular
memory writes are never re-ordered by the CPU. Only compiler can
reorder such writes. So yes, on this platform a "compiler barrier" does
provide necessary and sufficient guarantees agains write reordering in a
multithreaded environment, both with and without SMP.
--
MST
next prev parent reply other threads:[~2009-11-11 13:15 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-26 13:17 [Qemu-devel] [PATCH] qemu/virtio: make wmb compiler barrier + comments Michael S. Tsirkin
2009-11-11 1:34 ` Paul Brook
2009-11-11 9:37 ` [Qemu-devel] " Michael S. Tsirkin
2009-11-11 13:01 ` Paul Brook
2009-11-11 13:12 ` Michael S. Tsirkin [this message]
2009-11-11 13:45 ` Paul Brook
2009-11-11 14:08 ` Michael S. Tsirkin
2009-11-11 14:16 ` Paul Brook
2009-11-11 14:34 ` Michael S. Tsirkin
2009-11-11 16:13 ` Paul Brook
2009-11-11 17:18 ` Scott Tsai
2009-11-11 18:08 ` Michael S. Tsirkin
2009-11-11 18:09 ` Michael S. Tsirkin
2009-11-11 18:37 ` Scott Tsai
2009-11-11 19:56 ` Michael S. Tsirkin
2009-11-13 3:00 ` Jamie Lokier
2009-11-11 13:15 ` Michael S. Tsirkin
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=20091111131253.GC23036@redhat.com \
--to=mst@redhat.com \
--cc=paul@codesourcery.com \
--cc=qemu-devel@nongnu.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).