Skip to content

Commit

Permalink
iommu/amd: Fix I/O page table memory leak
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ssuthiku-amd authored and joergroedel committed Feb 14, 2022
1 parent 5ce97f4 commit 6b0b2d9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions drivers/iommu/amd/io_pgtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,18 +492,18 @@ static void v1_free_pgtable(struct io_pgtable *iop)

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

/* Update data structure */
amd_iommu_domain_clr_pt_root(dom);

/* Make changes visible to IOMMUs */
amd_iommu_domain_update(dom);

/* Page-table is not visible to IOMMU anymore, so free it */
BUG_ON(pgtable->mode < PAGE_MODE_NONE ||
pgtable->mode > PAGE_MODE_6_LEVEL);

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

/* Update data structure */
amd_iommu_domain_clr_pt_root(dom);

/* Make changes visible to IOMMUs */
amd_iommu_domain_update(dom);

put_pages_list(&freelist);
}

Expand Down

0 comments on commit 6b0b2d9

Please sign in to comment.