Skip to content

Commit 89e07fd

Browse files
nicolincjgunthorpe
authored andcommitted
vfio: Do not allow !ops->dma_unmap in vfio_pin/unpin_pages()
A driver that doesn't implement ops->dma_unmap shouldn't be allowed to do vfio_pin/unpin_pages(), though it can use vfio_dma_rw() to access an iova range. Deny !ops->dma_unmap cases in vfio_pin/unpin_pages(). Link: https://lore.kernel.org/r/85d622729d8f2334b35d42f1c568df1ededb9171.1690523699.git.nicolinc@nvidia.com Suggested-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Yi Liu <yi.l.liu@intel.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 6583c86 commit 89e07fd

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/vfio/vfio_main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,8 @@ int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova,
14831483
/* group->container cannot change while a vfio device is open */
14841484
if (!pages || !npage || WARN_ON(!vfio_assert_device_open(device)))
14851485
return -EINVAL;
1486+
if (!device->ops->dma_unmap)
1487+
return -EINVAL;
14861488
if (vfio_device_has_container(device))
14871489
return vfio_device_container_pin_pages(device, iova,
14881490
npage, prot, pages);
@@ -1520,6 +1522,8 @@ void vfio_unpin_pages(struct vfio_device *device, dma_addr_t iova, int npage)
15201522
{
15211523
if (WARN_ON(!vfio_assert_device_open(device)))
15221524
return;
1525+
if (WARN_ON(!device->ops->dma_unmap))
1526+
return;
15231527

15241528
if (vfio_device_has_container(device)) {
15251529
vfio_device_container_unpin_pages(device, iova, npage);

0 commit comments

Comments
 (0)