ddf19c
From ab87c0ed2a8f0a626099261a3028bc34cfac3929 Mon Sep 17 00:00:00 2001
ddf19c
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
ddf19c
Date: Tue, 14 Jan 2020 20:23:31 +0000
ddf19c
Subject: [PATCH 5/5] xhci: recheck slot status
ddf19c
MIME-Version: 1.0
ddf19c
Content-Type: text/plain; charset=UTF-8
ddf19c
Content-Transfer-Encoding: 8bit
ddf19c
ddf19c
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
ddf19c
Message-id: <20200114202331.51831-3-dgilbert@redhat.com>
ddf19c
Patchwork-id: 93345
ddf19c
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH 2/2] xhci: recheck slot status
ddf19c
Bugzilla: 1790844
ddf19c
RH-Acked-by: Peter Xu <peterx@redhat.com>
ddf19c
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
ddf19c
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
ddf19c
ddf19c
From: Gerd Hoffmann <kraxel@redhat.com>
ddf19c
ddf19c
Factor out slot status check into a helper function.  Add an additional
ddf19c
check after completing transfers.  This is needed in case a guest
ddf19c
queues multiple transfers in a row and a device unplug happens while
ddf19c
qemu processes them.
ddf19c
ddf19c
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1786413
ddf19c
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
ddf19c
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
ddf19c
Message-id: 20200107083606.12393-1-kraxel@redhat.com
ddf19c
(cherry picked from commit 236846a019c4f7aa3111026fc9a1fe09684c8978)
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
---
ddf19c
 hw/usb/hcd-xhci.c | 15 ++++++++++++---
ddf19c
 1 file changed, 12 insertions(+), 3 deletions(-)
ddf19c
ddf19c
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
ddf19c
index d2b9744..646c78c 100644
ddf19c
--- a/hw/usb/hcd-xhci.c
ddf19c
+++ b/hw/usb/hcd-xhci.c
ddf19c
@@ -1861,6 +1861,13 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
ddf19c
     xhci_kick_epctx(epctx, streamid);
ddf19c
 }
ddf19c
 
ddf19c
+static bool xhci_slot_ok(XHCIState *xhci, int slotid)
ddf19c
+{
ddf19c
+    return (xhci->slots[slotid - 1].uport &&
ddf19c
+            xhci->slots[slotid - 1].uport->dev &&
ddf19c
+            xhci->slots[slotid - 1].uport->dev->attached);
ddf19c
+}
ddf19c
+
ddf19c
 static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
ddf19c
 {
ddf19c
     XHCIState *xhci = epctx->xhci;
ddf19c
@@ -1878,9 +1885,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
ddf19c
 
ddf19c
     /* If the device has been detached, but the guest has not noticed this
ddf19c
        yet the 2 above checks will succeed, but we must NOT continue */
ddf19c
-    if (!xhci->slots[epctx->slotid - 1].uport ||
ddf19c
-        !xhci->slots[epctx->slotid - 1].uport->dev ||
ddf19c
-        !xhci->slots[epctx->slotid - 1].uport->dev->attached) {
ddf19c
+    if (!xhci_slot_ok(xhci, epctx->slotid)) {
ddf19c
         return;
ddf19c
     }
ddf19c
 
ddf19c
@@ -1987,6 +1992,10 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
ddf19c
         } else {
ddf19c
             xhci_fire_transfer(xhci, xfer, epctx);
ddf19c
         }
ddf19c
+        if (!xhci_slot_ok(xhci, epctx->slotid)) {
ddf19c
+            /* surprise removal -> stop processing */
ddf19c
+            break;
ddf19c
+        }
ddf19c
         if (xfer->complete) {
ddf19c
             /* update ring dequeue ptr */
ddf19c
             xhci_set_ep_state(xhci, epctx, stctx, epctx->state);
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c