Commit 07b46586 authored by Yi Liu's avatar Yi Liu Committed by Jason Gunthorpe

vfio: Swap order of vfio_device_container_register() and open_device()

This makes the DMA unmap callback registration to container be consistent
across the vfio iommufd compat mode and the legacy container mode.

In the vfio iommufd compat mode, this registration is done in the
vfio_iommufd_bind() when creating access which has an unmap callback. This
is prior to calling the open_device() op. The existing mdev drivers have
been converted to be OK with this order. So it is ok to swap the order of
vfio_device_container_register() and open_device() for legacy mode.

This also prepares for further moving group specific code into separate
source file.

Link: https://lore.kernel.org/r/20221201145535.589687-6-yi.l.liu@intel.comReviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Reviewed-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Reviewed-by: default avatarAlex Williamson <alex.williamson@redhat.com>
Tested-by: default avatarLixiao Yang <lixiao.yang@intel.com>
Tested-by: default avatarYu He <yu.he@intel.com>
Signed-off-by: default avatarYi Liu <yi.l.liu@intel.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 49ea02d3
......@@ -807,6 +807,7 @@ static int vfio_device_first_open(struct vfio_device *device)
ret = vfio_group_use_container(device->group);
if (ret)
goto err_module_put;
vfio_device_container_register(device);
} else if (device->group->iommufd) {
ret = vfio_iommufd_bind(device, device->group->iommufd);
if (ret)
......@@ -819,17 +820,17 @@ static int vfio_device_first_open(struct vfio_device *device)
if (ret)
goto err_container;
}
if (device->group->container)
vfio_device_container_register(device);
mutex_unlock(&device->group->group_lock);
return 0;
err_container:
device->kvm = NULL;
if (device->group->container)
if (device->group->container) {
vfio_device_container_unregister(device);
vfio_group_unuse_container(device->group);
else if (device->group->iommufd)
} else if (device->group->iommufd) {
vfio_iommufd_unbind(device);
}
err_module_put:
mutex_unlock(&device->group->group_lock);
module_put(device->dev->driver->owner);
......@@ -841,15 +842,15 @@ static void vfio_device_last_close(struct vfio_device *device)
lockdep_assert_held(&device->dev_set->lock);
mutex_lock(&device->group->group_lock);
if (device->group->container)
vfio_device_container_unregister(device);
if (device->ops->close_device)
device->ops->close_device(device);
device->kvm = NULL;
if (device->group->container)
if (device->group->container) {
vfio_device_container_unregister(device);
vfio_group_unuse_container(device->group);
else if (device->group->iommufd)
} else if (device->group->iommufd) {
vfio_iommufd_unbind(device);
}
mutex_unlock(&device->group->group_lock);
module_put(device->dev->driver->owner);
}
......
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