Skip to contentSkip to conversation

iommu/mediatek: Fix share pgtable for iova over 4GB

PATCH In review Yong Wu 4 participants 5 messages Aug 19, 2023 – Sep 25, 2023

Subsystems (3)
lore
Share & tools
lore

Yong Wu

author maintainer
#0 lore raw

PATCH 1/1 iommu/mediatek: Fix share pgtable for iova over 4GB

In mt8192/mt8186, there is only one MM IOMMU that supports 16GB iova space, which is shared by display, vcodec and camera. These two SoC use one pgtable and have not the flag SHARE_PGTABLE, we should also keep share pgtable for this case.

In mtk_iommu_domain_finalise, MM IOMMU always share pgtable, thus remove the flag SHARE_PGTABLE checking. Infra IOMMU always uses independent pgtable.

Fixes cf69ef46dbd9 ("iommu/mediatek: Fix two IOMMU share pagetable issue")

---
Base on next-20230818.

---
 drivers/iommu/mtk_iommu.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/iommu/mtk_iommu.c +4 -5
index b17d3e7288a7..b5fcba305d2a 100644
@@ -262,7 +262,7 @@ struct mtk_iommu_data {
 	struct device			*smicomm_dev;
 
 	struct mtk_iommu_bank_data	*bank;
-	struct mtk_iommu_domain		*share_dom; /* For 2 HWs share pgtable */
+	struct mtk_iommu_domain		*share_dom;
 
 	struct regmap			*pericfg;
 	struct mutex			mutex; /* Protect m4u_group/m4u_dom above */
@@ -643,8 +643,8 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom,
 	struct mtk_iommu_domain	*share_dom = data->share_dom;
 	const struct mtk_iommu_iova_region *region;
 
-	/* Always use share domain in sharing pgtable case */
-	if (MTK_IOMMU_HAS_FLAG(data->plat_data, SHARE_PGTABLE) && share_dom) {
+	/* Share pgtable when 2 MM IOMMU share the pgtable or one IOMMU use multiple iova ranges */
+	if (share_dom) {
 		dom->iop = share_dom->iop;
 		dom->cfg = share_dom->cfg;
 		dom->domain.pgsize_bitmap = share_dom->cfg.pgsize_bitmap;
@@ -677,8 +677,7 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom,
 	/* Update our support page sizes bitmap */
 	dom->domain.pgsize_bitmap = dom->cfg.pgsize_bitmap;
 
-	if (MTK_IOMMU_HAS_FLAG(data->plat_data, SHARE_PGTABLE))
-		data->share_dom = dom;
+	data->share_dom = dom;
 
 update_iova_region:
 	/* Update the iova region for this domain */
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Yong Wu

Il 19/08/23 10:14, Yong Wu ha scritto:

Quoted 5 lines

In mt8192/mt8186, there is only one MM IOMMU that supports 16GB iova space, which is shared by display, vcodec and camera. These two SoC use one pgtable and have not the flag SHARE_PGTABLE, we should also keep share pgtable for this case.

Quoted 8 lines

In mtk_iommu_domain_finalise, MM IOMMU always share pgtable, thus remove the flag SHARE_PGTABLE checking. Infra IOMMU always uses independent pgtable.

Fixes cf69ef46dbd9 ("iommu/mediatek: Fix two IOMMU share pagetable issue")

This is urgent. Fixes multiple machines.

Quoted 40 lines

---
Base on next-20230818.

---
  drivers/iommu/mtk_iommu.c | 9 ++++-----
  1 file changed, 4 insertions(+), 5 deletions(-)
drivers/iommu/mtk_iommu.c +4 -5
index b17d3e7288a7..b5fcba305d2a 100644
@@ -262,7 +262,7 @@ struct mtk_iommu_data {
  	struct device			*smicomm_dev;
 
  	struct mtk_iommu_bank_data	*bank;
-	struct mtk_iommu_domain		*share_dom; /* For 2 HWs share pgtable */
+	struct mtk_iommu_domain		*share_dom;
 
  	struct regmap			*pericfg;
  	struct mutex			mutex; /* Protect m4u_group/m4u_dom above */
@@ -643,8 +643,8 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom,
  	struct mtk_iommu_domain	*share_dom = data->share_dom;
  	const struct mtk_iommu_iova_region *region;
 
-	/* Always use share domain in sharing pgtable case */
-	if (MTK_IOMMU_HAS_FLAG(data->plat_data, SHARE_PGTABLE) && share_dom) {
+	/* Share pgtable when 2 MM IOMMU share the pgtable or one IOMMU use multiple iova ranges */
+	if (share_dom) {
  		dom->iop = share_dom->iop;
  		dom->cfg = share_dom->cfg;
  		dom->domain.pgsize_bitmap = share_dom->cfg.pgsize_bitmap;
@@ -677,8 +677,7 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom,
  	/* Update our support page sizes bitmap */
  	dom->domain.pgsize_bitmap = dom->cfg.pgsize_bitmap;
 
-	if (MTK_IOMMU_HAS_FLAG(data->plat_data, SHARE_PGTABLE))
-		data->share_dom = dom;
+	data->share_dom = dom;
 
  update_iova_region:
  	/* Update the iova region for this domain */
#3 lore raw
In reply to Yong Wu

Il 19/08/23 10:14, Yong Wu ha scritto:

Quoted 13 lines

In mt8192/mt8186, there is only one MM IOMMU that supports 16GB iova space, which is shared by display, vcodec and camera. These two SoC use one pgtable and have not the flag SHARE_PGTABLE, we should also keep share pgtable for this case.

In mtk_iommu_domain_finalise, MM IOMMU always share pgtable, thus remove the flag SHARE_PGTABLE checking. Infra IOMMU always uses independent pgtable.

Fixes cf69ef46dbd9 ("iommu/mediatek: Fix two IOMMU share pagetable issue")
Quoted 5 lines

---
Base on next-20230818.

---
  drivers/iommu/mtk_iommu.c | 9 ++++-----
  1 file changed, 4 insertions(+), 5 deletions(-)

Gentle ping for an important fix.

Thanks,
Angelo