Skip to contentSkip to conversation

PCI: leak fixes, removable generic PCI host, assorted stuff

PATCH Applied Jan Kiszka 5 participants 25 messages Apr 30, 2018 – May 10, 2018

Subsystems (6)

v2 of 4 Applied Latest is v4 →

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

v2 cover PCI: leak fixes, removable generic PCI host, assorted stuff

Changes in v2:
- patch 1: commit message reworking as suggested by Lorenzo
- patch 3-6: split-up as suggested by Bjorn
- patch 8: new
- patch 10: select PCI_DOMAINS from PCI_HOST_GENERIC, rather than allowing manual choice, as suggested by Lorenzo

This primarily enables to unbind the generic PCI host controller without leaving lots of memory leaks behind. A previous proposal patch 5 was rejected because of those issues [1].

The fixes have been validated in the Jailhouse setup, where we add and remove a virtual PCI host controller on hypervisor activation/ deactivation, with the help of kmemleak.

Besides that, there is tiny PCI API cleanup at the beginning and support for manually enabled PCI domains at the end that enables the Jailhouse scenario.

Jan

[1] http://lkml.iu.edu/hypermail/linux/kernel/1606.3/00072.html

CC Jingoo Han <[email protected]>
CC Joao Pinto <[email protected]>
CC Lorenzo Pieralisi <[email protected]>
CC Will Deacon <[email protected]>

Jan Kiszka (10):
PCI: Make pci_get_new_domain_nr() static
PCI: Fix memory leak of devm_pci_alloc_host_bridge()
PCI: Factor out __of_pci_get_host_bridge_resources()
PCI: Add dev parameter to __of_pci_get_host_bridge_resources()
PCI: Replace pr_*() with dev_*() in
__of_pci_get_host_bridge_resources()
PCI: Introduce devm_of_pci_get_host_bridge_resources()
PCI: Convert of_pci_get_host_bridge_resources() users to devm variant
PCI: Deprecate of_pci_get_host_bridge_resources()
PCI: Add support for unbinding the generic PCI host controller
PCI: Enable PCI_DOMAINS along with generic PCI host controller

 drivers/pci/dwc/pcie-designware-host.c |   2 +-
 drivers/pci/host/Kconfig               |   1 +
 drivers/pci/host/pci-aardvark.c        |   5 +-
 drivers/pci/host/pci-ftpci100.c        |   4 +-
 drivers/pci/host/pci-host-common.c     |  13 ++++
 drivers/pci/host/pci-host-generic.c    |   1 +
 drivers/pci/host/pci-v3-semi.c         |   3 +-
 drivers/pci/host/pci-versatile.c       |   3 +-
 drivers/pci/host/pci-xgene.c           |   3 +-
 drivers/pci/host/pcie-altera.c         |   5 +-
 drivers/pci/host/pcie-iproc-platform.c |   4 +-
 drivers/pci/host/pcie-rcar.c           |   5 +-
 drivers/pci/host/pcie-rockchip.c       |   4 +-
 drivers/pci/host/pcie-xilinx-nwl.c     |   4 +-
 drivers/pci/host/pcie-xilinx.c         |   4 +-
 drivers/pci/of.c                       | 105 +++++++++++++++++++++------------
 drivers/pci/pci.c                      |   6 +-
 drivers/pci/probe.c                    |   4 +-
 include/linux/of_pci.h                 |  42 ++++++++++++-
 include/linux/pci-ecam.h               |   1 +
 include/linux/pci.h                    |   3 -
 21 files changed, 149 insertions(+), 73 deletions(-)
Signature · 1 line
2.13.6
author
#1 lore raw

PATCH v2 1/10 PCI: Make pci_get_new_domain_nr() static

From: Jan Kiszka <[email protected]>

The only user of pci_get_new_domain_nr() is of_pci_bus_find_domain_nr(). Since they are defined in the same compilation unit, pci_get_new_domain_nr() can be made static, which also simplifies preprocessor conditionals.

No functional change intended.

---
 drivers/pci/pci.c   | 6 ++----
 include/linux/pci.h | 3 ---
 2 files changed, 2 insertions(+), 7 deletions(-)
drivers/pci/pci.c +2 -4
index a04197ce767d..811d71e7ee05 100644
@@ -5702,15 +5702,14 @@ static void pci_no_domains(void)
 #endif
 }
 
-#ifdef CONFIG_PCI_DOMAINS
+#ifdef CONFIG_PCI_DOMAINS_GENERIC
 static atomic_t __domain_nr = ATOMIC_INIT(-1);
 
-int pci_get_new_domain_nr(void)
+static int pci_get_new_domain_nr(void)
 {
 	return atomic_inc_return(&__domain_nr);
 }
 
-#ifdef CONFIG_PCI_DOMAINS_GENERIC
 static int of_pci_bus_find_domain_nr(struct device *parent)
 {
 	static int use_dt_domains = -1;
@@ -5765,7 +5764,6 @@ int pci_bus_find_domain_nr(struct pci_bus *bus, struct device *parent)
 			       acpi_pci_bus_find_domain_nr(bus);
 }
 #endif
-#endif
 
 /**
  * pci_ext_cfg_avail - can we access extended PCI config space?
include/linux/pci.h +0 -3
index 73178a2fcee0..963232a6cd2e 100644
@@ -1510,12 +1510,10 @@ void pci_cfg_access_unlock(struct pci_dev *dev);
  */
 #ifdef CONFIG_PCI_DOMAINS
 extern int pci_domains_supported;
-int pci_get_new_domain_nr(void);
 #else
 enum { pci_domains_supported = 0 };
 static inline int pci_domain_nr(struct pci_bus *bus) { return 0; }
 static inline int pci_proc_domain(struct pci_bus *bus) { return 0; }
-static inline int pci_get_new_domain_nr(void) { return -ENOSYS; }
 #endif /* CONFIG_PCI_DOMAINS */
 
 /*
@@ -1670,7 +1668,6 @@ static inline struct pci_dev *pci_get_domain_bus_and_slot(int domain,
 
 static inline int pci_domain_nr(struct pci_bus *bus) { return 0; }
 static inline struct pci_dev *pci_dev_get(struct pci_dev *dev) { return NULL; }
-static inline int pci_get_new_domain_nr(void) { return -ENOSYS; }
 
 #define dev_is_pci(d) (false)
 #define dev_is_pf(d) (false)
Signature · 1 line
2.13.6
author
#2 lore raw

PATCH v2 2/10 PCI: Fix memory leak of devm_pci_alloc_host_bridge()

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

devm_pci_release_host_bridge_dev() failed to release the resource list.

Fixes 5c3f18cce083 ("PCI: Add devm_pci_alloc_host_bridge() interface")
---
 drivers/pci/probe.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pci/probe.c +3 -1
index ac91b6fd0bcd..eccf204c9160 100644
@@ -526,12 +526,14 @@ static void devm_pci_release_host_bridge_dev(struct device *dev)
 
 	if (bridge->release_fn)
 		bridge->release_fn(bridge);
+
+	pci_free_resource_list(&bridge->windows);
 }
 
 static void pci_release_host_bridge_dev(struct device *dev)
 {
 	devm_pci_release_host_bridge_dev(dev);
-	pci_free_host_bridge(to_pci_host_bridge(dev));
+	kfree(to_pci_host_bridge(dev));
 }
 
 struct pci_host_bridge *pci_alloc_host_bridge(size_t priv)
Signature · 1 line
2.13.6
author
#3 lore raw

PATCH v2 3/10 PCI: Factor out __of_pci_get_host_bridge_resources()

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

This will be needed for sharing the core logic between current of_pci_get_host_bridge_resources() and upcoming devm_of_pci_get_host_bridge_resources().

Already rename the dev parameter to dev_node in order to free the namespace for a real device parameter.

No functional changes.

---
 drivers/pci/of.c       | 63 ++++++++++++++++++++++++++++----------------------
 include/linux/of_pci.h |  4 ++--
 2 files changed, 38 insertions(+), 29 deletions(-)
drivers/pci/of.c +36 -27
index a28355c273ae..375de447a58e 100644
@@ -243,26 +243,8 @@ void of_pci_check_probe_only(void)
 EXPORT_SYMBOL_GPL(of_pci_check_probe_only);
 
 #if defined(CONFIG_OF_ADDRESS)
-/**
- * of_pci_get_host_bridge_resources - Parse PCI host bridge resources from DT
- * @dev: device node of the host bridge having the range property
- * @busno: bus number associated with the bridge root bus
- * @bus_max: maximum number of buses for this bridge
- * @resources: list where the range of resources will be added after DT parsing
- * @io_base: pointer to a variable that will contain on return the physical
- * address for the start of the I/O range. Can be NULL if the caller doesn't
- * expect I/O ranges to be present in the device tree.
- *
- * It is the caller's job to free the @resources list.
- *
- * This function will parse the "ranges" property of a PCI host bridge device
- * node and setup the resource mapping based on its content. It is expected
- * that the property conforms with the Power ePAPR document.
- *
- * It returns zero if the range parsing has been successful or a standard error
- * value if it failed.
- */
-int of_pci_get_host_bridge_resources(struct device_node *dev,
+static int __of_pci_get_host_bridge_resources(
+			struct device_node *dev_node,
 			unsigned char busno, unsigned char bus_max,
 			struct list_head *resources, resource_size_t *io_base)
 {
@@ -281,15 +263,15 @@ int of_pci_get_host_bridge_resources(struct device_node *dev,
 	if (!bus_range)
 		return -ENOMEM;
 
-	pr_info("host bridge %pOF ranges:\n", dev);
+	pr_info("host bridge %pOF ranges:\n", dev_node);
 
-	err = of_pci_parse_bus_range(dev, bus_range);
+	err = of_pci_parse_bus_range(dev_node, bus_range);
 	if (err) {
 		bus_range->start = busno;
 		bus_range->end = bus_max;
 		bus_range->flags = IORESOURCE_BUS;
 		pr_info("  No bus range found for %pOF, using %pR\n",
-			dev, bus_range);
+			dev_node, bus_range);
 	} else {
 		if (bus_range->end > bus_range->start + bus_max)
 			bus_range->end = bus_range->start + bus_max;
@@ -297,7 +279,7 @@ int of_pci_get_host_bridge_resources(struct device_node *dev,
 	pci_add_resource(resources, bus_range);
 
 	/* Check for ranges property */
-	err = of_pci_range_parser_init(&parser, dev);
+	err = of_pci_range_parser_init(&parser, dev_node);
 	if (err)
 		goto parse_failed;
 
@@ -327,7 +309,7 @@ int of_pci_get_host_bridge_resources(struct device_node *dev,
 			goto parse_failed;
 		}
 
-		err = of_pci_range_to_resource(&range, dev, res);
+		err = of_pci_range_to_resource(&range, dev_node, res);
 		if (err) {
 			kfree(res);
 			continue;
@@ -336,13 +318,13 @@ int of_pci_get_host_bridge_resources(struct device_node *dev,
 		if (resource_type(res) == IORESOURCE_IO) {
 			if (!io_base) {
 				pr_err("I/O range found for %pOF. Please provide an io_base pointer to save CPU base address\n",
-					dev);
+					dev_node);
 				err = -EINVAL;
 				goto conversion_failed;
 			}
 			if (*io_base != (resource_size_t)OF_BAD_ADDR)
 				pr_warn("More than one I/O resource converted for %pOF. CPU base address for old range lost!\n",
-					dev);
+					dev_node);
 			*io_base = range.cpu_addr;
 		}
 
@@ -359,6 +341,33 @@ int of_pci_get_host_bridge_resources(struct device_node *dev,
 	pci_free_resource_list(resources);
 	return err;
 }
+
+/**
+ * of_pci_get_host_bridge_resources() - Parse PCI host bridge resources from DT
+ * @dev_node: device node of the host bridge having the range property
+ * @busno: bus number associated with the bridge root bus
+ * @bus_max: maximum number of buses for this bridge
+ * @resources: list where the range of resources will be added after DT parsing
+ * @io_base: pointer to a variable that will contain on return the physical
+ * address for the start of the I/O range. Can be NULL if the caller doesn't
+ * expect I/O ranges to be present in the device tree.
+ *
+ * It is the caller's job to free the @resources list.
+ *
+ * This function will parse the "ranges" property of a PCI host bridge device
+ * node and setup the resource mapping based on its content. It is expected
+ * that the property conforms with the Power ePAPR document.
+ *
+ * It returns zero if the range parsing has been successful or a standard error
+ * value if it failed.
+ */
+int of_pci_get_host_bridge_resources(struct device_node *dev_node,
+			unsigned char busno, unsigned char bus_max,
+			struct list_head *resources, resource_size_t *io_base)
+{
+	return __of_pci_get_host_bridge_resources(dev_node, busno,
+						  bus_max, resources, io_base);
+}
 EXPORT_SYMBOL_GPL(of_pci_get_host_bridge_resources);
 #endif /* CONFIG_OF_ADDRESS */
 
include/linux/of_pci.h +2 -2
index 091033a6b836..74eec1943ad2 100644
@@ -71,11 +71,11 @@ of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin)
 #endif
 
 #if defined(CONFIG_OF_ADDRESS)
-int of_pci_get_host_bridge_resources(struct device_node *dev,
+int of_pci_get_host_bridge_resources(struct device_node *dev_node,
 			unsigned char busno, unsigned char bus_max,
 			struct list_head *resources, resource_size_t *io_base);
 #else
-static inline int of_pci_get_host_bridge_resources(struct device_node *dev,
+static inline int of_pci_get_host_bridge_resources(struct device_node *dev_node,
 			unsigned char busno, unsigned char bus_max,
 			struct list_head *resources, resource_size_t *io_base)
 {
Signature · 1 line
2.13.6
author
#5 lore raw

PATCH v2 4/10 PCI: Add dev parameter to __of_pci_get_host_bridge_resources()

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

When non-NULL, use the new dev parameter of __of_pci_get_host_bridge_resources() to allocate the resource data structures via devm_kzalloc. That allows to release them automatically during device destruction.

---
 drivers/pci/of.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/pci/of.c +11 -4
index 375de447a58e..bfa282b538d5 100644
@@ -243,7 +243,7 @@ void of_pci_check_probe_only(void)
 EXPORT_SYMBOL_GPL(of_pci_check_probe_only);
 
 #if defined(CONFIG_OF_ADDRESS)
-static int __of_pci_get_host_bridge_resources(
+static int __of_pci_get_host_bridge_resources(struct device *dev,
 			struct device_node *dev_node,
 			unsigned char busno, unsigned char bus_max,
 			struct list_head *resources, resource_size_t *io_base)
@@ -259,7 +259,10 @@ static int __of_pci_get_host_bridge_resources(
 	if (io_base)
 		*io_base = (resource_size_t)OF_BAD_ADDR;
 
-	bus_range = kzalloc(sizeof(*bus_range), GFP_KERNEL);
+	if (dev)
+		bus_range = devm_kzalloc(dev,sizeof(*bus_range), GFP_KERNEL);
+	else
+		bus_range = kzalloc(sizeof(*bus_range), GFP_KERNEL);
 	if (!bus_range)
 		return -ENOMEM;
 
@@ -303,7 +306,11 @@ static int __of_pci_get_host_bridge_resources(
 		if (range.cpu_addr == OF_BAD_ADDR || range.size == 0)
 			continue;
 
-		res = kzalloc(sizeof(struct resource), GFP_KERNEL);
+		if (dev)
+			res = devm_kzalloc(dev, sizeof(struct resource),
+					   GFP_KERNEL);
+		else
+			res = kzalloc(sizeof(struct resource), GFP_KERNEL);
 		if (!res) {
 			err = -ENOMEM;
 			goto parse_failed;
@@ -365,7 +372,7 @@ int of_pci_get_host_bridge_resources(struct device_node *dev_node,
 			unsigned char busno, unsigned char bus_max,
 			struct list_head *resources, resource_size_t *io_base)
 {
-	return __of_pci_get_host_bridge_resources(dev_node, busno,
+	return __of_pci_get_host_bridge_resources(NULL, dev_node, busno,
 						  bus_max, resources, io_base);
 }
 EXPORT_SYMBOL_GPL(of_pci_get_host_bridge_resources);
Signature · 1 line
2.13.6
author
#7 lore raw

PATCH v2 5/10 PCI: Replace pr_*() with dev_*() in __of_pci_get_host_bridge_resources()

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

Now that we have a device reference, make use of it for printing. And as long as dev can still be NULL, we will still get some reasonable output nevertheless.

---
 drivers/pci/of.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/pci/of.c +12 -10
index bfa282b538d5..8f6cbf13e18d 100644
@@ -266,15 +266,15 @@ static int __of_pci_get_host_bridge_resources(struct device *dev,
 	if (!bus_range)
 		return -ENOMEM;
 
-	pr_info("host bridge %pOF ranges:\n", dev_node);
+	dev_info(dev, "host bridge %pOF ranges:\n", dev_node);
 
 	err = of_pci_parse_bus_range(dev_node, bus_range);
 	if (err) {
 		bus_range->start = busno;
 		bus_range->end = bus_max;
 		bus_range->flags = IORESOURCE_BUS;
-		pr_info("  No bus range found for %pOF, using %pR\n",
-			dev_node, bus_range);
+		dev_info(dev, "  No bus range found for %pOF, using %pR\n",
+			 dev_node, bus_range);
 	} else {
 		if (bus_range->end > bus_range->start + bus_max)
 			bus_range->end = bus_range->start + bus_max;
@@ -286,7 +286,7 @@ static int __of_pci_get_host_bridge_resources(struct device *dev,
 	if (err)
 		goto parse_failed;
 
-	pr_debug("Parsing ranges property...\n");
+	dev_dbg(dev, "Parsing ranges property...\n");
 	for_each_of_pci_range(&parser, &range) {
 		/* Read next ranges element */
 		if ((range.flags & IORESOURCE_TYPE_BITS) == IORESOURCE_IO)
@@ -295,9 +295,9 @@ static int __of_pci_get_host_bridge_resources(struct device *dev,
 			snprintf(range_type, 4, "MEM");
 		else
 			snprintf(range_type, 4, "err");
-		pr_info("  %s %#010llx..%#010llx -> %#010llx\n", range_type,
-			range.cpu_addr, range.cpu_addr + range.size - 1,
-			range.pci_addr);
+		dev_info(dev, "  %s %#010llx..%#010llx -> %#010llx\n",
+			 range_type, range.cpu_addr,
+			 range.cpu_addr + range.size - 1, range.pci_addr);
 
 		/*
 		 * If we failed translation or got a zero-sized region
@@ -324,14 +324,16 @@ static int __of_pci_get_host_bridge_resources(struct device *dev,
 
 		if (resource_type(res) == IORESOURCE_IO) {
 			if (!io_base) {
-				pr_err("I/O range found for %pOF. Please provide an io_base pointer to save CPU base address\n",
+				dev_err(dev,
+					"I/O range found for %pOF. Please provide an io_base pointer to save CPU base address\n",
 					dev_node);
 				err = -EINVAL;
 				goto conversion_failed;
 			}
 			if (*io_base != (resource_size_t)OF_BAD_ADDR)
-				pr_warn("More than one I/O resource converted for %pOF. CPU base address for old range lost!\n",
-					dev_node);
+				dev_warn(dev,
+					 "More than one I/O resource converted for %pOF. CPU base address for old range lost!\n",
+					 dev_node);
 			*io_base = range.cpu_addr;
 		}
 
Signature · 1 line
2.13.6
author
#9 lore raw

PATCH v2 6/10 PCI: Introduce devm_of_pci_get_host_bridge_resources()

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

of_pci_get_host_bridge_resources() allocates the resource structures it fills dynamically, but none of its callers care to release them so far. Rather than requiring everyone to do this explicitly, introduce a managed version of that service. This differs API-wise only in taking a reference to the associated device, rather than to the device tree node.

As of_pci_get_host_bridge_resources() is an exported interface, we cannot simply drop it at this point. After converting all in-tree users to the new API, we will phase out the unmanaged one.

---
 drivers/pci/of.c       | 28 ++++++++++++++++++++++++++++
 include/linux/of_pci.h | 10 ++++++++++
 2 files changed, 38 insertions(+)
drivers/pci/of.c +28 -0
index 8f6cbf13e18d..f16b343d3b85 100644
@@ -378,6 +378,34 @@ int of_pci_get_host_bridge_resources(struct device_node *dev_node,
 						  bus_max, resources, io_base);
 }
 EXPORT_SYMBOL_GPL(of_pci_get_host_bridge_resources);
+
+/**
+ * of_pci_get_host_bridge_resources() - Resource-managed parsing of PCI host
+ *                                      bridge resources from DT
+ * @dev: host bridge device
+ * @busno: bus number associated with the bridge root bus
+ * @bus_max: maximum number of buses for this bridge
+ * @resources: list where the range of resources will be added after DT parsing
+ * @io_base: pointer to a variable that will contain on return the physical
+ * address for the start of the I/O range. Can be NULL if the caller doesn't
+ * expect I/O ranges to be present in the device tree.
+ *
+ * This function will parse the "ranges" property of a PCI host bridge device
+ * node and setup the resource mapping based on its content. It is expected
+ * that the property conforms with the Power ePAPR document.
+ *
+ * It returns zero if the range parsing has been successful or a standard error
+ * value if it failed.
+ */
+int devm_of_pci_get_host_bridge_resources(struct device *dev,
+			unsigned char busno, unsigned char bus_max,
+			struct list_head *resources, resource_size_t *io_base)
+{
+	return __of_pci_get_host_bridge_resources(dev, dev->of_node, busno,
+						  bus_max, resources, io_base);
+}
+EXPORT_SYMBOL_GPL(devm_of_pci_get_host_bridge_resources);
+
 #endif /* CONFIG_OF_ADDRESS */
 
 /**
include/linux/of_pci.h +10 -0
index 74eec1943ad2..08b8f02426a5 100644
@@ -74,6 +74,9 @@ of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin)
 int of_pci_get_host_bridge_resources(struct device_node *dev_node,
 			unsigned char busno, unsigned char bus_max,
 			struct list_head *resources, resource_size_t *io_base);
+int devm_of_pci_get_host_bridge_resources(struct device *dev,
+			unsigned char busno, unsigned char bus_max,
+			struct list_head *resources, resource_size_t *io_base);
 #else
 static inline int of_pci_get_host_bridge_resources(struct device_node *dev_node,
 			unsigned char busno, unsigned char bus_max,
@@ -81,6 +84,13 @@ static inline int of_pci_get_host_bridge_resources(struct device_node *dev_node,
 {
 	return -EINVAL;
 }
+
+static inline int devm_of_pci_get_host_bridge_resources(struct device *dev,
+			unsigned char busno, unsigned char bus_max,
+			struct list_head *resources, resource_size_t *io_base)
+{
+	return -EINVAL;
+}
 #endif
 
 #endif
Signature · 1 line
2.13.6
author
#11 lore raw

PATCH v2 7/10 PCI: Convert of_pci_get_host_bridge_resources() users to devm variant

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

Straightforward for all of them, no more leaks afterwards.

CC Jingoo Han <[email protected]>
CC Joao Pinto <[email protected]>
CC Lorenzo Pieralisi <[email protected]>
---
 drivers/pci/dwc/pcie-designware-host.c | 2 +-
 drivers/pci/host/pci-aardvark.c        | 5 ++---
 drivers/pci/host/pci-ftpci100.c        | 4 ++--
 drivers/pci/host/pci-v3-semi.c         | 3 ++-
 drivers/pci/host/pci-versatile.c       | 3 +--
 drivers/pci/host/pci-xgene.c           | 3 ++-
 drivers/pci/host/pcie-altera.c         | 5 ++---
 drivers/pci/host/pcie-iproc-platform.c | 4 ++--
 drivers/pci/host/pcie-rcar.c           | 5 ++---
 drivers/pci/host/pcie-rockchip.c       | 4 ++--
 drivers/pci/host/pcie-xilinx-nwl.c     | 4 ++--
 drivers/pci/host/pcie-xilinx.c         | 4 ++--
 drivers/pci/of.c                       | 4 ++--
 13 files changed, 24 insertions(+), 26 deletions(-)
drivers/pci/dwc/pcie-designware-host.c +1 -1
index 6c409079d514..a8f6ab54b4c0 100644
@@ -342,7 +342,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 	if (!bridge)
 		return -ENOMEM;
 
-	ret = of_pci_get_host_bridge_resources(np, 0, 0xff,
+	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
 					&bridge->windows, &pp->io_base);
 	if (ret)
 		return ret;
drivers/pci/host/pci-aardvark.c +2 -3
index 9abf549631b4..1e048dd806dc 100644
@@ -822,14 +822,13 @@ static int advk_pcie_parse_request_of_pci_ranges(struct advk_pcie *pcie)
 {
 	int err, res_valid = 0;
 	struct device *dev = &pcie->pdev->dev;
-	struct device_node *np = dev->of_node;
 	struct resource_entry *win, *tmp;
 	resource_size_t iobase;
 
 	INIT_LIST_HEAD(&pcie->resources);
 
-	err = of_pci_get_host_bridge_resources(np, 0, 0xff, &pcie->resources,
-					       &iobase);
+	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
+						    &pcie->resources, &iobase);
 	if (err)
 		return err;
 
drivers/pci/host/pci-ftpci100.c +2 -2
index 5008fd87956a..87748eaeaaed 100644
@@ -476,8 +476,8 @@ static int faraday_pci_probe(struct platform_device *pdev)
 	if (IS_ERR(p->base))
 		return PTR_ERR(p->base);
 
-	ret = of_pci_get_host_bridge_resources(dev->of_node, 0, 0xff,
-					       &res, &io_base);
+	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
+						    &res, &io_base);
 	if (ret)
 		return ret;
 
drivers/pci/host/pci-v3-semi.c +2 -1
index 0a4dea796663..167bf6f6b378 100644
@@ -791,7 +791,8 @@ static int v3_pci_probe(struct platform_device *pdev)
 	if (IS_ERR(v3->config_base))
 		return PTR_ERR(v3->config_base);
 
-	ret = of_pci_get_host_bridge_resources(np, 0, 0xff, &res, &io_base);
+	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
+						    &io_base);
 	if (ret)
 		return ret;
 
drivers/pci/host/pci-versatile.c +1 -2
index 5b3876f5312b..ff2cd12b3978 100644
@@ -64,11 +64,10 @@ static int versatile_pci_parse_request_of_pci_ranges(struct device *dev,
 						     struct list_head *res)
 {
 	int err, mem = 1, res_valid = 0;
-	struct device_node *np = dev->of_node;
 	resource_size_t iobase;
 	struct resource_entry *win, *tmp;
 
-	err = of_pci_get_host_bridge_resources(np, 0, 0xff, res, &iobase);
+	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, res, &iobase);
 	if (err)
 		return err;
 
drivers/pci/host/pci-xgene.c +2 -1
index 0a0d7ee6d3c9..7b3ed6e34b6c 100644
@@ -632,7 +632,8 @@ static int xgene_pcie_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	ret = of_pci_get_host_bridge_resources(dn, 0, 0xff, &res, &iobase);
+	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
+						    &iobase);
 	if (ret)
 		return ret;
 
drivers/pci/host/pcie-altera.c +2 -3
index a6af62e0256d..49410c7ba0cc 100644
@@ -488,11 +488,10 @@ static int altera_pcie_parse_request_of_pci_ranges(struct altera_pcie *pcie)
 {
 	int err, res_valid = 0;
 	struct device *dev = &pcie->pdev->dev;
-	struct device_node *np = dev->of_node;
 	struct resource_entry *win;
 
-	err = of_pci_get_host_bridge_resources(np, 0, 0xff, &pcie->resources,
-					       NULL);
+	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff
+						    &pcie->resources, NULL);
 	if (err)
 		return err;
 
drivers/pci/host/pcie-iproc-platform.c +2 -2
index e764a2a2693c..99c2022813e4 100644
@@ -99,8 +99,8 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
 		pcie->phy = NULL;
 	}
 
-	ret = of_pci_get_host_bridge_resources(np, 0, 0xff, &resources,
-					       &iobase);
+	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &resources,
+						    &iobase);
 	if (ret) {
 		dev_err(dev, "unable to get PCI host bridge resources\n");
 		return ret;
drivers/pci/host/pcie-rcar.c +2 -3
index 6ab28f29ac6a..6eb36c924983 100644
@@ -1067,12 +1067,11 @@ static int rcar_pcie_parse_request_of_pci_ranges(struct rcar_pcie *pci)
 {
 	int err;
 	struct device *dev = pci->dev;
-	struct device_node *np = dev->of_node;
 	resource_size_t iobase;
 	struct resource_entry *win, *tmp;
 
-	err = of_pci_get_host_bridge_resources(np, 0, 0xff, &pci->resources,
-					       &iobase);
+	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
+						    &pci->resources, &iobase);
 	if (err)
 		return err;
 
drivers/pci/host/pcie-rockchip.c +2 -2
index f1e8f97ea1fb..27b97fcddf15 100644
@@ -1560,8 +1560,8 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
 	if (err < 0)
 		goto err_deinit_port;
 
-	err = of_pci_get_host_bridge_resources(dev->of_node, 0, 0xff,
-					       &res, &io_base);
+	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
+						    &res, &io_base);
 	if (err)
 		goto err_remove_irq_domain;
 
drivers/pci/host/pcie-xilinx-nwl.c +2 -2
index 4839ae578711..64df768c795c 100644
@@ -825,7 +825,6 @@ static const struct of_device_id nwl_pcie_of_match[] = {
 static int nwl_pcie_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	struct device_node *node = dev->of_node;
 	struct nwl_pcie *pcie;
 	struct pci_bus *bus;
 	struct pci_bus *child;
@@ -855,7 +854,8 @@ static int nwl_pcie_probe(struct platform_device *pdev)
 		return err;
 	}
 
-	err = of_pci_get_host_bridge_resources(node, 0, 0xff, &res, &iobase);
+	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
+						    &iobase);
 	if (err) {
 		dev_err(dev, "Getting bridge resources failed\n");
 		return err;
drivers/pci/host/pcie-xilinx.c +2 -2
index 0ad188effc09..88c96e5669e0 100644
@@ -643,8 +643,8 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
 		return err;
 	}
 
-	err = of_pci_get_host_bridge_resources(dev->of_node, 0, 0xff, &res,
-					       &iobase);
+	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
+						    &iobase);
 	if (err) {
 		dev_err(dev, "Getting bridge resources failed\n");
 		return err;
drivers/pci/of.c +2 -2
index f16b343d3b85..5a88d46a41b7 100644
@@ -645,12 +645,12 @@ int pci_parse_request_of_pci_ranges(struct device *dev,
 				    struct resource **bus_range)
 {
 	int err, res_valid = 0;
-	struct device_node *np = dev->of_node;
 	resource_size_t iobase;
 	struct resource_entry *win, *tmp;
 
 	INIT_LIST_HEAD(resources);
-	err = of_pci_get_host_bridge_resources(np, 0, 0xff, resources, &iobase);
+	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, resources,
+						    &iobase);
 	if (err)
 		return err;
 
Signature · 1 line
2.13.6
author
#15 lore raw

PATCH v2 8/10 PCI: Deprecate of_pci_get_host_bridge_resources()

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

There are no in-tree users remaining, all are converted to the managed variant. And it is unlikely that any out-of-tree user got the resource management right as well. So deprecate the interface and push users to the managed version instead.

To avoid raising a warning when exporting a deprecated symbol, wrap the API with an inline and export an internal name.

---
 drivers/pci/of.c       | 23 ++---------------------
 include/linux/of_pci.h | 36 ++++++++++++++++++++++++++++++++----
 2 files changed, 34 insertions(+), 25 deletions(-)
drivers/pci/of.c +2 -21
index 5a88d46a41b7..ccf8c7544e10 100644
@@ -351,33 +351,14 @@ static int __of_pci_get_host_bridge_resources(struct device *dev,
 	return err;
 }
 
-/**
- * of_pci_get_host_bridge_resources() - Parse PCI host bridge resources from DT
- * @dev_node: device node of the host bridge having the range property
- * @busno: bus number associated with the bridge root bus
- * @bus_max: maximum number of buses for this bridge
- * @resources: list where the range of resources will be added after DT parsing
- * @io_base: pointer to a variable that will contain on return the physical
- * address for the start of the I/O range. Can be NULL if the caller doesn't
- * expect I/O ranges to be present in the device tree.
- *
- * It is the caller's job to free the @resources list.
- *
- * This function will parse the "ranges" property of a PCI host bridge device
- * node and setup the resource mapping based on its content. It is expected
- * that the property conforms with the Power ePAPR document.
- *
- * It returns zero if the range parsing has been successful or a standard error
- * value if it failed.
- */
-int of_pci_get_host_bridge_resources(struct device_node *dev_node,
+int __of_pci_get_host_bridge_resources_deprecated(struct device_node *dev_node,
 			unsigned char busno, unsigned char bus_max,
 			struct list_head *resources, resource_size_t *io_base)
 {
 	return __of_pci_get_host_bridge_resources(NULL, dev_node, busno,
 						  bus_max, resources, io_base);
 }
-EXPORT_SYMBOL_GPL(of_pci_get_host_bridge_resources);
+EXPORT_SYMBOL_GPL(__of_pci_get_host_bridge_resources_deprecated);
 
 /**
  * of_pci_get_host_bridge_resources() - Resource-managed parsing of PCI host
include/linux/of_pci.h +32 -4
index 08b8f02426a5..c6408bd6f862 100644
@@ -71,26 +71,54 @@ of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin)
 #endif
 
 #if defined(CONFIG_OF_ADDRESS)
-int of_pci_get_host_bridge_resources(struct device_node *dev_node,
+int __of_pci_get_host_bridge_resources_deprecated(struct device_node *dev_node,
 			unsigned char busno, unsigned char bus_max,
 			struct list_head *resources, resource_size_t *io_base);
 int devm_of_pci_get_host_bridge_resources(struct device *dev,
 			unsigned char busno, unsigned char bus_max,
 			struct list_head *resources, resource_size_t *io_base);
 #else
-static inline int of_pci_get_host_bridge_resources(struct device_node *dev_node,
+static inline int devm_of_pci_get_host_bridge_resources(struct device *dev,
 			unsigned char busno, unsigned char bus_max,
 			struct list_head *resources, resource_size_t *io_base)
 {
 	return -EINVAL;
 }
+#endif
 
-static inline int devm_of_pci_get_host_bridge_resources(struct device *dev,
+/**
+ * of_pci_get_host_bridge_resources() - Parse PCI host bridge resources from DT
+ * @dev_node: device node of the host bridge having the range property
+ * @busno: bus number associated with the bridge root bus
+ * @bus_max: maximum number of buses for this bridge
+ * @resources: list where the range of resources will be added after DT parsing
+ * @io_base: pointer to a variable that will contain on return the physical
+ * address for the start of the I/O range. Can be NULL if the caller doesn't
+ * expect I/O ranges to be present in the device tree.
+ *
+ * It is the caller's job to free the @resources list.
+ *
+ * This function will parse the "ranges" property of a PCI host bridge device
+ * node and setup the resource mapping based on its content. It is expected
+ * that the property conforms with the Power ePAPR document.
+ *
+ * It returns zero if the range parsing has been successful or a standard error
+ * value if it failed.
+ *
+ * Note: This function is deprecated and will eventually be removed. Use
+ * devm_of_pci_get_host_bridge_resources() instead.
+ */
+static inline int __deprecated of_pci_get_host_bridge_resources(
+			struct device_node *dev_node,
 			unsigned char busno, unsigned char bus_max,
 			struct list_head *resources, resource_size_t *io_base)
 {
+#if defined(CONFIG_OF_ADDRESS)
+	return __of_pci_get_host_bridge_resources_deprecated(dev_node, busno,
+			bus_max, resources, io_base);
+#else
 	return -EINVAL;
-}
 #endif
+}
 
 #endif
Signature · 1 line
2.13.6
author
#20 lore raw

PATCH v2 9/10 PCI: Add support for unbinding the generic PCI host controller

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

Particularly useful when working in virtual environments where the controller may come and go, but possibly not only there.

CC Will Deacon <[email protected]>
CC Lorenzo Pieralisi <[email protected]>
---
 drivers/pci/host/pci-host-common.c  | 13 +++++++++++++
 drivers/pci/host/pci-host-generic.c |  1 +
 include/linux/pci-ecam.h            |  1 +
 3 files changed, 15 insertions(+)
drivers/pci/host/pci-host-common.c +13 -0
index 5d028f53fdcd..d8f10451f273 100644
@@ -101,5 +101,18 @@ int pci_host_common_probe(struct platform_device *pdev,
 		return ret;
 	}
 
+	platform_set_drvdata(pdev, bridge->bus);
+	return 0;
+}
+
+int pci_host_common_remove(struct platform_device *pdev)
+{
+	struct pci_bus *bus = platform_get_drvdata(pdev);
+
+	pci_lock_rescan_remove();
+	pci_stop_root_bus(bus);
+	pci_remove_root_bus(bus);
+	pci_unlock_rescan_remove();
+
 	return 0;
 }
drivers/pci/host/pci-host-generic.c +1 -0
index 45319ee3b484..dea3ec7592a2 100644
@@ -95,5 +95,6 @@ static struct platform_driver gen_pci_driver = {
 		.suppress_bind_attrs = true,
 	},
 	.probe = gen_pci_probe,
+	.remove = pci_host_common_remove,
 };
 builtin_platform_driver(gen_pci_driver);
include/linux/pci-ecam.h +1 -0
index baadad1aabbc..29efa09d686b 100644
@@ -62,5 +62,6 @@ extern struct pci_ecam_ops xgene_v2_pcie_ecam_ops; /* APM X-Gene PCIe v2.x */
 /* for DT-based PCI controllers that support ECAM */
 int pci_host_common_probe(struct platform_device *pdev,
 			  struct pci_ecam_ops *ops);
+int pci_host_common_remove(struct platform_device *pdev);
 #endif
 #endif
Signature · 1 line
2.13.6
author
#21 lore raw

PATCH v2 10/10 PCI: Enable PCI_DOMAINS along with generic PCI host controller

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

This controller is often instantiated by hypervisors, and they may add multiple of them or add them in addition to a physical host controller like the Jailhouse hypervisor is doing. Therefore allow for multiple domains so that we can handle them all.

---
 drivers/pci/host/Kconfig | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/host/Kconfig +1 -0
index 0d0177ce436c..3d25b35bb5ab 100644
@@ -68,6 +68,7 @@ config PCI_HOST_GENERIC
 	depends on (ARM || ARM64) && OF
 	select PCI_HOST_COMMON
 	select IRQ_DOMAIN
+	select PCI_DOMAINS
 	help
 	  Say Y here if you want to support a simple generic PCI host
 	  controller, such as the one emulated by kvmtool.
Signature · 1 line
2.13.6
#16 lore raw

Re: [PATCH v2 08/10] PCI: Deprecate of_pci_get_host_bridge_resources()

In reply to Jan Kiszka
Quoted 9 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

There are no in-tree users remaining, all are converted to the managed variant. And it is unlikely that any out-of-tree user got the resource management right as well. So deprecate the interface and push users to the managed version instead.

To avoid raising a warning when exporting a deprecated symbol, wrap the API with an inline and export an internal name.

Don't deprecated it, just remove it.

#22 lore raw
In reply to Jan Kiszka

Hi Jan,

Quoted 7 lines · Jan Kiszka

Changes in v2:
- patch 1: commit message reworking as suggested by Lorenzo
- patch 3-6: split-up as suggested by Bjorn
- patch 8: new
- patch 10: select PCI_DOMAINS from PCI_HOST_GENERIC, rather than allowing manual choice, as suggested by Lorenzo

Quoted 7 lines

This primarily enables to unbind the generic PCI host controller without leaving lots of memory leaks behind. A previous proposal patch 5 was rejected because of those issues [1].

The fixes have been validated in the Jailhouse setup, where we add and remove a virtual PCI host controller on hypervisor activation/ deactivation, with the help of kmemleak.

by chance I was looking into a memleak in of_pci_get_host_bridge_resources(), so I can give you a number of review tags.

FWIW the state of unfixably broken https://patchwork.kernel.org/patch/9662893/
should be changed to obsoleted/deprecated/rejected.

--
With best wishes,
Vladimir

Reviewed-by Tested-by on v2 3/10
#4 lore raw

Re: [PATCH v2 03/10] PCI: Factor out __of_pci_get_host_bridge_resources()

In reply to Jan Kiszka
Quoted 6 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

This will be needed for sharing the core logic between current of_pci_get_host_bridge_resources() and upcoming devm_of_pci_get_host_bridge_resources().

Quoted 6 lines

Already rename the dev parameter to dev_node in order to free the namespace for a real device parameter.

No functional changes.

--
With best wishes,
Vladimir

Reviewed-by Tested-by on v2 4/10
#6 lore raw

Re: [PATCH v2 04/10] PCI: Add dev parameter to __of_pci_get_host_bridge_resources()

In reply to Jan Kiszka
Quoted 8 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

When non-NULL, use the new dev parameter of __of_pci_get_host_bridge_resources() to allocate the resource data structures via devm_kzalloc. That allows to release them automatically during device destruction.

--
With best wishes,
Vladimir

Reviewed-by Tested-by on v2 5/10
#8 lore raw

Re: [PATCH v2 05/10] PCI: Replace pr_*() with dev_*() in __of_pci_get_host_bridge_resources()

In reply to Jan Kiszka
Quoted 7 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Now that we have a device reference, make use of it for printing. And as long as dev can still be NULL, we will still get some reasonable output nevertheless.

--
With best wishes,
Vladimir

Reviewed-by Tested-by on v2 6/10
#10 lore raw

Re: [PATCH v2 06/10] PCI: Introduce devm_of_pci_get_host_bridge_resources()

In reply to Jan Kiszka
Quoted 8 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

of_pci_get_host_bridge_resources() allocates the resource structures it fills dynamically, but none of its callers care to release them so far. Rather than requiring everyone to do this explicitly, introduce a managed version of that service. This differs API-wise only in taking a reference to the associated device, rather than to the device tree node.

Quoted 5 lines

As of_pci_get_host_bridge_resources() is an exported interface, we cannot simply drop it at this point. After converting all in-tree users to the new API, we will phase out the unmanaged one.

--
With best wishes,
Vladimir

Reviewed-by Tested-by on v2 7/10
#12 lore raw

Re: [PATCH v2 07/10] PCI: Convert of_pci_get_host_bridge_resources() users to devm variant

In reply to Jan Kiszka

Hi Jan,

Quoted 9 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Straightforward for all of them, no more leaks afterwards.

CC Jingoo Han <[email protected]>
CC Joao Pinto <[email protected]>
CC Lorenzo Pieralisi <[email protected]>

[snip]

Quoted 9 lines
drivers/pci/host/pcie-rcar.c +0 -1
index 6ab28f29ac6a..6eb36c924983 100644
@@ -1067,12 +1067,11 @@ static int rcar_pcie_parse_request_of_pci_ranges(struct rcar_pcie *pci)
 {
 	int err;
 	struct device *dev = pci->dev;
-	struct device_node *np = dev->of_node;

drivers/pci/host/pcie-rcar.c static int rcar_pcie_parse_request_of_pci_ranges(struct rcar_pcie *pci) · line 1077

Quoted 10 lines
drivers/pci/host/pcie-rcar.c +2 -2
 	resource_size_t iobase;
 	struct resource_entry *win, *tmp;
 
-	err = of_pci_get_host_bridge_resources(np, 0, 0xff, &pci->resources,
-					       &iobase);
+	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
+						    &pci->resources, &iobase);
 	if (err)
 		return err;
 

this one snippet is obsoleted by https://patchwork.ozlabs.org/patch/904326/

If 08/10 remains a deprecation, then it is sufficient to exclude the R-Car change, otherwise I hope maintainers can deal with the proper ordering.

For PCI OF change:

Quoted 10 lines
drivers/pci/of.c +0 -1
index f16b343d3b85..5a88d46a41b7 100644
@@ -645,12 +645,12 @@ int pci_parse_request_of_pci_ranges(struct device *dev,
 				    struct resource **bus_range)
 {
 	int err, res_valid = 0;
-	struct device_node *np = dev->of_node;

drivers/pci/of.c int pci_parse_request_of_pci_ranges(struct device *dev, · line 656

Quoted 10 lines
drivers/pci/of.c +2 -1
 	resource_size_t iobase;
 	struct resource_entry *win, *tmp;
 
 	INIT_LIST_HEAD(resources);
-	err = of_pci_get_host_bridge_resources(np, 0, 0xff, resources, &iobase);
+	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, resources,
+						    &iobase);
 	if (err)
 		return err;
 

--
With best wishes,
Vladimir

author
#23 lore raw
In reply to Vladimir Zapolskiy

Hey Vladimir,

Quoted 14 lines · Vladimir Zapolskiy

Hi Jan,

Quoted 11 lines · Jan Kiszka

Changes in v2:
- patch 1: commit message reworking as suggested by Lorenzo
- patch 3-6: split-up as suggested by Bjorn
- patch 8: new
- patch 10: select PCI_DOMAINS from PCI_HOST_GENERIC, rather than allowing manual choice, as suggested by Lorenzo

This primarily enables to unbind the generic PCI host controller without leaving lots of memory leaks behind. A previous proposal patch 5 was rejected because of those issues [1].

Quoted 6 lines
Quoted 3 lines

The fixes have been validated in the Jailhouse setup, where we add and remove a virtual PCI host controller on hypervisor activation/ deactivation, with the help of kmemleak.

by chance I was looking into a memleak in of_pci_get_host_bridge_resources(), so I can give you a number of review tags.

Thanks for the reviews and tests! And the pointer for the maintainers to the conflict around patch 7.

Quoted 3 lines

FWIW the state of unfixably broken https://patchwork.kernel.org/patch/9662893/
should be changed to obsoleted/deprecated/rejected.

Indeed.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux
author
#17 lore raw

Re: [PATCH v2 08/10] PCI: Deprecate of_pci_get_host_bridge_resources()

In reply to Christoph Hellwig
Quoted 8 lines · Christoph Hellwig
Quoted 7 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

There are no in-tree users remaining, all are converted to the managed variant. And it is unlikely that any out-of-tree user got the resource management right as well. So deprecate the interface and push users to the managed version instead.

Quoted 5 lines
Quoted 2 lines

To avoid raising a warning when exporting a deprecated symbol, wrap the API with an inline and export an internal name.

Don't deprecated it, just remove it.

I see a clear favorite now: consider this patch obsolete. I'll send a separate removal patch, or a v3 of this series when otherwise needed.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux
#13 lore raw

Re: [PATCH v2 07/10] PCI: Convert of_pci_get_host_bridge_resources() users to devm variant

In reply to Vladimir Zapolskiy
Quoted 37 lines · Vladimir Zapolskiy

Hi Jan,

Quoted 9 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Straightforward for all of them, no more leaks afterwards.

CC Jingoo Han <[email protected]>
CC Joao Pinto <[email protected]>
CC Lorenzo Pieralisi <[email protected]>

[snip]

Quoted 9 lines
drivers/pci/host/pcie-rcar.c +0 -1
index 6ab28f29ac6a..6eb36c924983 100644
@@ -1067,12 +1067,11 @@ static int rcar_pcie_parse_request_of_pci_ranges(struct rcar_pcie *pci)
 {
 	int err;
 	struct device *dev = pci->dev;
-	struct device_node *np = dev->of_node;

drivers/pci/host/pcie-rcar.c static int rcar_pcie_parse_request_of_pci_ranges(struct rcar_pcie *pci) · line 1077

Quoted 10 lines
drivers/pci/host/pcie-rcar.c +2 -2
 	resource_size_t iobase;
 	struct resource_entry *win, *tmp;
 
-	err = of_pci_get_host_bridge_resources(np, 0, 0xff, &pci->resources,
-					       &iobase);
+	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
+						    &pci->resources, &iobase);
 	if (err)
 		return err;
 

this one snippet is obsoleted by https://patchwork.ozlabs.org/patch/904326/

Quoted 2 lines

If 08/10 remains a deprecation, then it is sufficient to exclude the R-Car change, otherwise I hope maintainers can deal with the proper ordering.

Isn't applying your patch:

https://patchwork.ozlabs.org/patch/904326/

and dropping the rcar hunk from this patch enough ?

Lorenzo

#14 lore raw

Re: [PATCH v2 07/10] PCI: Convert of_pci_get_host_bridge_resources() users to devm variant

Hi Lorenzo,

Quoted 38 lines · Lorenzo Pieralisi
Quoted 37 lines · Vladimir Zapolskiy

Hi Jan,

Quoted 9 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Straightforward for all of them, no more leaks afterwards.

CC Jingoo Han <[email protected]>
CC Joao Pinto <[email protected]>
CC Lorenzo Pieralisi <[email protected]>

[snip]

Quoted 9 lines
drivers/pci/host/pcie-rcar.c +0 -1
index 6ab28f29ac6a..6eb36c924983 100644
@@ -1067,12 +1067,11 @@ static int rcar_pcie_parse_request_of_pci_ranges(struct rcar_pcie *pci)
 {
 	int err;
 	struct device *dev = pci->dev;
-	struct device_node *np = dev->of_node;

drivers/pci/host/pcie-rcar.c static int rcar_pcie_parse_request_of_pci_ranges(struct rcar_pcie *pci) · line 1077

Quoted 10 lines
drivers/pci/host/pcie-rcar.c +2 -2
 	resource_size_t iobase;
 	struct resource_entry *win, *tmp;
 
-	err = of_pci_get_host_bridge_resources(np, 0, 0xff, &pci->resources,
-					       &iobase);
+	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
+						    &pci->resources, &iobase);
 	if (err)
 		return err;
 

this one snippet is obsoleted by https://patchwork.ozlabs.org/patch/904326/

Quoted 9 lines
Quoted 2 lines

If 08/10 remains a deprecation, then it is sufficient to exclude the R-Car change, otherwise I hope maintainers can deal with the proper ordering.

Isn't applying your patch:

https://patchwork.ozlabs.org/patch/904326/

and dropping the rcar hunk from this patch enough ?

absolutely, but it relies on any of two assumptions that
* my unmodified change is applied first, then Jan's adjusted change is applied,
* Jan's unmodified change is applied first, then my adjusted change is applied.

Otherwise there will be a trivial merge conflict, or even worse, if R-Car hunk is removed as suggested, then of_pci_get_host_bridge_resources() is removed instead of deprecation, and then my unmodified change is applied on top, it will result in a window of commits, where R-Car PCIe driver won't be buildable, and git-bisect users can be disappointed.

It makes little sense to include my change into Jan's series, thus I rely on maintainers' awareness and smooth resolution of the issue by maintainers.

For what it's worth, I vote for of_pci_get_host_bridge_resources() removal.

--
With best wishes,
Vladimir

#18 lore raw

Re: [PATCH v2 08/10] PCI: Deprecate of_pci_get_host_bridge_resources()

In reply to Jan Kiszka
Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Christoph Hellwig
Quoted 7 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

There are no in-tree users remaining, all are converted to the managed variant. And it is unlikely that any out-of-tree user got the resource management right as well. So deprecate the interface and push users to the managed version instead.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

To avoid raising a warning when exporting a deprecated symbol, wrap the API with an inline and export an internal name.

Don't deprecated it, just remove it.

I see a clear favorite now: consider this patch obsolete. I'll send a separate removal patch, or a v3 of this series when otherwise needed.

Can you just send an update to this patch to remove it? I've got these on a branch and will just update my branch with the removal.

Then I'll coordinate with Lorenzo and make sure the dependency issue is resolved.

author
#19 lore raw

PATCH v3 8/10 PCI: Remove of_pci_get_host_bridge_resources()

There are no in-tree users remaining, all are converted to the managed variant. And it is unlikely that any out-of-tree user got the resource management right as well. So remove the interface.

---

This replaces "PCI: Deprecate of_pci_get_host_bridge_resources()" from the round v2.

 drivers/pci/of.c       | 88 +++++++++++++-------------------------------------
 include/linux/of_pci.h | 10 ------
 2 files changed, 22 insertions(+), 76 deletions(-)
drivers/pci/of.c +22 -66
index 5a88d46a41b7..38469ffd1d7e 100644
@@ -243,11 +243,29 @@ void of_pci_check_probe_only(void)
 EXPORT_SYMBOL_GPL(of_pci_check_probe_only);
 
 #if defined(CONFIG_OF_ADDRESS)
-static int __of_pci_get_host_bridge_resources(struct device *dev,
-			struct device_node *dev_node,
+/**
+ * devm_of_pci_get_host_bridge_resources() - Resource-managed parsing of PCI
+ *                                           host bridge resources from DT
+ * @dev: host bridge device
+ * @busno: bus number associated with the bridge root bus
+ * @bus_max: maximum number of buses for this bridge
+ * @resources: list where the range of resources will be added after DT parsing
+ * @io_base: pointer to a variable that will contain on return the physical
+ * address for the start of the I/O range. Can be NULL if the caller doesn't
+ * expect I/O ranges to be present in the device tree.
+ *
+ * This function will parse the "ranges" property of a PCI host bridge device
+ * node and setup the resource mapping based on its content. It is expected
+ * that the property conforms with the Power ePAPR document.
+ *
+ * It returns zero if the range parsing has been successful or a standard error
+ * value if it failed.
+ */
+int devm_of_pci_get_host_bridge_resources(struct device *dev,
 			unsigned char busno, unsigned char bus_max,
 			struct list_head *resources, resource_size_t *io_base)
 {
+	struct device_node *dev_node = dev->of_node;
 	struct resource_entry *window;
 	struct resource *res;
 	struct resource *bus_range;
@@ -259,10 +277,7 @@ static int __of_pci_get_host_bridge_resources(struct device *dev,
 	if (io_base)
 		*io_base = (resource_size_t)OF_BAD_ADDR;
 
-	if (dev)
-		bus_range = devm_kzalloc(dev,sizeof(*bus_range), GFP_KERNEL);
-	else
-		bus_range = kzalloc(sizeof(*bus_range), GFP_KERNEL);
+	bus_range = devm_kzalloc(dev,sizeof(*bus_range), GFP_KERNEL);
 	if (!bus_range)
 		return -ENOMEM;
 
@@ -306,11 +321,7 @@ static int __of_pci_get_host_bridge_resources(struct device *dev,
 		if (range.cpu_addr == OF_BAD_ADDR || range.size == 0)
 			continue;
 
-		if (dev)
-			res = devm_kzalloc(dev, sizeof(struct resource),
-					   GFP_KERNEL);
-		else
-			res = kzalloc(sizeof(struct resource), GFP_KERNEL);
+		res = devm_kzalloc(dev, sizeof(struct resource), GFP_KERNEL);
 		if (!res) {
 			err = -ENOMEM;
 			goto parse_failed;
@@ -350,62 +361,7 @@ static int __of_pci_get_host_bridge_resources(struct device *dev,
 	pci_free_resource_list(resources);
 	return err;
 }
-
-/**
- * of_pci_get_host_bridge_resources() - Parse PCI host bridge resources from DT
- * @dev_node: device node of the host bridge having the range property
- * @busno: bus number associated with the bridge root bus
- * @bus_max: maximum number of buses for this bridge
- * @resources: list where the range of resources will be added after DT parsing
- * @io_base: pointer to a variable that will contain on return the physical
- * address for the start of the I/O range. Can be NULL if the caller doesn't
- * expect I/O ranges to be present in the device tree.
- *
- * It is the caller's job to free the @resources list.
- *
- * This function will parse the "ranges" property of a PCI host bridge device
- * node and setup the resource mapping based on its content. It is expected
- * that the property conforms with the Power ePAPR document.
- *
- * It returns zero if the range parsing has been successful or a standard error
- * value if it failed.
- */
-int of_pci_get_host_bridge_resources(struct device_node *dev_node,
-			unsigned char busno, unsigned char bus_max,
-			struct list_head *resources, resource_size_t *io_base)
-{
-	return __of_pci_get_host_bridge_resources(NULL, dev_node, busno,
-						  bus_max, resources, io_base);
-}
-EXPORT_SYMBOL_GPL(of_pci_get_host_bridge_resources);
-
-/**
- * of_pci_get_host_bridge_resources() - Resource-managed parsing of PCI host
- *                                      bridge resources from DT
- * @dev: host bridge device
- * @busno: bus number associated with the bridge root bus
- * @bus_max: maximum number of buses for this bridge
- * @resources: list where the range of resources will be added after DT parsing
- * @io_base: pointer to a variable that will contain on return the physical
- * address for the start of the I/O range. Can be NULL if the caller doesn't
- * expect I/O ranges to be present in the device tree.
- *
- * This function will parse the "ranges" property of a PCI host bridge device
- * node and setup the resource mapping based on its content. It is expected
- * that the property conforms with the Power ePAPR document.
- *
- * It returns zero if the range parsing has been successful or a standard error
- * value if it failed.
- */
-int devm_of_pci_get_host_bridge_resources(struct device *dev,
-			unsigned char busno, unsigned char bus_max,
-			struct list_head *resources, resource_size_t *io_base)
-{
-	return __of_pci_get_host_bridge_resources(dev, dev->of_node, busno,
-						  bus_max, resources, io_base);
-}
 EXPORT_SYMBOL_GPL(devm_of_pci_get_host_bridge_resources);
-
 #endif /* CONFIG_OF_ADDRESS */
 
 /**
include/linux/of_pci.h +0 -10
index 08b8f02426a5..fa4463a52900 100644
@@ -71,20 +71,10 @@ of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin)
 #endif
 
 #if defined(CONFIG_OF_ADDRESS)
-int of_pci_get_host_bridge_resources(struct device_node *dev_node,
-			unsigned char busno, unsigned char bus_max,
-			struct list_head *resources, resource_size_t *io_base);
 int devm_of_pci_get_host_bridge_resources(struct device *dev,
 			unsigned char busno, unsigned char bus_max,
 			struct list_head *resources, resource_size_t *io_base);
 #else
-static inline int of_pci_get_host_bridge_resources(struct device_node *dev_node,
-			unsigned char busno, unsigned char bus_max,
-			struct list_head *resources, resource_size_t *io_base)
-{
-	return -EINVAL;
-}
-
 static inline int devm_of_pci_get_host_bridge_resources(struct device *dev,
 			unsigned char busno, unsigned char bus_max,
 			struct list_head *resources, resource_size_t *io_base)
Signature · 1 line
2.13.6
#24 lore raw
In reply to Jan Kiszka
Quoted 29 lines · Jan Kiszka

Changes in v2:
- patch 1: commit message reworking as suggested by Lorenzo
- patch 3-6: split-up as suggested by Bjorn
- patch 8: new
- patch 10: select PCI_DOMAINS from PCI_HOST_GENERIC, rather than allowing manual choice, as suggested by Lorenzo

This primarily enables to unbind the generic PCI host controller without leaving lots of memory leaks behind. A previous proposal patch 5 was rejected because of those issues [1].

The fixes have been validated in the Jailhouse setup, where we add and remove a virtual PCI host controller on hypervisor activation/ deactivation, with the help of kmemleak.

Besides that, there is tiny PCI API cleanup at the beginning and support for manually enabled PCI domains at the end that enables the Jailhouse scenario.

Jan

[1] http://lkml.iu.edu/hypermail/linux/kernel/1606.3/00072.html

CC Jingoo Han <[email protected]>
CC Joao Pinto <[email protected]>
CC Lorenzo Pieralisi <[email protected]>
CC Will Deacon <[email protected]>
Quoted 12 lines

Jan Kiszka (10):
PCI: Make pci_get_new_domain_nr() static
PCI: Fix memory leak of devm_pci_alloc_host_bridge()
PCI: Factor out __of_pci_get_host_bridge_resources()
PCI: Add dev parameter to __of_pci_get_host_bridge_resources()
PCI: Replace pr_*() with dev_*() in
__of_pci_get_host_bridge_resources()
PCI: Introduce devm_of_pci_get_host_bridge_resources()
PCI: Convert of_pci_get_host_bridge_resources() users to devm variant
PCI: Deprecate of_pci_get_host_bridge_resources()
PCI: Add support for unbinding the generic PCI host controller
PCI: Enable PCI_DOMAINS along with generic PCI host controller

Applied to pci/resource for v4.18, thanks!

I added the reviewed-by tags from Vladimir (thank you!) and replaced the "Deprecate" patch by the v3 "Remove" patch.

Quoted 26 lines
 drivers/pci/dwc/pcie-designware-host.c |   2 +-
 drivers/pci/host/Kconfig               |   1 +
 drivers/pci/host/pci-aardvark.c        |   5 +-
 drivers/pci/host/pci-ftpci100.c        |   4 +-
 drivers/pci/host/pci-host-common.c     |  13 ++++
 drivers/pci/host/pci-host-generic.c    |   1 +
 drivers/pci/host/pci-v3-semi.c         |   3 +-
 drivers/pci/host/pci-versatile.c       |   3 +-
 drivers/pci/host/pci-xgene.c           |   3 +-
 drivers/pci/host/pcie-altera.c         |   5 +-
 drivers/pci/host/pcie-iproc-platform.c |   4 +-
 drivers/pci/host/pcie-rcar.c           |   5 +-
 drivers/pci/host/pcie-rockchip.c       |   4 +-
 drivers/pci/host/pcie-xilinx-nwl.c     |   4 +-
 drivers/pci/host/pcie-xilinx.c         |   4 +-
 drivers/pci/of.c                       | 105 +++++++++++++++++++++------------
 drivers/pci/pci.c                      |   6 +-
 drivers/pci/probe.c                    |   4 +-
 include/linux/of_pci.h                 |  42 ++++++++++++-
 include/linux/pci-ecam.h               |   1 +
 include/linux/pci.h                    |   3 -
 21 files changed, 149 insertions(+), 73 deletions(-)
Signature · 1 line
2.13.6