From patchwork Thu Jun 23 11:42:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yijing Wang X-Patchwork-Id: 9194887 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 65AB26075C for ; Thu, 23 Jun 2016 11:35:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5740626C2F for ; Thu, 23 Jun 2016 11:35:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B78E28451; Thu, 23 Jun 2016 11:35:35 +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=-6.9 required=2.0 tests=BAYES_00,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 4DC742844E for ; Thu, 23 Jun 2016 11:35:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751425AbcFWLfX (ORCPT ); Thu, 23 Jun 2016 07:35:23 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:4762 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752242AbcFWLfV (ORCPT ); Thu, 23 Jun 2016 07:35:21 -0400 Received: from 172.24.1.136 (EHLO szxeml433-hub.china.huawei.com) ([172.24.1.136]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DJF64712; Thu, 23 Jun 2016 19:35:17 +0800 (CST) Received: from localhost.localdomain (10.175.100.166) by szxeml433-hub.china.huawei.com (10.82.67.210) with Microsoft SMTP Server id 14.3.235.1; Thu, 23 Jun 2016 19:35:06 +0800 From: Yijing Wang To: CC: , , , Yijing Wang Subject: [PATCH] PCI: release pci_host_bridge resource after remove root bus Date: Thu, 23 Jun 2016 19:42:18 +0800 Message-ID: <1466682138-25281-1-git-send-email-wangyijing@huawei.com> X-Mailer: git-send-email 1.7.1 MIME-Version: 1.0 X-Originating-IP: [10.175.100.166] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090206.576BC975.00BC, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 6440a88bd3d71823bf534bb8b0baf8bc Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP pci_host_bridge holds the top resources(IO port/Mem/bus), now we release pci_host_bridge resources in acpi_pci_root_release_info() which would be called when pci_host_bridge device refcount reach 0. In some cases, pci_host_bridge refcount cannot reach 0 after we remove pci root bus in pci_remove_root_bus(). Then if we want to hot add pci root bus, we cannot use pci_host_bridge resources because of conflicts with old resources which are still in system. I think this is not reasonable. 1. For pci devices, we would release their resources in pci_destroy_dev() regardless of pci device refcount. 2. When we try to remove pci root bus, there is no devices need to use the pci_host_bridge resources again, release pci_host_bridge resources is safe. 3. In some cases, users woule make mistake, for example, user get a pci device(increase refcount), but forget to put this device, then if we do hotplug pci root bus, it would make all pci devices cannot work after hot add. I found this issue in the following case: 1. I have a raid pci device in my system; 2. I mount a disk which connect to this raid. 3. hot remove the pci root bus. 4. hot add the pci root bus. 5. found the resource conflicts for the children pci devices under this root bus. pci_root_bus increase a refcount at pci_host_bridge. pci_root_bus decrease a refcount at pci_host_bridge in release_pcibus_dev() when pci_root_bus device refcount reach 0. pci_dev increase a refcount at pci_bus in pci_alloc_dev(). pci_dev decrease a refcount at pci_bus in pci_release_dev() when pci_dev refcount reach 0. If any pci device refcount cannot reach 0, then its pci_bus refcount cannot reach 0 too, the result is pci_host_bridge refcount cannot reach 0. Signed-off-by: Yijing Wang --- drivers/acpi/pci_root.c | 11 ----------- drivers/pci/host-bridge.c | 15 +++++++++++++++ drivers/pci/pci.h | 2 +- drivers/pci/remove.c | 1 + 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c index d144168..c5142d0 100644 --- a/drivers/acpi/pci_root.c +++ b/drivers/acpi/pci_root.c @@ -839,17 +839,6 @@ static void __acpi_pci_root_release_info(struct acpi_pci_root_info *info) static void acpi_pci_root_release_info(struct pci_host_bridge *bridge) { - struct resource *res; - struct resource_entry *entry; - - resource_list_for_each_entry(entry, &bridge->windows) { - res = entry->res; - if (res->flags & IORESOURCE_IO) - pci_unmap_iospace(res); - if (res->parent && - (res->flags & (IORESOURCE_MEM | IORESOURCE_IO))) - release_resource(res); - } __acpi_pci_root_release_info(bridge->release_data); } diff --git a/drivers/pci/host-bridge.c b/drivers/pci/host-bridge.c index 5f4a2e0..3594967 100644 --- a/drivers/pci/host-bridge.c +++ b/drivers/pci/host-bridge.c @@ -8,6 +8,21 @@ #include "pci.h" +void release_host_bridge_resources(struct pci_host_bridge *bridge) +{ + struct resource *res; + struct resource_entry *entry; + + resource_list_for_each_entry(entry, &bridge->windows) { + res = entry->res; + if (res->flags & IORESOURCE_IO) + pci_unmap_iospace(res); + if (res->parent && + (res->flags & (IORESOURCE_MEM | IORESOURCE_IO))) + release_resource(res); + } +} + static struct pci_bus *find_pci_root_bus(struct pci_bus *bus) { while (bus->parent) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 9730c47..46725d9 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -11,7 +11,7 @@ extern const unsigned char pcie_link_speed[]; bool pcie_cap_has_lnkctl(const struct pci_dev *dev); /* Functions internal to the PCI core code */ - +void release_host_bridge_resources(struct pci_host_bridge *bridge); int pci_create_sysfs_dev_files(struct pci_dev *pdev); void pci_remove_sysfs_dev_files(struct pci_dev *pdev); #if !defined(CONFIG_DMI) && !defined(CONFIG_ACPI) diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index d1ef7ac..a42b396 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -161,6 +161,7 @@ void pci_remove_root_bus(struct pci_bus *bus) pci_remove_bus(bus); host_bridge->bus = NULL; + release_host_bridge_resources(host_bridge); /* remove the host bridge */ device_unregister(&host_bridge->dev); }