From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Eduardo Habkost <ehabkost@redhat.com>, Gerd Hoffmann <kraxel@redhat.com>
Subject: [PULL 5/5] xhci: recheck slot status
Date: Mon, 13 Jan 2020 14:06:46 +0100 [thread overview]
Message-ID: <20200113130646.30099-6-kraxel@redhat.com> (raw)
In-Reply-To: <20200113130646.30099-1-kraxel@redhat.com>
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>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-id: 20200107083606.12393-1-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 0d3d96d05a00..fb05de4b0524 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
next prev parent reply other threads:[~2020-01-13 13:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-13 13:06 [PULL 0/5] Usb 20200113 patches Gerd Hoffmann
2020-01-13 13:06 ` [PULL 1/5] usb-host: remove 'remote wakeup' flag from configuration descriptor Gerd Hoffmann
2020-01-13 13:06 ` [PULL 2/5] usb-redir: " Gerd Hoffmann
2020-01-13 13:06 ` [PULL 3/5] usbredir: Prevent recursion in usbredir_write Gerd Hoffmann
2020-01-13 13:06 ` [PULL 4/5] xhci: Fix memory leak in xhci_kick_epctx when poweroff GuestOS Gerd Hoffmann
2020-01-13 13:06 ` Gerd Hoffmann [this message]
2020-01-13 14:57 ` [PULL 0/5] Usb 20200113 patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200113130646.30099-6-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=ehabkost@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).