diff mbox series

[V2,1/2] iommu: Fix race condition during default domain allocation

Message ID 1623961837-12540-2-git-send-email-amhetre@nvidia.com (mailing list archive)
State New, archived
Headers show
Series iommu/arm-smmu: Fix races in iommu domain/group creation | expand

Commit Message

Ashish Mhetre June 17, 2021, 8:30 p.m. UTC
Domain is getting created more than once during asynchronous multiple
display heads(devices) probe. All the display heads share same SID and
are expected to be in same domain. As iommu_alloc_default_domain() call
is not protected, it ends up in creating two domains for two display
devices which should ideally be in same domain.
iommu_alloc_default_domain() checks whether domain is already allocated for
given iommu group, but due to this race the check condition is failing and
two different domains are getting created.
This is leading to context faults when one device is accessing the IOVA
mapped by other device.
Fix this by protecting iommu_alloc_default_domain() call with group->mutex.
With this fix serialization will happen only for the devices sharing same
group. Also, only first device in group will hold the mutex till group is
created and for rest of the devices it will just check for existing domain
and then release the mutex.

Signed-off-by: Ashish Mhetre <amhetre@nvidia.com>
Changes since V1:
- Update the commit message per Will's suggestion

 drivers/iommu/iommu.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series


diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 808ab70..2700500 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -273,7 +273,9 @@  int iommu_probe_device(struct device *dev)
 	 * support default domains, so the return value is not yet
 	 * checked.
+	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);