Skip to content

Commit 0c7f249

Browse files
yiliu1765joergroedel
authored andcommitted
iommu/vt-d: Wrap the dirty tracking loop to be a helper
Add device_set_dirty_tracking() to loop all the devices and set the dirty tracking per the @enable parameter. Signed-off-by: Yi Liu <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Joao Martins <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lu Baolu <[email protected]> Signed-off-by: Joerg Roedel <[email protected]>
1 parent 56ecaf6 commit 0c7f249

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4729,23 +4729,38 @@ static void *intel_iommu_hw_info(struct device *dev, u32 *length, u32 *type)
47294729
return vtd;
47304730
}
47314731

4732+
/*
4733+
* Set dirty tracking for the device list of a domain. The caller must
4734+
* hold the domain->lock when calling it.
4735+
*/
4736+
static int device_set_dirty_tracking(struct list_head *devices, bool enable)
4737+
{
4738+
struct device_domain_info *info;
4739+
int ret = 0;
4740+
4741+
list_for_each_entry(info, devices, link) {
4742+
ret = intel_pasid_setup_dirty_tracking(info->iommu, info->dev,
4743+
IOMMU_NO_PASID, enable);
4744+
if (ret)
4745+
break;
4746+
}
4747+
4748+
return ret;
4749+
}
4750+
47324751
static int intel_iommu_set_dirty_tracking(struct iommu_domain *domain,
47334752
bool enable)
47344753
{
47354754
struct dmar_domain *dmar_domain = to_dmar_domain(domain);
4736-
struct device_domain_info *info;
47374755
int ret;
47384756

47394757
spin_lock(&dmar_domain->lock);
47404758
if (dmar_domain->dirty_tracking == enable)
47414759
goto out_unlock;
47424760

4743-
list_for_each_entry(info, &dmar_domain->devices, link) {
4744-
ret = intel_pasid_setup_dirty_tracking(info->iommu, info->dev,
4745-
IOMMU_NO_PASID, enable);
4746-
if (ret)
4747-
goto err_unwind;
4748-
}
4761+
ret = device_set_dirty_tracking(&dmar_domain->devices, enable);
4762+
if (ret)
4763+
goto err_unwind;
47494764

47504765
dmar_domain->dirty_tracking = enable;
47514766
out_unlock:
@@ -4754,10 +4769,8 @@ static int intel_iommu_set_dirty_tracking(struct iommu_domain *domain,
47544769
return 0;
47554770

47564771
err_unwind:
4757-
list_for_each_entry(info, &dmar_domain->devices, link)
4758-
intel_pasid_setup_dirty_tracking(info->iommu, info->dev,
4759-
IOMMU_NO_PASID,
4760-
dmar_domain->dirty_tracking);
4772+
device_set_dirty_tracking(&dmar_domain->devices,
4773+
dmar_domain->dirty_tracking);
47614774
spin_unlock(&dmar_domain->lock);
47624775
return ret;
47634776
}

0 commit comments

Comments
 (0)