diff mbox

[RFC,v7,2/3] PCI: Restore resource's size if we expand it by using resource_alignment

Message ID 1477464813-2499-3-git-send-email-xyjxie@linux.vnet.ibm.com
State Superseded
Headers show

Commit Message

Yongji Xie Oct. 26, 2016, 6:53 a.m. UTC
When using resource_alignment kernel parameter, the current implement
reassigns the alignment by changing resources' size which can
potentially break some drivers. For example, the driver uses the size
to locate some register whose length is related to the size.

This saves the increased sizes in pci_reassigndev_resource_alignment()
and restores to original sizes after PCI resource sizing/assigning are
done.

Signed-off-by: Yongji Xie <xyjxie@linux.vnet.ibm.com>
---
 drivers/pci/pci.c       |    1 +
 drivers/pci/setup-bus.c |   19 +++++++++++++++++++
 include/linux/pci.h     |    1 +
 3 files changed, 21 insertions(+)
diff mbox

Patch

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 9a30832..2933c81 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5130,6 +5130,7 @@  void pci_reassigndev_resource_alignment(struct pci_dev *dev)
 
 		size = resource_size(r);
 		if (size < align) {
+			dev->bars_addsize[i] = align - size;
 			size = align;
 			dev_info(&dev->dev,
 				"Rounding up size of resource #%d to %#llx.\n",
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index f30ca75..12f0e2b 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1387,6 +1387,24 @@  static void pdev_assign_fixed_resources(struct pci_dev *dev)
 	}
 }
 
+static inline void pdev_restore_resource_sizes(struct pci_dev *dev)
+{
+	struct resource *r;
+	int i;
+
+	for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
+		r = &dev->resource[i];
+		if (r->flags & IORESOURCE_UNSET)
+			continue;
+
+		if (!dev->bars_addsize[i])
+			continue;
+
+		r->end -= dev->bars_addsize[i];
+		dev->bars_addsize[i] = 0;
+	}
+}
+
 void __pci_bus_assign_resources(const struct pci_bus *bus,
 				struct list_head *realloc_head,
 				struct list_head *fail_head)
@@ -1398,6 +1416,7 @@  void __pci_bus_assign_resources(const struct pci_bus *bus,
 
 	list_for_each_entry(dev, &bus->devices, bus_list) {
 		pdev_assign_fixed_resources(dev);
+		pdev_restore_resource_sizes(dev);
 
 		b = dev->subordinate;
 		if (!b)
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 0e49f70..a60e8c5 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -334,6 +334,7 @@  struct pci_dev {
 	unsigned int	irq;
 	struct cpumask	*irq_affinity;
 	struct resource resource[DEVICE_COUNT_RESOURCE]; /* I/O and memory regions + expansion ROMs */
+	resource_size_t bars_addsize[PCI_ROM_RESOURCE + 1];
 
 	bool match_driver;		/* Skip attaching driver */
 	/* These fields are used by common fixups */