]> git.baikalelectronics.ru Git - kernel.git/commit
vfio/type1: Empty batch for pfnmap pages
authorDaniel Jordan <daniel.m.jordan@oracle.com>
Thu, 25 Mar 2021 01:05:52 +0000 (21:05 -0400)
committerAlex Williamson <alex.williamson@redhat.com>
Thu, 25 Mar 2021 18:48:38 +0000 (12:48 -0600)
commit1b8a37c12113fabc065e9f1666aabc69c126777d
treec970b68f92ec70b92e4e882fe2ebfb11ad0a0399
parent6df5d3638abbd720089114129009990030b5c942
vfio/type1: Empty batch for pfnmap pages

When vfio_pin_pages_remote() returns with a partial batch consisting of
a single VM_PFNMAP pfn, a subsequent call will unfortunately try
restoring it from batch->pages, resulting in vfio mapping the wrong page
and unbalancing the page refcount.

Prevent the function from returning with this kind of partial batch to
avoid the issue.  There's no explicit check for a VM_PFNMAP pfn because
it's awkward to do so, so infer it from characteristics of the batch
instead.  This may result in occasional false positives but keeps the
code simpler.

Fixes: c805ec1e6bc3 ("vfio/type1: Batch page pinning")
Link: https://lkml.kernel.org/r/20210323133254.33ed9161@omen.home.shazbot.org/
Reported-by: Alex Williamson <alex.williamson@redhat.com>
Suggested-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Daniel Jordan <daniel.m.jordan@oracle.com>
Message-Id: <20210325010552.185481-1-daniel.m.jordan@oracle.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/vfio_iommu_type1.c