Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vfio/type1: fix vaddr_get_pfns() return in vfio_pin_page_external()

vaddr_get_pfns() now returns the positive number of pfns successfully
gotten instead of zero. vfio_pin_page_external() might return 1 to
vfio_iommu_type1_pin_pages(), which will treat it as an error, if
vaddr_get_pfns() is successful but vfio_pin_page_external() doesn't
reach vfio_lock_acct().

Fix it up in vfio_pin_page_external(). Found by inspection.

Fixes: be16c1fd99f4 ("vfio/type1: Change success value of vaddr_get_pfn()")
Signed-off-by: Daniel Jordan <daniel.m.jordan@oracle.com>
Message-Id: <20210308172452.38864-1-daniel.m.jordan@oracle.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

authored by

Daniel Jordan and committed by
Alex Williamson
4ab4fcfc b2b12db5

+7 -1
+7 -1
drivers/vfio/vfio_iommu_type1.c
··· 785 785 return -ENODEV; 786 786 787 787 ret = vaddr_get_pfns(mm, vaddr, 1, dma->prot, pfn_base, pages); 788 - if (ret == 1 && do_accounting && !is_invalid_reserved_pfn(*pfn_base)) { 788 + if (ret != 1) 789 + goto out; 790 + 791 + ret = 0; 792 + 793 + if (do_accounting && !is_invalid_reserved_pfn(*pfn_base)) { 789 794 ret = vfio_lock_acct(dma, 1, true); 790 795 if (ret) { 791 796 put_pfn(*pfn_base, dma->prot); ··· 802 797 } 803 798 } 804 799 800 + out: 805 801 mmput(mm); 806 802 return ret; 807 803 }