qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org, agraf@suse.de, aik@ozlabs.ru,
	Paul 'Rusty' Russell <rusty@rustcorp.com.au>,
	Benjamin Herrenschmidt <benh@au.ibm.com>
Subject: Re: [Qemu-devel] Missing barriers in hw/virtio.c
Date: Fri, 26 Aug 2011 08:28:05 +0200	[thread overview]
Message-ID: <4E573CF5.2020609@redhat.com> (raw)
In-Reply-To: <20110826054008.GL2308@yookeroo.fritz.box>

On 08/26/2011 07:40 AM, David Gibson wrote:
> Near the top of hw/virtio.c we have this:
>
> /* QEMU doesn't strictly need write barriers since everything runs in
>   * lock-step.  We'll leave the calls to wmb() in though to make it
>   obvious for
>   * KVM or if kqemu gets SMP support.
>   * In any case, we must prevent the compiler from reordering the code.
>   * TODO: we likely need some rmb()/mb() as well.
>   */
>
> #define wmb() __asm__ __volatile__("": : :"memory")
>
>
> However, as far as I can tell when using both kvm and io-thread, the
> assertion that barriers aren't necessary just isn't true.  Although it
> probably works on x86 with its strongly ordered model.
>
> We think we've hit a race due to this with kvm on POWER, described in
> the forwarded message below.  Adding a barrier fixes the problem.
> Below we just stuck in a powerpc specific barrier which was useful as
> proof of concept, but I'm not sure how to go about putting a proper,
> architecture-appropriate barrier into this code.

Yes, I think you are right.  To get a full memory barrier you can add 
__sync_synchronize() and require GCC 4.2 or later (or Red Hat 4.1).  Or 
we can import a library of atomic functions from e.g. liburcu, which 
will provide separate macros for mb()/rmb()/wmb().  Alternatively, we 
can define all of

#define mb()     __sync_synchronize()
#define rmb()    __sync_synchronize()
#define wmb()    __sync_synchronize()

So that we can still differentiate at the source-code level, even though 
all the macros will emit full barriers.

Paolo

  reply	other threads:[~2011-08-26  6:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-26  5:40 [Qemu-devel] Missing barriers in hw/virtio.c David Gibson
2011-08-26  6:28 ` Paolo Bonzini [this message]
2011-08-29  2:43 ` Rusty Russell

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=4E573CF5.2020609@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=agraf@suse.de \
    --cc=aik@ozlabs.ru \
    --cc=benh@au.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rusty@rustcorp.com.au \
    /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).