From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46171) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMtMf-0002yv-55 for qemu-devel@nongnu.org; Tue, 12 Jul 2016 04:48:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bMtMa-0000al-ER for qemu-devel@nongnu.org; Tue, 12 Jul 2016 04:48:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48369) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMtMa-0000aQ-8w for qemu-devel@nongnu.org; Tue, 12 Jul 2016 04:48:20 -0400 From: Gerd Hoffmann Date: Tue, 12 Jul 2016 10:48:08 +0200 Message-Id: <1468313290-14308-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1468313290-14308-1-git-send-email-kraxel@redhat.com> References: <1468313290-14308-1-git-send-email-kraxel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 1/3] nec-usb-xhci: set the device state to USB_STATE_DEFAULT List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Zhang Shuaiyi , Gerd Hoffmann From: Zhang Shuaiyi This patch is a rough fix to "hw/usb/core.c:401: usb_handle_packet: Assertion `dev->state =3D=3D 3' failed.". Qemu will crash when a usb3 device redirect to Windows7 VM via nec-usb-xhci. In extensible-host-controler-interface-usb-xhci.pdf P94(4.6.5 Address Device): =E2=80=A2 If the Block Set Address Request (BSR) flag =3D =E2=80=981=E2= =80=99 =E2=80=A2 If the slot is in the Enabled state: ... =E2=80=A2 Set the Slot State in the Output Slot Context to De= fault. BSR =3D =E2=80=981=E2=80=99: Enabled state to Default state; BSR =3D =E2=80= =980=E2=80=99: Default state to Addressed state. Try to call usb_device_reset to set device state to USB_STATE_DEFAULT in xhci_address_slot wether bsr is zero. Signed-off-by: Zhang Shuaiyi Message-id: 1467258640-11921-1-git-send-email-zhang_syi@massclouds.com Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-xhci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 1a3377f..976bfb0 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -2364,6 +2364,8 @@ static TRBCCode xhci_address_slot(XHCIState *xhci, = unsigned int slotid, slot->uport =3D uport; slot->ctx =3D octx; =20 + /* Make sure device is in USB_STATE_DEFAULT state */ + usb_device_reset(dev); if (bsr) { slot_ctx[3] =3D SLOT_DEFAULT << SLOT_STATE_SHIFT; } else { @@ -2371,7 +2373,6 @@ static TRBCCode xhci_address_slot(XHCIState *xhci, = unsigned int slotid, uint8_t buf[1]; =20 slot_ctx[3] =3D (SLOT_ADDRESSED << SLOT_STATE_SHIFT) | slotid; - usb_device_reset(dev); memset(&p, 0, sizeof(p)); usb_packet_addbuf(&p, buf, sizeof(buf)); usb_packet_setup(&p, USB_TOKEN_OUT, --=20 1.8.3.1