From: Yongji Xie <xyjxie@linux.vnet.ibm.com>
To: bhelgaas@google.com
Cc: linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
alex.williamson@redhat.com, paulus@samba.org, aik@ozlabs.ru,
gwshan@linux.vnet.ibm.com, benh@kernel.crashing.org,
mpe@ellerman.id.au, zhong@linux.vnet.ibm.com
Subject: [RFC PATCH v7 2/3] PCI: Restore resource's size if we expand it by using resource_alignment
Date: Wed, 26 Oct 2016 14:53:32 +0800 [thread overview]
Message-ID: <1477464813-2499-3-git-send-email-xyjxie@linux.vnet.ibm.com> (raw)
In-Reply-To: <1477464813-2499-1-git-send-email-xyjxie@linux.vnet.ibm.com>
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 --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 */
--
1.7.9.5
next prev parent reply other threads:[~2016-10-26 6:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-26 6:53 [RFC PATCH v7 0/3] PCI: Introduce a way to enforce all MMIO BARs not to share PAGE_SIZE Yongji Xie
2016-10-26 6:53 ` [RFC PATCH v7 1/3] PCI: Ignore requested alignment for IOV BARs Yongji Xie
2016-10-26 6:53 ` Yongji Xie [this message]
2016-10-26 6:53 ` [RFC PATCH v7 3/3] PCI: Add a macro to set default alignment for all PCI devices Yongji Xie
2016-11-15 2:53 ` [RFC PATCH v7 0/3] PCI: Introduce a way to enforce all MMIO BARs not to share PAGE_SIZE Yongji Xie
2016-12-01 2:32 ` Alexey Kardashevskiy
2016-12-20 7:22 ` Alexey Kardashevskiy
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=1477464813-2499-3-git-send-email-xyjxie@linux.vnet.ibm.com \
--to=xyjxie@linux.vnet.ibm.com \
--cc=aik@ozlabs.ru \
--cc=alex.williamson@redhat.com \
--cc=benh@kernel.crashing.org \
--cc=bhelgaas@google.com \
--cc=gwshan@linux.vnet.ibm.com \
--cc=linux-pci@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=paulus@samba.org \
--cc=zhong@linux.vnet.ibm.com \
/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).