diff mbox series

[2/7] vfio: Export unmap_mapping_range() wrapper

Message ID 162818324222.1511194.15934590640437021149.stgit@omen (mailing list archive)
State New, archived
Headers show
Series vfio: device fd address space and vfio-pci mmap invalidation cleanup | expand

Commit Message

Alex Williamson Aug. 5, 2021, 5:07 p.m. UTC
Allow bus drivers to use vfio pseudo fs mapping to zap all mmaps
across a range of their device files.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 drivers/vfio/vfio.c  |    7 +++++++
 include/linux/vfio.h |    2 ++
 2 files changed, 9 insertions(+)

Comments

Christoph Hellwig Aug. 10, 2021, 8:45 a.m. UTC | #1
> +void vfio_device_unmap_mapping_range(struct vfio_device *device,
> +				     loff_t start, loff_t len)
> +{
> +	unmap_mapping_range(device->inode->i_mapping, start, len, true);
> +}
> +EXPORT_SYMBOL_GPL(vfio_device_unmap_mapping_range);

Instead of mirroring the name of unmap_mapping_range maybe give this
a name to document the use case?

> +extern void vfio_device_unmap_mapping_range(struct vfio_device *device,
> +					    loff_t start, loff_t len);

No need for the extern.
Peter Xu Aug. 10, 2021, 6:56 p.m. UTC | #2
On Thu, Aug 05, 2021 at 11:07:22AM -0600, Alex Williamson wrote:
> +void vfio_device_unmap_mapping_range(struct vfio_device *device,
> +				     loff_t start, loff_t len)
> +{
> +	unmap_mapping_range(device->inode->i_mapping, start, len, true);

(not a big deal, but still raise this up)

It seems to me VFIO MMIO regions do not allow private maps, so even_cow==true
should be the same with even_cow==false. even_cow==true will just check the
page mapping for each pte even though they should just all match, imho, so
logically "false" should work the same and should be tiny-little faster.

Thanks,

> +}
> +EXPORT_SYMBOL_GPL(vfio_device_unmap_mapping_range);
diff mbox series

Patch

diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
index b88de89bda31..1e4fc69fee7d 100644
--- a/drivers/vfio/vfio.c
+++ b/drivers/vfio/vfio.c
@@ -560,6 +560,13 @@  static struct inode *vfio_fs_inode_new(void)
 	return inode;
 }
 
+void vfio_device_unmap_mapping_range(struct vfio_device *device,
+				     loff_t start, loff_t len)
+{
+	unmap_mapping_range(device->inode->i_mapping, start, len, true);
+}
+EXPORT_SYMBOL_GPL(vfio_device_unmap_mapping_range);
+
 /**
  * Device objects - create, release, get, put, search
  */
diff --git a/include/linux/vfio.h b/include/linux/vfio.h
index 90bcc2e9c8eb..712813703e5a 100644
--- a/include/linux/vfio.h
+++ b/include/linux/vfio.h
@@ -66,6 +66,8 @@  int vfio_register_group_dev(struct vfio_device *device);
 void vfio_unregister_group_dev(struct vfio_device *device);
 extern struct vfio_device *vfio_device_get_from_dev(struct device *dev);
 extern void vfio_device_put(struct vfio_device *device);
+extern void vfio_device_unmap_mapping_range(struct vfio_device *device,
+					    loff_t start, loff_t len);
 
 /* events for the backend driver notify callback */
 enum vfio_iommu_notify_type {