public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Dor Laor <dor.laor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: kvm-devel
	<kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>,
	virtualization
	<virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>,
	Anthony Liguori
	<aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>,
	Rusty Russell <rusty-8n+1lVoiYb80n/F98K4Iww@public.gmane.org>,
Subject: [Virtio-for-kvm] [PATCH 6/7] userspace virtio
Date: Fri, 21 Dec 2007 16:44:35 +0200	[thread overview]
Message-ID: <476BD153.6080609@qumranet.com> (raw)

 From 1b493ba192cd677d9feb886eb494cb266a8604e2 Mon Sep 17 00:00:00 2001
From: Dor Laor <dor.laor-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
Date: Thu, 20 Dec 2007 10:48:32 +0200
Subject: [PATCH] [VIRTIO] Add 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 <dor.laor-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
---
 qemu/hw/virtio.c |   24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/qemu/hw/virtio.c b/qemu/hw/virtio.c
index 6a1d380..e7fcfa3 100644
--- a/qemu/hw/virtio.c
+++ b/qemu/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;
 }
-- 
1.5.3.3


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

                 reply	other threads:[~2007-12-21 14:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=476BD153.6080609@qumranet.com \
    --to=dor.laor-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org \
    --cc=dor.laor-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=rusty-8n+1lVoiYb80n/F98K4Iww@public.gmane.org \
    --cc=virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox