Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752425AbcJDEvl (ORCPT ); Tue, 4 Oct 2016 00:51:41 -0400 Received: from p3plsmtps2ded01.prod.phx3.secureserver.net ([208.109.80.58]:41514 "EHLO p3plsmtps2ded01.prod.phx3.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751223AbcJDEvj (ORCPT ); Tue, 4 Oct 2016 00:51:39 -0400 x-originating-ip: 72.167.245.219 From: Long Li To: "K. Y. Srinivasan" , Haiyang Zhang , Bjorn Helgaas Cc: devel@linuxdriverproject.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Long Li Subject: [PATCH 1/2 v3] pci-hyperv: properly handle pci bus remove Date: Mon, 3 Oct 2016 23:42:47 -0700 Message-Id: <1475563367-16511-1-git-send-email-longli@exchange.microsoft.com> X-Mailer: git-send-email 1.7.4.1 X-CMAE-Envelope: MS4wfOs6OaCyJZzc3VXWKKYUHrC4osSm/z5qSnv+q2hvxFY2mXyaqos135Z/aJNZTd56RlWhw0hpCD+GFBI8FhmTeR7d4L0XhC+xyUwH21HjMA+5qTQvYhfN T8T9bn9da9FIC0eeO741TXefHyfWUUiFHKsoC7Bc0GfvLR40RTOmq5CGOUeRWVo+JhVCkWQYJSMs4jBKVLbRasAlBB5sjPKdi6IEtYdWE5K9EpJqP+dGmLnW Ztf6lGBUPaSXzVl+2ZWxPmCGlCWTx3Sgi4TGfOmgB5P8DNGsjY+a3xmorHbtYAhMcBWoz6cAgMyj7O39M6n9IR/ugnzmTwRra51GoymVdQOoS4C3FsflvVSH Zz4JaiSWtv2h1CZcPvbdpzvDo1qYR3F2otDNN8d85r4GN1XvXE0= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2161 Lines: 69 From: Long Li 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 Tested-by: Cathy Avery Reported-by: Xiaofeng Wang --- 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); -- 1.8.5.6