[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <648acac966bac4c4760faf8be5b05d054b8f3f6a.1679939952.git.nicolinc@nvidia.com>
Date: Mon, 27 Mar 2023 11:05:02 -0700
From: Nicolin Chen <nicolinc@...dia.com>
To: <jgg@...dia.com>, <kevin.tian@...el.com>, <joro@...tes.org>,
<will@...nel.org>, <robin.murphy@....com>,
<alex.williamson@...hat.com>, <shuah@...nel.org>
CC: <yi.l.liu@...el.com>, <linux-kernel@...r.kernel.org>,
<iommu@...ts.linux.dev>, <kvm@...r.kernel.org>,
<linux-kselftest@...r.kernel.org>, <mjrosato@...ux.ibm.com>,
<farman@...ux.ibm.com>
Subject: [PATCH v6 1/4] 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().
Suggested-by: Kevin Tian <kevin.tian@...el.com>
Reviewed-by: Kevin Tian <kevin.tian@...el.com>
Reviewed-by: Yi Liu <yi.l.liu@...el.com>
Reviewed-by: Jason Gunthorpe <jgg@...dia.com>
Signed-off-by: Nicolin Chen <nicolinc@...dia.com>
---
drivers/vfio/vfio_main.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
index 896d8bb49585..48807d587946 100644
--- a/drivers/vfio/vfio_main.c
+++ b/drivers/vfio/vfio_main.c
@@ -1485,6 +1485,8 @@ int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova,
/* group->container cannot change while a vfio device is open */
if (!pages || !npage || WARN_ON(!vfio_assert_device_open(device)))
return -EINVAL;
+ if (!device->ops->dma_unmap)
+ return -EINVAL;
if (vfio_device_has_container(device))
return vfio_device_container_pin_pages(device, iova,
npage, prot, pages);
@@ -1522,6 +1524,8 @@ void vfio_unpin_pages(struct vfio_device *device, dma_addr_t iova, int npage)
{
if (WARN_ON(!vfio_assert_device_open(device)))
return;
+ if (WARN_ON(!device->ops->dma_unmap))
+ return;
if (vfio_device_has_container(device)) {
vfio_device_container_unpin_pages(device, iova, npage);
--
2.40.0
Powered by blists - more mailing lists