Skip to content

Commit 6ccb72f

Browse files
Andrei Duleajoergroedel
authored andcommitted
iommu/amd: Fix downgrading default page-sizes in alloc_pte()
Downgrading an existing large mapping to a mapping using smaller page-sizes works only for the mappings created with page-mode 7 (i.e. non-default page size). Treat large mappings created with page-mode 0 (i.e. default page size) like a non-present mapping and allow to overwrite it in alloc_pte(). While around, make sure that we flush the TLB only if we change an existing mapping, otherwise we might end up acting on garbage PTEs. Fixes: 6d568ef ("iommu/amd: Allow downgrading page-sizes in alloc_pte()") Signed-off-by: Andrei Dulea <[email protected]>
1 parent 34c0989 commit 6ccb72f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/iommu/amd_iommu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,7 @@ static u64 *alloc_pte(struct protection_domain *domain,
14901490
pte_level = PM_PTE_LEVEL(__pte);
14911491

14921492
if (!IOMMU_PTE_PRESENT(__pte) ||
1493+
pte_level == PAGE_MODE_NONE ||
14931494
pte_level == PAGE_MODE_7_LEVEL) {
14941495
page = (u64 *)get_zeroed_page(gfp);
14951496
if (!page)
@@ -1500,7 +1501,7 @@ static u64 *alloc_pte(struct protection_domain *domain,
15001501
/* pte could have been changed somewhere. */
15011502
if (cmpxchg64(pte, __pte, __npte) != __pte)
15021503
free_page((unsigned long)page);
1503-
else if (pte_level == PAGE_MODE_7_LEVEL)
1504+
else if (IOMMU_PTE_PRESENT(__pte))
15041505
domain->updated = true;
15051506

15061507
continue;

0 commit comments

Comments
 (0)