Skip to contentSkip to conversation

PCI/P2PDMA: Root complex whitelist should not apply when an IOMMU is present

PATCH Applied Logan Gunthorpe 2 participants 2 messages Jun 19, 2019

Subsystems (2)
lore
Share & tools
lore

Logan Gunthorpe

author maintainer
#0 lore raw

PATCH v2 1/1 PCI/P2PDMA: Root complex whitelist should not apply when an IOMMU is present

Presently, there is no path to DMA map P2PDMA memory, so if a TLP targeting this memory hits the root complex and an IOMMU is present, the IOMMU will reject the transaction, even if the RC would support P2PDMA.

So until the kernel knows to map these DMA addresses in the IOMMU, we should not enable the whitelist when an IOMMU is present.

Fixes 0f97da831026 ("PCI/P2PDMA: Allow P2P DMA between any devices under AMD ZEN Root Complex")
Cc Bjorn Helgaas <[email protected]>
Cc Christoph Hellwig <[email protected]>
---
 drivers/pci/p2pdma.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/p2pdma.c +4 -0
index a98126ad9c3a..a4994aa3acc0 100644
@@ -18,6 +18,7 @@
 #include <linux/percpu-refcount.h>
 #include <linux/random.h>
 #include <linux/seq_buf.h>
+#include <linux/iommu.h>
 
 struct pci_p2pdma {
 	struct gen_pool *pool;
@@ -299,6 +300,9 @@ static bool root_complex_whitelist(struct pci_dev *dev)
 	struct pci_dev *root = pci_get_slot(host->bus, PCI_DEVFN(0, 0));
 	unsigned short vendor, device;
 
+	if (iommu_present(dev->dev.bus))
+		return false;
+
 	if (!root)
 		return false;
 
Signature · 1 line
2.20.1
#1 lore raw
Quoted 8 lines · Logan Gunthorpe

Presently, there is no path to DMA map P2PDMA memory, so if a TLP targeting this memory hits the root complex and an IOMMU is present, the IOMMU will reject the transaction, even if the RC would support P2PDMA.

So until the kernel knows to map these DMA addresses in the IOMMU, we should not enable the whitelist when an IOMMU is present.

Quoted 6 lines
Fixes 0f97da831026 ("PCI/P2PDMA: Allow P2P DMA between any devices under AMD ZEN Root Complex")
Cc Bjorn Helgaas <[email protected]>
Cc Christoph Hellwig <[email protected]>

Applied to for-linus for v5.2, since we merged 0f97da831026 during the v5.2 merge window, thanks!

Quoted 29 lines
---
 drivers/pci/p2pdma.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/p2pdma.c +4 -0
index a98126ad9c3a..a4994aa3acc0 100644
@@ -18,6 +18,7 @@
 #include <linux/percpu-refcount.h>
 #include <linux/random.h>
 #include <linux/seq_buf.h>
+#include <linux/iommu.h>
 
 struct pci_p2pdma {
 	struct gen_pool *pool;
@@ -299,6 +300,9 @@ static bool root_complex_whitelist(struct pci_dev *dev)
 	struct pci_dev *root = pci_get_slot(host->bus, PCI_DEVFN(0, 0));
 	unsigned short vendor, device;
 
+	if (iommu_present(dev->dev.bus))
+		return false;
+
 	if (!root)
 		return false;
 
Signature · 1 line
2.20.1