diff mbox series

[RFC,3/4] PCI: Invalidate the released BAR resources

Message ID 20180914161404.4685-4-s.miroshnichenko@yadro.com (mailing list archive)
State New, archived
Delegated to: Bjorn Helgaas
Headers show
Series PCI: Allow BAR movement during hotplug | expand

Commit Message

Sergei Miroshnichenko Sept. 14, 2018, 4:14 p.m. UTC
Otherwise after release_child_resources() there can be resources
with the IORESOURCE_STARTALIGN flag remaining, but with start
dropped to zero, that makes them not valid for re-assigning.

Signed-off-by: Sergey Miroshnichenko <s.miroshnichenko@yadro.com>
---
 drivers/pci/setup-bus.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index fd5675bb501f..ec88461462b8 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1521,7 +1521,7 @@  static void __pci_bridge_assign_resources(const struct pci_dev *bridge,
 static void pci_bridge_release_resources(struct pci_bus *bus,
 					  unsigned long type)
 {
-	struct pci_dev *dev = bus->self;
+	struct pci_dev *dev = bus->self, *child_dev;
 	struct resource *r;
 	unsigned old_flags = 0;
 	struct resource *b_res;
@@ -1564,6 +1564,25 @@  static void pci_bridge_release_resources(struct pci_bus *bus,
 	 *  all
 	 */
 	release_child_resources(r);
+	list_for_each_entry(child_dev, &bus->devices, bus_list) {
+		int i;
+
+		if (child_dev->subordinate)
+			continue;
+
+		for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
+			struct resource *res = &child_dev->resource[i];
+			resource_size_t size = resource_size(res);
+
+			if (!res->flags)
+				continue;
+
+			res->end = size - 1;
+			res->start = 0;
+			res->flags &= ~IORESOURCE_STARTALIGN;
+			res->flags |= IORESOURCE_SIZEALIGN;
+		}
+	}
 	if (!release_resource(r)) {
 		type = old_flags = r->flags & PCI_RES_TYPE_MASK;
 		pci_printk(KERN_DEBUG, dev, "resource %d %pR released\n",