Patchwork [2/2] qemu/virtio: fix reset with device removal

login
register
mail settings
Submitter Michael S. Tsirkin
Date Sept. 15, 2009, 2:33 p.m.
Message ID <20090915143352.GC24708@redhat.com>
Download mbox | patch
Permalink /patch/33655/
State Superseded
Headers show

Comments

Michael S. Tsirkin - Sept. 15, 2009, 2:33 p.m.
virtio pci registers its own reset handler, but fails to unregister it,
which will lead to crashes after device removal.  Solve this problem by
switching to qdev reset handler, which is automatically unregistered.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/virtio-pci.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)
Gerd Hoffmann - Sept. 15, 2009, 3:30 p.m.
On 09/15/09 16:33, Michael S. Tsirkin wrote:
> virtio pci registers its own reset handler, but fails to unregister it,
> which will lead to crashes after device removal.  Solve this problem by
> switching to qdev reset handler, which is automatically unregistered.

Looks good.

Acked-by: Gerd Hoffmann <kraxel@redhat.com>

cheers,
   Gerd

Patch

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index f7a51ff..951d1dc 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -155,9 +155,8 @@  static int virtio_pci_load_queue(void * opaque, int n, QEMUFile *f)
     return 0;
 }
 
-static void virtio_pci_reset(void *opaque)
+static void virtio_pci_reset(VirtIOPCIProxy *proxy)
 {
-    VirtIOPCIProxy *proxy = opaque;
     virtio_reset(proxy->vdev);
     msix_reset(&proxy->pci_dev);
 }
@@ -429,8 +428,6 @@  static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,
     pci_register_bar(&proxy->pci_dev, 0, size, PCI_ADDRESS_SPACE_IO,
                            virtio_map);
 
-    qemu_register_reset(virtio_pci_reset, proxy);
-
     virtio_bind_device(vdev, &virtio_pci_bindings, proxy);
 }
 
@@ -514,6 +511,11 @@  static int virtio_balloon_init_pci(PCIDevice *pci_dev)
     return 0;
 }
 
+static void virtio_reset_pci(DeviceState *d)
+{
+    virtio_pci_reset(container_of(d, VirtIOPCIProxy, pci_dev.qdev));
+}
+
 static PCIDeviceInfo virtio_info[] = {
     {
         .qdev.name = "virtio-blk-pci",
@@ -525,6 +527,7 @@  static PCIDeviceInfo virtio_info[] = {
             DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
             DEFINE_PROP_END_OF_LIST(),
         },
+        .qdev.reset = virtio_reset_pci,
     },{
         .qdev.name  = "virtio-net-pci",
         .qdev.size  = sizeof(VirtIOPCIProxy),
@@ -534,6 +537,7 @@  static PCIDeviceInfo virtio_info[] = {
                                NIC_NVECTORS_UNSPECIFIED),
             DEFINE_PROP_END_OF_LIST(),
         },
+        .qdev.reset = virtio_reset_pci,
     },{
         .qdev.name = "virtio-console-pci",
         .qdev.size = sizeof(VirtIOPCIProxy),
@@ -542,10 +546,12 @@  static PCIDeviceInfo virtio_info[] = {
             DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
             DEFINE_PROP_END_OF_LIST(),
         },
+        .qdev.reset = virtio_reset_pci,
     },{
         .qdev.name = "virtio-balloon-pci",
         .qdev.size = sizeof(VirtIOPCIProxy),
         .init      = virtio_balloon_init_pci,
+        .qdev.reset = virtio_reset_pci,
     },{
         /* end of list */
     }