Re: [PATCH vfio 2/2] vfio: Split migration ops from main device ops

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 17 Jun 2022 08:50:00 +0000
Shameerali Kolothum Thodi <shameerali.kolothum.thodi@xxxxxxxxxx> wrote:

> > -----Original Message-----
> > From: Alex Williamson [mailto:alex.williamson@xxxxxxxxxx]
> > Sent: 17 June 2022 00:01
> > To: Yishai Hadas <yishaih@xxxxxxxxxx>
> > Cc: Tian, Kevin <kevin.tian@xxxxxxxxx>; maorg@xxxxxxxxxx;
> > cohuck@xxxxxxxxxx; Shameerali Kolothum Thodi
> > <shameerali.kolothum.thodi@xxxxxxxxxx>; liulongfang
> > <liulongfang@xxxxxxxxxx>; kvm@xxxxxxxxxxxxxxx; jgg@xxxxxxxxxx
> > Subject: Re: [PATCH vfio 2/2] vfio: Split migration ops from main device ops
> > 
> > On Thu, 16 Jun 2022 17:18:16 +0300
> > Yishai Hadas <yishaih@xxxxxxxxxx> wrote:
> >   
> > > On 13/06/2022 10:13, Yishai Hadas wrote:  
> > > > On 10/06/2022 6:32, Tian, Kevin wrote:  
> > > >>> From: Yishai Hadas <yishaih@xxxxxxxxxx>
> > > >>> Sent: Monday, June 6, 2022 4:56 PM
> > > >>>
> > > >>> vfio core checks whether the driver sets some migration op (e.g.
> > > >>> set_state/get_state) and accordingly calls its op.
> > > >>>
> > > >>> However, currently mlx5 driver sets the above ops without regards to
> > > >>> its
> > > >>> migration caps.
> > > >>>
> > > >>> This might lead to unexpected usage/Oops if user space may call to the
> > > >>> above ops even if the driver doesn't support migration. As for example,
> > > >>> the migration state_mutex is not initialized in that case.
> > > >>>
> > > >>> The cleanest way to manage that seems to split the migration ops from
> > > >>> the main device ops, this will let the driver setting them separately
> > > >>> from the main ops when it's applicable.
> > > >>>
> > > >>> As part of that, changed HISI driver to match this scheme.
> > > >>>
> > > >>> This scheme may enable down the road to come with some extra  
> > group of  
> > > >>> ops (e.g. DMA log) that can be set without regards to the other options
> > > >>> based on driver caps.
> > > >>>
> > > >>> Fixes: 6fadb021266d ("vfio/mlx5: Implement vfio_pci driver for mlx5
> > > >>> devices")
> > > >>> Signed-off-by: Yishai Hadas <yishaih@xxxxxxxxxx>  
> > > >> Reviewed-by: Kevin Tian <kevin.tian@xxxxxxxxx>, with one nit:  
> > > >
> > > > Thanks Kevin, please see below.
> > > >  
> > > >>  
> > > >>> @@ -1534,8 +1534,8 @@  
> > vfio_ioctl_device_feature_mig_device_state(struct  
> > > >>> vfio_device *device,
> > > >>>       struct file *filp = NULL;
> > > >>>       int ret;
> > > >>>
> > > >>> -    if (!device->ops->migration_set_state ||
> > > >>> -        !device->ops->migration_get_state)
> > > >>> +    if (!device->mig_ops->migration_set_state ||
> > > >>> +        !device->mig_ops->migration_get_state)
> > > >>>           return -ENOTTY;  
> > > >> ...
> > > >>  
> > > >>> @@ -1582,8 +1583,8 @@ static int
> > > >>> vfio_ioctl_device_feature_migration(struct vfio_device *device,
> > > >>>       };
> > > >>>       int ret;
> > > >>>
> > > >>> -    if (!device->ops->migration_set_state ||
> > > >>> -        !device->ops->migration_get_state)
> > > >>> +    if (!device->mig_ops->migration_set_state ||
> > > >>> +        !device->mig_ops->migration_get_state)
> > > >>>           return -ENOTTY;
> > > >>>  
> > > >> Above checks can be done once when the device is registered then
> > > >> here replaced with a single check on device->mig_ops.
> > > >>  
> > > > I agree, it may look as of below.
> > > >
> > > > Theoretically, this could be done even before this patch upon device
> > > > registration.
> > > >
> > > > We could check that both 'ops' were set and *not* only one of and
> > > > later check for the specific 'op' upon the feature request.
> > > >
> > > > Alex,
> > > >
> > > > Do you prefer to switch to the below as part of V2 or stay as of
> > > > current submission and I'll just add Kevin as Reviewed-by ?
> > > >
> > > > diff --git a/drivers/vfio/pci/vfio_pci_core.c
> > > > b/drivers/vfio/pci/vfio_pci_core.c
> > > > index a0d69ddaf90d..f42102a03851 100644
> > > > --- a/drivers/vfio/pci/vfio_pci_core.c
> > > > +++ b/drivers/vfio/pci/vfio_pci_core.c
> > > > @@ -1855,6 +1855,11 @@ int vfio_pci_core_register_device(struct
> > > > vfio_pci_core_device *vdev)
> > > >         if (pdev->hdr_type != PCI_HEADER_TYPE_NORMAL)
> > > >                 return -EINVAL;
> > > >
> > > > +       if (vdev->vdev.mig_ops &&
> > > > +          !(vdev->vdev.mig_ops->migration_get_state &&
> > > > +            vdev->vdev.mig_ops->migration_get_state))
> > > > +               return -EINVAL;
> > > > +
> > > >
> > > > Yishai
> > > >  
> > > Hi Alex,
> > >
> > > Did you have the chance to review the above note ?
> > >
> > > I would like to send V2 with Kevin's Reviewed-by tag for both patches,
> > > just wonder about the nit.  
> > 
> > The whole mig_ops handling seems rather ad-hoc to me.  What tells a
> > developer when mig_ops can be set?  Can they be unset?  Does this
> > enable a device feature callout to dynamically enable migration?  Why do
> > we init the device with vfio_device_ops, but then open code per driver
> > setting vfio_migration_ops?
> > 
> > For the hisi_acc changes, they're specifically defining two device_ops,
> > one for migration and one without migration.  This patch oddly makes
> > them identical other than the name and doesn't simplify the setup path,
> > which should now only require a single call point for init-device with
> > the proposed API rather than the existing three.  
> 
> I think one of the reasons we ended up using two diff ops were to restrict
> exposing the migration BAR regions to Guest(and for that we only expose
> half of the BAR region now). And for nested assignments this may result
> in invalid BAR sizes if we do it for no migration cases. Hence we have
> overrides for read/write/mmap/ioctl functions in hisi_acc_vfio_pci_migrn_ops .

Darn, I always forget about that and skimmed too quickly, the close,
read, write, and mmap callbacks are all different.  Sorry about that.

> If we have to simplify the setup path, I guess we retain only the _migrn_ops and
> add explicit checks for migration support in the above override functions.  

Yes, that's an option and none of those callbacks should be terribly
performance sensitive to an inline test, it's just a matter of where we
want to simplify the code.  Given the additional differences in
callbacks I'm not necessarily suggesting this is something we need to
change.

> > If we remove the migration callbacks from vfio_device_ops, there's also
> > an opportunity that we can fix the vfio_device_ops.name handling in
> > hisi_acc, where the only current user of this is to set the driver
> > override for spawned VFs from a vfio owned PF.  This is probably
> > irrelevant for this driver, but clearly we have an expectation there
> > that name is the name of the module providing the ops and we have no
> > module named hisi-acc-vfio-pci-migration.  Thanks,
> >   
> 
> Since the driver is mainly to provide migration support, I am just thinking
> whether it make sense to return failure in probe() if migration cannot be
> supported and then if user wishes can bind to the generic vfio-pci driver
> instead.

That might be asking too much for userspace.  We're conveying to
userspace via the modinfo alias information which vfio-pci variant to
use for the device, but then to have the driver reject the device and
expect userspace to move to the next match seems like a lot to ask.  It
doesn't seem wrong for a driver to have multiple vfio_device_ops, but
we might need to think more about the purpose of the name field, if the
use of it for capturing VFs is valid, or if we'd rather have some sort
of explicit capture driver provided by the ops.  Thanks,

Alex





[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux