This series introduces a way for PCI resource allocator to force
MMIO BARs not to share PAGE_SIZE. This would make sense to VFIO
driver. Because current VFIO implementation disallows to mmap
sub-page(size < PAGE_SIZE) MMIO BARs which may share the same page
with other BARs for security reasons. Thus, we have to handle mmio
access to these BARs in QEMU emulation rather than in guest which
will cause some performance loss.
In our solution, we try to make use of the existing code path of
resource_alignment kernel parameter and add a macro to set default
alignment for it. Thus we can define this macro by default on some
archs which may easily hit the performance issue because of their
64K page.
In this series, patch 1,2 fixed bugs of using resource_alignment;
patch 3 tried to use IORESOURCE_STARTALIGN to specify the alignment
of PCI BARs when using resource_alignment; patch 4 adds a macro to
set the default alignment of all MMIO BARs.
Changelog v6:
- Remove the option "noresize@" of resource_alignment
Changelog v5:
- Rebased against v4.8-rc6
- Drop the patch that forbidding disable memory decoding in
pci_reassigndev_resource_alignment()
Changelog v4:
- Rebased against v4.8-rc1
- Drop one irrelevant patch
- Drop the patch that adding wildcard to resource_alignment to enforce
the alignment of all MMIO BARs to be at least PAGE_SIZE
- Change the format of option "noresize" of resource_alignment
- Code style improvements
Changelog v3:
- Ignore enforced alignment to fixed BARs
- Fix issue that disabling memory decoding when reassigning the alignment
- Only enable default alignment on PowerNV platform
Changelog v2:
- Ignore enforced alignment to VF BARs on pci_reassigndev_resource_alignment()
Yongji Xie (4):
PCI: Ignore enforced alignment when kernel uses existing firmware setup
PCI: Ignore enforced alignment to VF BARs
PCI: Don't change resources' size when using resource_alignment
PCI: Add a macro to set default alignment for all PCI devices
arch/powerpc/include/asm/pci.h | 4 ++++
drivers/pci/pci.c | 38 +++++++++++++++++++++++++++++---------
2 files changed, 33 insertions(+), 9 deletions(-)
--
1.7.9.5
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 <redacted>
---
drivers/pci/pci.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
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 <redacted>
---
drivers/pci/pci.c | 9 +++++++++
1 file changed, 9 insertions(+)
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 <redacted>
---
drivers/pci/pci.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
@@ -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,(unsignedlonglong)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,*toenablethekerneltoreassignnewresource
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 <redacted>
---
arch/powerpc/include/asm/pci.h | 4 ++++
drivers/pci/pci.c | 3 +++
2 files changed, 7 insertions(+)