From 73eb7f53587e56e2c697664822904cfc441106e2 Mon Sep 17 00:00:00 2001 From: Dor Laor Date: Mon, 31 Dec 2007 00:18:27 +0200 Subject: [PATCH] Reset support This adds a virtio_reset() callback. Call it when the driver sets the pfn to zero and also on qemu_reset notifier list. This fixes crashes when virtio driver unloads or when rebooting the guest. Signed-off-by: Dor Laor Signed-off-by: Avi Kivity --- hw/virtio.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/hw/virtio.c b/hw/virtio.c index 6a1d380791..e7fcfa3cc3 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -158,6 +158,25 @@ static void virtio_update_irq(VirtIODevice *vdev) qemu_set_irq(vdev->pci_dev.irq[0], vdev->isr & 1); } +void virtio_reset(void *opaque) +{ + VirtIODevice *vdev = opaque; + int i; + + vdev->features = 0; + vdev->queue_sel = 0; + vdev->status = 0; + vdev->isr = 0; + + for(i = 0; i < VIRTIO_PCI_QUEUE_MAX; i++) { + vdev->vq[i].vring.desc = NULL; + vdev->vq[i].vring.avail = NULL; + vdev->vq[i].vring.used = NULL; + vdev->vq[i].last_avail_idx = 0; + vdev->vq[i].pfn = 0; + } +} + static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val) { VirtIODevice *vdev = to_virtio_device(opaque); @@ -175,9 +194,7 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val) pa = (ram_addr_t)val << TARGET_PAGE_BITS; vdev->vq[vdev->queue_sel].pfn = val; if (pa == 0) { - vdev->vq[vdev->queue_sel].vring.desc = NULL; - vdev->vq[vdev->queue_sel].vring.avail = NULL; - vdev->vq[vdev->queue_sel].vring.used = NULL; + virtio_reset(vdev); } else if (pa < (ram_size - TARGET_PAGE_SIZE)) { virtqueue_init(&vdev->vq[vdev->queue_sel], phys_ram_base + pa); /* FIXME if pa == 0, deal with device tear down */ @@ -417,6 +434,7 @@ VirtIODevice *virtio_init_pci(PCIBus *bus, const char *name, pci_register_io_region(pci_dev, 0, 20 + config_size, PCI_ADDRESS_SPACE_IO, virtio_map); + qemu_register_reset(virtio_reset, vdev); return vdev; } -- 2.11.4.GIT