Skip to contentSkip to conversation

virtio-net: drop assert on vm stop

PATCH In review Michael S. Tsirkin 3 participants 5 messages Sep 11, 2014 – Sep 15, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 virtio-net: drop assert on vm stop

On vm stop, vm_running state set to stopped
before device is notified, so callbacks can get envoked with vm_running = false; and this is not an error.

---
 hw/net/virtio-net.c | 2 --
 1 file changed, 2 deletions(-)
hw/net/virtio-net.c +0 -2
index 826a2a5..2040eac 100644
@@ -1125,8 +1125,6 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)
         return num_packets;
     }
 
-    assert(vdev->vm_running);
-
     if (q->async_tx.elem.out_num) {
         virtio_queue_set_notification(q->tx_vq, 0);
         return num_packets;
Signature · 1 line
MST
#1 lore raw

PATCH 2/2 Revert "virtio: don't call device on !vm_running"

This reverts commit a1bc7b827e422e1ff065640d8ec5347c4aadfcd8.
virtio: don't call device on !vm_running
It turns out that virtio net assumes that vm_running is updated before device status callback in many places, so this change leads to asserts.
Previous commit fixes the root issue that motivated a1bc7b827e422e1ff065640d8ec5347c4aadfcd8 differently, so there's no longer a need for this change.

In the future, we might be able to drop checking vm_running completely, and check vm state directly.

---
 hw/virtio/virtio.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
hw/virtio/virtio.c +1 -8
index ac22238..5c98180 100644
@@ -1108,10 +1108,7 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
     BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
     bool backend_run = running && (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK);
-
-    if (running) {
-        vdev->vm_running = running;
-    }
+    vdev->vm_running = running;
 
     if (backend_run) {
         virtio_set_status(vdev, vdev->status);
@@ -1124,10 +1121,6 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
     if (!backend_run) {
         virtio_set_status(vdev, vdev->status);
     }
-
-    if (!running) {
-        vdev->vm_running = running;
-    }
 }
 
 void virtio_init(VirtIODevice *vdev, const char *name,
Signature · 1 line
MST
Acked-by on v1 2/2
#2 lore raw

Re: [Qemu-devel] [PATCH 2/2] Revert "virtio: don't call device on !vm_running"

Quoted 11 lines · Michael S. Tsirkin

This reverts commit a1bc7b827e422e1ff065640d8ec5347c4aadfcd8.
virtio: don't call device on !vm_running
It turns out that virtio net assumes that vm_running is updated before device status callback in many places, so this change leads to asserts.
Previous commit fixes the root issue that motivated a1bc7b827e422e1ff065640d8ec5347c4aadfcd8 differently, so there's no longer a need for this change.

In the future, we might be able to drop checking vm_running completely, and check vm state directly.

Quoted 35 lines
---
 hw/virtio/virtio.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
hw/virtio/virtio.c +1 -8
index ac22238..5c98180 100644
@@ -1108,10 +1108,7 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
     BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
     bool backend_run = running && (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK);
-
-    if (running) {
-        vdev->vm_running = running;
-    }
+    vdev->vm_running = running;
 
     if (backend_run) {
         virtio_set_status(vdev, vdev->status);
@@ -1124,10 +1121,6 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
     if (!backend_run) {
         virtio_set_status(vdev, vdev->status);
     }
-
-    if (!running) {
-        vdev->vm_running = running;
-    }
 }
 
 void virtio_init(VirtIODevice *vdev, const char *name,
Tested-by on v1 2/2
#3 lore raw

Re: [Qemu-devel] [PATCH 2/2] Revert "virtio: don't call device on !vm_running"

In reply to Michael S. Tsirkin
Quoted 9 lines · Michael S. Tsirkin

This reverts commit a1bc7b827e422e1ff065640d8ec5347c4aadfcd8.
virtio: don't call device on !vm_running
It turns out that virtio net assumes that vm_running is updated before device status callback in many places, so this change leads to asserts.
Previous commit fixes the root issue that motivated a1bc7b827e422e1ff065640d8ec5347c4aadfcd8 differently, so there's no longer a need for this change.

Quoted 7 lines

In the future, we might be able to drop checking vm_running completely, and check vm state directly.

Quoted 32 lines
---
 hw/virtio/virtio.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
hw/virtio/virtio.c +1 -8
index ac22238..5c98180 100644
@@ -1108,10 +1108,7 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
     BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
     bool backend_run = running && (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK);
-
-    if (running) {
-        vdev->vm_running = running;
-    }
+    vdev->vm_running = running;
 
     if (backend_run) {
         virtio_set_status(vdev, vdev->status);
@@ -1124,10 +1121,6 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
     if (!backend_run) {
         virtio_set_status(vdev, vdev->status);
     }
-
-    if (!running) {
-        vdev->vm_running = running;
-    }
 }
 
 void virtio_init(VirtIODevice *vdev, const char *name,
Acked-by on v1 1/2
#4 lore raw
In reply to Michael S. Tsirkin
Quoted 3 lines · Michael S. Tsirkin

On vm stop, vm_running state set to stopped
before device is notified, so callbacks can get envoked with vm_running = false; and this is not an error.

This is consistent with virtio-blk which also has such kinds of callbacks. This fixes the issue of qemu crashing when stop during transmission.

Quoted 20 lines
---
 hw/net/virtio-net.c | 2 --
 1 file changed, 2 deletions(-)
hw/net/virtio-net.c +0 -2
index 826a2a5..2040eac 100644
@@ -1125,8 +1125,6 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)
         return num_packets;
     }
 
-    assert(vdev->vm_running);
-
     if (q->async_tx.elem.out_num) {
         virtio_queue_set_notification(q->tx_vq, 0);
         return num_packets;