@@ -43,6 +43,7 @@
#include "migration/blocker.h"
#include "migration/qemu-file.h"
#include "linux/iommufd.h"
+#include "sysemu/iommufd.h"
#define TYPE_VFIO_PCI_NOHOTPLUG "vfio-pci-nohotplug"
@@ -3175,6 +3176,15 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
char uuid[UUID_FMT_LEN];
char *name;
+#ifdef CONFIG_IOMMUFD
+ if (vbasedev->iommufd) {
+ iommufd_backend_connect(vbasedev->iommufd, errp);
+ if (*errp) {
+ return;
+ }
+ }
+#endif
+
if (!vbasedev->sysfsdev) {
if (!(~vdev->host.domain || ~vdev->host.bus ||
~vdev->host.slot || ~vdev->host.function)) {
@@ -3470,6 +3480,9 @@ error:
static void vfio_instance_finalize(Object *obj)
{
VFIOPCIDevice *vdev = VFIO_PCI(obj);
+#ifdef CONFIG_IOMMUFD
+ VFIODevice *vbasedev = &vdev->vbasedev;
+#endif
vfio_display_finalize(vdev);
vfio_bars_finalize(vdev);
@@ -3483,6 +3496,11 @@ static void vfio_instance_finalize(Object *obj)
* g_free(vdev->igd_opregion);
*/
vfio_put_device(vdev);
+#ifdef CONFIG_IOMMUFD
+ if (vbasedev->iommufd) {
+ iommufd_backend_disconnect(vbasedev->iommufd);
+ }
+#endif
}
static void vfio_exitfn(PCIDevice *pdev)
@@ -3609,11 +3627,10 @@ static Property vfio_pci_dev_properties[] = {
qdev_prop_nv_gpudirect_clique, uint8_t),
DEFINE_PROP_OFF_AUTO_PCIBAR("x-msix-relocation", VFIOPCIDevice, msix_relo,
OFF_AUTOPCIBAR_OFF),
- /*
- * TODO - support passed fds... is this necessary?
- * DEFINE_PROP_STRING("vfiofd", VFIOPCIDevice, vfiofd_name),
- * DEFINE_PROP_STRING("vfiogroupfd, VFIOPCIDevice, vfiogroupfd_name),
- */
+#ifdef CONFIG_IOMMUFD
+ DEFINE_PROP_LINK("iommufd", VFIOPCIDevice, vbasedev.iommufd,
+ TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *),
+#endif
DEFINE_PROP_END_OF_LIST(),
};