From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NI2oi-0005Db-7w for qemu-devel@nongnu.org; Tue, 08 Dec 2009 11:21:36 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NI2od-000583-LY for qemu-devel@nongnu.org; Tue, 08 Dec 2009 11:21:35 -0500 Received: from [199.232.76.173] (port=38419 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NI2od-00057y-CB for qemu-devel@nongnu.org; Tue, 08 Dec 2009 11:21:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:29929) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NI2oc-0002sy-SM for qemu-devel@nongnu.org; Tue, 08 Dec 2009 11:21:31 -0500 Date: Tue, 8 Dec 2009 18:18:38 +0200 From: "Michael S. Tsirkin" Message-ID: <20091208161838.GD32188@redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: [Qemu-devel] [PATCH-RFC 3/3] virtio: add missing barriers List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Anthony Liguori , Paul Brook 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 --- 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