120 lines
4.5 KiB
Diff
120 lines
4.5 KiB
Diff
|
|
From db8ef4524568c2379c25986db6e30cb0f6c0ec05 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Joao Martins <joao.m.martins@oracle.com>
|
||
|
|
Date: Mon, 22 Jul 2024 22:13:22 +0100
|
||
|
|
Subject: [PATCH] vfio/iommufd: Probe and request hwpt dirty tracking
|
||
|
|
capability
|
||
|
|
MIME-Version: 1.0
|
||
|
|
Content-Type: text/plain; charset=UTF-8
|
||
|
|
Content-Transfer-Encoding: 8bit
|
||
|
|
|
||
|
|
In preparation to using the dirty tracking UAPI, probe whether the IOMMU
|
||
|
|
supports dirty tracking. This is done via the data stored in
|
||
|
|
hiod::caps::hw_caps initialized from GET_HW_INFO.
|
||
|
|
|
||
|
|
Qemu doesn't know if VF dirty tracking is supported when allocating
|
||
|
|
hardware pagetable in iommufd_cdev_autodomains_get(). This is because
|
||
|
|
VFIODevice migration state hasn't been initialized *yet* hence it can't pick
|
||
|
|
between VF dirty tracking vs IOMMU dirty tracking. So, if IOMMU supports
|
||
|
|
dirty tracking it always creates HWPTs with IOMMU_HWPT_ALLOC_DIRTY_TRACKING
|
||
|
|
even if later on VFIOMigration decides to use VF dirty tracking instead.
|
||
|
|
|
||
|
|
Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
|
||
|
|
[ clg: - Fixed vbasedev->iommu_dirty_tracking assignment in
|
||
|
|
iommufd_cdev_autodomains_get()
|
||
|
|
- Added warning for heterogeneous dirty page tracking support
|
||
|
|
in iommufd_cdev_autodomains_get() ]
|
||
|
|
Signed-off-by: Cédric Le Goater <clg@redhat.com>
|
||
|
|
Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
|
||
|
|
---
|
||
|
|
hw/vfio/iommufd.c | 26 ++++++++++++++++++++++++++
|
||
|
|
include/hw/vfio/vfio-common.h | 2 ++
|
||
|
|
2 files changed, 28 insertions(+)
|
||
|
|
|
||
|
|
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
|
||
|
|
index 8fd6826826..a9400d8107 100644
|
||
|
|
--- a/hw/vfio/iommufd.c
|
||
|
|
+++ b/hw/vfio/iommufd.c
|
||
|
|
@@ -114,6 +114,11 @@ static void iommufd_cdev_unbind_and_disconnect(VFIODevice *vbasedev)
|
||
|
|
iommufd_backend_disconnect(vbasedev->iommufd);
|
||
|
|
}
|
||
|
|
|
||
|
|
+static bool iommufd_hwpt_dirty_tracking(VFIOIOASHwpt *hwpt)
|
||
|
|
+{
|
||
|
|
+ return hwpt && hwpt->hwpt_flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING;
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
static int iommufd_cdev_getfd(const char *sysfs_path, Error **errp)
|
||
|
|
{
|
||
|
|
long int ret = -ENOTTY;
|
||
|
|
@@ -256,10 +261,22 @@ static int iommufd_cdev_autodomains_get(VFIODevice *vbasedev,
|
||
|
|
} else {
|
||
|
|
vbasedev->hwpt = hwpt;
|
||
|
|
QLIST_INSERT_HEAD(&hwpt->device_list, vbasedev, hwpt_next);
|
||
|
|
+ vbasedev->iommu_dirty_tracking = iommufd_hwpt_dirty_tracking(hwpt);
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
+ /*
|
||
|
|
+ * This is quite early and VFIO Migration state isn't yet fully
|
||
|
|
+ * initialized, thus rely only on IOMMU hardware capabilities as to
|
||
|
|
+ * whether IOMMU dirty tracking is going to be requested. Later
|
||
|
|
+ * vfio_migration_realize() may decide to use VF dirty tracking
|
||
|
|
+ * instead.
|
||
|
|
+ */
|
||
|
|
+ if (vbasedev->hiod->caps.hw_caps & IOMMU_HW_CAP_DIRTY_TRACKING) {
|
||
|
|
+ flags = IOMMU_HWPT_ALLOC_DIRTY_TRACKING;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
if (!iommufd_backend_alloc_hwpt(iommufd, vbasedev->devid,
|
||
|
|
container->ioas_id, flags,
|
||
|
|
IOMMU_HWPT_DATA_NONE, 0, NULL,
|
||
|
|
@@ -269,6 +286,7 @@ static int iommufd_cdev_autodomains_get(VFIODevice *vbasedev,
|
||
|
|
|
||
|
|
hwpt = g_malloc0(sizeof(*hwpt));
|
||
|
|
hwpt->hwpt_id = hwpt_id;
|
||
|
|
+ hwpt->hwpt_flags = flags;
|
||
|
|
QLIST_INIT(&hwpt->device_list);
|
||
|
|
|
||
|
|
ret = iommufd_cdev_attach_ioas_hwpt(vbasedev, hwpt->hwpt_id, errp);
|
||
|
|
@@ -279,8 +297,16 @@ static int iommufd_cdev_autodomains_get(VFIODevice *vbasedev,
|
||
|
|
}
|
||
|
|
|
||
|
|
vbasedev->hwpt = hwpt;
|
||
|
|
+ vbasedev->iommu_dirty_tracking = iommufd_hwpt_dirty_tracking(hwpt);
|
||
|
|
QLIST_INSERT_HEAD(&hwpt->device_list, vbasedev, hwpt_next);
|
||
|
|
QLIST_INSERT_HEAD(&container->hwpt_list, hwpt, next);
|
||
|
|
+ container->bcontainer.dirty_pages_supported |=
|
||
|
|
+ vbasedev->iommu_dirty_tracking;
|
||
|
|
+ if (container->bcontainer.dirty_pages_supported &&
|
||
|
|
+ !vbasedev->iommu_dirty_tracking) {
|
||
|
|
+ warn_report("IOMMU instance for device %s doesn't support dirty tracking",
|
||
|
|
+ vbasedev->name);
|
||
|
|
+ }
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
|
||
|
|
index 63da291456..22a7386591 100644
|
||
|
|
--- a/include/hw/vfio/vfio-common.h
|
||
|
|
+++ b/include/hw/vfio/vfio-common.h
|
||
|
|
@@ -109,6 +109,7 @@ typedef struct IOMMUFDBackend IOMMUFDBackend;
|
||
|
|
|
||
|
|
typedef struct VFIOIOASHwpt {
|
||
|
|
uint32_t hwpt_id;
|
||
|
|
+ uint32_t hwpt_flags;
|
||
|
|
QLIST_HEAD(, VFIODevice) device_list;
|
||
|
|
QLIST_ENTRY(VFIOIOASHwpt) next;
|
||
|
|
} VFIOIOASHwpt;
|
||
|
|
@@ -148,6 +149,7 @@ typedef struct VFIODevice {
|
||
|
|
OnOffAuto pre_copy_dirty_page_tracking;
|
||
|
|
bool dirty_pages_supported;
|
||
|
|
bool dirty_tracking;
|
||
|
|
+ bool iommu_dirty_tracking;
|
||
|
|
HostIOMMUDevice *hiod;
|
||
|
|
int devid;
|
||
|
|
IOMMUFDBackend *iommufd;
|
||
|
|
--
|
||
|
|
2.41.0.windows.1
|
||
|
|
|