From: Yongji Xie <elohimes@gmail.com>
To: bhelgaas@google.com
Cc: linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
alex.williamson@redhat.com, gwshan@linux.vnet.ibm.com,
aik@ozlabs.ru, benh@kernel.crashing.org, mpe@ellerman.id.au,
paulus@samba.org, zhong@linux.vnet.ibm.com
Subject: [PATCH v10 2/4] PCI: Add pcibios_default_alignment() for arch-specific alignment control
Date: Mon, 10 Apr 2017 19:58:12 +0800 [thread overview]
Message-ID: <1491825494-19331-3-git-send-email-elohimes@gmail.com> (raw)
In-Reply-To: <1491825494-19331-1-git-send-email-elohimes@gmail.com>
When VFIO passes through a PCI device to a guest, it does not allow
the guest to mmap BARs that are smaller than PAGE_SIZE unless it
can reserve the rest of the page (see vfio_pci_probe_mmaps()). This
is because a page might contain several small BARs for unrelated
devices and a guest should not be able to access all of them.
VFIO emulates guest accesses to non-mappable BARs, which is functional
but slow. On systems with large page sizes, e.g., PowerNV with 64K pages,
BARs are more likely to share a page and performance is more likely to
be a problem.
Add a weak function to set default alignment for all PCI devices.
An arch can override it to force the PCI core to place memory BARs on
their own pages.
Signed-off-by: Yongji Xie <elohimes@gmail.com>
---
drivers/pci/pci.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7904d02..02f1255 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -4947,6 +4947,11 @@ void pci_ignore_hotplug(struct pci_dev *dev)
}
EXPORT_SYMBOL_GPL(pci_ignore_hotplug);
+resource_size_t __weak pcibios_default_alignment(struct pci_dev *dev)
+{
+ return 0;
+}
+
#define RESOURCE_ALIGNMENT_PARAM_SIZE COMMAND_LINE_SIZE
static char resource_alignment_param[RESOURCE_ALIGNMENT_PARAM_SIZE] = {0};
static DEFINE_SPINLOCK(resource_alignment_lock);
@@ -4962,14 +4967,15 @@ static resource_size_t pci_specified_resource_alignment(struct pci_dev *dev)
{
int seg, bus, slot, func, align_order, count;
unsigned short vendor, device, subsystem_vendor, subsystem_device;
- resource_size_t align = 0;
+ resource_size_t align = pcibios_default_alignment(dev);
char *p;
spin_lock(&resource_alignment_lock);
p = resource_alignment_param;
- if (!*p)
+ if (!*p && !align)
goto out;
if (pci_has_flag(PCI_PROBE_ONLY)) {
+ align = 0;
pr_info_once("PCI: Ignoring requested alignments (PCI_PROBE_ONLY)\n");
goto out;
}
--
1.7.9.5
next prev parent reply other threads:[~2017-04-10 12:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-10 11:58 [PATCH v10 0/4] PCI: Introduce a way to enforce all MMIO BARs not to share PAGE_SIZE Yongji Xie
2017-04-10 11:58 ` [PATCH v10 1/4] PCI: A fix for caculating bridge window's size and alignment Yongji Xie
2017-04-10 11:58 ` Yongji Xie [this message]
2017-04-10 11:58 ` [PATCH v10 3/4] powerpc/powernv: Override pcibios_default_alignment() to force PCI devices to be page aligned Yongji Xie
2017-04-14 15:58 ` Bjorn Helgaas
2017-04-14 21:52 ` Benjamin Herrenschmidt
2017-04-15 16:36 ` Bjorn Helgaas
2017-04-15 22:06 ` Benjamin Herrenschmidt
2017-04-17 15:51 ` Bjorn Helgaas
2017-04-10 11:58 ` [PATCH v10 4/4] PCI: Don't extend device's size when using default alignment for all devices Yongji Xie
2017-04-14 22:54 ` Bjorn Helgaas
2017-04-17 6:27 ` Yongji Xie
2017-04-17 20:33 ` Bjorn Helgaas
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=1491825494-19331-3-git-send-email-elohimes@gmail.com \
--to=elohimes@gmail.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).