[1/7] iommu/vt-d: Allocate pasid table in device probe path

Message ID 20221103055329.633052-2-baolu.lu@linux.intel.com
State New
Headers
Series iommu/vt-d: Some cleanups |

Commit Message

Baolu Lu Nov. 3, 2022, 5:53 a.m. UTC
  Whether or not a domain is attached to the device, the pasid table should
always be valid as long as it has been probed. This moves the pasid table
allocation from the domain attaching device path to device probe path and
frees it in the device release path.

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel/iommu.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
  

Comments

Tian, Kevin Nov. 4, 2022, 2:06 a.m. UTC | #1
> From: Lu Baolu <baolu.lu@linux.intel.com>
> Sent: Thursday, November 3, 2022 1:53 PM
> 
> @@ -4513,6 +4506,16 @@ static struct iommu_device
> *intel_iommu_probe_device(struct device *dev)
> 
>  	dev_iommu_priv_set(dev, info);
> 
> +	if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev)) {
> +		ret = intel_pasid_alloc_table(dev);
> +		if (ret) {
> +			dev_err(dev, "PASID table allocation failed\n");
> +			dev_iommu_priv_set(dev, NULL);
> +			kfree(info);
> +			return ERR_PTR(ret);
> +		}
> +	}
> +

move the added lines before dev_iommu_priv_set()
  
Baolu Lu Nov. 5, 2022, 1:09 a.m. UTC | #2
On 2022/11/4 10:06, Tian, Kevin wrote:
>> From: Lu Baolu <baolu.lu@linux.intel.com>
>> Sent: Thursday, November 3, 2022 1:53 PM
>>
>> @@ -4513,6 +4506,16 @@ static struct iommu_device
>> *intel_iommu_probe_device(struct device *dev)
>>
>>   	dev_iommu_priv_set(dev, info);
>>
>> +	if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev)) {
>> +		ret = intel_pasid_alloc_table(dev);
>> +		if (ret) {
>> +			dev_err(dev, "PASID table allocation failed\n");
>> +			dev_iommu_priv_set(dev, NULL);
>> +			kfree(info);
>> +			return ERR_PTR(ret);
>> +		}
>> +	}
>> +
> 
> move the added lines before dev_iommu_priv_set()

intel_pasid_alloc_table() needs to reference info and store the pasid
table into it.

Best regards,
baolu
  
Tian, Kevin Nov. 5, 2022, 1:33 a.m. UTC | #3
> From: Baolu Lu <baolu.lu@linux.intel.com>
> Sent: Saturday, November 5, 2022 9:10 AM
> 
> On 2022/11/4 10:06, Tian, Kevin wrote:
> >> From: Lu Baolu <baolu.lu@linux.intel.com>
> >> Sent: Thursday, November 3, 2022 1:53 PM
> >>
> >> @@ -4513,6 +4506,16 @@ static struct iommu_device
> >> *intel_iommu_probe_device(struct device *dev)
> >>
> >>   	dev_iommu_priv_set(dev, info);
> >>
> >> +	if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev)) {
> >> +		ret = intel_pasid_alloc_table(dev);
> >> +		if (ret) {
> >> +			dev_err(dev, "PASID table allocation failed\n");
> >> +			dev_iommu_priv_set(dev, NULL);
> >> +			kfree(info);
> >> +			return ERR_PTR(ret);
> >> +		}
> >> +	}
> >> +
> >
> > move the added lines before dev_iommu_priv_set()
> 
> intel_pasid_alloc_table() needs to reference info and store the pasid
> table into it.
> 

Yes, I overlooked it.

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
  

Patch

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index a934a46bb9e6..e28faba1095f 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -2477,13 +2477,6 @@  static int domain_add_dev_info(struct dmar_domain *domain, struct device *dev)
 
 	/* PASID table is mandatory for a PCI device in scalable mode. */
 	if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev)) {
-		ret = intel_pasid_alloc_table(dev);
-		if (ret) {
-			dev_err(dev, "PASID table allocation failed\n");
-			dmar_remove_one_dev_info(dev);
-			return ret;
-		}
-
 		/* Setup the PASID entry for requests without PASID: */
 		if (hw_pass_through && domain_type_is_si(domain))
 			ret = intel_pasid_setup_pass_through(iommu, domain,
@@ -4108,7 +4101,6 @@  static void dmar_remove_one_dev_info(struct device *dev)
 
 		iommu_disable_dev_iotlb(info);
 		domain_context_clear(info);
-		intel_pasid_free_table(info->dev);
 	}
 
 	spin_lock_irqsave(&domain->lock, flags);
@@ -4470,6 +4462,7 @@  static struct iommu_device *intel_iommu_probe_device(struct device *dev)
 	struct device_domain_info *info;
 	struct intel_iommu *iommu;
 	u8 bus, devfn;
+	int ret;
 
 	iommu = device_to_iommu(dev, &bus, &devfn);
 	if (!iommu || !iommu->iommu.ops)
@@ -4513,6 +4506,16 @@  static struct iommu_device *intel_iommu_probe_device(struct device *dev)
 
 	dev_iommu_priv_set(dev, info);
 
+	if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev)) {
+		ret = intel_pasid_alloc_table(dev);
+		if (ret) {
+			dev_err(dev, "PASID table allocation failed\n");
+			dev_iommu_priv_set(dev, NULL);
+			kfree(info);
+			return ERR_PTR(ret);
+		}
+	}
+
 	return &iommu->iommu;
 }
 
@@ -4521,6 +4524,7 @@  static void intel_iommu_release_device(struct device *dev)
 	struct device_domain_info *info = dev_iommu_priv_get(dev);
 
 	dmar_remove_one_dev_info(dev);
+	intel_pasid_free_table(dev);
 	dev_iommu_priv_set(dev, NULL);
 	kfree(info);
 	set_dma_ops(dev, NULL);