From patchwork Tue Dec 8 16:18:38 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 40644 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EEFD0B7BC3 for ; Wed, 9 Dec 2009 03:34:17 +1100 (EST) Received: from localhost ([127.0.0.1]:51641 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NI30x-0002Pz-8S for incoming@patchwork.ozlabs.org; Tue, 08 Dec 2009 11:34:15 -0500 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 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nB8GLM9J002984 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 8 Dec 2009 11:21:22 -0500 Received: from redhat.com (vpn2-9-36.ams2.redhat.com [10.36.9.36]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id nB8GLKSB030927; Tue, 8 Dec 2009 11:21:21 -0500 Date: Tue, 8 Dec 2009 18:18:38 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org, Anthony Liguori , Paul Brook Message-ID: <20091208161838.GD32188@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Subject: [Qemu-devel] [PATCH-RFC 3/3] virtio: add missing barriers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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)) ||