iommu/vt-d: Fix PASID reference leak
Subsystems (2)
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
@@ -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
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().Signed-off-by Fenghua Yu <[email protected]>
Nice catch! Thanks!
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@@ -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
Lu Baolu
maintainerQuoted 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().Signed-off-by Fenghua Yu<[email protected]>
Patch has been queued for iommu/fix.
Best regards,
baolu
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu