[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220517120110.GS1343366@nvidia.com>
Date: Tue, 17 May 2022 09:01:10 -0300
From: Jason Gunthorpe <jgg@...dia.com>
To: Christoph Hellwig <hch@...radead.org>
Cc: Matthew Rosato <mjrosato@...ux.ibm.com>,
linux-s390@...r.kernel.org, alex.williamson@...hat.com,
cohuck@...hat.com, schnelle@...ux.ibm.com, farman@...ux.ibm.com,
pmorel@...ux.ibm.com, borntraeger@...ux.ibm.com, hca@...ux.ibm.com,
gor@...ux.ibm.com, gerald.schaefer@...ux.ibm.com,
agordeev@...ux.ibm.com, svens@...ux.ibm.com, frankja@...ux.ibm.com,
david@...hat.com, imbrenda@...ux.ibm.com, vneethv@...ux.ibm.com,
oberpar@...ux.ibm.com, freude@...ux.ibm.com, thuth@...hat.com,
pasic@...ux.ibm.com, pbonzini@...hat.com, corbet@....net,
kvm@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-doc@...r.kernel.org
Subject: Re: [PATCH v7 17/22] vfio-pci/zdev: add open/close device hooks
On Mon, May 16, 2022 at 11:21:19PM -0700, Christoph Hellwig wrote:
> On Mon, May 16, 2022 at 02:27:34PM -0300, Jason Gunthorpe wrote:
> > Normally you'd want to do what is kvm_s390_pci_register_kvm() here,
> > where a failure can be propogated but then you have a race condition
> > with the kvm.
> >
> > Blech, maybe it is time to just fix this race condition permanently,
> > what do you think? (I didn't even compile it)
>
> This is roughly were I was planning to get to, with one difference:
> I don't think we need or even want the VFIO_DEVICE_NEEDS_KVM flag.
> Instead just propagation ->kvm to the device whenever it is set and
> let drivers that have a hard requirements on it like gvt fail if it
> isn't there.
I did it so we didn't uselessly hold a ref on the kvm object, but
maybe that is not relevant.
> The other question is if we even need an extra reference per device,
> can't we hold the group reference until all devices are gone
> anyway? That would remove the need to include kvm_host.h in the
> vfio code.
The device does now hold a reference on the group fd after this patch
series:
https://lore.kernel.org/r/0-v2-d035a1842d81+1bf-vfio_group_locking_jgg@nvidia.com
However the group does not hold a reference on the KVM, it has a
set/remove interface toward KVM and can have its group->kvm pointer
NULL'd via an ioctl at any time.
So, the semantic here is that the KVM is captured when the device FD
opens and then is immutable for the lifetime of that device FD even if
the group FD's KVM is reassigned or removed.
And I realize that it is all botched, this needs to check and respect
the open_count which requires nesting the locks..
Jason
Powered by blists - more mailing lists