From patchwork Fri Feb 24 21:41:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Long Li X-Patchwork-Id: 9591267 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 1F5936020A for ; Fri, 24 Feb 2017 21:42:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E10F2623C for ; Fri, 24 Feb 2017 21:42:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F41DA285D6; Fri, 24 Feb 2017 21:42:02 +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 977AA2623C for ; Fri, 24 Feb 2017 21:42:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751334AbdBXVmB (ORCPT ); Fri, 24 Feb 2017 16:42:01 -0500 Received: from mail-by2nam01on0091.outbound.protection.outlook.com ([104.47.34.91]:14112 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751292AbdBXVmA (ORCPT ); Fri, 24 Feb 2017 16:42:00 -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=bgLd2TkoTpeEauoANMTteSdwF/yRFssfI0xASPZmlPM=; b=jGCbNIXOczvCK5VS7/jNL+1cQhJ7UIWSpM4RZtfZn+0EQ9ciQEANZRmYvIIXVh3Ck0wPCb7wmRV5/p9kBlyYEVueaN2xqyD0o3dGGNg1oL3W8ANhTzizmQ+D0A0LaG88UOWXMKH0b+v7zDfzeoqMOyy1gSzfjkVOGRFXxi8ElOc= Received: from BN3PR03MB2227.namprd03.prod.outlook.com (10.166.74.12) by BN3PR03MB1414.namprd03.prod.outlook.com (10.163.34.21) 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:41:57 +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:41:57 +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 1/2 v3] pci-hyperv: properly handle pci bus remove Thread-Topic: [Resend PATCH 1/2 v3] pci-hyperv: properly handle pci bus remove Thread-Index: AdKO5pQXEoycq7XxTx2Qpx96k/55ig== Date: Fri, 24 Feb 2017 21:41:57 +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: a3e6081b-fdaf-4968-511b-08d45cfdf550 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:BN3PR03MB1414; x-microsoft-exchange-diagnostics: 1; BN3PR03MB1414; 7:daCnAkyNXRIE6rW6yBl+in/xV62aso5z0QxqJGwairiHaPYULVKuLog8sfTL0ERl9Ikzd1noxoOHS/WSBktQfPNvSpDLrBXNIx00hH1ks+XVE4giXJq2oMrP3Ke0H2TRkvTK/ZlHIew7/btC848jf0YwDqcIX22ctbKNibGgI1Tqk03vAmc73CwzrSHOIE2wBzHj9W3Hncd6SqbVCXMpcTts6po52P0vhm13dKS7KbELiYL4Bsc6VSNORddduIeVfEYPxVTlJwY474VlG9CGYnPZGV+rTPnVuUbf5FZX0TL7GQ9kzvjXfsKm5p9y4zLPWBpCF3KjC5pXwA4A44yX3SUjVjM2UPs6wo8xdo8Xu4I= 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)(5005006)(8121501046)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041248)(20161123555025)(20161123560025)(20161123558025)(20161123562025)(20161123564025)(6072148)(6042181); SRVR:BN3PR03MB1414; BCL:0; PCL:0; RULEID:; SRVR:BN3PR03MB1414; x-forefront-prvs: 0228DDDDD7 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(7916002)(3660700001)(8936002)(8676002)(122556002)(77096006)(1511001)(81166006)(2421001)(6506006)(6436002)(3280700002)(38730400002)(2906002)(86612001)(55016002)(25786008)(54906002)(9686003)(99286003)(6116002)(102836003)(305945005)(8990500004)(7736002)(53936002)(50986999)(7696004)(10090500001)(74316002)(92566002)(4326007)(33656002)(5005710100001)(54356999)(10290500002)(5660300001)(189998001); DIR:OUT; SFP:1102; SCL:1; SRVR:BN3PR03MB1414; 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:41:57.5232 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR03MB1414 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 hv_pci_devices_present is called in hv_pci_remove when we remove a PCI device from host (e.g. by disabling SRIOV on a device). In hv_pci_remove, the bus is already removed before the call, so we don't need to rescan the bus in the workqueue scheduled from hv_pci_devices_present. By introducing status hv_pcibus_removed, we can avoid this situation. Signed-off-by: Long Li Reported-by: Xiaofeng Wang Acked-by: K. Y. Srinivasan --- drivers/pci/host/pci-hyperv.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c index a8deeca..4a37598 100644 --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c @@ -348,6 +348,7 @@ enum hv_pcibus_state { hv_pcibus_init = 0, hv_pcibus_probed, hv_pcibus_installed, + hv_pcibus_removed, hv_pcibus_maximum }; @@ -1481,13 +1482,24 @@ static void pci_devices_present_work(struct work_struct *work) put_pcichild(hpdev, hv_pcidev_ref_initial); } - /* Tell the core to rescan bus because there may have been changes. */ - if (hbus->state == hv_pcibus_installed) { + switch (hbus->state) { + case hv_pcibus_installed: + /* + * Tell the core to rescan bus + * because there may have been changes. + */ pci_lock_rescan_remove(); pci_scan_child_bus(hbus->pci_bus); pci_unlock_rescan_remove(); - } else { + break; + + case hv_pcibus_init: + case hv_pcibus_probed: survey_child_resources(hbus); + break; + + default: + break; } up(&hbus->enum_sem); @@ -2163,6 +2175,7 @@ static int hv_pci_probe(struct hv_device *hdev, hbus = kzalloc(sizeof(*hbus), GFP_KERNEL); if (!hbus) return -ENOMEM; + hbus->state = hv_pcibus_init; /* * The PCI bus "domain" is what is called "segment" in ACPI and @@ -2305,6 +2318,7 @@ static int hv_pci_remove(struct hv_device *hdev) pci_stop_root_bus(hbus->pci_bus); pci_remove_root_bus(hbus->pci_bus); pci_unlock_rescan_remove(); + hbus->state = hv_pcibus_removed; } ret = hv_send_resources_released(hdev);