提交 e489030d 编写于 作者: M Michael S. Tsirkin 提交者: Anthony Liguori

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: NMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 7f23f812
...@@ -155,9 +155,9 @@ static int virtio_pci_load_queue(void * opaque, int n, QEMUFile *f) ...@@ -155,9 +155,9 @@ static int virtio_pci_load_queue(void * opaque, int n, QEMUFile *f)
return 0; 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); virtio_reset(proxy->vdev);
msix_reset(&proxy->pci_dev); msix_reset(&proxy->pci_dev);
} }
...@@ -184,7 +184,7 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val) ...@@ -184,7 +184,7 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
case VIRTIO_PCI_QUEUE_PFN: case VIRTIO_PCI_QUEUE_PFN:
pa = (target_phys_addr_t)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT; pa = (target_phys_addr_t)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT;
if (pa == 0) if (pa == 0)
virtio_pci_reset(proxy); virtio_pci_reset(&proxy->pci_dev.qdev);
else else
virtio_queue_set_addr(vdev, vdev->queue_sel, pa); virtio_queue_set_addr(vdev, vdev->queue_sel, pa);
break; break;
...@@ -198,7 +198,7 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val) ...@@ -198,7 +198,7 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
case VIRTIO_PCI_STATUS: case VIRTIO_PCI_STATUS:
vdev->status = val & 0xFF; vdev->status = val & 0xFF;
if (vdev->status == 0) if (vdev->status == 0)
virtio_pci_reset(proxy); virtio_pci_reset(&proxy->pci_dev.qdev);
break; break;
case VIRTIO_MSI_CONFIG_VECTOR: case VIRTIO_MSI_CONFIG_VECTOR:
msix_vector_unuse(&proxy->pci_dev, vdev->config_vector); msix_vector_unuse(&proxy->pci_dev, vdev->config_vector);
...@@ -429,8 +429,6 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev, ...@@ -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, pci_register_bar(&proxy->pci_dev, 0, size, PCI_ADDRESS_SPACE_IO,
virtio_map); virtio_map);
qemu_register_reset(virtio_pci_reset, proxy);
virtio_bind_device(vdev, &virtio_pci_bindings, proxy); virtio_bind_device(vdev, &virtio_pci_bindings, proxy);
} }
...@@ -534,6 +532,7 @@ static PCIDeviceInfo virtio_info[] = { ...@@ -534,6 +532,7 @@ static PCIDeviceInfo virtio_info[] = {
DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2), DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
DEFINE_PROP_END_OF_LIST(), DEFINE_PROP_END_OF_LIST(),
}, },
.qdev.reset = virtio_pci_reset,
},{ },{
.qdev.name = "virtio-net-pci", .qdev.name = "virtio-net-pci",
.qdev.size = sizeof(VirtIOPCIProxy), .qdev.size = sizeof(VirtIOPCIProxy),
...@@ -543,6 +542,7 @@ static PCIDeviceInfo virtio_info[] = { ...@@ -543,6 +542,7 @@ static PCIDeviceInfo virtio_info[] = {
NIC_NVECTORS_UNSPECIFIED), NIC_NVECTORS_UNSPECIFIED),
DEFINE_PROP_END_OF_LIST(), DEFINE_PROP_END_OF_LIST(),
}, },
.qdev.reset = virtio_pci_reset,
},{ },{
.qdev.name = "virtio-console-pci", .qdev.name = "virtio-console-pci",
.qdev.size = sizeof(VirtIOPCIProxy), .qdev.size = sizeof(VirtIOPCIProxy),
...@@ -551,10 +551,12 @@ static PCIDeviceInfo virtio_info[] = { ...@@ -551,10 +551,12 @@ static PCIDeviceInfo virtio_info[] = {
DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0), DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
DEFINE_PROP_END_OF_LIST(), DEFINE_PROP_END_OF_LIST(),
}, },
.qdev.reset = virtio_pci_reset,
},{ },{
.qdev.name = "virtio-balloon-pci", .qdev.name = "virtio-balloon-pci",
.qdev.size = sizeof(VirtIOPCIProxy), .qdev.size = sizeof(VirtIOPCIProxy),
.init = virtio_balloon_init_pci, .init = virtio_balloon_init_pci,
.qdev.reset = virtio_pci_reset,
},{ },{
/* end of list */ /* end of list */
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册