aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2009-09-16 13:40:37 +0300
committerAnthony Liguori <aliguori@us.ibm.com>2009-10-05 09:32:50 -0500
commite489030df2448d22b3cb92fd5dcb22c6fa0fc9e1 (patch)
treefa7fbf08a1d4ba2d303b93bbbaa2224421cc68b9
parent7f23f812c49da6d6fe03bcd4bc2d07341e93db11 (diff)
qemu/virtio: fix reset with device removal
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> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r--hw/virtio-pci.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 7b86bfc9ef..c4d93fa730 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -155,9 +155,9 @@ 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(DeviceState *d)
{
- VirtIOPCIProxy *proxy = opaque;
+ VirtIOPCIProxy *proxy = container_of(d, VirtIOPCIProxy, pci_dev.qdev);
virtio_reset(proxy->vdev);
msix_reset(&proxy->pci_dev);
}
@@ -184,7 +184,7 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
case VIRTIO_PCI_QUEUE_PFN:
pa = (target_phys_addr_t)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT;
if (pa == 0)
- virtio_pci_reset(proxy);
+ virtio_pci_reset(&proxy->pci_dev.qdev);
else
virtio_queue_set_addr(vdev, vdev->queue_sel, pa);
break;
@@ -198,7 +198,7 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
case VIRTIO_PCI_STATUS:
vdev->status = val & 0xFF;
if (vdev->status == 0)
- virtio_pci_reset(proxy);
+ virtio_pci_reset(&proxy->pci_dev.qdev);
break;
case VIRTIO_MSI_CONFIG_VECTOR:
msix_vector_unuse(&proxy->pci_dev, vdev->config_vector);
@@ -429,8 +429,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);
}
@@ -534,6 +532,7 @@ static PCIDeviceInfo virtio_info[] = {
DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
DEFINE_PROP_END_OF_LIST(),
},
+ .qdev.reset = virtio_pci_reset,
},{
.qdev.name = "virtio-net-pci",
.qdev.size = sizeof(VirtIOPCIProxy),
@@ -543,6 +542,7 @@ static PCIDeviceInfo virtio_info[] = {
NIC_NVECTORS_UNSPECIFIED),
DEFINE_PROP_END_OF_LIST(),
},
+ .qdev.reset = virtio_pci_reset,
},{
.qdev.name = "virtio-console-pci",
.qdev.size = sizeof(VirtIOPCIProxy),
@@ -551,10 +551,12 @@ static PCIDeviceInfo virtio_info[] = {
DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
DEFINE_PROP_END_OF_LIST(),
},
+ .qdev.reset = virtio_pci_reset,
},{
.qdev.name = "virtio-balloon-pci",
.qdev.size = sizeof(VirtIOPCIProxy),
.init = virtio_balloon_init_pci,
+ .qdev.reset = virtio_pci_reset,
},{
/* end of list */
}