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

vfio: Remove vfio_free_device

With the "mess" sorted out, we should be able to inline the
vfio_free_device call introduced by commit cb9ff3f3b84c
("vfio: Add helpers for unifying vfio_device life cycle")
and remove them from driver release callbacks.

Signed-off-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Tony Krowiak <akrowiak@linux.ibm.com> # vfio-ap part
Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
Link: https://lore.kernel.org/r/20221104142007.1314999-8-farman@linux.ibm.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

authored by

Eric Farman and committed by
Alex Williamson
913447d0 d1104f93

+4 -35
-1
drivers/gpu/drm/i915/gvt/kvmgt.c
··· 1461 1461 struct intel_vgpu *vgpu = vfio_dev_to_vgpu(vfio_dev); 1462 1462 1463 1463 intel_gvt_destroy_vgpu(vgpu); 1464 - vfio_free_device(vfio_dev); 1465 1464 } 1466 1465 1467 1466 static const struct vfio_device_ops intel_vgpu_dev_ops = {
-2
drivers/s390/cio/vfio_ccw_ops.c
··· 143 143 kmem_cache_free(vfio_ccw_io_region, private->io_region); 144 144 kfree(private->cp.guest_cp); 145 145 mutex_destroy(&private->io_mutex); 146 - 147 - vfio_free_device(vdev); 148 146 } 149 147 150 148 static void vfio_ccw_mdev_remove(struct mdev_device *mdev)
-6
drivers/s390/crypto/vfio_ap_ops.c
··· 765 765 } 766 766 } 767 767 768 - static void vfio_ap_mdev_release_dev(struct vfio_device *vdev) 769 - { 770 - vfio_free_device(vdev); 771 - } 772 - 773 768 static void vfio_ap_mdev_remove(struct mdev_device *mdev) 774 769 { 775 770 struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(&mdev->dev); ··· 1779 1784 1780 1785 static const struct vfio_device_ops vfio_ap_matrix_dev_ops = { 1781 1786 .init = vfio_ap_mdev_init_dev, 1782 - .release = vfio_ap_mdev_release_dev, 1783 1787 .open_device = vfio_ap_mdev_open_device, 1784 1788 .close_device = vfio_ap_mdev_close_device, 1785 1789 .ioctl = vfio_ap_mdev_ioctl,
-1
drivers/vfio/fsl-mc/vfio_fsl_mc.c
··· 568 568 569 569 vfio_fsl_uninit_device(vdev); 570 570 mutex_destroy(&vdev->igate); 571 - vfio_free_device(core_vdev); 572 571 } 573 572 574 573 static int vfio_fsl_mc_remove(struct fsl_mc_device *mc_dev)
-1
drivers/vfio/pci/vfio_pci_core.c
··· 2109 2109 mutex_destroy(&vdev->vma_lock); 2110 2110 kfree(vdev->region); 2111 2111 kfree(vdev->pm_save); 2112 - vfio_free_device(core_vdev); 2113 2112 } 2114 2113 EXPORT_SYMBOL_GPL(vfio_pci_core_release_dev); 2115 2114
-1
drivers/vfio/platform/vfio_amba.c
··· 95 95 96 96 vfio_platform_release_common(vdev); 97 97 kfree(vdev->name); 98 - vfio_free_device(core_vdev); 99 98 } 100 99 101 100 static void vfio_amba_remove(struct amba_device *adev)
-1
drivers/vfio/platform/vfio_platform.c
··· 83 83 container_of(core_vdev, struct vfio_platform_device, vdev); 84 84 85 85 vfio_platform_release_common(vdev); 86 - vfio_free_device(core_vdev); 87 86 } 88 87 89 88 static int vfio_platform_remove(struct platform_device *pdev)
+4 -18
drivers/vfio/vfio_main.c
··· 339 339 vfio_release_device_set(device); 340 340 ida_free(&vfio.device_ida, device->index); 341 341 342 - /* 343 - * kvfree() cannot be done here due to a life cycle mess in 344 - * vfio-ccw. Before the ccw part is fixed all drivers are 345 - * required to support @release and call vfio_free_device() 346 - * from there. 347 - */ 348 - device->ops->release(device); 342 + if (device->ops->release) 343 + device->ops->release(device); 344 + 345 + kvfree(device); 349 346 } 350 347 351 348 static int vfio_init_device(struct vfio_device *device, struct device *dev, ··· 420 423 ida_free(&vfio.device_ida, device->index); 421 424 return ret; 422 425 } 423 - 424 - /* 425 - * The helper called by driver @release callback to free the device 426 - * structure. Drivers which don't have private data to clean can 427 - * simply use this helper as its @release. 428 - */ 429 - void vfio_free_device(struct vfio_device *device) 430 - { 431 - kvfree(device); 432 - } 433 - EXPORT_SYMBOL_GPL(vfio_free_device); 434 426 435 427 static struct vfio_group *vfio_noiommu_group_alloc(struct device *dev, 436 428 enum vfio_group_type type)
-1
include/linux/vfio.h
··· 176 176 dev, ops), \ 177 177 struct dev_struct, member) 178 178 179 - void vfio_free_device(struct vfio_device *device); 180 179 static inline void vfio_put_device(struct vfio_device *device) 181 180 { 182 181 put_device(&device->device);
-1
samples/vfio-mdev/mbochs.c
··· 594 594 atomic_add(mdev_state->type->mbytes, &mbochs_avail_mbytes); 595 595 kfree(mdev_state->pages); 596 596 kfree(mdev_state->vconfig); 597 - vfio_free_device(vdev); 598 597 } 599 598 600 599 static void mbochs_remove(struct mdev_device *mdev)
-1
samples/vfio-mdev/mdpy.c
··· 283 283 284 284 vfree(mdev_state->memblk); 285 285 kfree(mdev_state->vconfig); 286 - vfio_free_device(vdev); 287 286 } 288 287 289 288 static void mdpy_remove(struct mdev_device *mdev)
-1
samples/vfio-mdev/mtty.c
··· 784 784 785 785 atomic_add(mdev_state->nr_ports, &mdev_avail_ports); 786 786 kfree(mdev_state->vconfig); 787 - vfio_free_device(vdev); 788 787 } 789 788 790 789 static void mtty_remove(struct mdev_device *mdev)