yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-xhci-Add-a-few-missing-checks-for-disconnected-devic.patch

958e1b
From d6c5ce73edbc928cce19a095a27e2feff9db8884 Mon Sep 17 00:00:00 2001
958e1b
From: Gerd Hoffmann <kraxel@redhat.com>
958e1b
Date: Fri, 11 Jul 2014 14:20:52 +0200
958e1b
Subject: [PATCH 18/43] xhci: Add a few missing checks for disconnected devices
958e1b
958e1b
Message-id: <1405088470-24115-20-git-send-email-kraxel@redhat.com>
958e1b
Patchwork-id: 59827
958e1b
O-Subject: [RHEL-7.1 qemu-kvm PATCH 19/37] xhci: Add a few missing checks for disconnected devices
958e1b
Bugzilla: 980833
958e1b
RH-Acked-by: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
958e1b
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
958e1b
958e1b
From: Hans de Goede <hdegoede@redhat.com>
958e1b
958e1b
One of the reworks of qemu's usb core made changes to usb-port's disconnect
958e1b
handling. Now ports with a device will always have a non 0 dev member, but
958e1b
if the device is not attached (which is possible with usb redirection),
958e1b
dev->attached will be 0.
958e1b
958e1b
So supplement all checks for dev to also check dev->attached, and add an
958e1b
extra check in a path where a device check was completely missing.
958e1b
958e1b
This fixes various crashes (asserts triggering) I've been seeing when xhci
958e1b
attached usb devices get disconnected at the wrong time.
958e1b
958e1b
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
958e1b
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
958e1b
(cherry picked from commit de9de157fbb9aa66380ab1973dd6ecf12fbd8b25)
958e1b
---
958e1b
 hw/usb/hcd-xhci.c | 13 +++++++++++--
958e1b
 1 file changed, 11 insertions(+), 2 deletions(-)
958e1b
958e1b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
---
958e1b
 hw/usb/hcd-xhci.c | 13 +++++++++++--
958e1b
 1 file changed, 11 insertions(+), 2 deletions(-)
958e1b
958e1b
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
958e1b
index ef0c073..944b255 100644
958e1b
--- a/hw/usb/hcd-xhci.c
958e1b
+++ b/hw/usb/hcd-xhci.c
958e1b
@@ -1498,7 +1498,8 @@ static TRBCCode xhci_reset_ep(XHCIState *xhci, unsigned int slotid,
958e1b
     }
958e1b
 
958e1b
     if (!xhci->slots[slotid-1].uport ||
958e1b
-        !xhci->slots[slotid-1].uport->dev) {
958e1b
+        !xhci->slots[slotid-1].uport->dev ||
958e1b
+        !xhci->slots[slotid-1].uport->dev->attached) {
958e1b
         return CC_USB_TRANSACTION_ERROR;
958e1b
     }
958e1b
 
958e1b
@@ -1985,6 +1986,14 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
958e1b
         return;
958e1b
     }
958e1b
 
958e1b
+    /* If the device has been detached, but the guest has not noticed this
958e1b
+       yet the 2 above checks will succeed, but we must NOT continue */
958e1b
+    if (!xhci->slots[slotid - 1].uport ||
958e1b
+        !xhci->slots[slotid - 1].uport->dev ||
958e1b
+        !xhci->slots[slotid - 1].uport->dev->attached) {
958e1b
+        return;
958e1b
+    }
958e1b
+
958e1b
     if (epctx->retry) {
958e1b
         XHCITransfer *xfer = epctx->retry;
958e1b
 
958e1b
@@ -2209,7 +2218,7 @@ static TRBCCode xhci_address_slot(XHCIState *xhci, unsigned int slotid,
958e1b
     trace_usb_xhci_slot_address(slotid, uport->path);
958e1b
 
958e1b
     dev = uport->dev;
958e1b
-    if (!dev) {
958e1b
+    if (!dev || !dev->attached) {
958e1b
         fprintf(stderr, "xhci: port %s not connected\n", uport->path);
958e1b
         return CC_USB_TRANSACTION_ERROR;
958e1b
     }
958e1b
-- 
958e1b
1.8.3.1
958e1b