Skip to content

Commit 0e5a3f2

Browse files
YongWu-HFjoergroedel
authored andcommitted
iommu/mediatek: Add mutex for m4u_group and m4u_dom in data
Add a mutex to protect the data in the structure mtk_iommu_data, like ->"m4u_group" ->"m4u_dom". For the internal data, we should protect it in ourselves driver. Add a mutex for this. This could be a fix for the multi-groups support. Fixes: c3045f3 ("iommu/mediatek: Support for multi domains") Signed-off-by: Yunfei Wang <yf.wang@mediatek.com> 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-8-yong.wu@mediatek.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 98df772 commit 0e5a3f2

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

drivers/iommu/mtk_iommu.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,25 +464,31 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain,
464464
dom->data = data;
465465
}
466466

467+
mutex_lock(&data->mutex);
467468
if (!data->m4u_dom) { /* Initialize the M4U HW */
468469
ret = pm_runtime_resume_and_get(m4udev);
469470
if (ret < 0)
470-
return ret;
471+
goto err_unlock;
471472

472473
ret = mtk_iommu_hw_init(data);
473474
if (ret) {
474475
pm_runtime_put(m4udev);
475-
return ret;
476+
goto err_unlock;
476477
}
477478
data->m4u_dom = dom;
478479
writel(dom->cfg.arm_v7s_cfg.ttbr & MMU_PT_ADDR_MASK,
479480
data->base + REG_MMU_PT_BASE_ADDR);
480481

481482
pm_runtime_put(m4udev);
482483
}
484+
mutex_unlock(&data->mutex);
483485

484486
mtk_iommu_config(data, dev, true, domid);
485487
return 0;
488+
489+
err_unlock:
490+
mutex_unlock(&data->mutex);
491+
return ret;
486492
}
487493

488494
static void mtk_iommu_detach_device(struct iommu_domain *domain,
@@ -622,6 +628,7 @@ static struct iommu_group *mtk_iommu_device_group(struct device *dev)
622628
if (domid < 0)
623629
return ERR_PTR(domid);
624630

631+
mutex_lock(&data->mutex);
625632
group = data->m4u_group[domid];
626633
if (!group) {
627634
group = iommu_group_alloc();
@@ -630,6 +637,7 @@ static struct iommu_group *mtk_iommu_device_group(struct device *dev)
630637
} else {
631638
iommu_group_ref_get(group);
632639
}
640+
mutex_unlock(&data->mutex);
633641
return group;
634642
}
635643

@@ -910,6 +918,7 @@ static int mtk_iommu_probe(struct platform_device *pdev)
910918
}
911919

912920
platform_set_drvdata(pdev, data);
921+
mutex_init(&data->mutex);
913922

914923
ret = iommu_device_sysfs_add(&data->iommu, dev, NULL,
915924
"mtk-iommu.%pa", &ioaddr);

drivers/iommu/mtk_iommu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ struct mtk_iommu_data {
8080

8181
struct dma_iommu_mapping *mapping; /* For mtk_iommu_v1.c */
8282

83+
struct mutex mutex; /* Protect m4u_group/m4u_dom above */
84+
8385
struct list_head list;
8486
struct mtk_smi_larb_iommu larb_imu[MTK_LARB_NR_MAX];
8587
};

0 commit comments

Comments
 (0)