@@ -1110,20 +1110,6 @@ void iommu_group_remove_device(struct device *dev)
11101110}
11111111EXPORT_SYMBOL_GPL (iommu_group_remove_device );
11121112
1113- static int __iommu_group_for_each_dev (struct iommu_group * group , void * data ,
1114- int (* fn )(struct device * , void * ))
1115- {
1116- struct group_device * device ;
1117- int ret = 0 ;
1118-
1119- for_each_group_device (group , device ) {
1120- ret = fn (device -> dev , data );
1121- if (ret )
1122- break ;
1123- }
1124- return ret ;
1125- }
1126-
11271113/**
11281114 * iommu_group_for_each_dev - iterate over each device in the group
11291115 * @group: the group
@@ -1138,10 +1124,15 @@ static int __iommu_group_for_each_dev(struct iommu_group *group, void *data,
11381124int iommu_group_for_each_dev (struct iommu_group * group , void * data ,
11391125 int (* fn )(struct device * , void * ))
11401126{
1141- int ret ;
1127+ struct group_device * device ;
1128+ int ret = 0 ;
11421129
11431130 mutex_lock (& group -> mutex );
1144- ret = __iommu_group_for_each_dev (group , data , fn );
1131+ for_each_group_device (group , device ) {
1132+ ret = fn (device -> dev , data );
1133+ if (ret )
1134+ break ;
1135+ }
11451136 mutex_unlock (& group -> mutex );
11461137
11471138 return ret ;
@@ -1791,20 +1782,12 @@ static int iommu_get_default_domain_type(struct iommu_group *group,
17911782 return best_type ;
17921783}
17931784
1794- static int iommu_group_do_probe_finalize (struct device * dev , void * data )
1785+ static void iommu_group_do_probe_finalize (struct device * dev )
17951786{
17961787 const struct iommu_ops * ops = dev_iommu_ops (dev );
17971788
17981789 if (ops -> probe_finalize )
17991790 ops -> probe_finalize (dev );
1800-
1801- return 0 ;
1802- }
1803-
1804- static void __iommu_group_dma_finalize (struct iommu_group * group )
1805- {
1806- __iommu_group_for_each_dev (group , group -> default_domain ,
1807- iommu_group_do_probe_finalize );
18081791}
18091792
18101793int bus_iommu_probe (const struct bus_type * bus )
@@ -1823,6 +1806,8 @@ int bus_iommu_probe(const struct bus_type *bus)
18231806 return ret ;
18241807
18251808 list_for_each_entry_safe (group , next , & group_list , entry ) {
1809+ struct group_device * gdev ;
1810+
18261811 mutex_lock (& group -> mutex );
18271812
18281813 /* Remove item from the list */
@@ -1834,7 +1819,15 @@ int bus_iommu_probe(const struct bus_type *bus)
18341819 return ret ;
18351820 }
18361821 mutex_unlock (& group -> mutex );
1837- __iommu_group_dma_finalize (group );
1822+
1823+ /*
1824+ * FIXME: Mis-locked because the ops->probe_finalize() call-back
1825+ * of some IOMMU drivers calls arm_iommu_attach_device() which
1826+ * in-turn might call back into IOMMU core code, where it tries
1827+ * to take group->mutex, resulting in a deadlock.
1828+ */
1829+ for_each_group_device (group , gdev )
1830+ iommu_group_do_probe_finalize (gdev -> dev );
18381831 }
18391832
18401833 return 0 ;
@@ -2995,8 +2988,12 @@ static ssize_t iommu_group_store_type(struct iommu_group *group,
29952988 mutex_unlock (& group -> mutex );
29962989
29972990 /* Make sure dma_ops is appropriatley set */
2998- if (!ret )
2999- __iommu_group_dma_finalize (group );
2991+ if (!ret ) {
2992+ struct group_device * gdev ;
2993+
2994+ for_each_group_device (group , gdev )
2995+ iommu_group_do_probe_finalize (gdev -> dev );
2996+ }
30002997
30012998 return ret ?: count ;
30022999}
0 commit comments