Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vfio/mdev: Remove vfio_mdev.c

Now that all mdev drivers directly create their own mdev_device driver and
directly register with the vfio core's vfio_device_ops this is all dead
code.

Delete vfio_mdev.c and the mdev_parent_ops members that are connected to
it.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Zhi Wang <zhi.a.wang@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20220411141403.86980-31-hch@lst.de
Reviewed-by: Kirti Wankhede <kwankhede@nvidia.com>
Reviewed-by: Zhi Wang <zhi.a.wang@intel.com>

authored by

Jason Gunthorpe and committed by
Zhi Wang
6c7f98b3 cba619cb

+6 -251
-3
Documentation/driver-api/vfio-mediated-device.rst
··· 138 138 * supported_config: attributes to define supported configurations 139 139 * device_driver: device driver to bind for mediated device instances 140 140 141 - The mdev_parent_ops also still has various functions pointers. Theses exist 142 - for historical reasons only and shall not be used for new drivers. 143 - 144 141 When a driver wants to add the GUID creation sysfs to an existing device it has 145 142 probe'd to then it should call:: 146 143
+1 -1
drivers/vfio/mdev/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 3 - mdev-y := mdev_core.o mdev_sysfs.o mdev_driver.o vfio_mdev.o 3 + mdev-y := mdev_core.o mdev_sysfs.o mdev_driver.o 4 4 5 5 obj-$(CONFIG_VFIO_MDEV) += mdev.o
+4 -36
drivers/vfio/mdev/mdev_core.c
··· 89 89 static void mdev_device_remove_common(struct mdev_device *mdev) 90 90 { 91 91 struct mdev_parent *parent = mdev->type->parent; 92 - int ret; 93 92 94 93 mdev_remove_sysfs_files(mdev); 95 94 device_del(&mdev->dev); 96 95 lockdep_assert_held(&parent->unreg_sem); 97 - if (parent->ops->remove) { 98 - ret = parent->ops->remove(mdev); 99 - if (ret) 100 - dev_err(&mdev->dev, "Remove failed: err=%d\n", ret); 101 - } 102 - 103 96 /* Balances with device_initialize() */ 104 97 put_device(&mdev->dev); 105 98 } ··· 124 131 /* check for mandatory ops */ 125 132 if (!ops || !ops->supported_type_groups) 126 133 return -EINVAL; 127 - if (!ops->device_driver && (!ops->create || !ops->remove)) 134 + if (!ops->device_driver) 128 135 return -EINVAL; 129 136 130 137 dev = get_device(dev); ··· 290 297 goto out_put_device; 291 298 } 292 299 293 - if (parent->ops->create) { 294 - ret = parent->ops->create(mdev); 295 - if (ret) 296 - goto out_unlock; 297 - } 298 - 299 300 ret = device_add(&mdev->dev); 300 301 if (ret) 301 - goto out_remove; 302 + goto out_unlock; 302 303 303 - if (!drv) 304 - drv = &vfio_mdev_driver; 305 304 ret = device_driver_attach(&drv->driver, &mdev->dev); 306 305 if (ret) 307 306 goto out_del; ··· 310 325 311 326 out_del: 312 327 device_del(&mdev->dev); 313 - out_remove: 314 - if (parent->ops->remove) 315 - parent->ops->remove(mdev); 316 328 out_unlock: 317 329 up_read(&parent->unreg_sem); 318 330 out_put_device: ··· 352 370 353 371 static int __init mdev_init(void) 354 372 { 355 - int rc; 356 - 357 - rc = mdev_bus_register(); 358 - if (rc) 359 - return rc; 360 - rc = mdev_register_driver(&vfio_mdev_driver); 361 - if (rc) 362 - goto err_bus; 363 - return 0; 364 - err_bus: 365 - mdev_bus_unregister(); 366 - return rc; 373 + return bus_register(&mdev_bus_type); 367 374 } 368 375 369 376 static void __exit mdev_exit(void) 370 377 { 371 - mdev_unregister_driver(&vfio_mdev_driver); 372 - 373 378 if (mdev_bus_compat_class) 374 379 class_compat_unregister(mdev_bus_compat_class); 375 - 376 - mdev_bus_unregister(); 380 + bus_unregister(&mdev_bus_type); 377 381 } 378 382 379 383 subsys_initcall(mdev_init)
-10
drivers/vfio/mdev/mdev_driver.c
··· 74 74 driver_unregister(&drv->driver); 75 75 } 76 76 EXPORT_SYMBOL(mdev_unregister_driver); 77 - 78 - int mdev_bus_register(void) 79 - { 80 - return bus_register(&mdev_bus_type); 81 - } 82 - 83 - void mdev_bus_unregister(void) 84 - { 85 - bus_unregister(&mdev_bus_type); 86 - }
-2
drivers/vfio/mdev/mdev_private.h
··· 37 37 #define to_mdev_type(_kobj) \ 38 38 container_of(_kobj, struct mdev_type, kobj) 39 39 40 - extern struct mdev_driver vfio_mdev_driver; 41 - 42 40 int parent_create_sysfs_files(struct mdev_parent *parent); 43 41 void parent_remove_sysfs_files(struct mdev_parent *parent); 44 42
-152
drivers/vfio/mdev/vfio_mdev.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * VFIO based driver for Mediated device 4 - * 5 - * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. 6 - * Author: Neo Jia <cjia@nvidia.com> 7 - * Kirti Wankhede <kwankhede@nvidia.com> 8 - */ 9 - 10 - #include <linux/init.h> 11 - #include <linux/module.h> 12 - #include <linux/device.h> 13 - #include <linux/kernel.h> 14 - #include <linux/slab.h> 15 - #include <linux/vfio.h> 16 - #include <linux/mdev.h> 17 - 18 - #include "mdev_private.h" 19 - 20 - static int vfio_mdev_open_device(struct vfio_device *core_vdev) 21 - { 22 - struct mdev_device *mdev = to_mdev_device(core_vdev->dev); 23 - struct mdev_parent *parent = mdev->type->parent; 24 - 25 - if (unlikely(!parent->ops->open_device)) 26 - return 0; 27 - 28 - return parent->ops->open_device(mdev); 29 - } 30 - 31 - static void vfio_mdev_close_device(struct vfio_device *core_vdev) 32 - { 33 - struct mdev_device *mdev = to_mdev_device(core_vdev->dev); 34 - struct mdev_parent *parent = mdev->type->parent; 35 - 36 - if (likely(parent->ops->close_device)) 37 - parent->ops->close_device(mdev); 38 - } 39 - 40 - static long vfio_mdev_unlocked_ioctl(struct vfio_device *core_vdev, 41 - unsigned int cmd, unsigned long arg) 42 - { 43 - struct mdev_device *mdev = to_mdev_device(core_vdev->dev); 44 - struct mdev_parent *parent = mdev->type->parent; 45 - 46 - if (unlikely(!parent->ops->ioctl)) 47 - return 0; 48 - 49 - return parent->ops->ioctl(mdev, cmd, arg); 50 - } 51 - 52 - static ssize_t vfio_mdev_read(struct vfio_device *core_vdev, char __user *buf, 53 - size_t count, loff_t *ppos) 54 - { 55 - struct mdev_device *mdev = to_mdev_device(core_vdev->dev); 56 - struct mdev_parent *parent = mdev->type->parent; 57 - 58 - if (unlikely(!parent->ops->read)) 59 - return -EINVAL; 60 - 61 - return parent->ops->read(mdev, buf, count, ppos); 62 - } 63 - 64 - static ssize_t vfio_mdev_write(struct vfio_device *core_vdev, 65 - const char __user *buf, size_t count, 66 - loff_t *ppos) 67 - { 68 - struct mdev_device *mdev = to_mdev_device(core_vdev->dev); 69 - struct mdev_parent *parent = mdev->type->parent; 70 - 71 - if (unlikely(!parent->ops->write)) 72 - return -EINVAL; 73 - 74 - return parent->ops->write(mdev, buf, count, ppos); 75 - } 76 - 77 - static int vfio_mdev_mmap(struct vfio_device *core_vdev, 78 - struct vm_area_struct *vma) 79 - { 80 - struct mdev_device *mdev = to_mdev_device(core_vdev->dev); 81 - struct mdev_parent *parent = mdev->type->parent; 82 - 83 - if (unlikely(!parent->ops->mmap)) 84 - return -EINVAL; 85 - 86 - return parent->ops->mmap(mdev, vma); 87 - } 88 - 89 - static void vfio_mdev_request(struct vfio_device *core_vdev, unsigned int count) 90 - { 91 - struct mdev_device *mdev = to_mdev_device(core_vdev->dev); 92 - struct mdev_parent *parent = mdev->type->parent; 93 - 94 - if (parent->ops->request) 95 - parent->ops->request(mdev, count); 96 - else if (count == 0) 97 - dev_notice(mdev_dev(mdev), 98 - "No mdev vendor driver request callback support, blocked until released by user\n"); 99 - } 100 - 101 - static const struct vfio_device_ops vfio_mdev_dev_ops = { 102 - .name = "vfio-mdev", 103 - .open_device = vfio_mdev_open_device, 104 - .close_device = vfio_mdev_close_device, 105 - .ioctl = vfio_mdev_unlocked_ioctl, 106 - .read = vfio_mdev_read, 107 - .write = vfio_mdev_write, 108 - .mmap = vfio_mdev_mmap, 109 - .request = vfio_mdev_request, 110 - }; 111 - 112 - static int vfio_mdev_probe(struct mdev_device *mdev) 113 - { 114 - struct vfio_device *vdev; 115 - int ret; 116 - 117 - vdev = kzalloc(sizeof(*vdev), GFP_KERNEL); 118 - if (!vdev) 119 - return -ENOMEM; 120 - 121 - vfio_init_group_dev(vdev, &mdev->dev, &vfio_mdev_dev_ops); 122 - ret = vfio_register_emulated_iommu_dev(vdev); 123 - if (ret) 124 - goto out_uninit; 125 - 126 - dev_set_drvdata(&mdev->dev, vdev); 127 - return 0; 128 - 129 - out_uninit: 130 - vfio_uninit_group_dev(vdev); 131 - kfree(vdev); 132 - return ret; 133 - } 134 - 135 - static void vfio_mdev_remove(struct mdev_device *mdev) 136 - { 137 - struct vfio_device *vdev = dev_get_drvdata(&mdev->dev); 138 - 139 - vfio_unregister_group_dev(vdev); 140 - vfio_uninit_group_dev(vdev); 141 - kfree(vdev); 142 - } 143 - 144 - struct mdev_driver vfio_mdev_driver = { 145 - .driver = { 146 - .name = "vfio_mdev", 147 - .owner = THIS_MODULE, 148 - .mod_name = KBUILD_MODNAME, 149 - }, 150 - .probe = vfio_mdev_probe, 151 - .remove = vfio_mdev_remove, 152 - };
+1 -47
include/linux/mdev.h
··· 40 40 * @mdev_attr_groups: Attributes of the mediated device. 41 41 * @supported_type_groups: Attributes to define supported types. It is mandatory 42 42 * to provide supported types. 43 - * @create: Called to allocate basic resources in parent device's 44 - * driver for a particular mediated device. It is 45 - * mandatory to provide create ops. 46 - * @mdev: mdev_device structure on of mediated device 47 - * that is being created 48 - * Returns integer: success (0) or error (< 0) 49 - * @remove: Called to free resources in parent device's driver for 50 - * a mediated device. It is mandatory to provide 'remove' 51 - * ops. 52 - * @mdev: mdev_device device structure which is being 53 - * destroyed 54 - * Returns integer: success (0) or error (< 0) 55 - * @read: Read emulation callback 56 - * @mdev: mediated device structure 57 - * @buf: read buffer 58 - * @count: number of bytes to read 59 - * @ppos: address. 60 - * Retuns number on bytes read on success or error. 61 - * @write: Write emulation callback 62 - * @mdev: mediated device structure 63 - * @buf: write buffer 64 - * @count: number of bytes to be written 65 - * @ppos: address. 66 - * Retuns number on bytes written on success or error. 67 - * @ioctl: IOCTL callback 68 - * @mdev: mediated device structure 69 - * @cmd: ioctl command 70 - * @arg: arguments to ioctl 71 - * @mmap: mmap callback 72 - * @mdev: mediated device structure 73 - * @vma: vma structure 74 - * @request: request callback to release device 75 - * @mdev: mediated device structure 76 - * @count: request sequence number 43 + * 77 44 * Parent device that support mediated device should be registered with mdev 78 45 * module with mdev_parent_ops structure. 79 46 **/ ··· 50 83 const struct attribute_group **dev_attr_groups; 51 84 const struct attribute_group **mdev_attr_groups; 52 85 struct attribute_group **supported_type_groups; 53 - 54 - int (*create)(struct mdev_device *mdev); 55 - int (*remove)(struct mdev_device *mdev); 56 - int (*open_device)(struct mdev_device *mdev); 57 - void (*close_device)(struct mdev_device *mdev); 58 - ssize_t (*read)(struct mdev_device *mdev, char __user *buf, 59 - size_t count, loff_t *ppos); 60 - ssize_t (*write)(struct mdev_device *mdev, const char __user *buf, 61 - size_t count, loff_t *ppos); 62 - long (*ioctl)(struct mdev_device *mdev, unsigned int cmd, 63 - unsigned long arg); 64 - int (*mmap)(struct mdev_device *mdev, struct vm_area_struct *vma); 65 - void (*request)(struct mdev_device *mdev, unsigned int count); 66 86 }; 67 87 68 88 /* interface for exporting mdev supported type attributes */