From patchwork Tue Mar 17 11:28:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 450946 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 6CBE6140172 for ; Tue, 17 Mar 2015 22:51:43 +1100 (AEDT) Received: from localhost ([::1]:53983 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YXq29-0003AU-Nj for incoming@patchwork.ozlabs.org; Tue, 17 Mar 2015 07:51:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51093) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YXq1m-0002eL-Uo for qemu-devel@nongnu.org; Tue, 17 Mar 2015 07:51:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YXq1i-0000uP-GH for qemu-devel@nongnu.org; Tue, 17 Mar 2015 07:51:18 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:40230) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YXq1g-0000sd-VT; Tue, 17 Mar 2015 07:51:14 -0400 Received: from 172.24.2.119 (EHLO szxeml432-hub.china.huawei.com) ([172.24.2.119]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BDG09349; Tue, 17 Mar 2015 19:28:53 +0800 (CST) Received: from localhost (10.177.19.102) by szxeml432-hub.china.huawei.com (10.82.67.209) with Microsoft SMTP Server id 14.3.158.1; Tue, 17 Mar 2015 19:28:42 +0800 From: To: Date: Tue, 17 Mar 2015 19:28:31 +0800 Message-ID: <1426591711-14472-1-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 1.7.3.1.msysgit.0 MIME-Version: 1.0 X-Originating-IP: [10.177.19.102] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020204.55081526.0121, ss=1, re=0.001, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 68bfd5aa499956659cc742aed209094d X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.66 Cc: qemu-stable , Gonglei , peter.huangpeng@huawei.com, kraxel@redhat.com Subject: [Qemu-devel] [PATCH] usb: fix segfault when hot-unplugging usb host adapter 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 From: Gonglei When hot-unplugging the usb controllers (ehci/uhci), we have to clean all resouce of these devices, involed registered reset handler. Otherwise, it may cause NULL pointer access and/or segmentation fault if we reboot the guest os after hot-unplugging. Cc: qemu-stable Reported-by: Lidonglin Signed-off-by: Gonglei --- hw/usb/hcd-ehci.c | 1 + hw/usb/hcd-ohci.c | 1 + hw/usb/hcd-uhci.c | 2 ++ 3 files changed, 4 insertions(+) diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c index ccf54b6..5be41f8 100644 --- a/hw/usb/hcd-ehci.c +++ b/hw/usb/hcd-ehci.c @@ -2495,6 +2495,7 @@ void usb_ehci_unrealize(EHCIState *s, DeviceState *dev, Error **errp) memory_region_del_subregion(&s->mem, &s->mem_opreg); memory_region_del_subregion(&s->mem, &s->mem_ports); + qemu_unregister_reset(ehci_reset, s); usb_bus_release(&s->bus); if (s->vmstate) { diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index a0d478e..840d254 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -1949,6 +1949,7 @@ static void usb_ohci_exit(PCIDevice *dev) if (!ohci->masterbus) { usb_bus_release(&s->bus); } + qemu_register_reset(ohci_reset, ohci); } #define TYPE_SYSBUS_OHCI "sysbus-ohci" diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c index f903de7..70ad52a 100644 --- a/hw/usb/hcd-uhci.c +++ b/hw/usb/hcd-uhci.c @@ -1274,6 +1274,8 @@ static void usb_uhci_exit(PCIDevice *dev) if (!s->masterbus) { usb_bus_release(&s->bus); } + + qemu_unregister_reset(uhci_reset, s); } static Property uhci_properties_companion[] = {