From: Yi Liu Date: Mon, 27 Mar 2023 09:33:51 +0000 (-0700) Subject: vfio: Check the presence for iommufd callbacks in __vfio_register_dev() X-Git-Tag: v6.4-rc1~129^2~3^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d12578c5d508050554bcd9ca3d2331914d86d71;p=thirdparty%2Flinux.git vfio: Check the presence for iommufd callbacks in __vfio_register_dev() After making the no-DMA drivers (samples/vfio-mdev) providing iommufd callbacks, __vfio_register_dev() should check the presence of the iommufd callbacks if CONFIG_IOMMUFD is enabled. Link: https://lore.kernel.org/r/20230327093351.44505-7-yi.l.liu@intel.com Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian Tested-by: Terrence Xu Tested-by: Nicolin Chen Signed-off-by: Yi Liu Acked-by: Alex Williamson Signed-off-by: Jason Gunthorpe --- diff --git a/drivers/vfio/iommufd.c b/drivers/vfio/iommufd.c index 890ea101685c1..88b00c5010152 100644 --- a/drivers/vfio/iommufd.c +++ b/drivers/vfio/iommufd.c @@ -32,9 +32,6 @@ int vfio_iommufd_bind(struct vfio_device *vdev, struct iommufd_ctx *ictx) return 0; } - if (WARN_ON(!vdev->ops->bind_iommufd)) - return -ENODEV; - ret = vdev->ops->bind_iommufd(vdev, ictx, &device_id); if (ret) return ret; diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index 43bd6b76e2b6f..89497c9334907 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -255,8 +255,9 @@ static int __vfio_register_dev(struct vfio_device *device, { int ret; - if (WARN_ON(device->ops->bind_iommufd && - (!device->ops->unbind_iommufd || + if (WARN_ON(IS_ENABLED(CONFIG_IOMMUFD) && + (!device->ops->bind_iommufd || + !device->ops->unbind_iommufd || !device->ops->attach_ioas))) return -EINVAL;