All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Cornelia Huck <cohuck@redhat.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>,
	Jonathan Corbet <corbet@lwn.net>,
	kvm@vger.kernel.org, linux-doc@vger.kernel.org, "Raj,
	Ashok" <ashok.raj@intel.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Daniel Vetter <daniel@ffwll.ch>, Christoph Hellwig <hch@lst.de>,
	Leon Romanovsky <leonro@nvidia.com>,
	Max Gurtovoy <mgurtovoy@nvidia.com>,
	Tarun Gupta <targupta@nvidia.com>, Liu Yi L <yi.l.liu@intel.com>
Subject: Re: [PATCH v2 03/14] vfio: Split creation of a vfio_device into init and register ops
Date: Tue, 16 Mar 2021 15:13:06 -0600	[thread overview]
Message-ID: <20210316151306.3829ef82@omen.home.shazbot.org> (raw)
In-Reply-To: <20210316132559.6e6bc79a.cohuck@redhat.com>

On Tue, 16 Mar 2021 13:25:59 +0100
Cornelia Huck <cohuck@redhat.com> wrote:

> On Fri, 12 Mar 2021 20:55:55 -0400
> Jason Gunthorpe <jgg@nvidia.com> wrote:
> 
> > This makes the struct vfio_pci_device part of the public interface so it

s/_pci//

> > can be used with container_of and so forth, as is typical for a Linux
> > subystem.
> > 
> > This is the first step to bring some type-safety to the vfio interface by
> > allowing the replacement of 'void *' and 'struct device *' inputs with a
> > simple and clear 'struct vfio_pci_device *'

s/_pci//

> > 
> > For now the self-allocating vfio_add_group_dev() interface is kept so each
> > user can be updated as a separate patch.
> > 
> > The expected usage pattern is
> > 
> >   driver core probe() function:
> >      my_device = kzalloc(sizeof(*mydevice));
> >      vfio_init_group_dev(&my_device->vdev, dev, ops, mydevice);
> >      /* other driver specific prep */
> >      vfio_register_group_dev(&my_device->vdev);
> >      dev_set_drvdata(my_device);
> > 
> >   driver core remove() function:
> >      my_device = dev_get_drvdata(dev);
> >      vfio_unregister_group_dev(&my_device->vdev);
> >      /* other driver specific tear down */
> >      kfree(my_device);
> > 
> > Allowing the driver to be able to use the drvdata and vifo_device to go  
> 
> s/vifo_device/vfio_device/
> 
> > to/from its own data.
> > 
> > The pattern also makes it clear that vfio_register_group_dev() must be
> > last in the sequence, as once it is called the core code can immediately
> > start calling ops. The init/register gap is provided to allow for the
> > driver to do setup before ops can be called and thus avoid races.
> > 
> > Reviewed-by: Christoph Hellwig <hch@lst.de>
> > Reviewed-by: Liu Yi L <yi.l.liu@intel.com>
> > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> > ---
> >  Documentation/driver-api/vfio.rst |  31 ++++----
> >  drivers/vfio/vfio.c               | 123 ++++++++++++++++--------------
> >  include/linux/vfio.h              |  16 ++++
> >  3 files changed, 98 insertions(+), 72 deletions(-)
> > 
> > diff --git a/Documentation/driver-api/vfio.rst b/Documentation/driver-api/vfio.rst
> > index f1a4d3c3ba0bb1..d3a02300913a7f 100644
> > --- a/Documentation/driver-api/vfio.rst
> > +++ b/Documentation/driver-api/vfio.rst
> > @@ -249,18 +249,23 @@ VFIO bus driver API
> >  
> >  VFIO bus drivers, such as vfio-pci make use of only a few interfaces
> >  into VFIO core.  When devices are bound and unbound to the driver,
> > -the driver should call vfio_add_group_dev() and vfio_del_group_dev()
> > -respectively::
> > -
> > -	extern int vfio_add_group_dev(struct device *dev,
> > -				      const struct vfio_device_ops *ops,
> > -				      void *device_data);
> > -
> > -	extern void *vfio_del_group_dev(struct device *dev);
> > -
> > -vfio_add_group_dev() indicates to the core to begin tracking the
> > -iommu_group of the specified dev and register the dev as owned by
> > -a VFIO bus driver.  The driver provides an ops structure for callbacks
> > +the driver should call vfio_register_group_dev() and
> > +vfio_unregister_group_dev() respectively::
> > +
> > +	void vfio_init_group_dev(struct vfio_device *device,
> > +				struct device *dev,
> > +				const struct vfio_device_ops *ops,
> > +				void *device_data);
> > +	int vfio_register_group_dev(struct vfio_device *device);
> > +	void vfio_unregister_group_dev(struct vfio_device *device);
> > +
> > +The driver should embed the vfio_device in its own structure and call
> > +vfio_init_group_dev() to pre-configure it before going to registration.  
> 
> s/it/that structure/ (I guess?)

Seems less clear actually, is the object of "that structure" the
"vfio_device" or "its own structure".  Phrasing somewhat suggests the
latter.  s/it/the vfio_device structure/ seems excessively verbose.  I
think "it" is probably sufficient here.  Thanks,

Alex

 
> > +vfio_register_group_dev() indicates to the core to begin tracking the
> > +iommu_group of the specified dev and register the dev as owned by a VFIO bus
> > +driver. Once vfio_register_group_dev() returns it is possible for userspace to
> > +start accessing the driver, thus the driver should ensure it is completely
> > +ready before calling it. The driver provides an ops structure for callbacks
> >  similar to a file operations structure::
> >  
> >  	struct vfio_device_ops {  
> 
> Reviewed-by: Cornelia Huck <cohuck@redhat.com>


  reply	other threads:[~2021-03-16 21:14 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210316151306.3829ef82@omen.home.shazbot.org \
    --to=alex.williamson@redhat.com \
    --cc=ashok.raj@intel.com \
    --cc=cohuck@redhat.com \
    --cc=corbet@lwn.net \
    --cc=dan.j.williams@intel.com \
    --cc=daniel@ffwll.ch \
    --cc=hch@lst.de \
    --cc=jgg@nvidia.com \
    --cc=kvm@vger.kernel.org \
    --cc=leonro@nvidia.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=mgurtovoy@nvidia.com \
    --cc=targupta@nvidia.com \
    --cc=yi.l.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.