On 2025-07-27 13:05, Jason Gunthorpe wrote: > On Fri, Jul 25, 2025 at 10:30:46AM -0600, Logan Gunthorpe wrote: >> >> >> On 2025-07-24 02:13, Leon Romanovsky wrote: >>> On Thu, Jul 24, 2025 at 10:03:13AM +0200, Christoph Hellwig wrote: >>>> On Wed, Jul 23, 2025 at 04:00:06PM +0300, Leon Romanovsky wrote: >>>>> From: Leon Romanovsky <leonro@xxxxxxxxxx> >>>>> >>>>> Export the pci_p2pdma_map_type() function to allow external modules >>>>> and subsystems to determine the appropriate mapping type for P2PDMA >>>>> transfers between a provider and target device. >>>> >>>> External modules have no business doing this. >>> >>> VFIO PCI code is built as module. There is no way to access PCI p2p code >>> without exporting functions in it. >> >> The solution that would make more sense to me would be for either >> dma_iova_try_alloc() or another helper in dma-iommu.c to handle the >> P2PDMA case. > > This has nothing to do with dma-iommu.c, the decisions here still need > to be made even if dma-iommu.c is not compiled in. Doesn't it though? Every single call in patch 10 to the newly exported PCI functions calls into the the dma-iommu functions. If there were non-iommu paths then I would expect the code would use the regular DMA api directly which would then call in to dma-iommu. I can't imagine a use case where someone would want to call the p2pdma functions to map p2p memory and not have a similar path to do the exact same mapping with vanilla memory and thus call the DMA API. And it seems much better to me to export higher level functions to drivers that take care of the details correctly than to expose the nuts and bolts to every driver. The thing that seems special to me about VFIO is that it is calling directly into dma-iommu code to setup unique mappings as opposed to using the higher level DMA API. I don't see in what way it is special that it needs to know intimate details of the memory it's mapping and have different paths to map different types of memory. That's what the dma layer is for. Logan