cryptospore / rpms / qemu-kvm

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