iommu/arm-smmu: change pud/pmd entry fill sequence
PATCH 1/1 iommu/arm-smmu: change pud/pmd entry fill sequence
From: Yifan Zhang <[email protected]>
Pgd/pud entry should be filled only once when their next level pud/pmd created, the value should be pud/pmd start address, while in current code, pgd/pud entry is filled every time when pud/pmd walk occurs, the value is pud/pmd start address + iova pud/pmd index , this is incorrect; Besides, when pud/pmd are created, we need to add pud/pmd index, then pass to next level, while in currect code, if a new pud/pmd created, their iova pud/pmd index is not taken into account, only existing pud/pmd do. This patch change pud/pmd entry fill sequence, fixes the 2 bugs.
--- drivers/iommu/arm-smmu.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/iommu/arm-smmu.c +10 -4
@@ -1317,6 +1317,11 @@ static int arm_smmu_alloc_init_pmd(struct arm_smmu_device *smmu, pud_t *pud, pmd =pmd_alloc_one (NULL , addr);if (!pmd)return -ENOMEM ; + +pud_populate (NULL , pud, pmd); +arm_smmu_flush_pgtable (smmu, pud,sizeof (*pud)); + + pmd +=pmd_index (addr); } else#endif pmd =pmd_offset (pud, addr);
@@ -1325,8 +1330,6 @@ static int arm_smmu_alloc_init_pmd(struct arm_smmu_device *smmu, pud_t *pud, next =pmd_addr_end (addr, end); ret =arm_smmu_alloc_init_pte (smmu, pmd, addr, end, pfn, flags, stage); -pud_populate (NULL , pud, pmd); -arm_smmu_flush_pgtable (smmu, pud,sizeof (*pud)); phys += next - addr; }while (pmd++, addr = next, addr < end);
@@ -1346,6 +1349,11 @@ static int arm_smmu_alloc_init_pud(struct arm_smmu_device *smmu, pgd_t *pgd, pud =pud_alloc_one (NULL , addr);if (!pud)return -ENOMEM ; + +pgd_populate (NULL , pgd, pud); +arm_smmu_flush_pgtable (smmu, pgd,sizeof (*pgd)); + + pud +=pud_index (addr); } else#endif pud =pud_offset (pgd, addr);
@@ -1354,8 +1362,6 @@ static int arm_smmu_alloc_init_pud(struct arm_smmu_device *smmu, pgd_t *pgd, next =pud_addr_end (addr, end); ret =arm_smmu_alloc_init_pmd (smmu, pud, addr, next, phys, flags, stage); -pgd_populate (NULL , pud, pgd); -arm_smmu_flush_pgtable (smmu, pgd,sizeof (*pgd)); phys += next - addr; }while (pud++, addr = next, addr < end);
Signature · 1 line
1.7.9.5
A message that is not in the archive (sent off-list or not yet received): 1388750486-5060-1-git-send-email-yifan.zhangm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Hi Will,
I found current smmu driver may generate wrong page tables, after apply this patch, the result is correct. I have verified this patch on our platform.
BR,
Yifan
Quoted 76 lines · Yifan Zhang
From: Yifan Zhang <[email protected]>
Pgd/pud entry should be filled only once when their next level pud/pmd created, the value should be pud/pmd start address, while in current code, pgd/pud entry is filled every time when pud/pmd walk occurs, the value is pud/pmd start address + iova pud/pmd index , this is incorrect; Besides, when pud/pmd are created, we need to add pud/pmd index, then pass to next level, while in currect code, if a new pud/pmd created, their iova pud/pmd index is not taken into account, only existing pud/pmd do. This patch change pud/pmd entry fill sequence, fixes the 2 bugs.
Signed-off-by Yifan Zhang <[email protected]>--- drivers/iommu/arm-smmu.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)drivers/iommu/arm-smmu.c +5
-0@@ -1317,6 +1317,11 @@ static int arm_smmu_alloc_init_pmd(struct arm_smmu_device *smmu, pud_t *pud, pmd =pmd_alloc_one (NULL , addr);if (!pmd)return -ENOMEM ; + +pud_populate (NULL , pud, pmd); +arm_smmu_flush_pgtable (smmu, pud,sizeof (*pud)); + + pmd +=pmd_index (addr); } else#endif pmd = pmd_offset(pud, addr);drivers/iommu/arm-smmu.c +5
-2@@ -1325,8 +1330,6 @@ static int arm_smmu_alloc_init_pmd(struct arm_smmu_device *smmu, pud_t *pud, next =pmd_addr_end (addr, end); ret =arm_smmu_alloc_init_pte (smmu, pmd, addr, end, pfn, flags, stage); -pud_populate (NULL , pud, pmd); -arm_smmu_flush_pgtable (smmu, pud,sizeof (*pud)); phys += next - addr; }while (pmd++, addr = next, addr < end);@@ -1346,6 +1349,11 @@ static int arm_smmu_alloc_init_pud(struct arm_smmu_device *smmu, pgd_t *pgd, pud =pud_alloc_one (NULL , addr);if (!pud)return -ENOMEM ; + +pgd_populate (NULL , pgd, pud); +arm_smmu_flush_pgtable (smmu, pgd,sizeof (*pgd)); + + pud +=pud_index (addr); } else#endif pud = pud_offset(pgd, addr);drivers/iommu/arm-smmu.c +0
-3@@ -1354,8 +1362,6 @@ static int arm_smmu_alloc_init_pud(struct arm_smmu_device *smmu, pgd_t *pgd, next =pud_addr_end (addr, end); ret =arm_smmu_alloc_init_pmd (smmu, pud, addr, next, phys, flags, stage); -pgd_populate (NULL , pud, pgd); -arm_smmu_flush_pgtable (smmu, pgd,sizeof (*pgd)); phys += next - addr; }while (pud++, addr = next, addr < end); --1.7.9.5
_______________________________________________
linux-arm-kernel mailing list linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 1/1 iommu/arm-smmu: change pud/pmd entry fill sequence
In reply to Yifan ZhangQuoted 12 lines · Yifan Zhang
From: Yifan Zhang <[email protected]>
Pgd/pud entry should be filled only once when their next level pud/pmd created, the value should be pud/pmd start address, while in current code, pgd/pud entry is filled every time when pud/pmd walk occurs, the value is pud/pmd start address + iova pud/pmd index , this is incorrect; Besides, when pud/pmd are created, we need to add pud/pmd index, then pass to next level, while in currect code, if a new pud/pmd created, their iova pud/pmd index is not taken into account, only existing pud/pmd do. This patch change pud/pmd entry fill sequence, fixes the 2 bugs.
Quoted 1 line
Signed-off-by Yifan Zhang <[email protected]>
Thanks Yifan, this looks good to me. It's strange that I got the pte handling correct, but screwed up the equivalent pmd and pud code!
Will
A message that is not in the archive (sent off-list or not yet received): 20140106142833.GC10449-MRww78TxoiP5vMa5CHWGZ34zcgK1vI+I0E9HWUfgJXw@public.gmane.org
Hi Will,
It seems this patch is still not merged yet, any concerns about it ?
BR,
Yifan
Quoted 20 lines · Will Deacon
Quoted 12 lines · Yifan Zhang
From: Yifan Zhang <[email protected]>
Pgd/pud entry should be filled only once when their next level pud/pmd created, the value should be pud/pmd start address, while in current code, pgd/pud entry is filled every time when pud/pmd walk occurs, the value is pud/pmd start address + iova pud/pmd index , this is incorrect; Besides, when pud/pmd are created, we need to add pud/pmd index, then pass to next level, while in currect code, if a new pud/pmd created, their iova pud/pmd index is not taken into account, only existing pud/pmd do. This patch change pud/pmd entry fill sequence, fixes the 2 bugs.
Quoted 1 line
Signed-off-by Yifan Zhang <[email protected]>Thanks Yifan, this looks good to me. It's strange that I got the pte handling correct, but screwed up the equivalent pmd and pud code!
Will
PATCH 1/1 iommu/arm-smmu: change pud/pmd entry fill sequence
Quoted 1 line · Yifan Zhang
It seems this patch is still not merged yet, any concerns about it ?
No, I was planning to send it at -rc1 with a CC stable.
Will
PATCH 1/1 iommu/arm-smmu: change pud/pmd entry fill sequence
Got it, Thanks :-)
Quoted 6 lines · Will Deacon
Quoted 1 line · Yifan Zhang
It seems this patch is still not merged yet, any concerns about it ?
No, I was planning to send it at -rc1 with a CC stable.
Will