virtio-net: drop assert on vm stop
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
@@ -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
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
@@ -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
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 thatvm_runningis updated before device status callback in many places, so this change leads to asserts.
Previous commit fixes the root issue that motivateda1bc7b827e422e1ff065640d8ec5347c4aadfcd8differently, so there's no longer a need for this change.In the future, we might be able to drop checking
vm_runningcompletely, and check vm state directly.
Quoted 35 lines
Reported-by Dietmar Maurer <[email protected]>Cc Jason Wang <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- hw/virtio/virtio.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)hw/virtio/virtio.c +1
-8@@ -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,
Re: [Qemu-devel] [PATCH 2/2] Revert "virtio: don't call device on !vm_running"
In reply to Michael S. TsirkinQuoted 9 lines · Michael S. Tsirkin
This reverts commit
a1bc7b827e422e1ff065640d8ec5347c4aadfcd8.
virtio: don't call device on !vm_running
It turns out that virtio net assumes thatvm_runningis updated before device status callback in many places, so this change leads to asserts.
Previous commit fixes the root issue that motivateda1bc7b827e422e1ff065640d8ec5347c4aadfcd8differently, so there's no longer a need for this change.
Quoted 7 lines
In the future, we might be able to drop checking
vm_runningcompletely, and check vm state directly.Reported-by Dietmar Maurer <[email protected]>Cc Jason Wang <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>
Quoted 32 lines
--- hw/virtio/virtio.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)hw/virtio/virtio.c +1
-8@@ -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,
Quoted 3 lines · Michael S. Tsirkin
On vm stop,
vm_runningstate set to stopped
before device is notified, so callbacks can get envoked withvm_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
Cc Jason Wang <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- hw/net/virtio-net.c | 2 -- 1 file changed, 2 deletions(-)hw/net/virtio-net.c +0
-2@@ -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;