summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Bennée2022-07-28 15:55:02 +0200
committerMichael S. Tsirkin2022-08-17 13:07:37 +0200
commit5a9d5f09b1f61bc7072c2389ba5b11350ae76b0d (patch)
treeaae04f6b062dc7b66d089257ce2aaf8461cea7b0
parenthw/virtio: gracefully handle unset vhost_dev vdev (diff)
downloadqemu-5a9d5f09b1f61bc7072c2389ba5b11350ae76b0d.tar.gz
qemu-5a9d5f09b1f61bc7072c2389ba5b11350ae76b0d.tar.xz
qemu-5a9d5f09b1f61bc7072c2389ba5b11350ae76b0d.zip
hw/virtio: handle un-configured shutdown in virtio-pci
The assert() protecting against leakage is a little aggressive and causes needless crashes if a device is shutdown without having been configured. In this case no descriptors are lost because none have been assigned. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20220728135503.1060062-4-alex.bennee@linaro.org> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
-rw-r--r--hw/virtio/virtio-pci.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 45327f0b31..5ce61f9b45 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -996,9 +996,14 @@ static int virtio_pci_set_guest_notifiers(DeviceState *d, int nvqs, bool assign)
nvqs = MIN(nvqs, VIRTIO_QUEUE_MAX);
- /* When deassigning, pass a consistent nvqs value
- * to avoid leaking notifiers.
+ /*
+ * When deassigning, pass a consistent nvqs value to avoid leaking
+ * notifiers. But first check we've actually been configured, exit
+ * early if we haven't.
*/
+ if (!assign && !proxy->nvqs_with_notifiers) {
+ return 0;
+ }
assert(assign || nvqs == proxy->nvqs_with_notifiers);
proxy->nvqs_with_notifiers = nvqs;