Skip to contentSkip to conversation

virtio: order used ring after used index read

PATCH In review Michael S. Tsirkin 2 participants 3 messages Oct 25, 2009

Subsystems (2)
lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

PATCH v2 1/1 virtio: order used ring after used index read

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.

---

Change from v1: indent with TAB and not spaces. sorry about the noise.

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(-)
drivers/virtio/virtio_ring.c +3 -0
index f536005..fbd2ecd 100644
@@ -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;
 
Signature · 1 line
1.6.5.rc2
#1 lore raw
Quoted 5 lines · Michael S. Tsirkin

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.

Thanks, good spotting. Applied.

Rusty.

#2 lore raw
In reply to Michael S. Tsirkin
Quoted 5 lines · Michael S. Tsirkin

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.

Thanks, good spotting. Applied.

Rusty.