Skip to content

Commit 6b0b2d9

Browse files
ssuthiku-amdjoergroedel
authored andcommitted
iommu/amd: Fix I/O page table memory leak
The current logic updates the I/O page table mode for the domain before calling the logic to free memory used for the page table. This results in IOMMU page table memory leak, and can be observed when launching VM w/ pass-through devices. Fix by freeing the memory used for page table before updating the mode. Cc: Joerg Roedel <[email protected]> Reported-by: Daniel Jordan <[email protected]> Tested-by: Daniel Jordan <[email protected]> Signed-off-by: Suravee Suthikulpanit <[email protected]> Fixes: e42ba06 ("iommu/amd: Restructure code for freeing page table") Link: https://lore.kernel.org/all/[email protected]/ Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 5ce97f4 commit 6b0b2d9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/iommu/amd/io_pgtable.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,18 +492,18 @@ static void v1_free_pgtable(struct io_pgtable *iop)
492492

493493
dom = container_of(pgtable, struct protection_domain, iop);
494494

495-
/* Update data structure */
496-
amd_iommu_domain_clr_pt_root(dom);
497-
498-
/* Make changes visible to IOMMUs */
499-
amd_iommu_domain_update(dom);
500-
501495
/* Page-table is not visible to IOMMU anymore, so free it */
502496
BUG_ON(pgtable->mode < PAGE_MODE_NONE ||
503497
pgtable->mode > PAGE_MODE_6_LEVEL);
504498

505499
free_sub_pt(pgtable->root, pgtable->mode, &freelist);
506500

501+
/* Update data structure */
502+
amd_iommu_domain_clr_pt_root(dom);
503+
504+
/* Make changes visible to IOMMUs */
505+
amd_iommu_domain_update(dom);
506+
507507
put_pages_list(&freelist);
508508
}
509509

0 commit comments

Comments
 (0)