From patchwork Tue May 13 03:53:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 348214 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5338C140080 for ; Tue, 13 May 2014 13:57:42 +1000 (EST) Received: from localhost ([::1]:41349 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wk3qW-0007DV-9T for incoming@patchwork.ozlabs.org; Mon, 12 May 2014 23:57:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47770) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wk3qA-0006ws-SV for qemu-devel@nongnu.org; Mon, 12 May 2014 23:57:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wk3q6-0003ne-EF for qemu-devel@nongnu.org; Mon, 12 May 2014 23:57:18 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:63319) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wk3q5-0003lN-Qt for qemu-devel@nongnu.org; Mon, 12 May 2014 23:57:14 -0400 Received: from 172.24.2.119 (EHLO szxeml209-edg.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BTR77462; Tue, 13 May 2014 11:57:02 +0800 (CST) Received: from SZXEML421-HUB.china.huawei.com (10.82.67.160) by szxeml209-edg.china.huawei.com (172.24.2.184) with Microsoft SMTP Server (TLS) id 14.3.158.1; Tue, 13 May 2014 11:54:27 +0800 Received: from SZXEMA403-HUB.china.huawei.com (10.82.72.35) by szxeml421-hub.china.huawei.com (10.82.67.160) with Microsoft SMTP Server (TLS) id 14.3.158.1; Tue, 13 May 2014 11:54:07 +0800 Received: from SZXEMA503-MBS.china.huawei.com ([169.254.6.230]) by SZXEMA403-HUB.china.huawei.com ([10.82.72.35]) with mapi id 14.03.0158.001; Tue, 13 May 2014 11:53:57 +0800 From: "Gonglei (Arei)" To: Gerd Hoffmann , "qemu-devel@nongnu.org" Thread-Topic: [Qemu-devel] [PATCH] xhci: child detach fix Thread-Index: AQHPbeDsRyBfVbIUnkS7LRW8YnRTVZs923+Q Date: Tue, 13 May 2014 03:53:56 +0000 Message-ID: <33183CC9F5247A488A2544077AF19020815E7FD4@SZXEMA503-MBS.china.huawei.com> References: <1399898994-17436-1-git-send-email-kraxel@redhat.com> In-Reply-To: <1399898994-17436-1-git-send-email-kraxel@redhat.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.177.19.102] MIME-Version: 1.0 X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.65 Subject: Re: [Qemu-devel] [PATCH] xhci: child detach fix X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org > -----Original Message----- > From: qemu-devel-bounces+arei.gonglei=huawei.com@nongnu.org > [mailto:qemu-devel-bounces+arei.gonglei=huawei.com@nongnu.org] On > Behalf Of Gerd Hoffmann > Sent: Monday, May 12, 2014 8:50 PM > To: qemu-devel@nongnu.org > Cc: Gerd Hoffmann > Subject: [Qemu-devel] [PATCH] xhci: child detach fix > > xhci_child_detach() zaps the wrong slot when unplugging a device > connected via usb-hub: Instead of the device's slot the slot of the > usb-hub is used. Fix it. > > https://bugzilla.redhat.com/show_bug.cgi?id=1075846 > > Signed-off-by: Gerd Hoffmann > --- > hw/usb/hcd-xhci.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c > index ef3177a..6753a42 100644 > --- a/hw/usb/hcd-xhci.c > +++ b/hw/usb/hcd-xhci.c > @@ -3435,7 +3435,7 @@ static void xhci_child_detach(USBPort *uport, > USBDevice *child) > USBBus *bus = usb_bus_from_device(child); > XHCIState *xhci = container_of(bus, XHCIState, bus); > > - xhci_detach_slot(xhci, uport); > + xhci_detach_slot(xhci, child->port); > } > > static USBPortOps xhci_uport_ops = { > -- > 1.8.3.1 > Reviewed-by: Gonglei BTW, in usb_release_port(), the detached port should be insert the head of bus->free list table. Because of the save/restore will cause qemu crash, after hot plug/hot unplug multi times. For example, save the port '2' to memory file, but when we restore it, the port will be assign to '1' over again, which not match with the memory file, and then crash qemu. The error log: "Unknown savevm section or instance '0000:00:04.0/3/usb-host' 2" The below patch can solve this problem. Signed-off-by: Gonglei --- hw/usb/bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/usb/bus.c b/hw/usb/bus.c index e48b19f..4e6ccad 100644 --- a/hw/usb/bus.c +++ b/hw/usb/bus.c @@ -442,7 +442,7 @@ void usb_release_port(USBDevice *dev) dev->port = NULL; port->dev = NULL; - QTAILQ_INSERT_TAIL(&bus->free, port, next); + QTAILQ_INSERT_HEAD(&bus->free, port, next); bus->nfree++; }