qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xhci: recheck slot status
@ 2020-01-07  8:36 Gerd Hoffmann
  2020-01-07  8:55 ` no-reply
  2020-01-07  9:10 ` Philippe Mathieu-Daudé
  0 siblings, 2 replies; 3+ messages in thread
From: Gerd Hoffmann @ 2020-01-07  8:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, dgilbert

Factor out slot status check into a helper function.  Add an additional
check after completing transfers.  This is needed in case a guest
queues multiple transfers in a row and a device unplug happens while
qemu processes them.

Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1786413
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb/hcd-xhci.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 80988bb305a1..c198a2d150c9 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -1861,6 +1861,13 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
     xhci_kick_epctx(epctx, streamid);
 }
 
+static bool xhci_slot_ok(XHCIState *xhci, int slotid)
+{
+    return (xhci->slots[slotid - 1].uport &&
+            xhci->slots[slotid - 1].uport->dev &&
+            xhci->slots[slotid - 1].uport->dev->attached);
+}
+
 static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
 {
     XHCIState *xhci = epctx->xhci;
@@ -1878,9 +1885,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
 
     /* If the device has been detached, but the guest has not noticed this
        yet the 2 above checks will succeed, but we must NOT continue */
-    if (!xhci->slots[epctx->slotid - 1].uport ||
-        !xhci->slots[epctx->slotid - 1].uport->dev ||
-        !xhci->slots[epctx->slotid - 1].uport->dev->attached) {
+    if (!xhci_slot_ok(xhci, epctx->slotid)) {
         return;
     }
 
@@ -1987,6 +1992,10 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
         } else {
             xhci_fire_transfer(xhci, xfer, epctx);
         }
+        if (!xhci_slot_ok(xhci, epctx->slotid)) {
+            /* surprise removal -> stop processing */
+            break;
+        }
         if (xfer->complete) {
             /* update ring dequeue ptr */
             xhci_set_ep_state(xhci, epctx, stctx, epctx->state);
-- 
2.18.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] xhci: recheck slot status
  2020-01-07  8:36 [PATCH] xhci: recheck slot status Gerd Hoffmann
@ 2020-01-07  8:55 ` no-reply
  2020-01-07  9:10 ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 3+ messages in thread
From: no-reply @ 2020-01-07  8:55 UTC (permalink / raw)
  To: kraxel; +Cc: qemu-devel, dgilbert, kraxel

Patchew URL: https://patchew.org/QEMU/20200107083606.12393-1-kraxel@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

N/A. Internal error while reading log file



The full log is available at
http://patchew.org/logs/20200107083606.12393-1-kraxel@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] xhci: recheck slot status
  2020-01-07  8:36 [PATCH] xhci: recheck slot status Gerd Hoffmann
  2020-01-07  8:55 ` no-reply
@ 2020-01-07  9:10 ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-01-07  9:10 UTC (permalink / raw)
  To: Gerd Hoffmann, qemu-devel; +Cc: dgilbert

On 1/7/20 9:36 AM, Gerd Hoffmann wrote:
> Factor out slot status check into a helper function.  Add an additional
> check after completing transfers.  This is needed in case a guest
> queues multiple transfers in a row and a device unplug happens while
> qemu processes them.
> 
> Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1786413
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>   hw/usb/hcd-xhci.c | 15 ++++++++++++---
>   1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
> index 80988bb305a1..c198a2d150c9 100644
> --- a/hw/usb/hcd-xhci.c
> +++ b/hw/usb/hcd-xhci.c
> @@ -1861,6 +1861,13 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
>       xhci_kick_epctx(epctx, streamid);
>   }
>   
> +static bool xhci_slot_ok(XHCIState *xhci, int slotid)
> +{
> +    return (xhci->slots[slotid - 1].uport &&
> +            xhci->slots[slotid - 1].uport->dev &&
> +            xhci->slots[slotid - 1].uport->dev->attached);
> +}
> +
>   static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
>   {
>       XHCIState *xhci = epctx->xhci;
> @@ -1878,9 +1885,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
>   
>       /* If the device has been detached, but the guest has not noticed this
>          yet the 2 above checks will succeed, but we must NOT continue */
> -    if (!xhci->slots[epctx->slotid - 1].uport ||
> -        !xhci->slots[epctx->slotid - 1].uport->dev ||
> -        !xhci->slots[epctx->slotid - 1].uport->dev->attached) {
> +    if (!xhci_slot_ok(xhci, epctx->slotid)) {
>           return;
>       }
>   
> @@ -1987,6 +1992,10 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
>           } else {
>               xhci_fire_transfer(xhci, xfer, epctx);
>           }
> +        if (!xhci_slot_ok(xhci, epctx->slotid)) {
> +            /* surprise removal -> stop processing */

I'd use "unexpected removal", but surprise is funnier :)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> +            break;
> +        }
>           if (xfer->complete) {
>               /* update ring dequeue ptr */
>               xhci_set_ep_state(xhci, epctx, stctx, epctx->state);
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-01-07 10:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-07  8:36 [PATCH] xhci: recheck slot status Gerd Hoffmann
2020-01-07  8:55 ` no-reply
2020-01-07  9:10 ` Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).