diff options
author | Xiaoyang Xu <xuxiaoyang2@huawei.com> | 2020-10-16 17:35:58 +0800 |
---|---|---|
committer | Alex Williamson <alex.williamson@redhat.com> | 2020-10-20 10:12:17 -0600 |
commit | 2e6cfd496f5b57034cf2aec738799571b5a52124 (patch) | |
tree | e3d4ec36020175bfb34add2a2aaf72e2a3711782 | |
parent | 852b1beecb6ff9326f7ca4bc0fe69ae860ebdb9e (diff) | |
download | lwn-2e6cfd496f5b57034cf2aec738799571b5a52124.tar.gz lwn-2e6cfd496f5b57034cf2aec738799571b5a52124.zip |
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: a54eb55045ae ("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>
-rw-r--r-- | drivers/vfio/vfio_iommu_type1.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index defd44522319..57b068abceb9 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -693,7 +693,8 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data, ret = vfio_add_to_pfn_list(dma, iova, phys_pfn[i]); if (ret) { - vfio_unpin_page_external(dma, iova, do_accounting); + if (put_pfn(phys_pfn[i], dma->prot) && do_accounting) + vfio_lock_acct(dma, -1, true); goto pin_unwind; } |