Skip to content

Commit 70b8170

Browse files
committed
iommu: Don't call .probe_finalize() under group->mutex
The .probe_finalize() call-back of some IOMMU drivers calls into arm_iommu_attach_device(). This function will call back into the IOMMU core code, where it tries to take group->mutex again, resulting in a deadlock. As there is no reason why .probe_finalize() needs to be called under that mutex, move it after the lock has been released to fix the deadlock. Fixes: deac0b3 ("iommu: Split off default domain allocation from group assignment") Reported-by: Yong Wu <[email protected]> Tested-by: Yong Wu <[email protected]> Signed-off-by: Joerg Roedel <[email protected]> Cc: Yong Wu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 2bc61fb commit 70b8170

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

drivers/iommu/iommu.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,17 +1674,8 @@ static void probe_alloc_default_domain(struct bus_type *bus,
16741674
static int iommu_group_do_dma_attach(struct device *dev, void *data)
16751675
{
16761676
struct iommu_domain *domain = data;
1677-
const struct iommu_ops *ops;
1678-
int ret;
1679-
1680-
ret = __iommu_attach_device(domain, dev);
1681-
1682-
ops = domain->ops;
1683-
1684-
if (ret == 0 && ops->probe_finalize)
1685-
ops->probe_finalize(dev);
16861677

1687-
return ret;
1678+
return __iommu_attach_device(domain, dev);
16881679
}
16891680

16901681
static int __iommu_group_dma_attach(struct iommu_group *group)
@@ -1693,6 +1684,21 @@ static int __iommu_group_dma_attach(struct iommu_group *group)
16931684
iommu_group_do_dma_attach);
16941685
}
16951686

1687+
static int iommu_group_do_probe_finalize(struct device *dev, void *data)
1688+
{
1689+
struct iommu_domain *domain = data;
1690+
1691+
if (domain->ops->probe_finalize)
1692+
domain->ops->probe_finalize(dev);
1693+
1694+
return 0;
1695+
}
1696+
1697+
static void __iommu_group_dma_finalize(struct iommu_group *group)
1698+
{
1699+
__iommu_group_for_each_dev(group, group->default_domain,
1700+
iommu_group_do_probe_finalize);
1701+
}
16961702
static int iommu_do_create_direct_mappings(struct device *dev, void *data)
16971703
{
16981704
struct iommu_group *group = data;
@@ -1745,6 +1751,8 @@ int bus_iommu_probe(struct bus_type *bus)
17451751

17461752
if (ret)
17471753
break;
1754+
1755+
__iommu_group_dma_finalize(group);
17481756
}
17491757

17501758
return ret;

0 commit comments

Comments
 (0)