Re: [PATCH v5 1/9] PCI/P2PDMA: Separate the mmap() support from the core logic

Christoph Hellwig
2025-10-20T12:27:11Z

On Fri, Oct 17, 2025 at 08:53:20AM -0300, Jason Gunthorpe wrote:
> On Thu, Oct 16, 2025 at 11:30:06PM -0700, Christoph Hellwig wrote:
> > On Mon, Oct 13, 2025 at 06:26:03PM +0300, Leon Romanovsky wrote:
> > > The DMA API now has a new flow, and has gained phys_addr_t support, so
> > > it no longer needs struct pages to perform P2P mapping.
> >
> > That's news to me. All the pci_p2pdma_map_state machinery is still
> > based on pgmaps and thus pages.
>
> We had this discussion already three months ago:
>
> https://lore.kernel.org/all/20250729131502.GJ36037@nvidia.com/
>
> These couple patches make the core pci_p2pdma_map_state machinery work
> on struct p2pdma_provider, and pgmap is just one way to get a
> p2pdma_provider *
>
> The struct page paths through pgmap go page->pgmap->mem to get
> p2pdma_provider.
>
> The non-struct page paths just have a p2pdma_provider * without a
> pgmap. In this series VFIO uses
>
> + *provider = pcim_p2pdma_provider(pdev, bar);
>
> To get the provider for a specific BAR.

And what protects that life time? I've not seen anyone actually
building the proper lifetime management. And if someone did the patches
need to clearly point to that.

> I think I've answered this three times now - for DMABUF the DMABUF
> invalidation scheme is used to control the lifetime and no DMA mapping
> outlives the provider, and the provider doesn't outlive the driver.

How?

> Obviously you cannot use the new p2provider mechanism without some
> kind of protection against use after hot unplug, but it doesn't have
> to be struct page based.

And how does this interact with everyone else expecting pgmap based
lifetime management.