diff mbox series

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

Message ID 20240117080414.316890-4-eric.auger@redhat.com
State New
Headers show
Series VIRTIO-IOMMU/VFIO: Fix host iommu geometry handling for hotplugged devices | expand

Commit Message

Eric Auger Jan. 17, 2024, 8:02 a.m. UTC
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 mbox series

Patch

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);