40b356
From e3e5226d8ed3907bb818eb8db74175c08c011459 Mon Sep 17 00:00:00 2001
40b356
From: Ladi Prosek <lprosek@redhat.com>
40b356
Date: Wed, 5 Oct 2016 17:22:28 +0200
40b356
Subject: [PATCH 6/8] virtio: zero vq->inuse in virtio_reset()
40b356
40b356
RH-Author: Ladi Prosek <lprosek@redhat.com>
40b356
Message-id: <1475666548-9186-7-git-send-email-lprosek@redhat.com>
40b356
Patchwork-id: 72485
40b356
O-Subject: [RHEL-7.4 qemu-kvm v2 PATCH 6/6] virtio: zero vq->inuse in virtio_reset()
40b356
Bugzilla: 1393484
40b356
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
40b356
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
40b356
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
40b356
40b356
From: Stefan Hajnoczi <stefanha@redhat.com>
40b356
40b356
vq->inuse must be zeroed upon device reset like most other virtqueue
40b356
fields.
40b356
40b356
In theory, virtio_reset() just needs assert(vq->inuse == 0) since
40b356
devices must clean up in-flight requests during reset (requests cannot
40b356
not be leaked!).
40b356
40b356
In practice, it is difficult to achieve vq->inuse == 0 across reset
40b356
because balloon, blk, 9p, etc implement various different strategies for
40b356
cleaning up requests.  Most devices call g_free(elem) directly without
40b356
telling virtio.c that the VirtQueueElement is cleaned up.  Therefore
40b356
vq->inuse is not decremented during reset.
40b356
40b356
This patch zeroes vq->inuse and trusts that devices are not leaking
40b356
VirtQueueElements across reset.
40b356
40b356
I will send a follow-up series that refactors request life-cycle across
40b356
all devices and converts vq->inuse = 0 into assert(vq->inuse == 0) but
40b356
this more invasive approach is not appropriate for stable trees.
40b356
40b356
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
40b356
Cc: qemu-stable <qemu-stable@nongnu.org>
40b356
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
40b356
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
40b356
Reviewed-by: Ladi Prosek <lprosek@redhat.com>
40b356
(cherry picked from commit 4b7f91ed0270a371e1933efa21ba600b6da23ab9)
40b356
Signed-off-by: Ladi Prosek <lprosek@redhat.com>
40b356
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
40b356
---
40b356
 hw/virtio/virtio.c | 1 +
40b356
 1 file changed, 1 insertion(+)
40b356
40b356
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
40b356
index 87a7639..cdb21b1 100644
40b356
--- a/hw/virtio/virtio.c
40b356
+++ b/hw/virtio/virtio.c
40b356
@@ -585,6 +585,7 @@ void virtio_reset(void *opaque)
40b356
         vdev->vq[i].signalled_used = 0;
40b356
         vdev->vq[i].signalled_used_valid = false;
40b356
         vdev->vq[i].notification = true;
40b356
+        vdev->vq[i].inuse = 0;
40b356
     }
40b356
 }
40b356
 
40b356
-- 
40b356
1.8.3.1
40b356