summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gunthorpe <jgg@nvidia.com>2022-09-22 21:20:23 +0200
committerAlex Williamson <alex.williamson@redhat.com>2022-09-22 23:46:06 +0200
commitc41da4622e08f874ab02e12eb6b6aaa9ac21daa7 (patch)
treea2257893ea9acaed073150767a913bc51d2bbd88
parentvfio: Remove #ifdefs around CONFIG_VFIO_NOIOMMU (diff)
downloadlinux-c41da4622e08f874ab02e12eb6b6aaa9ac21daa7.tar.xz
linux-c41da4622e08f874ab02e12eb6b6aaa9ac21daa7.zip
vfio: Split out container code from the init/cleanup functions
This miscdev, noiommu driver and a couple of globals are all container items. Move this init into its own functions. A following patch will move the vfio_container functions to their own .c file. Reviewed-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/5-v3-297af71838d2+b9-vfio_container_split_jgg@nvidia.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
-rw-r--r--drivers/vfio/vfio_main.c54
1 files changed, 36 insertions, 18 deletions
diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
index f79e7eb02931..3cb52e9ab035 100644
--- a/drivers/vfio/vfio_main.c
+++ b/drivers/vfio/vfio_main.c
@@ -2397,15 +2397,11 @@ static struct miscdevice vfio_dev = {
.mode = S_IRUGO | S_IWUGO,
};
-static int __init vfio_init(void)
+static int __init vfio_container_init(void)
{
int ret;
- ida_init(&vfio.group_ida);
- ida_init(&vfio.device_ida);
- mutex_init(&vfio.group_lock);
mutex_init(&vfio.iommu_drivers_lock);
- INIT_LIST_HEAD(&vfio.group_list);
INIT_LIST_HEAD(&vfio.iommu_drivers_list);
ret = misc_register(&vfio_dev);
@@ -2414,6 +2410,39 @@ static int __init vfio_init(void)
return ret;
}
+ if (IS_ENABLED(CONFIG_VFIO_NOIOMMU)) {
+ ret = vfio_register_iommu_driver(&vfio_noiommu_ops);
+ if (ret)
+ goto err_misc;
+ }
+ return 0;
+
+err_misc:
+ misc_deregister(&vfio_dev);
+ return ret;
+}
+
+static void vfio_container_cleanup(void)
+{
+ if (IS_ENABLED(CONFIG_VFIO_NOIOMMU))
+ vfio_unregister_iommu_driver(&vfio_noiommu_ops);
+ misc_deregister(&vfio_dev);
+ mutex_destroy(&vfio.iommu_drivers_lock);
+}
+
+static int __init vfio_init(void)
+{
+ int ret;
+
+ ida_init(&vfio.group_ida);
+ ida_init(&vfio.device_ida);
+ mutex_init(&vfio.group_lock);
+ INIT_LIST_HEAD(&vfio.group_list);
+
+ ret = vfio_container_init();
+ if (ret)
+ return ret;
+
/* /dev/vfio/$GROUP */
vfio.class = class_create(THIS_MODULE, "vfio");
if (IS_ERR(vfio.class)) {
@@ -2434,17 +2463,9 @@ static int __init vfio_init(void)
if (ret)
goto err_alloc_chrdev;
- if (IS_ENABLED(CONFIG_VFIO_NOIOMMU)) {
- ret = vfio_register_iommu_driver(&vfio_noiommu_ops);
- if (ret)
- goto err_driver_register;
- }
-
pr_info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
return 0;
-err_driver_register:
- unregister_chrdev_region(vfio.group_devt, MINORMASK + 1);
err_alloc_chrdev:
class_destroy(vfio.device_class);
vfio.device_class = NULL;
@@ -2452,7 +2473,7 @@ err_dev_class:
class_destroy(vfio.class);
vfio.class = NULL;
err_group_class:
- misc_deregister(&vfio_dev);
+ vfio_container_cleanup();
return ret;
}
@@ -2460,17 +2481,14 @@ static void __exit vfio_cleanup(void)
{
WARN_ON(!list_empty(&vfio.group_list));
- if (IS_ENABLED(CONFIG_VFIO_NOIOMMU))
- vfio_unregister_iommu_driver(&vfio_noiommu_ops);
-
ida_destroy(&vfio.device_ida);
ida_destroy(&vfio.group_ida);
unregister_chrdev_region(vfio.group_devt, MINORMASK + 1);
class_destroy(vfio.device_class);
vfio.device_class = NULL;
class_destroy(vfio.class);
+ vfio_container_cleanup();
vfio.class = NULL;
- misc_deregister(&vfio_dev);
xa_destroy(&vfio_device_set_xa);
}