From patchwork Thu May 16 15:50:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 244365 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id AE8202C0158 for ; Fri, 17 May 2013 01:53:33 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754742Ab3EPPvh (ORCPT ); Thu, 16 May 2013 11:51:37 -0400 Received: from mail-pb0-f51.google.com ([209.85.160.51]:51082 "EHLO mail-pb0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754704Ab3EPPvf (ORCPT ); Thu, 16 May 2013 11:51:35 -0400 Received: by mail-pb0-f51.google.com with SMTP id jt11so1382911pbb.38 for ; Thu, 16 May 2013 08:51:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=8iPiUQ1W7tSVAXeFIVhoTuxTM8eKTeNXTAUH5Ltlmqg=; b=v/1I4S5BkOHDPgN2A83vH8KFhLYxlDcYn3SLqs7E7YPY9BFfHypEh8R/u90IBmFec+ GO69lzqn856q4nVdq9jA3vcBCXPyuvN7pl1RuHlI/8wkSfrmrUKf7X3GouyLPTu0TGbp gx7PVaFjdX0RWMAUbedbGA/QbcILbVnTSDDttgg+e1fxIzqaWuZh4dO1OM9Um+z4pQhm rloVYg+ncrDtr9s/TBQFFvJQvQfizQ/oh1WPgIrinDnzuBDXzxGCnjsgJd2APlqByXYF oUKtts7QLRAH0Z8zrvszoFU8BCIws29lK0b1M2y5moGckEIU45fNGFvdD+P9iLr21RGq HpAg== X-Received: by 10.66.145.67 with SMTP id ss3mr44705088pab.18.1368719495231; Thu, 16 May 2013 08:51:35 -0700 (PDT) Received: from localhost.localdomain ([120.196.98.100]) by mx.google.com with ESMTPSA id ea15sm8026701pad.16.2013.05.16.08.51.31 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 16 May 2013 08:51:34 -0700 (PDT) From: Jiang Liu To: Bjorn Helgaas , Yinghai Lu Cc: Jiang Liu , "Rafael J . Wysocki" , Greg Kroah-Hartman , Gu Zheng , Toshi Kani , Myron Stowe , Yijing Wang , Jiang Liu , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v2, part3 05/11] PCI: enhance PCI core logic to support PCI bus lock Date: Thu, 16 May 2013 23:50:53 +0800 Message-Id: <1368719459-24800-6-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1368719459-24800-1-git-send-email-jiang.liu@huawei.com> References: <1368719459-24800-1-git-send-email-jiang.liu@huawei.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Every new PCI bus will be created with the PCI_BUS_STATE_LOCK bit set, so a typical PCI device hot-add flow is: pci_bus_lock(parent, PCI_BUS_STATE_STARTED, true); pci_scan_slot(parent, PCI_DEVFN(0, 0)); pci_bus_add_devices(parent); pci_bus_unlock(parent, true); // recursively unlock all PCI // buses, including new PCI buses This patch also changes behaviors of interfaces to create PCI root buses: pci_create_root_bus(): return with new PCI root bus locked pci_scan_bus_parented(): return with new PCI root bus locked pci_scan_root_bus(): return with new PCI root bus unlocked pci_scan_bus(): return with new PCI root bus unlocked pci_scan_bus_parented() has already been marked as __deprecated and all in-tree callers have been converted to use other interfaces. So following-on patches will enhance callers of pci_create_root_bus() to unlock returned root buses. Signed-off-by: Jiang Liu Cc: Yinghai Lu Cc: linux-pci@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/pci/hotplug-pci.c | 4 ++++ drivers/pci/probe.c | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/drivers/pci/hotplug-pci.c b/drivers/pci/hotplug-pci.c index 18533ed..8faa3c2 100644 --- a/drivers/pci/hotplug-pci.c +++ b/drivers/pci/hotplug-pci.c @@ -10,6 +10,10 @@ int __ref pci_hp_add_bridge(struct pci_dev *dev) int pass, busnr, start = parent->busn_res.start; int end = parent->busn_res.end; + BUG_ON(!pci_bus_is_locked(parent)); + if (pci_bus_get_state(parent) > PCI_BUS_STATE_STARTED) + return 0; + for (busnr = start; busnr <= end; busnr++) { if (!pci_bus_exists(pci_domain_nr(parent), busnr)) break; diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 9fcf3a3..0ddf5b8 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -745,6 +745,10 @@ int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, int pass) u8 primary, secondary, subordinate; int broken = 0; + BUG_ON(!pci_bus_is_locked(bus)); + if (pci_bus_get_state(bus) > PCI_BUS_STATE_STARTED) + return max; + pci_read_config_dword(dev, PCI_PRIMARY_BUS, &buses); primary = buses & 0xFF; secondary = (buses >> 8) & 0xFF; @@ -799,6 +803,8 @@ int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, int pass) pci_bus_insert_busn_res(child, secondary, subordinate); child->bridge_ctl = bctl; pci_bus_get(child); + } else { + BUG_ON(!pci_bus_is_locked(child)); } cmax = pci_scan_child_bus(child); @@ -837,6 +843,8 @@ int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, int pass) goto out; pci_bus_insert_busn_res(child, max, 0xff); pci_bus_get(child); + } else { + BUG_ON(!pci_bus_is_locked(child)); } buses = (buses & 0xff000000) | ((unsigned int)(child->primary) << 0) @@ -1322,6 +1330,7 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) { int ret; + BUG_ON(!pci_bus_is_locked(bus)); device_initialize(&dev->dev); dev->dev.release = pci_release_dev; @@ -1369,6 +1378,10 @@ struct pci_dev *__ref pci_scan_single_device(struct pci_bus *bus, int devfn) { struct pci_dev *dev; + BUG_ON(!pci_bus_is_locked(bus)); + if (pci_bus_get_state(bus) > PCI_BUS_STATE_STARTED) + return NULL; + dev = pci_get_slot(bus, devfn); if (dev) { pci_dev_put(dev); @@ -1624,6 +1637,8 @@ unsigned int pci_scan_child_bus(struct pci_bus *bus) unsigned int devfn, pass, max = bus->busn_res.start; struct pci_dev *dev; + BUG_ON(!pci_bus_is_locked(bus)); + BUG_ON(pci_bus_get_state(bus) > PCI_BUS_STATE_STARTED); dev_dbg(&bus->dev, "scanning bus\n"); /* Go find them, Rover! */ @@ -1872,6 +1887,8 @@ struct pci_bus *pci_scan_root_bus(struct device *parent, int bus, pci_bus_update_busn_res_end(b, max); pci_bus_add_devices(b); + pci_bus_unlock(b, true); + return b; } EXPORT_SYMBOL(pci_scan_root_bus); @@ -1908,6 +1925,7 @@ struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, if (b) { pci_scan_child_bus(b); pci_bus_add_devices(b); + pci_bus_unlock(b, true); } else { pci_free_resource_list(&resources); }