Skip to content

Commit ddf67a8

Browse files
YongWu-HFjoergroedel
authored andcommitted
iommu/mediatek: Add mutex for data in the mtk_iommu_domain
Same with the previous patch, add a mutex for the "data" in the mtk_iommu_domain. Just improve the safety for multi devices enter attach_device at the same time. We don't get the real issue for this. Signed-off-by: Yong Wu <yong.wu@mediatek.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com> Link: https://lore.kernel.org/r/20220503071427.2285-9-yong.wu@mediatek.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 0e5a3f2 commit ddf67a8

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

drivers/iommu/mtk_iommu.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ struct mtk_iommu_domain {
128128

129129
struct mtk_iommu_data *data;
130130
struct iommu_domain domain;
131+
132+
struct mutex mutex; /* Protect "data" in this structure */
131133
};
132134

133135
static const struct iommu_ops mtk_iommu_ops;
@@ -434,6 +436,7 @@ static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type)
434436
dom = kzalloc(sizeof(*dom), GFP_KERNEL);
435437
if (!dom)
436438
return NULL;
439+
mutex_init(&dom->mutex);
437440

438441
return &dom->domain;
439442
}
@@ -455,14 +458,19 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain,
455458
if (domid < 0)
456459
return domid;
457460

461+
mutex_lock(&dom->mutex);
458462
if (!dom->data) {
459463
/* Data is in the frstdata in sharing pgtable case. */
460464
frstdata = mtk_iommu_get_m4u_data();
461465

462-
if (mtk_iommu_domain_finalise(dom, frstdata, domid))
466+
ret = mtk_iommu_domain_finalise(dom, frstdata, domid);
467+
if (ret) {
468+
mutex_unlock(&dom->mutex);
463469
return -ENODEV;
470+
}
464471
dom->data = data;
465472
}
473+
mutex_unlock(&dom->mutex);
466474

467475
mutex_lock(&data->mutex);
468476
if (!data->m4u_dom) { /* Initialize the M4U HW */

0 commit comments

Comments
 (0)