From patchwork Fri Feb 24 21:49:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Long Li X-Patchwork-Id: 9591273 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 64EB76020A for ; Fri, 24 Feb 2017 21:49:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 580BB28714 for ; Fri, 24 Feb 2017 21:49:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4CE762895B; Fri, 24 Feb 2017 21:49:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C796B28714 for ; Fri, 24 Feb 2017 21:49:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751312AbdBXVtV (ORCPT ); Fri, 24 Feb 2017 16:49:21 -0500 Received: from mail-sn1nam01on0107.outbound.protection.outlook.com ([104.47.32.107]:19635 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751291AbdBXVtV (ORCPT ); Fri, 24 Feb 2017 16:49:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=v/5bUluUCOYwTWKxfgLp33zNAaFlDzQU1K7gtIyFn+w=; b=YKtVCZ7QCsI+MVtn2OvzWAdUyztx7eT31PQqog6krsJBcNDSzVUw11R86sq2BVkw+vK5ot2FSwT62l5U65IqhIDYI07U/DewpBGnwFPnxjmUpH02Xu93K1y2Vh7OxrLSCwIPDFsM9ovIEIahWnF6dtm4rnvVTxvoDs7LmZaKb+A= Received: from BN3PR03MB2227.namprd03.prod.outlook.com (10.166.74.12) by BN3PR03MB1413.namprd03.prod.outlook.com (10.163.34.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.933.12; Fri, 24 Feb 2017 21:49:18 +0000 Received: from BN3PR03MB2227.namprd03.prod.outlook.com ([10.166.74.12]) by BN3PR03MB2227.namprd03.prod.outlook.com ([10.166.74.12]) with mapi id 15.01.0933.016; Fri, 24 Feb 2017 21:49:17 +0000 From: Long Li To: KY Srinivasan , Haiyang Zhang , Bjorn Helgaas CC: "devel@linuxdriverproject.org" , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: [Resend PATCH 2/2 v3] pci-hyperv: lock pci bus on device eject Thread-Topic: [Resend PATCH 2/2 v3] pci-hyperv: lock pci bus on device eject Thread-Index: AdKO57eIDmoEjMKITgeRfMq0q38i5g== Date: Fri, 24 Feb 2017 21:49:17 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: microsoft.com; dkim=none (message not signed) header.d=none;microsoft.com; dmarc=none action=none header.from=microsoft.com; x-originating-ip: [2001:4898:80e8:8::735] x-ms-office365-filtering-correlation-id: 00bfdb79-0ef4-49d2-4a8a-08d45cfefbab x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:BN3PR03MB1413; x-microsoft-exchange-diagnostics: 1; BN3PR03MB1413; 7:06/OIeOfPXRL5NruMieW3f7P0TBHaYwy+u2vMsAlKqXjUvpED0BLvDsnPxw5RRZJcSg0zHNuqGRcm8pvpxrcrTCHIgDKHGxkT9k1RivS1cWUZJB18Jxo751c1ASoe6uScdk09JzYmie+TXgJHQLlj8GOCICLBC8YTkDPbJzz50KIsgRzO0xpdNqqFS9gaqv+C3eu4aw+CQrKOM7pCvGGDqDXJ6zEsm4uj0xru9Cicbv22r8t9X7Gqi/zTukWhLTEbkGWYV8HL1rB86wVOKthpxjDi0bIv3Ye2BxNUfRpaAXisg22hO994r25afgbUJX4raPTLyymQa+w97C5F59g8TlrnOTTx6LIHLZcemPeBsU= x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(61425038)(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026)(61426038)(61427038)(6041248)(20161123564025)(20161123562025)(20161123560025)(20161123558025)(20161123555025)(6072148)(6042181); SRVR:BN3PR03MB1413; BCL:0; PCL:0; RULEID:; SRVR:BN3PR03MB1413; x-forefront-prvs: 0228DDDDD7 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(7916002)(55016002)(99286003)(122556002)(81166006)(50986999)(54356999)(33656002)(8676002)(77096006)(6506006)(8990500004)(5005710100001)(5660300001)(3660700001)(10290500002)(53936002)(6116002)(102836003)(2421001)(2906002)(6436002)(25786008)(8936002)(86612001)(189998001)(3280700002)(7736002)(7696004)(54906002)(1511001)(74316002)(92566002)(305945005)(38730400002)(4326007)(10090500001)(9686003); DIR:OUT; SFP:1102; SCL:1; SRVR:BN3PR03MB1413; H:BN3PR03MB2227.namprd03.prod.outlook.com; FPR:; SPF:None; MLV:sfv; LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Feb 2017 21:49:17.7946 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR03MB1413 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A PCI_EJECT message can arrive at the same time we are calling pci_scan_child_bus in the workqueue for the previous PCI_BUS_RELATIONS message or in create_root_hv_pci_bus(), in this case we could potentailly modify the bus from multiple places. Properly lock the bus access. Thanks Dexuan Cui for pointing out the race condition in create_root_hv_pci_bus(). Signed-off-by: Long Li Reported-by: Xiaofeng Wang Acked-by: K. Y. Srinivasan --- drivers/pci/host/pci-hyperv.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c index 4a37598..33c75c9 100644 --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c @@ -1198,9 +1198,11 @@ static int create_root_hv_pci_bus(struct hv_pcibus_device *hbus) hbus->pci_bus->msi = &hbus->msi_chip; hbus->pci_bus->msi->dev = &hbus->hdev->device; + pci_lock_rescan_remove(); pci_scan_child_bus(hbus->pci_bus); pci_bus_assign_resources(hbus->pci_bus); pci_bus_add_devices(hbus->pci_bus); + pci_unlock_rescan_remove(); hbus->state = hv_pcibus_installed; return 0; } @@ -1590,8 +1592,10 @@ static void hv_eject_device_work(struct work_struct *work) pdev = pci_get_domain_bus_and_slot(hpdev->hbus->sysdata.domain, 0, wslot); if (pdev) { + pci_lock_rescan_remove(); pci_stop_and_remove_bus_device(pdev); pci_dev_put(pdev); + pci_unlock_rescan_remove(); } memset(&ctxt, 0, sizeof(ctxt));