virtio-balloon: resume collecting stats on vmload
cover virtio-balloon: resume collecting stats on vmload
Fix virtio-balloon stats acquisition which stops upon save/restore.
Roman Kagan (2):
virtio: add virtqueue_rewind
virtio-balloon: resume collecting stats on vmload
--- hw/virtio/virtio-balloon.c | 21 ++++++++++++++++++++- hw/virtio/virtio.c | 6 ++++++ include/hw/virtio/virtio.h | 1 + 3 files changed, 27 insertions(+), 1 deletion(-)
Signature · 1 line
2.7.4
PATCH 1/2 virtio: add virtqueue_rewind
If the in-use elements aren't migrated (like is the case with virtio-balloon stats vq), make virtqueue forget about them and pretend they haven't been popped yet, to allow to start over on load.
--- hw/virtio/virtio.c | 6 ++++++ include/hw/virtio/virtio.h | 1 + 2 files changed, 7 insertions(+)
hw/virtio/virtio.c +6 -0
@@ -272,6 +272,12 @@ void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem,virtqueue_unmap_sg (vq, elem, len); } +void virtqueue_rewind (VirtQueue *vq) +{ + vq->last_avail_idx -= vq->inuse; + vq->inuse =0 ; +} +void virtqueue_fill (VirtQueue *vq,const VirtQueueElement *elem,unsigned int len,unsigned int idx) {
include/hw/virtio/virtio.h +1 -0
@@ -154,6 +154,7 @@ void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem,void virtqueue_flush (VirtQueue *vq,unsigned int count);void virtqueue_discard (VirtQueue *vq,const VirtQueueElement *elem,unsigned int len); +void virtqueue_rewind (VirtQueue *vq);void virtqueue_fill (VirtQueue *vq,const VirtQueueElement *elem,unsigned int len,unsigned int idx);
Signature · 1 line
2.7.4
PATCH 2/2 virtio-balloon: resume collecting stats on vmload
In reply to Roman KaganUpon save/restore virtio-balloon stats acquisition stops. The reason is that the in-use virtqueue element is not saved, and upon restore it's not released to the guest, making further progress impossible.
Saving the information about the used element would introduce unjustified vmstate incompatibility.
However, the number of virtqueue in-use elements can be deduced from the data available on restore (see bccdef6b1a204db0f41ffb6e24ce373e4d7890d4 "virtio: recalculate vq->inuse after migration").
So make the stats virtqueue forget that an element was popped from it, and start over. As this tackles the problem on the "load" side, it is compatible with the state saved by earlier QEMU versions.
--- hw/virtio/virtio-balloon.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
hw/virtio/virtio-balloon.c +20 -1
@@ -406,7 +406,13 @@ static void virtio_balloon_save_device(VirtIODevice *vdev, QEMUFile *f)static int virtio_balloon_load (QEMUFile *f,void *opaque,size_t size) { -return virtio_load (VIRTIO_DEVICE (opaque), f,1 ); +VirtIODevice *vdev =VIRTIO_DEVICE (opaque); +VirtIOBalloon *s =VIRTIO_BALLOON (vdev); +int ret =virtio_load (vdev, f,1 ); +/* rewind needs vq->inuse populated which happens in virtio_load() after +* vdev->load */ +virtqueue_rewind (s->svq); +return ret; } static int virtio_balloon_load_device(VirtIODevice *vdev, QEMUFile *f,
@@ -468,6 +474,18 @@ static void virtio_balloon_device_reset(VirtIODevice *vdev) } } +static void virtio_balloon_set_status (VirtIODevice *vdev,uint8_t status) +{ +VirtIOBalloon *s =VIRTIO_BALLOON (vdev); + +if (vdev->vm_running &&balloon_stats_supported (s) && + (status &VIRTIO_CONFIG_S_DRIVER_OK ) && !s->stats_vq_elem) { +/* poll stats queue for the element we may have discarded when the VM +* was stopped */ +virtio_balloon_receive_stats (vdev, s->svq); + } +} +static void virtio_balloon_instance_init (Object *obj) {VirtIOBalloon *s =VIRTIO_BALLOON (obj);
@@ -505,6 +523,7 @@ static void virtio_balloon_class_init(ObjectClass *klass, void *data) vdc->get_features = virtio_balloon_get_features; vdc->save = virtio_balloon_save_device; vdc->load = virtio_balloon_load_device; + vdc->set_status = virtio_balloon_set_status; }static const TypeInfo virtio_balloon_info = {
Signature · 1 line
2.7.4
Quoted 62 lines · Roman Kagan
Upon save/restore virtio-balloon stats acquisition stops. The reason is that the in-use virtqueue element is not saved, and upon restore it's not released to the guest, making further progress impossible.
Saving the information about the used element would introduce unjustified vmstate incompatibility.
However, the number of virtqueue in-use elements can be deduced from the data available on restore (see
bccdef6b1a204db0f41ffb6e24ce373e4d7890d4"virtio: recalculatevq->inuseafter migration").So make the stats virtqueue forget that an element was popped from it, and start over. As this tackles the problem on the "load" side, it is compatible with the state saved by earlier QEMU versions.
Signed-off-by Roman Kagan <[email protected]>Cc "Michael S. Tsirkin" <[email protected]>Cc Ladi Prosek <[email protected]>Cc Stefan Hajnoczi <[email protected]>--- hw/virtio/virtio-balloon.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)hw/virtio/virtio-balloon.c +19
-1@@ -406,7 +406,13 @@ static void virtio_balloon_save_device(VirtIODevice *vdev, QEMUFile *f)static int virtio_balloon_load (QEMUFile *f,void *opaque,size_t size) { -return virtio_load (VIRTIO_DEVICE (opaque), f,1 ); +VirtIODevice *vdev =VIRTIO_DEVICE (opaque); +VirtIOBalloon *s =VIRTIO_BALLOON (vdev); +int ret =virtio_load (vdev, f,1 ); +/* rewind needs vq->inuse populated which happens in virtio_load() after +* vdev->load */ +virtqueue_rewind (s->svq); +return ret; } static int virtio_balloon_load_device(VirtIODevice *vdev, QEMUFile *f,@@ -468,6 +474,18 @@ static void virtio_balloon_device_reset(VirtIODevice *vdev) } } +static void virtio_balloon_set_status (VirtIODevice *vdev,uint8_t status) +{ +VirtIOBalloon *s =VIRTIO_BALLOON (vdev); + +if (vdev->vm_running &&balloon_stats_supported (s) && + (status &VIRTIO_CONFIG_S_DRIVER_OK ) && !s->stats_vq_elem) { +/* poll stats queue for the element we may have discarded when the VM +* was stopped */ +virtio_balloon_receive_stats (vdev, s->svq); + } +} +static void virtio_balloon_instance_init (Object *obj) {VirtIOBalloon *s =VIRTIO_BALLOON (obj);
hw/virtio/virtio-balloon.c static void virtio_balloon_class_init(ObjectClass *klass, void *data) · line 529
Quoted 7 lines
hw/virtio/virtio-balloon.c +1
-0@@ -505,6 +523,7 @@ static void virtio_balloon_class_init(ObjectClass *klass, void *data) vdc->get_features = virtio_balloon_get_features; vdc->save = virtio_balloon_save_device; vdc->load = virtio_balloon_load_device; + vdc->set_status = virtio_balloon_set_status; }static const TypeInfo virtio_balloon_info = {
I'm sorry - I don't like this patch. This means that virtio_balloon_receive_stats will be called and will poke at the ring even if the ring was never kicked.
This is why in my opinion it is cleaner to have virtqueue_rewind return a true/false status,
and only process the ring if ring was rewinded.
I think Stefan's patches did something similar.
Quoted 2 lines
Signature · 1 line
2.7.4
Quoted 69 lines · Michael S. Tsirkin
Quoted 68 lines · Roman Kagan
Upon save/restore virtio-balloon stats acquisition stops. The reason is that the in-use virtqueue element is not saved, and upon restore it's not released to the guest, making further progress impossible.
Saving the information about the used element would introduce unjustified vmstate incompatibility.
However, the number of virtqueue in-use elements can be deduced from the data available on restore (see
bccdef6b1a204db0f41ffb6e24ce373e4d7890d4"virtio: recalculatevq->inuseafter migration").So make the stats virtqueue forget that an element was popped from it, and start over. As this tackles the problem on the "load" side, it is compatible with the state saved by earlier QEMU versions.
Signed-off-by Roman Kagan <[email protected]>Cc "Michael S. Tsirkin" <[email protected]>Cc Ladi Prosek <[email protected]>Cc Stefan Hajnoczi <[email protected]>--- hw/virtio/virtio-balloon.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)hw/virtio/virtio-balloon.c +20
-1@@ -406,7 +406,13 @@ static void virtio_balloon_save_device(VirtIODevice *vdev, QEMUFile *f)static int virtio_balloon_load (QEMUFile *f,void *opaque,size_t size) { -return virtio_load (VIRTIO_DEVICE (opaque), f,1 ); +VirtIODevice *vdev =VIRTIO_DEVICE (opaque); +VirtIOBalloon *s =VIRTIO_BALLOON (vdev); +int ret =virtio_load (vdev, f,1 ); +/* rewind needs vq->inuse populated which happens in virtio_load() after +* vdev->load */ +virtqueue_rewind (s->svq); +return ret; } static int virtio_balloon_load_device(VirtIODevice *vdev, QEMUFile *f,@@ -468,6 +474,18 @@ static void virtio_balloon_device_reset(VirtIODevice *vdev) } } +static void virtio_balloon_set_status (VirtIODevice *vdev,uint8_t status) +{ +VirtIOBalloon *s =VIRTIO_BALLOON (vdev); + +if (vdev->vm_running &&balloon_stats_supported (s) && + (status &VIRTIO_CONFIG_S_DRIVER_OK ) && !s->stats_vq_elem) { +/* poll stats queue for the element we may have discarded when the VM +* was stopped */ +virtio_balloon_receive_stats (vdev, s->svq); + } +} +static void virtio_balloon_instance_init (Object *obj) {VirtIOBalloon *s =VIRTIO_BALLOON (obj);@@ -505,6 +523,7 @@ static void virtio_balloon_class_init(ObjectClass *klass, void *data) vdc->get_features = virtio_balloon_get_features; vdc->save = virtio_balloon_save_device; vdc->load = virtio_balloon_load_device; + vdc->set_status = virtio_balloon_set_status; }
Quoted 6 lines
hw/virtio/virtio-balloon.c static void virtio_balloon_class_init(ObjectClass *klass, void *data) · line 529
Quoted 1 line
hw/virtio/virtio-balloon.c +0
-0static const TypeInfo virtio_balloon_info = {I'm sorry - I don't like this patch. This means that
virtio_balloon_receive_statswill be called and will poke at the ring even if the ring was never kicked.
I'm not sure I understand what the problem is with that:virtio_balloon_receive_stats just returns early if virtio_queue_empty(), which is no more poking at the ring than is already done in virtio_load.
Quoted 5 lines
This is why in my opinion it is cleaner to have
virtqueue_rewindreturn a true/false status,
and only process the ring if ring was rewinded.I think Stefan's patches did something similar.
I'm fine with Stefan's patches, too.
Roman.
Quoted 77 lines · Roman Kagan
Quoted 69 lines · Michael S. Tsirkin
Quoted 68 lines · Roman Kagan
Upon save/restore virtio-balloon stats acquisition stops. The reason is that the in-use virtqueue element is not saved, and upon restore it's not released to the guest, making further progress impossible.
Saving the information about the used element would introduce unjustified vmstate incompatibility.
However, the number of virtqueue in-use elements can be deduced from the data available on restore (see
bccdef6b1a204db0f41ffb6e24ce373e4d7890d4"virtio: recalculatevq->inuseafter migration").So make the stats virtqueue forget that an element was popped from it, and start over. As this tackles the problem on the "load" side, it is compatible with the state saved by earlier QEMU versions.
Signed-off-by Roman Kagan <[email protected]>Cc "Michael S. Tsirkin" <[email protected]>Cc Ladi Prosek <[email protected]>Cc Stefan Hajnoczi <[email protected]>--- hw/virtio/virtio-balloon.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)hw/virtio/virtio-balloon.c +20
-1@@ -406,7 +406,13 @@ static void virtio_balloon_save_device(VirtIODevice *vdev, QEMUFile *f)static int virtio_balloon_load (QEMUFile *f,void *opaque,size_t size) { -return virtio_load (VIRTIO_DEVICE (opaque), f,1 ); +VirtIODevice *vdev =VIRTIO_DEVICE (opaque); +VirtIOBalloon *s =VIRTIO_BALLOON (vdev); +int ret =virtio_load (vdev, f,1 ); +/* rewind needs vq->inuse populated which happens in virtio_load() after +* vdev->load */ +virtqueue_rewind (s->svq); +return ret; } static int virtio_balloon_load_device(VirtIODevice *vdev, QEMUFile *f,@@ -468,6 +474,18 @@ static void virtio_balloon_device_reset(VirtIODevice *vdev) } } +static void virtio_balloon_set_status (VirtIODevice *vdev,uint8_t status) +{ +VirtIOBalloon *s =VIRTIO_BALLOON (vdev); + +if (vdev->vm_running &&balloon_stats_supported (s) && + (status &VIRTIO_CONFIG_S_DRIVER_OK ) && !s->stats_vq_elem) { +/* poll stats queue for the element we may have discarded when the VM +* was stopped */ +virtio_balloon_receive_stats (vdev, s->svq); + } +} +static void virtio_balloon_instance_init (Object *obj) {VirtIOBalloon *s =VIRTIO_BALLOON (obj);@@ -505,6 +523,7 @@ static void virtio_balloon_class_init(ObjectClass *klass, void *data) vdc->get_features = virtio_balloon_get_features; vdc->save = virtio_balloon_save_device; vdc->load = virtio_balloon_load_device; + vdc->set_status = virtio_balloon_set_status; }Quoted 6 lines
hw/virtio/virtio-balloon.c static void virtio_balloon_class_init(ObjectClass *klass, void *data) · line 529
Quoted 1 line
hw/virtio/virtio-balloon.c +0
-0static const TypeInfo virtio_balloon_info = {I'm sorry - I don't like this patch. This means that
virtio_balloon_receive_statswill be called and will poke at the ring even if the ring was never kicked.
Quoted 3 lines
I'm not sure I understand what the problem is with that:
virtio_balloon_receive_statsjust returns early ifvirtio_queue_empty(), which is no more poking at the ring than is already done invirtio_load.
Generally we should not look at ring until there was a kick.
Quoted 9 lines
Quoted 5 lines
This is why in my opinion it is cleaner to have
virtqueue_rewindreturn a true/false status,
and only process the ring if ring was rewinded.I think Stefan's patches did something similar.
I'm fine with Stefan's patches, too.
Roman.
Quoted 11 lines · Michael S. Tsirkin
Quoted 8 lines · Roman Kagan
Quoted 3 lines · Michael S. Tsirkin
I'm sorry - I don't like this patch. This means that
virtio_balloon_receive_statswill be called and will poke at the ring even if the ring was never kicked.I'm not sure I understand what the problem is with that:
virtio_balloon_receive_statsjust returns early ifvirtio_queue_empty(), which is no more poking at the ring than is already done invirtio_load.Generally we should not look at ring until there was a kick.
How else would you recover ->inuse?
Roman.
Quoted 11 lines · Roman Kagan
Quoted 10 lines · Michael S. Tsirkin
Quoted 8 lines · Roman Kagan
Quoted 3 lines · Michael S. Tsirkin
I'm sorry - I don't like this patch. This means that
virtio_balloon_receive_statswill be called and will poke at the ring even if the ring was never kicked.I'm not sure I understand what the problem is with that:
virtio_balloon_receive_statsjust returns early ifvirtio_queue_empty(), which is no more poking at the ring than is already done invirtio_load.
Quoted 5 lines
Quoted 1 line
Generally we should not look at ring until there was a kick.
How else would you recover ->inuse?
Roman.
We seem to do this:
+ vdev->vq[i].inuse = vdev->vq[i].last_avail_idx -
+ vdev->vq[i].used_idx;
Is this wrong?
Signature · 1 line
MST
Quoted 19 lines · Michael S. Tsirkin
Quoted 11 lines · Roman Kagan
Quoted 10 lines · Michael S. Tsirkin
Quoted 8 lines · Roman Kagan
Quoted 3 lines · Michael S. Tsirkin
I'm sorry - I don't like this patch. This means that
virtio_balloon_receive_statswill be called and will poke at the ring even if the ring was never kicked.I'm not sure I understand what the problem is with that:
virtio_balloon_receive_statsjust returns early ifvirtio_queue_empty(), which is no more poking at the ring than is already done invirtio_load.Quoted 5 lines
Quoted 1 line
Generally we should not look at ring until there was a kick.
How else would you recover ->inuse?
Roman.
We seem to do this:
Review
Quoted 2 lines
(quoted diff) +2
-0+ vdev->vq[i].inuse = vdev->vq[i].last_avail_idx - + vdev->vq[i].used_idx;
Right, but .used_idx is fetched from vring two lines above:
vdev->vq[i].used_idx = vring_used_idx(&vdev->vq[i]);
Quoted 1 line
Is this wrong?
And no, I don't think it is wrong :) I guess there's just no other way to obtain it.
Roman.
Quoted 25 lines · Roman Kagan
Quoted 19 lines · Michael S. Tsirkin
Quoted 11 lines · Roman Kagan
Quoted 10 lines · Michael S. Tsirkin
Quoted 8 lines · Roman Kagan
Quoted 3 lines · Michael S. Tsirkin
I'm sorry - I don't like this patch. This means that
virtio_balloon_receive_statswill be called and will poke at the ring even if the ring was never kicked.I'm not sure I understand what the problem is with that:
virtio_balloon_receive_statsjust returns early ifvirtio_queue_empty(), which is no more poking at the ring than is already done invirtio_load.Quoted 5 lines
Quoted 1 line
Generally we should not look at ring until there was a kick.
How else would you recover ->inuse?
Roman.
We seem to do this:
Review
Quoted 2 lines
(quoted diff) +2
-0+ vdev->vq[i].inuse = vdev->vq[i].last_avail_idx - + vdev->vq[i].used_idx;Right, but .used_idx is fetched from vring two lines above:
Quoted 8 lines
vdev->vq[i].used_idx = vring_used_idx(&vdev->vq[i]);Quoted 1 line
Is this wrong?
And no, I don't think it is wrong :) I guess there's just no other way to obtain it.
Roman.
Hmm right. It actually has a comment:
/* XXX virtio-1 devices */
So we do need to fix it.
Let's not add more stuff like this though.
Signature · 1 line
MST