Skip to contentSkip to conversation

PCI/P2PDMA: Fix missing check for dma_virt_ops

PATCH Applied Logan Gunthorpe 2 participants 2 messages Jul 2, 2019 – Jul 3, 2019

Subsystems (2)
lore
Share & tools
lore

Logan Gunthorpe

author maintainer
#0 lore raw

PATCH 1/1 PCI/P2PDMA: Fix missing check for dma_virt_ops

Drivers that use dma_virt_ops were meant to be rejected when testing compatibility for P2PDMA.

This check got inadvertantly dropped in one of the later versions of the original patchset, so add it back.

Fixes 52916982af48 ("PCI/P2PDMA: Support peer-to-peer memory")
---
 drivers/pci/p2pdma.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/pci/p2pdma.c +9 -1
index a4994aa3acc0..ab48babdf214 100644
@@ -487,6 +487,14 @@ int pci_p2pdma_distance_many(struct pci_dev *provider, struct device **clients,
 		return -1;
 
 	for (i = 0; i < num_clients; i++) {
+		if (IS_ENABLED(CONFIG_DMA_VIRT_OPS) &&
+		    clients[i]->dma_ops == &dma_virt_ops) {
+			if (verbose)
+				dev_warn(clients[i],
+					 "cannot be used for peer-to-peer DMA because the driver makes use of dma_virt_ops\n");
+			return -1;
+		}
+
 		pci_client = find_parent_pci_dev(clients[i]);
 		if (!pci_client) {
 			if (verbose)
@@ -765,7 +773,7 @@ int pci_p2pdma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
 	 * p2pdma mappings are not compatible with devices that use
 	 * dma_virt_ops. If the upper layers do the right thing
 	 * this should never happen because it will be prevented
-	 * by the check in pci_p2pdma_add_client()
+	 * by the check in pci_p2pdma_distance_many()
 	 */
 	if (WARN_ON_ONCE(IS_ENABLED(CONFIG_DMA_VIRT_OPS) &&
 			 dev->dma_ops == &dma_virt_ops))
Signature · 1 line
2.20.1
#1 lore raw
Quoted 8 lines · Logan Gunthorpe

Drivers that use dma_virt_ops were meant to be rejected when testing compatibility for P2PDMA.

This check got inadvertantly dropped in one of the later versions of the original patchset, so add it back.

Fixes 52916982af48 ("PCI/P2PDMA: Support peer-to-peer memory")

Applied to pci/peer-to-peer for v5.3, thanks!

Quoted 35 lines
---
 drivers/pci/p2pdma.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/pci/p2pdma.c +9 -1
index a4994aa3acc0..ab48babdf214 100644
@@ -487,6 +487,14 @@ int pci_p2pdma_distance_many(struct pci_dev *provider, struct device **clients,
 		return -1;
 
 	for (i = 0; i < num_clients; i++) {
+		if (IS_ENABLED(CONFIG_DMA_VIRT_OPS) &&
+		    clients[i]->dma_ops == &dma_virt_ops) {
+			if (verbose)
+				dev_warn(clients[i],
+					 "cannot be used for peer-to-peer DMA because the driver makes use of dma_virt_ops\n");
+			return -1;
+		}
+
 		pci_client = find_parent_pci_dev(clients[i]);
 		if (!pci_client) {
 			if (verbose)
@@ -765,7 +773,7 @@ int pci_p2pdma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
 	 * p2pdma mappings are not compatible with devices that use
 	 * dma_virt_ops. If the upper layers do the right thing
 	 * this should never happen because it will be prevented
-	 * by the check in pci_p2pdma_add_client()
+	 * by the check in pci_p2pdma_distance_many()
 	 */
 	if (WARN_ON_ONCE(IS_ENABLED(CONFIG_DMA_VIRT_OPS) &&
 			 dev->dma_ops == &dma_virt_ops))
Signature · 1 line
2.20.1