@@ -2900,6 +2900,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
VFIOPCIDevice *vdev = VFIO_PCI(pdev);
VFIODevice *vbasedev = &vdev->vbasedev;
VFIODevice *vbasedev_iter;
+ VFIOAddressSpace *space;
VFIOGroup *group;
char *tmp, *subsys, group_path[PATH_MAX], *group_name;
Error *err = NULL;
@@ -2961,6 +2962,9 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
goto error;
}
+ space = group->container->space;
+ space->iommu_mr = pci_device_iommu_memory_region(pdev);
+
QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
if (strcmp(vbasedev_iter->name, vbasedev->name) == 0) {
error_setg(errp, "device is already attached");
@@ -70,6 +70,7 @@ typedef struct VFIOMigration {
typedef struct VFIOAddressSpace {
AddressSpace *as;
+ IOMMUMemoryRegion *iommu_mr;
QLIST_HEAD(, VFIOContainer) containers;
QLIST_ENTRY(VFIOAddressSpace) list;
} VFIOAddressSpace;
vfio_get_group() allocates and fills the group/container/space on success which will store the AddressSpace inside the VFIOSpace struct. Use the newly added pci_device_iommu_memory_region() and store the IOMMU MR too. Today, this means only intel-iommu sets it. Signed-off-by: Joao Martins <joao.m.martins@oracle.com> --- hw/vfio/pci.c | 4 ++++ include/hw/vfio/vfio-common.h | 1 + 2 files changed, 5 insertions(+)