vfio/type1: Prune vfio_pin_page_external()
authorAlex Williamson <alex.williamson@redhat.com>
Sun, 16 Apr 2017 21:57:18 +0000 (15:57 -0600)
committerAlex Williamson <alex.williamson@redhat.com>
Tue, 18 Apr 2017 21:01:15 +0000 (15:01 -0600)
commit80dbe1fbafbf469fd19862f0d400b769bff0ee46
tree0e325bcf0e3990f28365485a146a2bae6467070a
parent0cfef2b7410b64d7a430947e0b533314c4f97153
vfio/type1: Prune vfio_pin_page_external()

With vfio_lock_acct() testing the locked memory limit under mmap_sem,
it's redundant to do it here for a single page.  We can also reorder
our tests such that we can avoid testing for reserved pages if we're
not doing accounting and let vfio_lock_acct() test the process
CAP_IPC_LOCK.  Finally, this function oddly returns 1 on success.
Update to return zero on success, -errno on error.  Since the function
only pins a single page, there's no need to return the number of pages
pinned.

N.B. vfio_pin_pages_remote() can pin a large contiguous range of pages
before calling vfio_lock_acct().  If we were to similarly remove the
extra test there, a user could temporarily pin far more pages than
they're allowed.

Suggested-by: Kirti Wankhede <kwankhede@nvidia.com>
Suggested-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Kirti Wankhede <kwankhede@nvidia.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/vfio_iommu_type1.c