* [PATCH v6 1/4] PCI: Ignore enforced alignment when kernel uses existing firmware setup
2016-09-29 6:46 [PATCH v6 0/4] PCI: Introduce a way to enforce all MMIO BARs not to share PAGE_SIZE Yongji Xie
@ 2016-09-29 6:46 ` Yongji Xie
2016-09-29 6:46 ` [PATCH v6 2/4] PCI: Ignore enforced alignment to VF BARs Yongji Xie
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Yongji Xie @ 2016-09-29 6:46 UTC (permalink / raw)
To: bhelgaas
Cc: linux-pci, linuxppc-dev, alex.williamson, paulus, aik, gwshan,
benh, mpe, zhong
PCI resources allocator will use firmware setup and not try to
reassign resource when PCI_PROBE_ONLY or IORESOURCE_PCI_FIXED
is set.
The enforced alignment in pci_reassigndev_resource_alignment()
should be ignored in this case. Otherwise, some PCI devices'
resources would be released here and not re-allocated.
Signed-off-by: Yongji Xie <xyjxie@linux.vnet.ibm.com>
---
drivers/pci/pci.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index aab9d51..2d85a96 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -4959,6 +4959,13 @@ static resource_size_t pci_specified_resource_alignment(struct pci_dev *dev)
spin_lock(&resource_alignment_lock);
p = resource_alignment_param;
+ if (pci_has_flag(PCI_PROBE_ONLY)) {
+ if (*p)
+ pr_info_once("PCI: resource_alignment ignored with PCI_PROBE_ONLY\n");
+ spin_unlock(&resource_alignment_lock);
+ return 0;
+ }
+
while (*p) {
count = 0;
if (sscanf(p, "%d%n", &align_order, &count) == 1 &&
@@ -5063,6 +5070,12 @@ void pci_reassigndev_resource_alignment(struct pci_dev *dev)
r = &dev->resource[i];
if (!(r->flags & IORESOURCE_MEM))
continue;
+ if (r->flags & IORESOURCE_PCI_FIXED) {
+ dev_info(&dev->dev, "No alignment for fixed BAR%d: %pR\n",
+ i, r);
+ continue;
+ }
+
size = resource_size(r);
if (size < align) {
size = align;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v6 2/4] PCI: Ignore enforced alignment to VF BARs
2016-09-29 6:46 [PATCH v6 0/4] PCI: Introduce a way to enforce all MMIO BARs not to share PAGE_SIZE Yongji Xie
2016-09-29 6:46 ` [PATCH v6 1/4] PCI: Ignore enforced alignment when kernel uses existing firmware setup Yongji Xie
@ 2016-09-29 6:46 ` Yongji Xie
2016-09-29 6:46 ` [PATCH v6 3/4] PCI: Don't change resources' size when using resource_alignment Yongji Xie
2016-09-29 6:46 ` [PATCH v6 4/4] PCI: Add a macro to set default alignment for all PCI devices Yongji Xie
3 siblings, 0 replies; 5+ messages in thread
From: Yongji Xie @ 2016-09-29 6:46 UTC (permalink / raw)
To: bhelgaas
Cc: linux-pci, linuxppc-dev, alex.williamson, paulus, aik, gwshan,
benh, mpe, zhong
VF BARs are read-only zeroes according to SRIOV spec,
the normal way(writing BARs) of allocating resources wouldn't
be applied to VFs. The VFs' resources would be allocated
when we enable SR-IOV capability. So we should not try to
reassign alignment after we enable VFs. It's meaningless
and will release the allocated resources which leads to a bug.
Signed-off-by: Yongji Xie <xyjxie@linux.vnet.ibm.com>
---
drivers/pci/pci.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 2d85a96..b8357d7 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5048,6 +5048,15 @@ void pci_reassigndev_resource_alignment(struct pci_dev *dev)
resource_size_t align, size;
u16 command;
+ /*
+ * VF BARs are RO zero according to SR-IOV spec 3.4.1.11. Their
+ * resources would be allocated when we enable them and not be
+ * re-allocated any more. So we should never try to reassign
+ * VF's alignment here.
+ */
+ if (dev->is_virtfn)
+ return;
+
/* check if specified PCI is target device to reassign */
align = pci_specified_resource_alignment(dev);
if (!align)
--
1.7.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v6 3/4] PCI: Don't change resources' size when using resource_alignment
2016-09-29 6:46 [PATCH v6 0/4] PCI: Introduce a way to enforce all MMIO BARs not to share PAGE_SIZE Yongji Xie
2016-09-29 6:46 ` [PATCH v6 1/4] PCI: Ignore enforced alignment when kernel uses existing firmware setup Yongji Xie
2016-09-29 6:46 ` [PATCH v6 2/4] PCI: Ignore enforced alignment to VF BARs Yongji Xie
@ 2016-09-29 6:46 ` Yongji Xie
2016-09-29 6:46 ` [PATCH v6 4/4] PCI: Add a macro to set default alignment for all PCI devices Yongji Xie
3 siblings, 0 replies; 5+ messages in thread
From: Yongji Xie @ 2016-09-29 6:46 UTC (permalink / raw)
To: bhelgaas
Cc: linux-pci, linuxppc-dev, alex.williamson, paulus, aik, gwshan,
benh, mpe, zhong
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 patch tries to use IORESOURCE_STARTALIGN to specify the
alignment instead of IORESOURCE_SIZEALIGN. Thus, we can
reassign the alignment without changing resources's size.
Signed-off-by: Yongji Xie <xyjxie@linux.vnet.ibm.com>
---
drivers/pci/pci.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index b8357d7..d867c90 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5086,15 +5086,10 @@ void pci_reassigndev_resource_alignment(struct pci_dev *dev)
}
size = resource_size(r);
- if (size < align) {
- size = align;
- dev_info(&dev->dev,
- "Rounding up size of resource #%d to %#llx.\n",
- i, (unsigned long long)size);
- }
- r->flags |= IORESOURCE_UNSET;
- r->end = size - 1;
- r->start = 0;
+ r->flags &= ~IORESOURCE_SIZEALIGN;
+ r->flags |= IORESOURCE_STARTALIGN | IORESOURCE_UNSET;
+ r->start = max(align, size);
+ r->end = r->start + size - 1;
}
/* Need to disable bridge's resource window,
* to enable the kernel to reassign new resource
--
1.7.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v6 4/4] PCI: Add a macro to set default alignment for all PCI devices
2016-09-29 6:46 [PATCH v6 0/4] PCI: Introduce a way to enforce all MMIO BARs not to share PAGE_SIZE Yongji Xie
` (2 preceding siblings ...)
2016-09-29 6:46 ` [PATCH v6 3/4] PCI: Don't change resources' size when using resource_alignment Yongji Xie
@ 2016-09-29 6:46 ` Yongji Xie
3 siblings, 0 replies; 5+ messages in thread
From: Yongji Xie @ 2016-09-29 6:46 UTC (permalink / raw)
To: bhelgaas
Cc: linux-pci, linuxppc-dev, alex.williamson, paulus, aik, gwshan,
benh, mpe, zhong
When vfio passthroughs a PCI device of which MMIO BARs are
smaller than PAGE_SIZE, guest will not handle the mmio
accesses to the BARs which leads to mmio emulations in host.
This is because vfio will not allow to passthrough one BAR's
mmio page which may be shared with other BARs. Otherwise,
there will be a backdoor that guest can use to access BARs
of other guest.
This patch adds a macro to set default alignment for all
PCI devices. Then we could solve this issue on some platforms
which would easily hit this issue because of their 64K page
such as PowerNV platform by defining this macro as PAGE_SIZE.
Signed-off-by: Yongji Xie <xyjxie@linux.vnet.ibm.com>
---
arch/powerpc/include/asm/pci.h | 4 ++++
drivers/pci/pci.c | 3 +++
2 files changed, 7 insertions(+)
diff --git a/arch/powerpc/include/asm/pci.h b/arch/powerpc/include/asm/pci.h
index e9bd6cf..5e31bc2 100644
--- a/arch/powerpc/include/asm/pci.h
+++ b/arch/powerpc/include/asm/pci.h
@@ -28,6 +28,10 @@
#define PCIBIOS_MIN_IO 0x1000
#define PCIBIOS_MIN_MEM 0x10000000
+#ifdef CONFIG_PPC_POWERNV
+#define PCIBIOS_DEFAULT_ALIGNMENT PAGE_SIZE
+#endif
+
struct pci_dev;
/* Values for the `which' argument to sys_pciconfig_iobase syscall. */
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index d867c90..b6e26c1 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -4957,6 +4957,9 @@ static resource_size_t pci_specified_resource_alignment(struct pci_dev *dev)
resource_size_t align = 0;
char *p;
+#ifdef PCIBIOS_DEFAULT_ALIGNMENT
+ align = PCIBIOS_DEFAULT_ALIGNMENT;
+#endif
spin_lock(&resource_alignment_lock);
p = resource_alignment_param;
if (pci_has_flag(PCI_PROBE_ONLY)) {
--
1.7.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread