Skip to contentSkip to conversation

virtio-balloon: stats vq migration spec compliance

PATCH In review Michael S. Tsirkin 3 participants 4 messages Aug 15, 2016 – Aug 23, 2016

lore
Share & tools
lore
#0 lore raw

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
index 65457e9..7189260 100644
@@ -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
#1 lore raw
Quoted 8 lines · Michael S. Tsirkin

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.

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

#2 lore raw
In reply to Michael S. Tsirkin
Quoted 25 lines · Michael S. Tsirkin

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 +1 -0
index 65457e9..7189260 100644
@@ -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

#3 lore raw
Quoted 41 lines · Stefan Hajnoczi
Quoted 25 lines · Michael S. Tsirkin

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 +1 -0
index 65457e9..7189260 100644
@@ -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.

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 in virtio_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.