[RFC 3/7] vfio/pci: Pass the usable IOVA ranges through PCIIOMMUOps

Eric Auger posted 7 patches 10 months, 2 weeks ago
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Alex Williamson <alex.williamson@redhat.com>, "Cédric Le Goater" <clg@redhat.com>, Eric Auger <eric.auger@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Peter Xu <peterx@redhat.com>, David Hildenbrand <david@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
There is a newer version of this series
[RFC 3/7] vfio/pci: Pass the usable IOVA ranges through PCIIOMMUOps
Posted by Eric Auger 10 months, 2 weeks ago
Pass the collected usable IOVA regions using the PCIIOMMUOps
set_host_iova_ranges() callback, if implemented.

Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
 hw/vfio/pci.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index d7fe06715c..63937952bb 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2485,6 +2485,28 @@ int vfio_pci_get_pci_hot_reset_info(VFIOPCIDevice *vdev,
     return 0;
 }
 
+static int vfio_pci_set_iova_ranges(VFIOPCIDevice *vdev, Error **errp)
+{
+    VFIODevice *vbasedev = &vdev->vbasedev;
+    PCIDevice *pdev = &vdev->pdev;
+    VFIOContainerBase *bcontainer = vbasedev->bcontainer;
+    PCIBus *bus, *iommu_bus;
+
+    if (!bcontainer->iova_ranges) {
+        return 0;
+    }
+
+    bus = pci_get_bus(pdev);
+    iommu_bus = pci_device_iommu_bus(pdev);
+    if (iommu_bus && iommu_bus->iommu_ops &&
+        iommu_bus->iommu_ops->set_host_iova_ranges) {
+        return iommu_bus->iommu_ops->set_host_iova_ranges(
+                   bus, iommu_bus->iommu_opaque,
+                   pdev->devfn, bcontainer->iova_ranges, errp);
+    }
+    return 0;
+}
+
 static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single)
 {
     VFIODevice *vbasedev = &vdev->vbasedev;
@@ -3004,6 +3026,11 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
         goto error;
     }
 
+    ret = vfio_pci_set_iova_ranges(vdev, errp);
+    if (ret) {
+        goto error;
+    }
+
     vfio_populate_device(vdev, &err);
     if (err) {
         error_propagate(errp, err);
-- 
2.41.0