diff mbox series

[rc,7/8] iommu/vt-d: Wrap the dirty tracking loop to be a helper

Message ID 20240208082307.15759-8-yi.l.liu@intel.com (mailing list archive)
State Accepted
Commit 0c7f2497b39da44253d7bcf2b41f52b0048859ad
Headers show
Series Add missing cache flush and dirty tracking set for nested parent domain | expand

Commit Message

Yi Liu Feb. 8, 2024, 8:23 a.m. UTC
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>
---
 drivers/iommu/intel/iommu.c | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

Comments

Tian, Kevin Feb. 8, 2024, 8:45 a.m. UTC | #1
> From: Liu, Yi L <yi.l.liu@intel.com>
> Sent: Thursday, February 8, 2024 4:23 PM
> 
> 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>
Joao Martins Feb. 8, 2024, 10:29 a.m. UTC | #2
On 08/02/2024 08:23, Yi Liu wrote:
> 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>

Nice cleanup,

Reviewed-by: Joao Martins <joao.m.martins@oracle.com>

> ---
>  drivers/iommu/intel/iommu.c | 32 +++++++++++++++++++++-----------
>  1 file changed, 21 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
> index dae20991e036..7636d3f03905 100644
> --- a/drivers/iommu/intel/iommu.c
> +++ b/drivers/iommu/intel/iommu.c
> @@ -4730,23 +4730,35 @@ static void *intel_iommu_hw_info(struct device *dev, u32 *length, u32 *type)
>  	return vtd;
>  }
>  
> +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:
> @@ -4755,10 +4767,8 @@ static int intel_iommu_set_dirty_tracking(struct iommu_domain *domain,
>  	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;
>  }
Baolu Lu Feb. 9, 2024, 2:40 a.m. UTC | #3
On 2024/2/8 16:23, Yi Liu wrote:
> --- a/drivers/iommu/intel/iommu.c
> +++ b/drivers/iommu/intel/iommu.c
> @@ -4730,23 +4730,35 @@ static void *intel_iommu_hw_info(struct device *dev, u32 *length, u32 *type)
>   	return vtd;
>   }
>   
> +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;
> +}

Let's make this helper specific. Something like below.

/*
  * Set dirty tracking for the device list of a domain. The caller must
  * hold the domain->lock when calling it.
  */
static int device_list_set_dirty_tracking(...)

Best regards,
baolu
diff mbox series

Patch

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index dae20991e036..7636d3f03905 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -4730,23 +4730,35 @@  static void *intel_iommu_hw_info(struct device *dev, u32 *length, u32 *type)
 	return vtd;
 }
 
+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:
@@ -4755,10 +4767,8 @@  static int intel_iommu_set_dirty_tracking(struct iommu_domain *domain,
 	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;
 }