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)
commit60c988bc154108bd522a21289e389143006a1ff0
treec970b68f92ec70b92e4e882fe2ebfb11ad0a0399
parent0d02ec6b3136c73c09e7859f0d0e4e2c4c07b49b
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: 4d83de6da265 ("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