Skip to contentSkip to conversation

iommu: Extend mutex lock scope in iommu_probe_device()

PATCH Applied Lu Baolu 2 participants 2 messages Nov 8, 2021 – Dec 6, 2021 IOMMU

lore
Share & tools
lore

Lu Baolu

author
#0 lore raw

PATCH 1/1 iommu: Extend mutex lock scope in iommu_probe_device()

Extend the scope of holding group->mutex so that it can cover the default domain check/attachment and direct mappings of reserved regions.

Cc Ashish Mhetre <[email protected]>
Fixes 211ff31b3d33b ("iommu: Fix race condition during default domain allocation")
---
 drivers/iommu/iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/iommu.c +2 -1
index dd7863e453a5..8b86406b7162 100644
@@ -288,11 +288,11 @@ int iommu_probe_device(struct device *dev)
 	 */
 	mutex_lock(&group->mutex);
 	iommu_alloc_default_domain(group, dev);
-	mutex_unlock(&group->mutex);
 
 	if (group->default_domain) {
 		ret = __iommu_attach_device(group->default_domain, dev);
 		if (ret) {
+			mutex_unlock(&group->mutex);
 			iommu_group_put(group);
 			goto err_release;
 		}
@@ -300,6 +300,7 @@ int iommu_probe_device(struct device *dev)
 
 	iommu_create_device_direct_mappings(group, dev);
 
+	mutex_unlock(&group->mutex);
 	iommu_group_put(group);
 
 	if (ops->probe_finalize)
Signature · 6 lines
2.25.1

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
maintainer Applied
#1 lore raw
Quoted 9 lines · Lu Baolu

Extend the scope of holding group->mutex so that it can cover the default domain check/attachment and direct mappings of reserved regions.

Cc Ashish Mhetre <[email protected]>
Fixes 211ff31b3d33b ("iommu: Fix race condition during default domain allocation")
---
 drivers/iommu/iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Applied, thanks. The __iommu_attach_device() function is called under group->mutex everywhere else, so it makes here too.

Regards,

Joerg