Skip to content

Commit b1a1347

Browse files
krishnareddy-dvwilldeacon
authored andcommitted
iommu/arm-smmu: Fix race condition during iommu_group creation
When two devices with same SID are getting probed concurrently through iommu_probe_device(), the iommu_group sometimes is getting allocated more than once as call to arm_smmu_device_group() is not protected for concurrency. Furthermore, it leads to each device holding a different iommu_group and 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_group allocation from concurrency in arm_smmu_device_group(). Signed-off-by: Krishna Reddy <[email protected]> Signed-off-by: Ashish Mhetre <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 211ff31 commit b1a1347

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/iommu/arm/arm-smmu/arm-smmu.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,7 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev)
14781478
struct iommu_group *group = NULL;
14791479
int i, idx;
14801480

1481+
mutex_lock(&smmu->stream_map_mutex);
14811482
for_each_cfg_sme(cfg, fwspec, i, idx) {
14821483
if (group && smmu->s2crs[idx].group &&
14831484
group != smmu->s2crs[idx].group)
@@ -1486,8 +1487,10 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev)
14861487
group = smmu->s2crs[idx].group;
14871488
}
14881489

1489-
if (group)
1490+
if (group) {
1491+
mutex_unlock(&smmu->stream_map_mutex);
14901492
return iommu_group_ref_get(group);
1493+
}
14911494

14921495
if (dev_is_pci(dev))
14931496
group = pci_device_group(dev);
@@ -1501,6 +1504,7 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev)
15011504
for_each_cfg_sme(cfg, fwspec, i, idx)
15021505
smmu->s2crs[idx].group = group;
15031506

1507+
mutex_unlock(&smmu->stream_map_mutex);
15041508
return group;
15051509
}
15061510

0 commit comments

Comments
 (0)