Skip to contentSkip to conversation

virtio: fixes

GIT PULL Applied Michael S. Tsirkin 2 participants 4 messages Aug 23, 2016 – Aug 24, 2016

lore
Share & tools
lore
#0 lore raw

The following changes since commit 6bbbb0ac136102098a70b97ab0c07bc7bf53131c:

target-arm: Fix warn about implicit conversion (2016-08-12 11:12:24 +0100)

are available in the git repository at:

git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream

for you to fetch changes up to 58a83c61496eeb0d31571a07a51bc1947e3379ac:

virtio: decrement vq->inuse in virtqueue_discard() (2016-08-23 19:20:24 +0300)

----------------------------------------------------------------
virtio: fixes

some bugfixes for virtio
balloon is still broken wrt migration

----------------------------------------------------------------
Stefan Hajnoczi (2):

      virtio: recalculate vq->inuse after migration
      virtio: decrement vq->inuse in virtqueue_discard()
 hw/virtio/virtio.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
#1 lore raw

[Qemu-devel] [PULL 1/2] virtio: recalculate vq->inuse after migration

From: Stefan Hajnoczi <[email protected]>

The vq->inuse field is not migrated. Many devices don't hold VirtQueueElements across migration so it doesn't matter that vq->inuse starts at 0 on the destination QEMU.

At least virtio-serial, virtio-blk, and virtio-balloon migrate while holding VirtQueueElements. For these devices we need to recalculate vq->inuse upon load so the value is correct.

---
 hw/virtio/virtio.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
hw/virtio/virtio.c +15 -0
index 15ee3a7..6105c6e 100644
@@ -1648,6 +1648,21 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
             }
             vdev->vq[i].used_idx = vring_used_idx(&vdev->vq[i]);
             vdev->vq[i].shadow_avail_idx = vring_avail_idx(&vdev->vq[i]);
+
+            /*
+             * Some devices migrate VirtQueueElements that have been popped
+             * from the avail ring but not yet returned to the used ring.
+             */
+            vdev->vq[i].inuse = vdev->vq[i].last_avail_idx -
+                                vdev->vq[i].used_idx;
+            if (vdev->vq[i].inuse > vdev->vq[i].vring.num) {
+                error_report("VQ %d size 0x%x < last_avail_idx 0x%x - "
+                             "used_idx 0x%x",
+                             i, vdev->vq[i].vring.num,
+                             vdev->vq[i].last_avail_idx,
+                             vdev->vq[i].used_idx);
+                return -1;
+            }
         }
     }
 
Signature · 1 line
MST
#2 lore raw

[Qemu-devel] [PULL 2/2] virtio: decrement vq->inuse in virtqueue_discard()

In reply to Michael S. Tsirkin

From: Stefan Hajnoczi <[email protected]>

virtqueue_discard() moves vq->last_avail_idx back so the element can be popped again. It's necessary to decrement vq->inuse to avoid "leaking" the element count.

---
 hw/virtio/virtio.c | 1 +
 1 file changed, 1 insertion(+)
hw/virtio/virtio.c +1 -0
index 6105c6e..74c085c 100644
@@ -268,6 +268,7 @@ void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem,
                        unsigned int len)
 {
     vq->last_avail_idx--;
+    vq->inuse--;
     virtqueue_unmap_sg(vq, elem, len);
 }
 
Signature · 1 line
MST
#3 lore raw
In reply to Michael S. Tsirkin
Quoted 10 lines · Michael S. Tsirkin

The following changes since commit 6bbbb0ac136102098a70b97ab0c07bc7bf53131c:

target-arm: Fix warn about implicit conversion (2016-08-12 11:12:24 +0100)

are available in the git repository at:

git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream

for you to fetch changes up to 58a83c61496eeb0d31571a07a51bc1947e3379ac:

Quoted 7 lines

virtio: decrement vq->inuse in virtqueue_discard() (2016-08-23 19:20:24 +0300)

----------------------------------------------------------------
virtio: fixes

some bugfixes for virtio
balloon is still broken wrt migration

Is this a bug we need to fix for the release?

Quoted 9 lines

----------------------------------------------------------------
Stefan Hajnoczi (2):

      virtio: recalculate vq->inuse after migration
      virtio: decrement vq->inuse in virtqueue_discard()
 hw/virtio/virtio.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Applied to master, thanks.

-- PMM