All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org, Anthony Liguori <anthony@codemonkey.ws>,
	Paul Brook <paul@codesourcery.com>
Subject: [Qemu-devel] [PATCH-RFC 3/3] virtio: add missing barriers
Date: Tue, 8 Dec 2009 18:18:38 +0200	[thread overview]
Message-ID: <20091208161838.GD32188@redhat.com> (raw)
In-Reply-To: <cover.1260273831.git.mst@redhat.com>

Add missing memory barriers in virtio:
- before checking interrupt enabled bit, make sure
  data has been written to memory
- make sure ring index has been read before reading ring data

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/virtio.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/hw/virtio.c b/hw/virtio.c
index 9f020cf..bbd7b51 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -119,8 +119,12 @@ static inline uint16_t vring_avail_flags(VirtQueue *vq)
 static inline uint16_t vring_avail_idx(VirtQueue *vq)
 {
     target_phys_addr_t pa;
+    uint16_t idx;
     pa = vq->vring.avail + offsetof(VRingAvail, idx);
-    return lduw_phys(pa);
+    idx = lduw_phys(pa);
+    /* Make sure data read happens after index read */
+    rmb();
+    return idx;
 }
 
 static inline uint16_t vring_avail_ring(VirtQueue *vq, int i)
@@ -588,6 +592,8 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
 
 void virtio_notify(VirtIODevice *vdev, VirtQueue *vq)
 {
+    /* Make sure used ring is updated before we check NO_INTERRUPT. */
+    mb();
     /* Always notify when queue is empty (when feature acknowledge) */
     if ((vring_avail_flags(vq) & VRING_AVAIL_F_NO_INTERRUPT) &&
         (!(vdev->features & (1 << VIRTIO_F_NOTIFY_ON_EMPTY)) ||
-- 
1.6.5.2.143.g8cc62

      parent reply	other threads:[~2009-12-08 16:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1260273831.git.mst@redhat.com>
2009-12-08 16:18 ` [Qemu-devel] [PATCH-RFC 1/3] qemu: add barriers.h header Michael S. Tsirkin
2009-12-08 16:18 ` [Qemu-devel] [PATCH-RFC 2/3] virtio: use a real wmb Michael S. Tsirkin
2009-12-08 16:18 ` Michael S. Tsirkin [this message]

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=20091208161838.GD32188@redhat.com \
    --to=mst@redhat.com \
    --cc=anthony@codemonkey.ws \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.