From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Michael S. Tsirkin" Subject: [PATCH] virtio: order used ring after used index read Date: Sun, 25 Oct 2009 14:22:18 +0200 Message-ID: <20091025122218.GA10992@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii To: virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, Rusty Russell Return-path: Received: from mx1.redhat.com ([209.132.183.28]:55959 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753494AbZJYMYj (ORCPT ); Sun, 25 Oct 2009 08:24:39 -0400 Content-Disposition: inline Sender: kvm-owner@vger.kernel.org List-ID: On SMP guests, reads from the ring might bypass used index reads. This causes guest crashes because host writes to used index to signal ring data readiness. Fix this by inserting rmb before used ring reads. Signed-off-by: Michael S. Tsirkin --- Rusty, I see guest crashes with virtio net on vhost sometimes, and the following seems to help. This seems an obviously correct thing to do, anyway. If you think so, too, can this be queued for 2.6.32 please? Thanks, drivers/virtio/virtio_ring.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index f536005..4c4df3e 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -285,6 +285,9 @@ static void *vring_get_buf(struct virtqueue *_vq, unsigned int *len) return NULL; } + /* Only get used array entries after they have been exposed by host. */ + rmb(); + i = vq->vring.used->ring[vq->last_used_idx%vq->vring.num].id; *len = vq->vring.used->ring[vq->last_used_idx%vq->vring.num].len; -- 1.6.5.rc2