virtio-balloon: stats vq migration spec compliance
PATCH 1/1 virtio-balloon: stats vq migration spec compliance
virtio spec says that devices must not touch VQs before DRIVER_OK is set.
Additionally, balloon must not touch stats VQ unless the stats feature bit has been negotiated.
--- hw/virtio/virtio-balloon.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/virtio/virtio-balloon.c +3 -1
@@ -427,6 +427,7 @@ static void virtio_balloon_vmstate_cb(void *opaque, int running, RunState state) {VirtIOBalloon *s = opaque; +VirtIODevice *vdev =VIRTIO_DEVICE (s);if (!running) {/* put the stats element back if the VM is not running */
@@ -436,7 +437,8 @@ static void virtio_balloon_vmstate_cb(void *opaque, int running, s->stats_vq_elem =NULL ; } - }else { + }else if (balloon_stats_supported (s) && + (vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) {/* poll stats queue for the element we may have discarded * when the VM was stopped */ virtio_balloon_receive_stats (VIRTIO_DEVICE (s), s->svq);
Signature · 1 line
MST
Quoted 8 lines · Michael S. Tsirkin
virtio spec says that devices must not touch VQs before
DRIVER_OKis set.Additionally, balloon must not touch stats VQ unless the stats feature bit has been negotiated.
Cc Ladi Prosek <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>
Looks good! Do you want me to add this to the patch that introduces virtio_balloon_vmstate_cb or will you apply it on top of it?
Thanks,
Ladi
Quoted 25 lines · Michael S. Tsirkin
virtio spec says that devices must not touch VQs before
DRIVER_OKis set.Additionally, balloon must not touch stats VQ unless the stats feature bit has been negotiated.
Cc Ladi Prosek <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- hw/virtio/virtio-balloon.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)hw/virtio/virtio-balloon.c +1
-0@@ -427,6 +427,7 @@ static void virtio_balloon_vmstate_cb(void *opaque, int running, RunState state) {VirtIOBalloon *s = opaque; +VirtIODevice *vdev =VIRTIO_DEVICE (s);if (!running) {/* put the stats element back if the VM is not running */
hw/virtio/virtio-balloon.c static void virtio_balloon_vmstate_cb(void *opaque, int running, · line 444
Quoted 9 lines
hw/virtio/virtio-balloon.c +2
-1@@ -436,7 +437,8 @@ static void virtio_balloon_vmstate_cb(void *opaque, int running, s->stats_vq_elem =NULL ; } - }else { + }else if (balloon_stats_supported (s) && + (vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) {/* poll stats queue for the element we may have discarded * when the VM was stopped */ virtio_balloon_receive_stats (VIRTIO_DEVICE (s), s->svq);
Another suspect case is when the feature bit was negotiated, VIRTIO_CONFIG_S_DRIVER_OK is set, but the virtqueue PFN wasn't set up.
In that case virtqueue_pop() will access junk values.
I'm not sure if anything terrible can happen but a check that vq->vring.desc != 0 would be nice - just like we do in virtio_queue_notify_vq().
Can you add a virtio_queue_get_addr() call to see if the PFN has been set?
Stefan
Quoted 41 lines · Stefan Hajnoczi
Quoted 25 lines · Michael S. Tsirkin
virtio spec says that devices must not touch VQs before
DRIVER_OKis set.Additionally, balloon must not touch stats VQ unless the stats feature bit has been negotiated.
Cc Ladi Prosek <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- hw/virtio/virtio-balloon.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)hw/virtio/virtio-balloon.c +1
-0@@ -427,6 +427,7 @@ static void virtio_balloon_vmstate_cb(void *opaque, int running, RunState state) {VirtIOBalloon *s = opaque; +VirtIODevice *vdev =VIRTIO_DEVICE (s);if (!running) {/* put the stats element back if the VM is not running */ hw/virtio/virtio-balloon.c static void virtio_balloon_vmstate_cb(void *opaque, int running, · line 444
Quoted 9 lines
hw/virtio/virtio-balloon.c +2
-1@@ -436,7 +437,8 @@ static void virtio_balloon_vmstate_cb(void *opaque, int running, s->stats_vq_elem =NULL ; } - }else { + }else if (balloon_stats_supported (s) && + (vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) {/* poll stats queue for the element we may have discarded * when the VM was stopped */ virtio_balloon_receive_stats (VIRTIO_DEVICE (s), s->svq);Another suspect case is when the feature bit was negotiated,
VIRTIO_CONFIG_S_DRIVER_OKis set, but the virtqueue PFN wasn't set up.In that case
virtqueue_pop()will access junk values.
Quoted 8 lines
I'm not sure if anything terrible can happen but a check that
vq->vring.desc!= 0 would be nice - just like we do invirtio_queue_notify_vq().Can you add a
virtio_queue_get_addr()call to see if the PFN has been set?Stefan
DRIVER_OK is set after VQs are initialized so I think that's enough.