mopsfelder / rpms / qemu

Forked from rpms/qemu 4 years ago
Clone
fa00e1e
From c8c0bea0209adabadc9649a556f7427cdd1664af Mon Sep 17 00:00:00 2001
c8dfc65
From: Hans de Goede <hdegoede@redhat.com>
5544c1b
Date: Wed, 12 Sep 2012 15:08:33 +0200
5544c1b
Subject: [PATCH] ehci: Walk async schedule before and after migration
c8dfc65
c8dfc65
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
5544c1b
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
5544c1b
(cherry picked from commit ceab6f96454fe6589d1b09ce64403c041d79f9d9)
5544c1b
5544c1b
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
c8dfc65
---
c8dfc65
 hw/usb/hcd-ehci.c | 28 ++++++++++++++++++++++++++++
c8dfc65
 1 file changed, 28 insertions(+)
c8dfc65
c8dfc65
diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
5544c1b
index bc86460..6a5da84 100644
c8dfc65
--- a/hw/usb/hcd-ehci.c
c8dfc65
+++ b/hw/usb/hcd-ehci.c
c8dfc65
@@ -34,6 +34,7 @@
c8dfc65
 #include "monitor.h"
c8dfc65
 #include "trace.h"
c8dfc65
 #include "dma.h"
c8dfc65
+#include "sysemu.h"
c8dfc65
 
c8dfc65
 #define EHCI_DEBUG   0
c8dfc65
 
5544c1b
@@ -2572,6 +2573,32 @@ static int usb_ehci_post_load(void *opaque, int version_id)
c8dfc65
     return 0;
c8dfc65
 }
c8dfc65
 
c8dfc65
+static void usb_ehci_vm_state_change(void *opaque, int running, RunState state)
c8dfc65
+{
c8dfc65
+    EHCIState *ehci = opaque;
c8dfc65
+
c8dfc65
+    /*
c8dfc65
+     * We don't migrate the EHCIQueue-s, instead we rebuild them for the
c8dfc65
+     * schedule in guest memory. We must do the rebuilt ASAP, so that
c8dfc65
+     * USB-devices which have async handled packages have a packet in the
c8dfc65
+     * ep queue to match the completion with.
c8dfc65
+     */
c8dfc65
+    if (state == RUN_STATE_RUNNING) {
c8dfc65
+        ehci_advance_async_state(ehci);
c8dfc65
+    }
c8dfc65
+
c8dfc65
+    /*
c8dfc65
+     * The schedule rebuilt from guest memory could cause the migration dest
c8dfc65
+     * to miss a QH unlink, and fail to cancel packets, since the unlinked QH
c8dfc65
+     * will never have existed on the destination. Therefor we must flush the
c8dfc65
+     * async schedule on savevm to catch any not yet noticed unlinks.
c8dfc65
+     */
c8dfc65
+    if (state == RUN_STATE_SAVE_VM) {
c8dfc65
+        ehci_advance_async_state(ehci);
c8dfc65
+        ehci_queues_rip_unseen(ehci, 1);
c8dfc65
+    }
c8dfc65
+}
c8dfc65
+
c8dfc65
 static const VMStateDescription vmstate_ehci = {
c8dfc65
     .name        = "ehci",
c8dfc65
     .version_id  = 2,
5544c1b
@@ -2721,6 +2748,7 @@ static int usb_ehci_initfn(PCIDevice *dev)
c8dfc65
     usb_packet_init(&s->ipacket);
c8dfc65
 
c8dfc65
     qemu_register_reset(ehci_reset, s);
c8dfc65
+    qemu_add_vm_change_state_handler(usb_ehci_vm_state_change, s);
c8dfc65
 
c8dfc65
     memory_region_init(&s->mem, "ehci", MMIO_SIZE);
c8dfc65
     memory_region_init_io(&s->mem_caps, &ehci_mmio_caps_ops, s,