Skip to content

Commit 3379374

Browse files
LuBaolujoergroedel
authored andcommitted
iommu: Move lock from iommu_change_dev_def_domain() to its caller
The intention is to make it possible to put group ownership check and default domain change in a same critical region protected by the group's mutex lock. No intentional functional change. Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/20230322064956.263419-5-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent dba9ca9 commit 3379374

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

drivers/iommu/iommu.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,7 +2889,7 @@ static int iommu_change_dev_def_domain(struct iommu_group *group,
28892889
int ret, dev_def_dom;
28902890
struct device *dev;
28912891

2892-
mutex_lock(&group->mutex);
2892+
lockdep_assert_held(&group->mutex);
28932893

28942894
if (group->default_domain != group->domain) {
28952895
dev_err_ratelimited(prev_dev, "Group not assigned to default domain\n");
@@ -2978,28 +2978,15 @@ static int iommu_change_dev_def_domain(struct iommu_group *group,
29782978
goto free_new_domain;
29792979

29802980
group->domain = group->default_domain;
2981-
2982-
/*
2983-
* Release the mutex here because ops->probe_finalize() call-back of
2984-
* some vendor IOMMU drivers calls arm_iommu_attach_device() which
2985-
* in-turn might call back into IOMMU core code, where it tries to take
2986-
* group->mutex, resulting in a deadlock.
2987-
*/
2988-
mutex_unlock(&group->mutex);
2989-
2990-
/* Make sure dma_ops is appropriatley set */
2991-
iommu_group_do_probe_finalize(dev, group->default_domain);
29922981
iommu_domain_free(prev_dom);
2982+
29932983
return 0;
29942984

29952985
free_new_domain:
29962986
iommu_domain_free(group->default_domain);
29972987
group->default_domain = prev_dom;
29982988
group->domain = prev_dom;
2999-
30002989
out:
3001-
mutex_unlock(&group->mutex);
3002-
30032990
return ret;
30042991
}
30052992

@@ -3089,7 +3076,19 @@ static ssize_t iommu_group_store_type(struct iommu_group *group,
30893076
goto out;
30903077
}
30913078

3079+
mutex_lock(&group->mutex);
30923080
ret = iommu_change_dev_def_domain(group, dev, req_type);
3081+
/*
3082+
* Release the mutex here because ops->probe_finalize() call-back of
3083+
* some vendor IOMMU drivers calls arm_iommu_attach_device() which
3084+
* in-turn might call back into IOMMU core code, where it tries to take
3085+
* group->mutex, resulting in a deadlock.
3086+
*/
3087+
mutex_unlock(&group->mutex);
3088+
3089+
/* Make sure dma_ops is appropriatley set */
3090+
if (!ret)
3091+
iommu_group_do_probe_finalize(dev, group->default_domain);
30933092
ret = ret ?: count;
30943093

30953094
out:

0 commit comments

Comments
 (0)