From d38afa6f4833cf2da736aba40a1457184ec12dcd Mon Sep 17 00:00:00 2001 From: Peter Fang Date: Sun, 17 Mar 2019 02:02:52 -0700 Subject: [PATCH] dm: virtio: make sure VQ_ALLOC is set after initialization Make sure VQ_ALLOC is visible only after vq is completely initialized. This ensures vq_ring_ready() is reliable when it returns true. Tracked-On: #2763 Signed-off-by: Peter Fang Reviewed-by: Shuo A Liu --- devicemodel/hw/pci/virtio/virtio.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/devicemodel/hw/pci/virtio/virtio.c b/devicemodel/hw/pci/virtio/virtio.c index dcc212961..5f16718ec 100644 --- a/devicemodel/hw/pci/virtio/virtio.c +++ b/devicemodel/hw/pci/virtio/virtio.c @@ -304,10 +304,13 @@ virtio_vq_init(struct virtio_base *base, uint32_t pfn) /* ... and the last page(s) are the used ring. */ vq->used = (struct vring_used *)vb; - /* Mark queue as allocated, and start at 0 when we use it. */ - vq->flags = VQ_ALLOC; + /* Start at 0 when we use it. */ vq->last_avail = 0; vq->save_used = 0; + + /* Mark queue as allocated after initialization is complete. */ + mb(); + vq->flags = VQ_ALLOC; } /* @@ -346,13 +349,16 @@ virtio_vq_enable(struct virtio_base *base) vb = paddr_guest2host(base->dev->vmctx, phys, size); vq->used = (struct vring_used *)vb; - /* Mark queue as allocated, and start at 0 when we use it. */ - vq->flags = VQ_ALLOC; + /* Start at 0 when we use it. */ vq->last_avail = 0; vq->save_used = 0; /* Mark queue as enabled. */ vq->enabled = true; + + /* Mark queue as allocated after initialization is complete. */ + mb(); + vq->flags = VQ_ALLOC; } /*