virtio: zero vq->inuse in virtio_reset()
PATCH 1/1 virtio: zero vq->inuse in virtio_reset()
vq->inuse must be zeroed upon device reset like most other virtqueue fields.
In theory, virtio_reset() just needs assert(vq->inuse == 0) since devices must clean up in-flight requests during reset (requests cannot not be leaked!).
In practice, it is difficult to achieve vq->inuse == 0 across reset because balloon, blk, 9p, etc implement various different strategies for cleaning up requests. Most devices call g_free(elem) directly without telling virtio.c that the VirtQueueElement is cleaned up. Therefore vq->inuse is not decremented during reset.
This patch zeroes vq->inuse and trusts that devices are not leaking VirtQueueElements across reset.
I will send a follow-up series that refactors request life-cycle across all devices and converts vq->inuse = 0 into assert(vq->inuse == 0) but this more invasive approach is not appropriate for stable trees.
--- hw/virtio/virtio.c | 1 + 1 file changed, 1 insertion(+)
hw/virtio/virtio.c +1 -0
@@ -822,6 +822,7 @@ void virtio_reset(void *opaque) vdev->vq[i].signalled_used_valid = false; vdev->vq[i].notification = true; vdev->vq[i].vring.num = vdev->vq[i].vring.num_default; + vdev->vq[i].inuse =0 ; } }
Signature · 1 line
2.7.4
Quoted 38 lines · Stefan Hajnoczi
vq->inusemust be zeroed upon device reset like most other virtqueue fields.In theory,
virtio_reset()just needsassert(vq->inuse == 0)since devices must clean up in-flight requests during reset (requests cannot not be leaked!).In practice, it is difficult to achieve
vq->inuse== 0 across reset because balloon, blk, 9p, etc implement various different strategies for cleaning up requests. Most devices callg_free(elem)directly without tellingvirtio.cthat the VirtQueueElement is cleaned up. Thereforevq->inuseis not decremented during reset.This patch zeroes
vq->inuseand trusts that devices are not leaking VirtQueueElements across reset.I will send a follow-up series that refactors request life-cycle across all devices and converts
vq->inuse= 0 intoassert(vq->inuse == 0)but this more invasive approach is not appropriate for stable trees.Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/virtio/virtio.c | 1 + 1 file changed, 1 insertion(+)hw/virtio/virtio.c +1
-1@@ -822,6 +822,7 @@ void virtio_reset(void *opaque) vdev->vq[i].signalled_used_valid = false; vdev->vq[i].notification = true; vdev->vq[i].vring.num = vdev->vq[i].vring.num_default; + vdev->vq[i].inuse =0 ; } } --
Quoted 1 line
2.7.4
CCing qemu-stable
Ladi Prosek
Reviewed-byQuoted 38 lines · Stefan Hajnoczi
Quoted 37 lines · Stefan Hajnoczi
vq->inusemust be zeroed upon device reset like most other virtqueue fields.In theory,
virtio_reset()just needsassert(vq->inuse == 0)since devices must clean up in-flight requests during reset (requests cannot not be leaked!).In practice, it is difficult to achieve
vq->inuse== 0 across reset because balloon, blk, 9p, etc implement various different strategies for cleaning up requests. Most devices callg_free(elem)directly without tellingvirtio.cthat the VirtQueueElement is cleaned up. Thereforevq->inuseis not decremented during reset.This patch zeroes
vq->inuseand trusts that devices are not leaking VirtQueueElements across reset.I will send a follow-up series that refactors request life-cycle across all devices and converts
vq->inuse= 0 intoassert(vq->inuse == 0)but this more invasive approach is not appropriate for stable trees.Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/virtio/virtio.c | 1 + 1 file changed, 1 insertion(+)hw/virtio/virtio.c +1
-0@@ -822,6 +822,7 @@ void virtio_reset(void *opaque) vdev->vq[i].signalled_used_valid = false; vdev->vq[i].notification = true; vdev->vq[i].vring.num = vdev->vq[i].vring.num_default; + vdev->vq[i].inuse =0 ; } }
Quoted 4 lines
Quoted 2 lines
--
2.7.4CCing qemu-stable
Quoted 30 lines · On Wed, 7 Sep 2016 11:51:25 -0400 Stefan Hajnoczi <[email protected]> wrote:
vq->inusemust be zeroed upon device reset like most other virtqueue fields.In theory,
virtio_reset()just needsassert(vq->inuse == 0)since devices must clean up in-flight requests during reset (requests cannot not be leaked!).In practice, it is difficult to achieve
vq->inuse== 0 across reset because balloon, blk, 9p, etc implement various different strategies for cleaning up requests. Most devices callg_free(elem)directly without tellingvirtio.cthat the VirtQueueElement is cleaned up. Thereforevq->inuseis not decremented during reset.This patch zeroes
vq->inuseand trusts that devices are not leaking VirtQueueElements across reset.I will send a follow-up series that refactors request life-cycle across all devices and converts
vq->inuse= 0 intoassert(vq->inuse == 0)but this more invasive approach is not appropriate for stable trees.Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/virtio/virtio.c | 1 + 1 file changed, 1 insertion(+)hw/virtio/virtio.c +0
-0
hw/virtio/virtio.c void virtio_reset(void *opaque) · line 828
Quoted 7 lines
hw/virtio/virtio.c +1
-0@@ -822,6 +822,7 @@ void virtio_reset(void *opaque) vdev->vq[i].signalled_used_valid = false; vdev->vq[i].notification = true; vdev->vq[i].vring.num = vdev->vq[i].vring.num_default; + vdev->vq[i].inuse =0 ; } }
This looks sane as a minimal change, and survives my smoketests.