Skip to content

Commit 211ff31

Browse files
ashishmhetre8willdeacon
authored andcommitted
iommu: Fix race condition during default domain allocation
When two devices with same SID are getting probed concurrently through iommu_probe_device(), the iommu_domain sometimes is getting allocated more than once as call to iommu_alloc_default_domain() is not protected for concurrency. Furthermore, it leads to each device holding a different iommu_domain pointer, separate IOVA space and only one of the devices' domain is used for translations from IOMMU. This causes accesses from other device to fault or see incorrect translations. Fix this by protecting iommu_alloc_default_domain() call with group->mutex and let all devices with same SID share same iommu_domain. Signed-off-by: Ashish Mhetre <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent afefe67 commit 211ff31

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/iommu/iommu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,9 @@ int iommu_probe_device(struct device *dev)
273273
* support default domains, so the return value is not yet
274274
* checked.
275275
*/
276+
mutex_lock(&group->mutex);
276277
iommu_alloc_default_domain(group, dev);
278+
mutex_unlock(&group->mutex);
277279

278280
if (group->default_domain) {
279281
ret = __iommu_attach_device(group->default_domain, dev);

0 commit comments

Comments
 (0)