linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiang Liu <liuj97@gmail.com>
To: Bjorn Helgaas <bhelgaas@google.com>,
	Don Dutile <ddutile@redhat.com>, Yinghai Lu <yinghai@kernel.org>,
	Greg KH <gregkh@linuxfoundation.org>,
	Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
Cc: Jiang Liu <jiang.liu@huawei.com>,
	Taku Izumi <izumi.taku@jp.fujitsu.com>,
	"Rafael J . Wysocki" <rjw@sisk.pl>,
	Yijing Wang <wangyijing@huawei.com>,
	Xinwei Hu <huxinwei@huawei.com>,
	linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
	Jiang Liu <liuj97@gmail.com>
Subject: [RFC PATCH v1 11/22] PCI: enhance PCI resource assignment logic to support PCI bus lock mechanism
Date: Wed,  8 Aug 2012 00:10:51 +0800	[thread overview]
Message-ID: <1344355862-2726-12-git-send-email-jiang.liu@huawei.com> (raw)
In-Reply-To: <1344355862-2726-1-git-send-email-jiang.liu@huawei.com>

This patch enhances PCI resource assignemnt logic to support PCI bus lock
mechanism.

Signed-off-by: Jiang Liu <liuj97@gmail.com>
---
 drivers/pci/setup-bus.c |   65 +++++++++++++++++++++++++++++++++++------------
 1 file changed, 49 insertions(+), 16 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 192172c..08bac37 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -47,6 +47,7 @@ static void free_list(struct list_head *head)
 
 	list_for_each_entry_safe(dev_res, tmp, head, list) {
 		list_del(&dev_res->list);
+		pci_dev_put(dev_res->dev);
 		kfree(dev_res);
 	}
 }
@@ -73,7 +74,7 @@ static int add_to_list(struct list_head *head,
 	}
 
 	tmp->res = res;
-	tmp->dev = dev;
+	tmp->dev = pci_dev_get(dev);
 	tmp->start = res->start;
 	tmp->end = res->end;
 	tmp->flags = res->flags;
@@ -93,6 +94,7 @@ static void remove_from_list(struct list_head *head,
 	list_for_each_entry_safe(dev_res, tmp, head, list) {
 		if (dev_res->res == res) {
 			list_del(&dev_res->list);
+			pci_dev_put(dev_res->dev);
 			kfree(dev_res);
 			break;
 		}
@@ -151,7 +153,7 @@ static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head)
 			panic("pdev_sort_resources(): "
 			      "kmalloc() failed!\n");
 		tmp->res = r;
-		tmp->dev = dev;
+		tmp->dev = pci_dev_get(dev);
 
 		/* fallback is smallest one or list is empty*/
 		n = head;
@@ -257,6 +259,7 @@ static void reassign_resources_sorted(struct list_head *realloc_head,
 		}
 out:
 		list_del(&add_res->list);
+		pci_dev_put(add_res->dev);
 		kfree(add_res);
 	}
 }
@@ -982,15 +985,16 @@ handle_done:
 	;
 }
 
-void __ref __pci_bus_size_bridges(struct pci_bus *bus,
+static void __ref __pci_bus_size_bridges(struct pci_bus *bus,
 			struct list_head *realloc_head)
 {
 	struct pci_dev *dev;
+	struct pci_bus *b;
 	unsigned long mask, prefmask;
 	resource_size_t additional_mem_size = 0, additional_io_size = 0;
 
 	list_for_each_entry(dev, &bus->devices, bus_list) {
-		struct pci_bus *b = dev->subordinate;
+		b = pci_lock_subordinate(dev, PCI_BUS_STATE_STOPPING - 1);
 		if (!b)
 			continue;
 
@@ -1004,6 +1008,8 @@ void __ref __pci_bus_size_bridges(struct pci_bus *bus,
 			__pci_bus_size_bridges(b, realloc_head);
 			break;
 		}
+
+		pci_bus_unlock(b);
 	}
 
 	/* The root bus? */
@@ -1063,7 +1069,7 @@ static void __ref __pci_bus_assign_resources(const struct pci_bus *bus,
 	pbus_assign_resources_sorted(bus, realloc_head, fail_head);
 
 	list_for_each_entry(dev, &bus->devices, bus_list) {
-		b = dev->subordinate;
+		b = pci_lock_subordinate(dev, PCI_BUS_STATE_STOPPING - 1);
 		if (!b)
 			continue;
 
@@ -1084,6 +1090,8 @@ static void __ref __pci_bus_assign_resources(const struct pci_bus *bus,
 				 "%04x:%02x\n", pci_domain_nr(b), b->number);
 			break;
 		}
+
+		pci_bus_unlock(b);
 	}
 }
 
@@ -1098,11 +1106,11 @@ static void __ref __pci_bridge_assign_resources(const struct pci_dev *bridge,
 					 struct list_head *fail_head)
 {
 	struct pci_bus *b;
+	struct pci_dev *dev = (struct pci_dev *)bridge;
 
-	pdev_assign_resources_sorted((struct pci_dev *)bridge,
-					 add_head, fail_head);
+	pdev_assign_resources_sorted(dev, add_head, fail_head);
 
-	b = bridge->subordinate;
+	b = pci_lock_subordinate(dev, PCI_BUS_STATE_STOPPING - 1);
 	if (!b)
 		return;
 
@@ -1122,7 +1130,10 @@ static void __ref __pci_bridge_assign_resources(const struct pci_dev *bridge,
 			 "%04x:%02x\n", pci_domain_nr(b), b->number);
 		break;
 	}
+
+	pci_bus_unlock(b);
 }
+
 static void pci_bridge_release_resources(struct pci_bus *bus,
 					  unsigned long type)
 {
@@ -1169,6 +1180,7 @@ enum release_type {
 	leaf_only,
 	whole_subtree,
 };
+
 /*
  * try to release pci bridge resources that is from leaf bridge,
  * so we can allocate big new one later
@@ -1190,9 +1202,14 @@ static void __ref pci_bus_release_bridge_resources(struct pci_bus *bus,
 		if ((dev->class >> 8) != PCI_CLASS_BRIDGE_PCI)
 			continue;
 
-		if (rel_type == whole_subtree)
+		if (rel_type != whole_subtree)
+			continue;
+
+		if (pci_bus_lock_states(b, PCI_BUS_STATE_STOPPING - 1) > 0) {
 			pci_bus_release_bridge_resources(b, type,
 						 whole_subtree);
+			pci_bus_unlock(b);
+		}
 	}
 
 	if (pci_is_root_bus(bus))
@@ -1253,6 +1270,7 @@ static int __init pci_bus_get_depth(struct pci_bus *bus)
 
 	return depth;
 }
+
 static int __init pci_get_max_depth(void)
 {
 	int depth = 0;
@@ -1285,6 +1303,7 @@ enum enable_type {
 };
 
 static enum enable_type pci_realloc_enable __initdata = undefined;
+
 void __init pci_realloc_get_opt(char *str)
 {
 	if (!strncmp(str, "off", 3))
@@ -1292,6 +1311,7 @@ void __init pci_realloc_get_opt(char *str)
 	else if (!strncmp(str, "on", 2))
 		pci_realloc_enable = user_enabled;
 }
+
 static bool __init pci_realloc_enabled(void)
 {
 	return pci_realloc_enable >= user_enabled;
@@ -1428,7 +1448,7 @@ enable_and_dump:
 
 void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
 {
-	struct pci_bus *parent = bridge->subordinate;
+	struct pci_bus *parent;
 	LIST_HEAD(add_list); /* list of resources that
 					want additional resources */
 	int tried_times = 0;
@@ -1438,6 +1458,10 @@ void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
 	unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
 				  IORESOURCE_PREFETCH;
 
+	parent = pci_lock_subordinate(bridge, PCI_BUS_STATE_STOPPING - 1);
+	if (!parent)
+		return;
+
 again:
 	__pci_bus_size_bridges(parent, &add_list);
 	__pci_bridge_assign_resources(bridge, &add_list, &fail_head);
@@ -1464,8 +1488,13 @@ again:
 		struct pci_bus *bus = fail_res->dev->bus;
 		unsigned long flags = fail_res->flags;
 
+		if (bus != parent && pci_bus_lock_states(bus,
+					PCI_BUS_STATE_STOPPING - 1) < 0)
+			continue;
 		pci_bus_release_bridge_resources(bus, flags & type_mask,
 						 whole_subtree);
+		if (bus != parent)
+			pci_bus_unlock(bus);
 	}
 	/* restore size and flags */
 	list_for_each_entry(fail_res, &fail_head, list) {
@@ -1485,6 +1514,7 @@ enable_all:
 	retval = pci_reenable_device(bridge);
 	pci_set_master(bridge);
 	pci_enable_bridges(parent);
+	pci_bus_unlock(parent);
 }
 EXPORT_SYMBOL_GPL(pci_assign_unassigned_bridge_resources);
 
@@ -1502,19 +1532,22 @@ unsigned int __ref pci_rescan_bus(struct pci_bus *bus)
 {
 	unsigned int max;
 	struct pci_dev *dev;
+	struct pci_bus *b;
 	LIST_HEAD(add_list); /* list of resources that
 					want additional resources */
 
 	max = pci_scan_child_bus(bus);
 
-	down_read(&pci_bus_sem);
 	list_for_each_entry(dev, &bus->devices, bus_list)
 		if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
-		    dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
-			if (dev->subordinate)
-				__pci_bus_size_bridges(dev->subordinate,
-							 &add_list);
-	up_read(&pci_bus_sem);
+		    dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
+			b = pci_lock_subordinate(dev,
+					PCI_BUS_STATE_STOPPING - 1);
+			if (b) {
+				__pci_bus_size_bridges(b, &add_list);
+				pci_bus_unlock(b);
+			}
+		}
 	__pci_bus_assign_resources(bus, &add_list, NULL);
 	BUG_ON(!list_empty(&add_list));
 
-- 
1.7.9.5


  parent reply	other threads:[~2012-08-07 16:20 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-07 16:10 [RFC PATCH v1 00/22] introduce PCI bus lock to serialize PCI hotplug operations Jiang Liu
2012-08-07 16:10 ` [RFC PATCH v1 01/22] PCI: use pci_get_domain_bus_and_slot() to avoid race conditions Jiang Liu
2012-09-11 22:00   ` Bjorn Helgaas
2012-09-12  8:37     ` Jiang Liu
2012-08-07 16:10 ` [RFC PATCH v1 02/22] PCI: trivial cleanups for drivers/pci/remove.c Jiang Liu
2012-09-11 22:03   ` Bjorn Helgaas
2012-09-12  8:50     ` Jiang Liu
2012-08-07 16:10 ` [RFC PATCH v1 03/22] PCI: change PCI device management code to better follow device model Jiang Liu
2012-09-11 22:03   ` Bjorn Helgaas
2012-08-07 16:10 ` [RFC PATCH v1 04/22] PCI: split PCI bus device registration into two stages Jiang Liu
2012-08-07 16:10 ` [RFC PATCH v1 05/22] PCI: introduce pci_bus_{get|put}() to manage PCI bus reference count Jiang Liu
2012-08-07 16:10 ` [RFC PATCH v1 06/22] PCI: use a global lock to serialize PCI root bridge hotplug operations Jiang Liu
2012-09-11 22:57   ` Bjorn Helgaas
2012-09-12 15:42     ` Jiang Liu
2012-09-12 16:51       ` Bjorn Helgaas
2012-09-17 15:51         ` Jiang Liu
2012-09-20 18:49         ` Paul E. McKenney
2012-08-07 16:10 ` [RFC PATCH v1 07/22] PCI: introduce PCI bus lock to serialize PCI " Jiang Liu
2012-09-11 23:24   ` Bjorn Helgaas
2012-08-07 16:10 ` [RFC PATCH v1 08/22] PCI: introduce hotplug safe search interfaces for PCI bus/device Jiang Liu
2012-08-07 16:10 ` [RFC PATCH v1 09/22] PCI: enhance PCI probe logic to support PCI bus lock mechanism Jiang Liu
2012-08-07 16:10 ` [RFC PATCH v1 10/22] PCI: enhance PCI bus specific " Jiang Liu
2012-08-07 16:10 ` Jiang Liu [this message]
2012-08-07 16:10 ` [RFC PATCH v1 12/22] PCI: enhance PCI remove " Jiang Liu
2012-08-07 16:10 ` [RFC PATCH v1 13/22] PCI: make each PCI device hold a reference to its parent PCI bus Jiang Liu
2012-08-07 16:10 ` [RFC PATCH v1 14/22] PCI/sysfs: use PCI bus lock to avoid race conditions Jiang Liu
2012-08-07 16:10 ` [RFC PATCH v1 15/22] PCI/eeepc: " Jiang Liu
2012-09-11 23:18   ` Bjorn Helgaas
2012-08-07 16:10 ` [RFC PATCH v1 16/22] PCI/asus-wmi: " Jiang Liu
2012-08-07 16:10 ` [RFC PATCH v1 17/22] PCI/pciehp: " Jiang Liu
2012-08-07 16:10 ` [RFC PATCH v1 18/22] PCI/acpiphp: " Jiang Liu
2012-08-07 16:10 ` [RFC PATCH v1 19/22] PCI/x86: enable PCI bus lock mechanism for x86 platforms Jiang Liu
2012-09-11 23:22   ` Bjorn Helgaas
2012-09-12  9:56     ` Jiang Liu
2012-08-07 16:11 ` [RFC PATCH v1 20/22] PCI/IA64: enable PCI bus lock mechanism for IA64 platforms Jiang Liu
2012-08-07 16:11 ` [RFC PATCH v1 21/22] PCI: cleanups for PCI bus lock implementation Jiang Liu
2012-09-11 23:21   ` Bjorn Helgaas
2012-09-12  8:58     ` Jiang Liu
2012-08-07 16:11 ` [RFC PATCH v1 22/22] PCI: unexport pci_root_buses Jiang Liu
2012-08-07 18:11 ` [RFC PATCH v1 00/22] introduce PCI bus lock to serialize PCI hotplug operations Don Dutile
2012-08-08 15:49   ` Jiang Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1344355862-2726-12-git-send-email-jiang.liu@huawei.com \
    --to=liuj97@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=ddutile@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=huxinwei@huawei.com \
    --cc=izumi.taku@jp.fujitsu.com \
    --cc=jiang.liu@huawei.com \
    --cc=kaneshige.kenji@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=rjw@sisk.pl \
    --cc=wangyijing@huawei.com \
    --cc=yinghai@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).