Commit 0a782d15 authored by Yi Liu's avatar Yi Liu Committed by Jason Gunthorpe

vfio/mdev: Uses the vfio emulated iommufd ops set in the mdev sample drivers

This harmonizes the no-DMA devices (the vfio-mdev sample drivers) with
the emulated devices (gvt-g, vfio-ap etc.). It makes it easier to add
BIND_IOMMUFD user interface which requires to return an iommufd ID to
represent the device/iommufd bond.

Link: https://lore.kernel.org/r/20230327093351.44505-6-yi.l.liu@intel.comReviewed-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Tested-by: default avatarTerrence Xu <terrence.xu@intel.com>
Tested-by: default avatarNicolin Chen <nicolinc@nvidia.com>
Signed-off-by: default avatarYi Liu <yi.l.liu@intel.com>
Acked-by: default avatarAlex Williamson <alex.williamson@redhat.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 632fda7f
...@@ -32,12 +32,8 @@ int vfio_iommufd_bind(struct vfio_device *vdev, struct iommufd_ctx *ictx) ...@@ -32,12 +32,8 @@ int vfio_iommufd_bind(struct vfio_device *vdev, struct iommufd_ctx *ictx)
return 0; return 0;
} }
/* if (WARN_ON(!vdev->ops->bind_iommufd))
* If the driver doesn't provide this op then it means the device does return -ENODEV;
* not do DMA at all. So nothing to do.
*/
if (!vdev->ops->bind_iommufd)
return 0;
ret = vdev->ops->bind_iommufd(vdev, ictx, &device_id); ret = vdev->ops->bind_iommufd(vdev, ictx, &device_id);
if (ret) if (ret)
...@@ -119,7 +115,8 @@ EXPORT_SYMBOL_GPL(vfio_iommufd_physical_attach_ioas); ...@@ -119,7 +115,8 @@ EXPORT_SYMBOL_GPL(vfio_iommufd_physical_attach_ioas);
/* /*
* The emulated standard ops mean that vfio_device is going to use the * The emulated standard ops mean that vfio_device is going to use the
* "mdev path" and will call vfio_pin_pages()/vfio_dma_rw(). Drivers using this * "mdev path" and will call vfio_pin_pages()/vfio_dma_rw(). Drivers using this
* ops set should call vfio_register_emulated_iommu_dev(). * ops set should call vfio_register_emulated_iommu_dev(). Drivers that do
* not call vfio_pin_pages()/vfio_dma_rw() have no need to provide dma_unmap.
*/ */
static void vfio_emulated_unmap(void *data, unsigned long iova, static void vfio_emulated_unmap(void *data, unsigned long iova,
...@@ -127,7 +124,8 @@ static void vfio_emulated_unmap(void *data, unsigned long iova, ...@@ -127,7 +124,8 @@ static void vfio_emulated_unmap(void *data, unsigned long iova,
{ {
struct vfio_device *vdev = data; struct vfio_device *vdev = data;
vdev->ops->dma_unmap(vdev, iova, length); if (vdev->ops->dma_unmap)
vdev->ops->dma_unmap(vdev, iova, length);
} }
static const struct iommufd_access_ops vfio_user_ops = { static const struct iommufd_access_ops vfio_user_ops = {
......
...@@ -1374,6 +1374,9 @@ static const struct vfio_device_ops mbochs_dev_ops = { ...@@ -1374,6 +1374,9 @@ static const struct vfio_device_ops mbochs_dev_ops = {
.write = mbochs_write, .write = mbochs_write,
.ioctl = mbochs_ioctl, .ioctl = mbochs_ioctl,
.mmap = mbochs_mmap, .mmap = mbochs_mmap,
.bind_iommufd = vfio_iommufd_emulated_bind,
.unbind_iommufd = vfio_iommufd_emulated_unbind,
.attach_ioas = vfio_iommufd_emulated_attach_ioas,
}; };
static struct mdev_driver mbochs_driver = { static struct mdev_driver mbochs_driver = {
......
...@@ -663,6 +663,9 @@ static const struct vfio_device_ops mdpy_dev_ops = { ...@@ -663,6 +663,9 @@ static const struct vfio_device_ops mdpy_dev_ops = {
.write = mdpy_write, .write = mdpy_write,
.ioctl = mdpy_ioctl, .ioctl = mdpy_ioctl,
.mmap = mdpy_mmap, .mmap = mdpy_mmap,
.bind_iommufd = vfio_iommufd_emulated_bind,
.unbind_iommufd = vfio_iommufd_emulated_unbind,
.attach_ioas = vfio_iommufd_emulated_attach_ioas,
}; };
static struct mdev_driver mdpy_driver = { static struct mdev_driver mdpy_driver = {
......
...@@ -1269,6 +1269,9 @@ static const struct vfio_device_ops mtty_dev_ops = { ...@@ -1269,6 +1269,9 @@ static const struct vfio_device_ops mtty_dev_ops = {
.read = mtty_read, .read = mtty_read,
.write = mtty_write, .write = mtty_write,
.ioctl = mtty_ioctl, .ioctl = mtty_ioctl,
.bind_iommufd = vfio_iommufd_emulated_bind,
.unbind_iommufd = vfio_iommufd_emulated_unbind,
.attach_ioas = vfio_iommufd_emulated_attach_ioas,
}; };
static struct mdev_driver mtty_driver = { static struct mdev_driver mtty_driver = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment