All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/14] Embed struct vfio_device in all sub-structures
@ 2021-03-13  0:55 Jason Gunthorpe
  2021-03-13  0:55 ` [PATCH v2 01/14] vfio: Remove extra put/gets around vfio_device->group Jason Gunthorpe
                   ` (13 more replies)
  0 siblings, 14 replies; 82+ messages in thread
From: Jason Gunthorpe @ 2021-03-13  0:55 UTC (permalink / raw)
  To: Alex Williamson, Cornelia Huck, Jonathan Corbet, Diana Craciun,
	Eric Auger, kvm, Kirti Wankhede, linux-doc
  Cc: Raj, Ashok, Bharat Bhushan, Christian Ehrhardt, Dan Williams,
	Daniel Vetter, Christoph Hellwig, Kevin Tian, Leon Romanovsky,
	Max Gurtovoy, Tarun Gupta, Liu Yi L

The main focus of this series is to make VFIO follow the normal kernel
convention of structure embedding for structure inheritance instead of
linking using a 'void *opaque'. Here we focus on moving the vfio_device to
be a member of every struct vfio_XX_device that is linked by a
vfio_add_group_dev().

In turn this allows 'struct vfio_device *' to be used everwhere, and the
public API out of vfio.c can be cleaned to remove places using 'struct
device *' and 'void *' as surrogates to refer to the device.

While this has the minor trade off of moving 'struct vfio_device' the
clarity of the design is worth it. I can speak directly to this idea, as
I've invested a fair amount of time carefully working backwards what all
the type-erased APIs are supposed to be and it is certainly not trivial or
intuitive.

When we get into mdev land things become even more inscrutable, and while
I now have a pretty clear picture, it was hard to obtain. I think this
agrees with the kernel style ideal of being explicit in typing and not
sacrificing clarity to create opaque structs.

After this series the general rules are:
 - Any vfio_XX_device * can be obtained at no cost from a vfio_device *
   using container_of(), and the reverse is possible by &XXdev->vdev

   This is similar to how 'struct pci_device' and 'struct device' are
   interrelated.

   This allows 'device_data' to be completely removed from the vfio.c API.

 - The drvdata for a struct device points at the vfio_XX_device that
   belongs to the driver that was probed. drvdata is removed from the core
   code, and only used as part of the implementation of the struct
   device_driver.

 - The lifetime of vfio_XX_device and vfio_device are identical, they are
   the same memory.

   This follows the existing model where vfio_del_group_dev() blocks until
   all vfio_device_put()'s are completed. This in turn means the struct
   device_driver remove() blocks, and thus under the driver_lock() a bound
   driver must have a valid drvdata pointing at both vfio device
   structs. A following series exploits this further.

Most vfio_XX_device structs have data that duplicates the 'struct
device *dev' member of vfio_device, a following series removes that
duplication too.

v2:
 - Split the get/put changes out of "Simlpify the lifetime logic for
   vfio_device"
 - Add a patch to fix probe ordering in fsl-mc and remove FIXME
 - Add a patch to re-org pci probe
 - Add a patch to fix probe odering in pci and remove FIXME
 - Remove the **pf_dev output from get_pf_vdev()
v1: https://lore.kernel.org/r/0-v1-7355d38b9344+17481-vfio1_jgg@nvidia.com

Thanks,
Jason

Jason Gunthorpe (14):
  vfio: Remove extra put/gets around vfio_device->group
  vfio: Simplify the lifetime logic for vfio_device
  vfio: Split creation of a vfio_device into init and register ops
  vfio/platform: Use vfio_init/register/unregister_group_dev
  vfio/fsl-mc: Re-order vfio_fsl_mc_probe()
  vfio/fsl-mc: Use vfio_init/register/unregister_group_dev
  vfio/pci: Move VGA and VF initialization to functions
  vfio/pci: Re-order vfio_pci_probe()
  vfio/pci: Use vfio_init/register/unregister_group_dev
  vfio/mdev: Use vfio_init/register/unregister_group_dev
  vfio/mdev: Make to_mdev_device() into a static inline
  vfio: Make vfio_device_ops pass a 'struct vfio_device *' instead of
    'void *'
  vfio/pci: Replace uses of vfio_device_data() with container_of
  vfio: Remove device_data from the vfio bus driver API

 Documentation/driver-api/vfio.rst             |  48 ++--
 drivers/vfio/fsl-mc/vfio_fsl_mc.c             |  96 ++++---
 drivers/vfio/fsl-mc/vfio_fsl_mc_private.h     |   1 +
 drivers/vfio/mdev/mdev_private.h              |   5 +-
 drivers/vfio/mdev/vfio_mdev.c                 |  57 ++--
 drivers/vfio/pci/vfio_pci.c                   | 253 ++++++++++--------
 drivers/vfio/pci/vfio_pci_private.h           |   1 +
 drivers/vfio/platform/vfio_amba.c             |   8 +-
 drivers/vfio/platform/vfio_platform.c         |  21 +-
 drivers/vfio/platform/vfio_platform_common.c  |  56 ++--
 drivers/vfio/platform/vfio_platform_private.h |   5 +-
 drivers/vfio/vfio.c                           | 210 +++++----------
 include/linux/vfio.h                          |  37 ++-
 13 files changed, 397 insertions(+), 401 deletions(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 82+ messages in thread

end of thread, other threads:[~2021-03-23 13:06 UTC | newest]

Thread overview: 82+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-13  0:55 [PATCH v2 00/14] Embed struct vfio_device in all sub-structures Jason Gunthorpe
2021-03-13  0:55 ` [PATCH v2 01/14] vfio: Remove extra put/gets around vfio_device->group Jason Gunthorpe
2021-03-16  7:33   ` Tian, Kevin
2021-03-16 23:07     ` Jason Gunthorpe
2021-03-17  0:47       ` Tian, Kevin
2021-03-19 13:58         ` Jason Gunthorpe
2021-03-16 11:15   ` Max Gurtovoy
2021-03-16 11:59   ` Cornelia Huck
2021-03-18  9:32   ` Auger Eric
2021-03-13  0:55 ` [PATCH v2 02/14] vfio: Simplify the lifetime logic for vfio_device Jason Gunthorpe
2021-03-16  7:38   ` Tian, Kevin
2021-03-16 12:10     ` Cornelia Huck
2021-03-16 20:24     ` Alex Williamson
2021-03-16 23:08       ` Jason Gunthorpe
2021-03-17  8:12       ` Cornelia Huck
2021-03-23 13:06         ` Jason Gunthorpe
2021-03-18 13:10   ` Auger Eric
2021-03-13  0:55 ` [PATCH v2 03/14] vfio: Split creation of a vfio_device into init and register ops Jason Gunthorpe
2021-03-16  7:55   ` Tian, Kevin
2021-03-16 13:34     ` Jason Gunthorpe
2021-03-17  0:55       ` Tian, Kevin
2021-03-16 12:25   ` Cornelia Huck
2021-03-16 21:13     ` Alex Williamson
2021-03-16 23:12       ` Jason Gunthorpe
2021-03-16 12:54   ` Max Gurtovoy
2021-03-18 13:18   ` Auger Eric
2021-03-13  0:55 ` [PATCH v2 04/14] vfio/platform: Use vfio_init/register/unregister_group_dev Jason Gunthorpe
2021-03-16 16:22   ` Cornelia Huck
2021-03-16 21:33   ` Alex Williamson
2021-03-16 21:45     ` Jason Gunthorpe
2021-03-18 13:40   ` Auger Eric
2021-03-13  0:55 ` [PATCH v2 05/14] vfio/fsl-mc: Re-order vfio_fsl_mc_probe() Jason Gunthorpe
2021-03-15  8:44   ` Christoph Hellwig
2021-03-16  9:16   ` Diana Craciun OSS
2021-03-16 16:28   ` Cornelia Huck
2021-03-17 16:36   ` Diana Craciun OSS
2021-03-17 22:59     ` Jason Gunthorpe
2021-03-13  0:55 ` [PATCH v2 06/14] vfio/fsl-mc: Use vfio_init/register/unregister_group_dev Jason Gunthorpe
2021-03-15  8:44   ` Christoph Hellwig
2021-03-16 16:43   ` Cornelia Huck
2021-03-13  0:55 ` [PATCH v2 07/14] vfio/pci: Move VGA and VF initialization to functions Jason Gunthorpe
2021-03-15  8:45   ` Christoph Hellwig
2021-03-15 23:07     ` Jason Gunthorpe
2021-03-16  6:27       ` Christoph Hellwig
2021-03-16  7:57   ` Tian, Kevin
2021-03-16 13:02   ` Max Gurtovoy
2021-03-16 23:04     ` Jason Gunthorpe
2021-03-16 16:51   ` Cornelia Huck
2021-03-18 16:34   ` Auger Eric
2021-03-13  0:56 ` [PATCH v2 08/14] vfio/pci: Re-order vfio_pci_probe() Jason Gunthorpe
2021-03-15  8:46   ` Christoph Hellwig
2021-03-16  8:04   ` Tian, Kevin
2021-03-16 13:20     ` Jason Gunthorpe
2021-03-16 22:27       ` Alex Williamson
2021-03-17  0:56         ` Tian, Kevin
2021-03-16 11:28   ` Max Gurtovoy
2021-03-17 10:32   ` Cornelia Huck
2021-03-18 16:50   ` Auger Eric
2021-03-13  0:56 ` [PATCH v2 09/14] vfio/pci: Use vfio_init/register/unregister_group_dev Jason Gunthorpe
2021-03-16  8:06   ` Tian, Kevin
2021-03-17 10:33   ` Cornelia Huck
2021-03-18 13:43   ` Auger Eric
2021-03-13  0:56 ` [PATCH v2 10/14] vfio/mdev: " Jason Gunthorpe
2021-03-16  8:09   ` Tian, Kevin
2021-03-16 22:51     ` Alex Williamson
2021-03-16 23:19     ` Jason Gunthorpe
2021-03-17 10:36   ` Cornelia Huck
2021-03-13  0:56 ` [PATCH v2 11/14] vfio/mdev: Make to_mdev_device() into a static inline Jason Gunthorpe
2021-03-16  8:10   ` Tian, Kevin
2021-03-16 22:55   ` Alex Williamson
2021-03-16 23:20     ` Jason Gunthorpe
2021-03-17 10:36   ` Cornelia Huck
2021-03-13  0:56 ` [PATCH v2 12/14] vfio: Make vfio_device_ops pass a 'struct vfio_device *' instead of 'void *' Jason Gunthorpe
2021-03-15  8:58   ` Christoph Hellwig
2021-03-17 11:33   ` Cornelia Huck
2021-03-13  0:56 ` [PATCH v2 13/14] vfio/pci: Replace uses of vfio_device_data() with container_of Jason Gunthorpe
2021-03-16  8:20   ` Tian, Kevin
2021-03-17 12:06   ` Cornelia Huck
2021-03-13  0:56 ` [PATCH v2 14/14] vfio: Remove device_data from the vfio bus driver API Jason Gunthorpe
2021-03-16  8:22   ` Tian, Kevin
2021-03-17 12:08   ` Cornelia Huck
2021-03-17 23:24   ` Max Gurtovoy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.