thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
Pablo Greco e6a3ae
From 1406157e5944e023b07a644d5a8377db708134e8 Mon Sep 17 00:00:00 2001
Pablo Greco e6a3ae
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Pablo Greco e6a3ae
Date: Wed, 15 Jan 2020 12:07:42 +0100
Pablo Greco e6a3ae
Subject: [PATCH 4/7] xhci: recheck slot status
Pablo Greco e6a3ae
MIME-Version: 1.0
Pablo Greco e6a3ae
Content-Type: text/plain; charset=UTF-8
Pablo Greco e6a3ae
Content-Transfer-Encoding: 8bit
Pablo Greco e6a3ae
Pablo Greco e6a3ae
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
Pablo Greco e6a3ae
Message-id: <20200115120742.19583-3-dgilbert@redhat.com>
Pablo Greco e6a3ae
Patchwork-id: 93353
Pablo Greco e6a3ae
O-Subject: [RHEL-8.2.0 qemu-kvm PATCH 2/2] xhci: recheck slot status
Pablo Greco e6a3ae
Bugzilla: 1752320
Pablo Greco e6a3ae
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Peter Xu <peterx@redhat.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
From: Gerd Hoffmann <kraxel@redhat.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Factor out slot status check into a helper function.  Add an additional
Pablo Greco e6a3ae
check after completing transfers.  This is needed in case a guest
Pablo Greco e6a3ae
queues multiple transfers in a row and a device unplug happens while
Pablo Greco e6a3ae
qemu processes them.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1786413
Pablo Greco e6a3ae
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Pablo Greco e6a3ae
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Pablo Greco e6a3ae
Message-id: 20200107083606.12393-1-kraxel@redhat.com
Pablo Greco e6a3ae
(cherry picked from commit 236846a019c4f7aa3111026fc9a1fe09684c8978)
Pablo Greco e6a3ae
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
Pablo Greco e6a3ae
---
Pablo Greco e6a3ae
 hw/usb/hcd-xhci.c | 15 ++++++++++++---
Pablo Greco e6a3ae
 1 file changed, 12 insertions(+), 3 deletions(-)
Pablo Greco e6a3ae
Pablo Greco e6a3ae
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
Pablo Greco e6a3ae
index 45fcce3..e63a603 100644
Pablo Greco e6a3ae
--- a/hw/usb/hcd-xhci.c
Pablo Greco e6a3ae
+++ b/hw/usb/hcd-xhci.c
Pablo Greco e6a3ae
@@ -1853,6 +1853,13 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
Pablo Greco e6a3ae
     xhci_kick_epctx(epctx, streamid);
Pablo Greco e6a3ae
 }
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
+static bool xhci_slot_ok(XHCIState *xhci, int slotid)
Pablo Greco e6a3ae
+{
Pablo Greco e6a3ae
+    return (xhci->slots[slotid - 1].uport &&
Pablo Greco e6a3ae
+            xhci->slots[slotid - 1].uport->dev &&
Pablo Greco e6a3ae
+            xhci->slots[slotid - 1].uport->dev->attached);
Pablo Greco e6a3ae
+}
Pablo Greco e6a3ae
+
Pablo Greco e6a3ae
 static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
Pablo Greco e6a3ae
 {
Pablo Greco e6a3ae
     XHCIState *xhci = epctx->xhci;
Pablo Greco e6a3ae
@@ -1870,9 +1877,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
     /* If the device has been detached, but the guest has not noticed this
Pablo Greco e6a3ae
        yet the 2 above checks will succeed, but we must NOT continue */
Pablo Greco e6a3ae
-    if (!xhci->slots[epctx->slotid - 1].uport ||
Pablo Greco e6a3ae
-        !xhci->slots[epctx->slotid - 1].uport->dev ||
Pablo Greco e6a3ae
-        !xhci->slots[epctx->slotid - 1].uport->dev->attached) {
Pablo Greco e6a3ae
+    if (!xhci_slot_ok(xhci, epctx->slotid)) {
Pablo Greco e6a3ae
         return;
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
@@ -1968,6 +1973,10 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
Pablo Greco e6a3ae
         } else {
Pablo Greco e6a3ae
             xhci_fire_transfer(xhci, xfer, epctx);
Pablo Greco e6a3ae
         }
Pablo Greco e6a3ae
+        if (!xhci_slot_ok(xhci, epctx->slotid)) {
Pablo Greco e6a3ae
+            /* surprise removal -> stop processing */
Pablo Greco e6a3ae
+            break;
Pablo Greco e6a3ae
+        }
Pablo Greco e6a3ae
         if (xfer->complete) {
Pablo Greco e6a3ae
             /* update ring dequeue ptr */
Pablo Greco e6a3ae
             xhci_set_ep_state(xhci, epctx, stctx, epctx->state);
Pablo Greco e6a3ae
-- 
Pablo Greco e6a3ae
1.8.3.1
Pablo Greco e6a3ae