From: David Woodhouse <[email protected]>

The dma-buf phys-map dispatch used by iommufd's IOMMU_IOAS_MAP_FILE path
currently knows only about the VFIO PCI exporter (looked up via
symbol_get(vfio_pci_dma_buf_iommufd_map)).  Widen the dispatch so
additional exporters can advertise the same well-known symbol name
convention and have their dma-bufs mapped without an explicit iommufd
dependency in each exporter's module.

For now the dispatch tries the sample guest_memfd provider's exporter
first, then falls back to VFIO PCI, both via symbol_get.  This mirrors
the pattern the in-tree comment already flags:

        "iommufd and vfio have a circular dependency.  Future work for a
         phys based private interconnect will remove this."

The eventual formal negotiated dma_buf_ops op that returns phys plus a
memory-type descriptor will subsume both of these lookups.  The next
patch plumbs the memory type through iommufd; a follow-up will convert
the symbol lookups to the negotiated op.

Based on a proof-of-concept by Connor Williamson <[email protected]>

Signed-off-by: David Woodhouse (Kiro) <[email protected]>
---
 drivers/iommu/iommufd/pages.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/iommu/iommufd/pages.c b/drivers/iommu/iommufd/pages.c
index 03c8379bbc34..2d4ea41460fd 100644
--- a/drivers/iommu/iommufd/pages.c
+++ b/drivers/iommu/iommufd/pages.c
@@ -1470,6 +1470,26 @@ sym_vfio_pci_dma_buf_iommufd_map(struct 
dma_buf_attachment *attachment,
        if (rc != -EOPNOTSUPP)
                return rc;
 
+       /*
+        * Prototype: try the sample gmem provider's dma-buf exporter.  This
+        * mirrors the vfio-pci private-interconnect hook, and (like it) is
+        * meant to be replaced by a formal negotiated exporter op returning
+        * phys for iommufd.
+        */
+       {
+               extern int gmem_provider_dma_buf_iommufd_map(
+                       struct dma_buf_attachment *, struct phys_vec *);
+               typeof(&gmem_provider_dma_buf_iommufd_map) gfn;
+
+               gfn = symbol_get(gmem_provider_dma_buf_iommufd_map);
+               if (gfn) {
+                       rc = gfn(attachment, phys);
+                       symbol_put(gmem_provider_dma_buf_iommufd_map);
+                       if (rc != -EOPNOTSUPP)
+                               return rc;
+               }
+       }
+
        if (!IS_ENABLED(CONFIG_VFIO_PCI_DMABUF))
                return -EOPNOTSUPP;
 
-- 
2.54.0

Reply via email to