PCI/P2PDMA: Fix missing check for dma_virt_ops
authorLogan Gunthorpe <logang@deltatee.com>
Tue, 2 Jul 2019 17:35:44 +0000 (11:35 -0600)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 2 Jul 2019 23:35:15 +0000 (18:35 -0500)
Drivers that use dma_virt_ops were meant to be rejected when testing
compatibility for P2PDMA.

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

Fixes: 52916982af48 ("PCI/P2PDMA: Support peer-to-peer memory")
Link: https://lore.kernel.org/r/20190702173544.21950-1-logang@deltatee.com
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/p2pdma.c

index 742928d0053ec79bf886a24939db4cdc799096d8..1940a7a0a684090082b889642f0650ac96291cbc 100644 (file)
@@ -468,6 +468,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)
@@ -732,7 +740,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))