On Wed, Jun 10, 2026 at 04:43:15PM +0100, Matt Evans wrote:
> The P2PDMA code currently provides two features under the same
> CONFIG_PCI_P2PDMA option:
> 
>  1.  Locate providers via pcim_p2pdma_provider()
>  2.  Manage actual P2P DMA
> 
> Some drivers (such as vfio-pci) depend on 1, without having a hard
> dependency on 2.
> 
> A future commit expands the use of DMABUF in vfio-pci for non-P2P
> scenarios, relying on pcim_p2pdma_provider() always being present.  If
> that depended on CONFIG_PCI_P2PDMA, it would make vfio-pci only
> available if CONFIG_ZONE_DEVICE is present (e.g. 64-bit systems), even
> when P2P is not needed.
> 
> To resolve this, introduce CONFIG_PCI_P2PDMA_CORE and refactor the
> basic provider functionality into a new p2pdma_core.c file.  This is
> available even if the CONFIG_PCI_P2PDMA feature is disabled (or
> unavailable due to !CONFIG_ZONE_DEVICE).  Then, drivers can enable any
> additional P2P features with the original CONFIG_PCI_P2PDMA (available
> when CONFIG_ZONE_DEVICE is set).
> 
> Signed-off-by: Matt Evans <[email protected]>

I thought this was going to be just a code move and new Kconfig
option, but it involves a little more than that, e.g., adding
pci_p2pdma_release_pool() and tweaking the RCU synchronization.

If possible, it would be nice to do that refactoring in a smaller
preliminary patch so it's easier to review/bisect/etc and make this
one a pure code move.

I guess CONFIG_PCI_P2PDMA_CORE selects just part 1 ("Locate providers
via pcim_p2pdma_provider()"), right?

> +++ b/drivers/pci/p2pdma.h
> @@ -0,0 +1,29 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * PCI Peer 2 Peer DMA support.
> + */
> +
> +#ifndef _PCI_P2PDMA_H
> +#define _PCI_P2PDMA_H
> +
> +#include <linux/genalloc.h>
> +#include <linux/pci-p2pdma.h>
> +#include <linux/xarray.h>
> +
> +struct pci_p2pdma {
> +     struct gen_pool *pool;
> +     bool p2pmem_published;
> +     struct xarray map_types;
> +     struct p2pdma_provider mem[PCI_STD_NUM_BARS];
> +};
> +
> +#ifdef CONFIG_PCI_P2PDMA
> +void pci_p2pdma_release_pool(struct pci_dev *pdev, struct pci_p2pdma 
> *p2pdma);
> +#else
> +static inline void pci_p2pdma_release_pool(struct pci_dev *pdev, struct 
> pci_p2pdma *p2pdma)

Wrap to fit in 80 columns like the rest of drivers/pci/

> +{
> +}
> +#endif
> +
> +#endif
> +

Spurious blank line at end.

> +++ b/drivers/pci/p2pdma_core.c
> @@ -0,0 +1,118 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * PCI Peer 2 Peer DMA support core, providing a bare-bones

In this English text, I think I would spell out "Peer to Peer" instead
of relying on the "2" homophone.  Same in p2pdma.h.

Reply via email to