All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Matthew Rosato <mjrosato@linux.ibm.com>
Cc: akrowiak@linux.ibm.com, jjherne@linux.ibm.com,
	farman@linux.ibm.com, imbrenda@linux.ibm.com,
	frankja@linux.ibm.com, pmorel@linux.ibm.com, david@redhat.com,
	seanjc@google.com, intel-gfx@lists.freedesktop.org,
	cohuck@redhat.com, linux-kernel@vger.kernel.org,
	pasic@linux.ibm.com, kvm@vger.kernel.org, pbonzini@redhat.com,
	linux-s390@vger.kernel.org, borntraeger@linux.ibm.com,
	intel-gvt-dev@lists.freedesktop.org
Subject: Re: [Intel-gfx] [PATCH v3] vfio: fix potential deadlock on vfio group lock
Date: Fri, 13 Jan 2023 14:52:56 -0400	[thread overview]
Message-ID: <Y8GoiCBQNiAuVcNw@nvidia.com> (raw)
In-Reply-To: <20230113171132.86057-1-mjrosato@linux.ibm.com>

On Fri, Jan 13, 2023 at 12:11:32PM -0500, Matthew Rosato wrote:
> @@ -462,9 +520,19 @@ static inline void vfio_device_pm_runtime_put(struct vfio_device *device)
>  static int vfio_device_fops_release(struct inode *inode, struct file *filep)
>  {
>  	struct vfio_device *device = filep->private_data;
> +	struct kvm *kvm = NULL;
>  
>  	vfio_device_group_close(device);
>  
> +	mutex_lock(&device->dev_set->lock);
> +	if (device->open_count == 0 && device->kvm) {
> +		kvm = device->kvm;
> +		device->kvm = NULL;
> +	}
> +	mutex_unlock(&device->dev_set->lock);

This still doesn't seem right, another thread could have incr'd the
open_count already 

This has to be done at the moment open_count is decremented to zero,
while still under the original lock.

Jason

WARNING: multiple messages have this Message-ID (diff)
From: Jason Gunthorpe <jgg@nvidia.com>
To: Matthew Rosato <mjrosato@linux.ibm.com>
Cc: alex.williamson@redhat.com, pbonzini@redhat.com,
	cohuck@redhat.com, farman@linux.ibm.com, pmorel@linux.ibm.com,
	borntraeger@linux.ibm.com, frankja@linux.ibm.com,
	imbrenda@linux.ibm.com, david@redhat.com, akrowiak@linux.ibm.com,
	jjherne@linux.ibm.com, pasic@linux.ibm.com,
	zhenyuw@linux.intel.com, zhi.a.wang@intel.com, seanjc@google.com,
	linux-s390@vger.kernel.org, kvm@vger.kernel.org,
	intel-gvt-dev@lists.freedesktop.org,
	intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] vfio: fix potential deadlock on vfio group lock
Date: Fri, 13 Jan 2023 14:52:56 -0400	[thread overview]
Message-ID: <Y8GoiCBQNiAuVcNw@nvidia.com> (raw)
In-Reply-To: <20230113171132.86057-1-mjrosato@linux.ibm.com>

On Fri, Jan 13, 2023 at 12:11:32PM -0500, Matthew Rosato wrote:
> @@ -462,9 +520,19 @@ static inline void vfio_device_pm_runtime_put(struct vfio_device *device)
>  static int vfio_device_fops_release(struct inode *inode, struct file *filep)
>  {
>  	struct vfio_device *device = filep->private_data;
> +	struct kvm *kvm = NULL;
>  
>  	vfio_device_group_close(device);
>  
> +	mutex_lock(&device->dev_set->lock);
> +	if (device->open_count == 0 && device->kvm) {
> +		kvm = device->kvm;
> +		device->kvm = NULL;
> +	}
> +	mutex_unlock(&device->dev_set->lock);

This still doesn't seem right, another thread could have incr'd the
open_count already 

This has to be done at the moment open_count is decremented to zero,
while still under the original lock.

Jason

  parent reply	other threads:[~2023-01-13 18:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-13 17:11 [Intel-gfx] [PATCH v3] vfio: fix potential deadlock on vfio group lock Matthew Rosato
2023-01-13 17:11 ` Matthew Rosato
2023-01-13 17:54 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for vfio: fix potential deadlock on vfio group lock (rev2) Patchwork
2023-01-13 18:52 ` Jason Gunthorpe [this message]
2023-01-13 18:52   ` [PATCH v3] vfio: fix potential deadlock on vfio group lock Jason Gunthorpe
2023-01-13 20:09   ` [Intel-gfx] " Matthew Rosato
2023-01-13 20:09     ` Matthew Rosato
2023-01-13 20:18     ` [Intel-gfx] " Jason Gunthorpe
2023-01-13 20:18       ` Jason Gunthorpe
2023-01-13 23:47 ` [Intel-gfx] ✓ Fi.CI.BAT: success for vfio: fix potential deadlock on vfio group lock (rev2) Patchwork

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=Y8GoiCBQNiAuVcNw@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=akrowiak@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=david@redhat.com \
    --cc=farman@linux.ibm.com \
    --cc=frankja@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-gvt-dev@lists.freedesktop.org \
    --cc=jjherne@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mjrosato@linux.ibm.com \
    --cc=pasic@linux.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=pmorel@linux.ibm.com \
    --cc=seanjc@google.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.