dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: "Tian, Kevin" <kevin.tian@intel.com>
To: "Wang, Zhi A" <zhi.a.wang@intel.com>,
	Alex Williamson <alex.williamson@redhat.com>,
	Zhenyu Wang <zhenyuw@linux.intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
	Jason Gunthorpe <jgg@nvidia.com>, David Airlie <airlied@linux.ie>,
	"intel-gfx@lists.freedesktop.org"
	<intel-gfx@lists.freedesktop.org>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"Vivi, Rodrigo" <rodrigo.vivi@intel.com>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>,
	"intel-gvt-dev@lists.freedesktop.org"
	<intel-gvt-dev@lists.freedesktop.org>,
	Christoph Hellwig <hch@lst.de>
Subject: RE: [PATCH] drm/i915/gvt: Add missing vfio_unregister_group_dev() call
Date: Wed, 19 Oct 2022 10:13:39 +0000	[thread overview]
Message-ID: <BN9PR11MB52761B9F3678DCB9D9482DFB8C2B9@BN9PR11MB5276.namprd11.prod.outlook.com> (raw)
In-Reply-To: <a2f60cc9-b468-2ef8-c9cc-b82675b157ed@intel.com>

> From: Wang, Zhi A <zhi.a.wang@intel.com>
> Sent: Wednesday, October 19, 2022 5:41 PM
> 
> On 10/6/22 18:31, Alex Williamson wrote:
> > On Thu, 6 Oct 2022 08:37:09 -0300
> > Jason Gunthorpe <jgg@nvidia.com> wrote:
> >
> >> On Wed, Oct 05, 2022 at 04:03:56PM -0600, Alex Williamson wrote:
> >>> We can't have a .remove callback that does nothing, this breaks
> >>> removing the device while it's in use.  Once we have the
> >>> vfio_unregister_group_dev() fix below, we'll block until the device is
> >>> unused, at which point vgpu->attached becomes false.  Unless I'm
> >>> missing something, I think we should also follow-up with a patch to
> >>> remove that bogus warn-on branch, right?  Thanks,
> >>
> >> Yes, looks right to me.
> >>
> >> I question all the logical arround attached, where is the locking?
> >
> > Zhenyu, Zhi, Kevin,
> >
> > Could someone please take a look at use of vgpu->attached in the GVT-g
> > driver?  It's use in intel_vgpu_remove() is bogus, the .release
> > callback needs to use vfio_unregister_group_dev() to wait for the
> > device to be unused.  The WARN_ON/return here breaks all future use of
> > the device.  I assume @attached has something to do with the page table
> > interface with KVM, but it all looks racy anyway.
> >
> Thanks for pointing this out.
> 
> It was introduced in the GVT-g refactor patch series and Christoph might
> not want to touch the vgpu->released while he needed a new state.
> 
> I dig it a bit. vgpu->attached would be used for preventing multiple open
> on a single vGPU and indicate the kvm_get_kvm() has been done.

vfio core already ensures that .open_device() is called only once:

vfio_device_open()
{
	...
	mutex_lock(&device->dev_set->lock);
	device->open_count++;
	if (device->open_count == 1) {
		...
		if (device->ops->open_device) {
			ret = device->ops->open_device(device);
			...
}

> vgpu->released was to prevent the release before close, which is now
> handled by the vfio_device_*.
> 
> What I would like to do are:
> 1) Remove the vgpu->released. 2) Use alock to protect vgpu->attached.
> 
> After those were solved, the WARN_ON/return in the intel_vgpu_remove()
> should be safely removed as the .release will be called after .close_device
> deceases the vfio_device->refcnt to zero.
> 
> Thanks,
> Zhi.
> 
> > Also, whatever purpose vgpu->released served looks unnecessary now.
> > Thanks,
> >
> > Alex
> >


  reply	other threads:[~2022-10-19 10:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-29 17:48 [PATCH] drm/i915/gvt: Add missing vfio_unregister_group_dev() call Jason Gunthorpe
2022-09-30  1:47 ` Tian, Kevin
2022-09-30 21:31 ` Alex Williamson
2022-10-05 20:17 ` Alex Williamson
2022-10-05 22:03   ` Alex Williamson
2022-10-06 11:37     ` Jason Gunthorpe
2022-10-06 18:31       ` Alex Williamson
2022-10-10 23:14         ` Tian, Kevin
2022-10-19  9:40         ` Wang, Zhi A
2022-10-19 10:13           ` Tian, Kevin [this message]
2022-10-06 11:35   ` Jason Gunthorpe

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=BN9PR11MB52761B9F3678DCB9D9482DFB8C2B9@BN9PR11MB5276.namprd11.prod.outlook.com \
    --to=kevin.tian@intel.com \
    --cc=airlied@linux.ie \
    --cc=alex.williamson@redhat.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hch@lst.de \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-gvt-dev@lists.freedesktop.org \
    --cc=jgg@nvidia.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=stable@vger.kernel.org \
    --cc=tvrtko.ursulin@linux.intel.com \
    --cc=zhenyuw@linux.intel.com \
    --cc=zhi.a.wang@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).