Skip to content

Commit 719c986

Browse files
lsgunthChristoph Hellwig
authored andcommitted
PCI/P2PDMA: Attempt to set map_type if it has not been set
Attempt to find the mapping type for P2PDMA pages on the first DMA map attempt if it has not been done ahead of time. Previously, the mapping type was expected to be calculated ahead of time, but if pages are to come from userspace then there's no way to ensure the path was checked ahead of time. This change will calculate the mapping type if it hasn't pre-calculated so it is no longer invalid to call pci_p2pdma_map_sg() before the mapping type is calculated, so drop the WARN_ON when that is the case. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Acked-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 4239930 commit 719c986

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

drivers/pci/p2pdma.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,7 @@ static enum pci_p2pdma_map_type pci_p2pdma_map_type(struct dev_pagemap *pgmap,
854854
struct pci_dev *provider = to_p2p_pgmap(pgmap)->provider;
855855
struct pci_dev *client;
856856
struct pci_p2pdma *p2pdma;
857+
int dist;
857858

858859
if (!provider->p2pdma)
859860
return PCI_P2PDMA_MAP_NOT_SUPPORTED;
@@ -870,6 +871,10 @@ static enum pci_p2pdma_map_type pci_p2pdma_map_type(struct dev_pagemap *pgmap,
870871
type = xa_to_value(xa_load(&p2pdma->map_types,
871872
map_types_idx(client)));
872873
rcu_read_unlock();
874+
875+
if (type == PCI_P2PDMA_MAP_UNKNOWN)
876+
return calc_map_type_and_dist(provider, client, &dist, true);
877+
873878
return type;
874879
}
875880

@@ -912,7 +917,7 @@ int pci_p2pdma_map_sg_attrs(struct device *dev, struct scatterlist *sg,
912917
case PCI_P2PDMA_MAP_BUS_ADDR:
913918
return __pci_p2pdma_map_sg(p2p_pgmap, dev, sg, nents);
914919
default:
915-
WARN_ON_ONCE(1);
920+
/* Mapping is not Supported */
916921
return 0;
917922
}
918923
}

0 commit comments

Comments
 (0)