Skip to contentSkip to conversation

iommu/vt-d: Fix PASID reference leak

PATCH In review Fenghua Yu 2 participants 3 messages Aug 13, 2021 – Aug 17, 2021

Subsystems (2)
lore
Share & tools
lore

Fenghua Yu

author
#0 lore raw

PATCH 1/1 iommu/vt-d: Fix PASID reference leak

A PASID reference is increased whenever a device is bound to an mm (and its PASID) successfully (i.e. the device's sdev user count is increased). But the reference is not dropped every time the device is unbound successfully from the mm (i.e. the device's sdev user count is decreased). The reference is dropped only once by calling intel_svm_free_pasid() when there isn't any device bound to the mm. intel_svm_free_pasid() drops the reference and only frees the PASID on zero reference.

Fix the issue by dropping the PASID reference and freeing the PASID when no reference on successful unbinding the device by calling intel_svm_free_pasid() .

---
 drivers/iommu/intel/svm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/intel/svm.c +2 -1
index 9b0f22bc0514..4b9b3f35ba0e 100644
@@ -675,7 +675,6 @@ static int intel_svm_unbind_mm(struct device *dev, u32 pasid)
 			kfree_rcu(sdev, rcu);
 
 			if (list_empty(&svm->devs)) {
-				intel_svm_free_pasid(mm);
 				if (svm->notifier.ops) {
 					mmu_notifier_unregister(&svm->notifier, mm);
 					/* Clear mm's pasid. */
@@ -690,6 +689,8 @@ static int intel_svm_unbind_mm(struct device *dev, u32 pasid)
 				kfree(svm);
 			}
 		}
+		/* Drop a PASID reference and free it if no reference. */
+		intel_svm_free_pasid(mm);
 	}
 out:
 	return ret;
Signature · 6 lines
2.32.0

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Fenghua Yu

A PASID reference is increased whenever a device is bound to an mm (and its PASID) successfully (i.e. the device's sdev user count is increased). But the reference is not dropped every time the device is unbound successfully from the mm (i.e. the device's sdev user count is decreased). The reference is dropped only once by calling intel_svm_free_pasid() when there isn't any device bound to the mm. intel_svm_free_pasid() drops the reference and only frees the PASID on zero reference.

Quoted 5 lines

Fix the issue by dropping the PASID reference and freeing the PASID when no reference on successful unbinding the device by calling intel_svm_free_pasid() .

Nice catch! Thanks!

Fixes 4048377414162 ("iommu/vt-d: Use iommu_sva_alloc(free)_pasid() helpers")

Best regards,
baolu

Quoted 18 lines
---
  drivers/iommu/intel/svm.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/intel/svm.c +0 -1
index 9b0f22bc0514..4b9b3f35ba0e 100644
@@ -675,7 +675,6 @@ static int intel_svm_unbind_mm(struct device *dev, u32 pasid)
  			kfree_rcu(sdev, rcu);
 
  			if (list_empty(&svm->devs)) {
-				intel_svm_free_pasid(mm);
  				if (svm->notifier.ops) {
  					mmu_notifier_unregister(&svm->notifier, mm);
  					/* Clear mm's pasid. */

drivers/iommu/intel/svm.c static int intel_svm_unbind_mm(struct device *dev, u32 pasid) · line 696

Quoted 8 lines
drivers/iommu/intel/svm.c +2 -0
@@ -690,6 +689,8 @@ static int intel_svm_unbind_mm(struct device *dev, u32 pasid)
  				kfree(svm);
  			}
  		}
+		/* Drop a PASID reference and free it if no reference. */
+		intel_svm_free_pasid(mm);
  	}
  out:
  	return ret;

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

maintainer
#2 lore raw
In reply to Fenghua Yu
Quoted 8 lines · Fenghua Yu

A PASID reference is increased whenever a device is bound to an mm (and its PASID) successfully (i.e. the device's sdev user count is increased). But the reference is not dropped every time the device is unbound successfully from the mm (i.e. the device's sdev user count is decreased). The reference is dropped only once by calling intel_svm_free_pasid() when there isn't any device bound to the mm. intel_svm_free_pasid() drops the reference and only frees the PASID on zero reference.

Quoted 5 lines

Fix the issue by dropping the PASID reference and freeing the PASID when no reference on successful unbinding the device by calling intel_svm_free_pasid() .

Patch has been queued for iommu/fix.

Best regards,
baolu
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu