iommu/vt-d: Wrap the dirty tracking loop to be a helper
authorYi Liu <yi.l.liu@intel.com>
Mon, 19 Feb 2024 11:15:58 +0000 (19:15 +0800)
committerJoerg Roedel <jroedel@suse.de>
Wed, 21 Feb 2024 09:28:47 +0000 (10:28 +0100)
Add device_set_dirty_tracking() to loop all the devices and set the dirty
tracking per the @enable parameter.

Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Joao Martins <joao.m.martins@oracle.com>
Link: https://lore.kernel.org/r/20240208082307.15759-8-yi.l.liu@intel.com
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/intel/iommu.c

index d286b8554227112ad31171cd3291c7d724057b88..2ad8fbe6dc210eb9261df72bb206ed3a537f2926 100644 (file)
@@ -4729,23 +4729,38 @@ static void *intel_iommu_hw_info(struct device *dev, u32 *length, u32 *type)
        return vtd;
 }
 
+/*
+ * Set dirty tracking for the device list of a domain. The caller must
+ * hold the domain->lock when calling it.
+ */
+static int device_set_dirty_tracking(struct list_head *devices, bool enable)
+{
+       struct device_domain_info *info;
+       int ret = 0;
+
+       list_for_each_entry(info, devices, link) {
+               ret = intel_pasid_setup_dirty_tracking(info->iommu, info->dev,
+                                                      IOMMU_NO_PASID, enable);
+               if (ret)
+                       break;
+       }
+
+       return ret;
+}
+
 static int intel_iommu_set_dirty_tracking(struct iommu_domain *domain,
                                          bool enable)
 {
        struct dmar_domain *dmar_domain = to_dmar_domain(domain);
-       struct device_domain_info *info;
        int ret;
 
        spin_lock(&dmar_domain->lock);
        if (dmar_domain->dirty_tracking == enable)
                goto out_unlock;
 
-       list_for_each_entry(info, &dmar_domain->devices, link) {
-               ret = intel_pasid_setup_dirty_tracking(info->iommu, info->dev,
-                                                      IOMMU_NO_PASID, enable);
-               if (ret)
-                       goto err_unwind;
-       }
+       ret = device_set_dirty_tracking(&dmar_domain->devices, enable);
+       if (ret)
+               goto err_unwind;
 
        dmar_domain->dirty_tracking = enable;
 out_unlock:
@@ -4754,10 +4769,8 @@ out_unlock:
        return 0;
 
 err_unwind:
-       list_for_each_entry(info, &dmar_domain->devices, link)
-               intel_pasid_setup_dirty_tracking(info->iommu, info->dev,
-                                                IOMMU_NO_PASID,
-                                                dmar_domain->dirty_tracking);
+       device_set_dirty_tracking(&dmar_domain->devices,
+                                 dmar_domain->dirty_tracking);
        spin_unlock(&dmar_domain->lock);
        return ret;
 }