Skip to content

Commit 2e6cfd4

Browse files
Xiaoyang XuAlex Williamson
authored andcommitted
vfio iommu type1: Fix memory leak in vfio_iommu_type1_pin_pages
pfn is not added to pfn_list when vfio_add_to_pfn_list fails. vfio_unpin_page_external will exit directly without calling vfio_iova_put_vfio_pfn. This will lead to a memory leak. Fixes: a54eb55 ("vfio iommu type1: Add support for mediated devices") Signed-off-by: Xiaoyang Xu <xuxiaoyang2@huawei.com> [aw: simplified logic, add Fixes] Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent 852b1be commit 2e6cfd4

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎drivers/vfio/vfio_iommu_type1.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,8 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data,
693693

694694
ret = vfio_add_to_pfn_list(dma, iova, phys_pfn[i]);
695695
if (ret) {
696-
vfio_unpin_page_external(dma, iova, do_accounting);
696+
if (put_pfn(phys_pfn[i], dma->prot) && do_accounting)
697+
vfio_lock_acct(dma, -1, true);
697698
goto pin_unwind;
698699
}
699700

0 commit comments

Comments
 (0)