All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Rosato <mjrosato@linux.ibm.com>
To: alex.williamson@redhat.com, pbonzini@redhat.com
Cc: jgg@nvidia.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, 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: [PATCH 2/2] KVM: s390: pci: use asyncronous kvm put
Date: Mon,  9 Jan 2023 15:10:37 -0500	[thread overview]
Message-ID: <20230109201037.33051-3-mjrosato@linux.ibm.com> (raw)
In-Reply-To: <20230109201037.33051-1-mjrosato@linux.ibm.com>

It's possible that the kvm refcount will reach 0 at this point while the
associated device is still in kvm device list - this would result in a
deadlock on the vfio group lock.  Avoid this possibility by using
kvm_put_kvm_async to do the kvm_destroy_vm asynchronously.

Fixes: 09340b2fca00 ("KVM: s390: pci: add routines to start/stop interpretive execution")
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
---
 arch/s390/kvm/pci.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/s390/kvm/pci.c b/arch/s390/kvm/pci.c
index ec51e810e381..d1d528438138 100644
--- a/arch/s390/kvm/pci.c
+++ b/arch/s390/kvm/pci.c
@@ -509,7 +509,7 @@ static int kvm_s390_pci_register_kvm(void *opaque, struct kvm *kvm)
 		kvm_s390_pci_dev_release(zdev);
 	mutex_unlock(&kvm->lock);
 	mutex_unlock(&zdev->kzdev_lock);
-	kvm_put_kvm(kvm);
+	kvm_put_kvm_async(kvm);
 	return rc;
 }
 
@@ -567,7 +567,11 @@ static void kvm_s390_pci_unregister_kvm(void *opaque)
 	mutex_unlock(&kvm->lock);
 	mutex_unlock(&zdev->kzdev_lock);
 
-	kvm_put_kvm(kvm);
+	/*
+	 * Avoid possible deadlock on any currently-held vfio lock by
+	 * ensuring the potential kvm_destroy_vm call is done asynchronously
+	 */
+	kvm_put_kvm_async(kvm);
 }
 
 void kvm_s390_pci_init_list(struct kvm *kvm)
-- 
2.39.0


WARNING: multiple messages have this Message-ID (diff)
From: Matthew Rosato <mjrosato@linux.ibm.com>
To: alex.williamson@redhat.com, pbonzini@redhat.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,
	linux-s390@vger.kernel.org, intel-gfx@lists.freedesktop.org,
	cohuck@redhat.com, linux-kernel@vger.kernel.org,
	pasic@linux.ibm.com, jgg@nvidia.com, kvm@vger.kernel.org,
	borntraeger@linux.ibm.com, intel-gvt-dev@lists.freedesktop.org
Subject: [Intel-gfx] [PATCH 2/2] KVM: s390: pci: use asyncronous kvm put
Date: Mon,  9 Jan 2023 15:10:37 -0500	[thread overview]
Message-ID: <20230109201037.33051-3-mjrosato@linux.ibm.com> (raw)
In-Reply-To: <20230109201037.33051-1-mjrosato@linux.ibm.com>

It's possible that the kvm refcount will reach 0 at this point while the
associated device is still in kvm device list - this would result in a
deadlock on the vfio group lock.  Avoid this possibility by using
kvm_put_kvm_async to do the kvm_destroy_vm asynchronously.

Fixes: 09340b2fca00 ("KVM: s390: pci: add routines to start/stop interpretive execution")
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
---
 arch/s390/kvm/pci.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/s390/kvm/pci.c b/arch/s390/kvm/pci.c
index ec51e810e381..d1d528438138 100644
--- a/arch/s390/kvm/pci.c
+++ b/arch/s390/kvm/pci.c
@@ -509,7 +509,7 @@ static int kvm_s390_pci_register_kvm(void *opaque, struct kvm *kvm)
 		kvm_s390_pci_dev_release(zdev);
 	mutex_unlock(&kvm->lock);
 	mutex_unlock(&zdev->kzdev_lock);
-	kvm_put_kvm(kvm);
+	kvm_put_kvm_async(kvm);
 	return rc;
 }
 
@@ -567,7 +567,11 @@ static void kvm_s390_pci_unregister_kvm(void *opaque)
 	mutex_unlock(&kvm->lock);
 	mutex_unlock(&zdev->kzdev_lock);
 
-	kvm_put_kvm(kvm);
+	/*
+	 * Avoid possible deadlock on any currently-held vfio lock by
+	 * ensuring the potential kvm_destroy_vm call is done asynchronously
+	 */
+	kvm_put_kvm_async(kvm);
 }
 
 void kvm_s390_pci_init_list(struct kvm *kvm)
-- 
2.39.0


  parent reply	other threads:[~2023-01-09 20:11 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-09 20:10 [PATCH 0/2] kvm/vfio: fix potential deadlock on vfio group lock Matthew Rosato
2023-01-09 20:10 ` [Intel-gfx] " Matthew Rosato
2023-01-09 20:10 ` [PATCH 1/2] KVM: async kvm_destroy_vm for vfio devices Matthew Rosato
2023-01-09 20:10   ` [Intel-gfx] " Matthew Rosato
2023-01-09 20:13   ` Jason Gunthorpe
2023-01-09 20:13     ` Jason Gunthorpe
2023-01-09 20:24     ` Matthew Rosato
2023-01-09 20:24       ` [Intel-gfx] " Matthew Rosato
2023-01-09 21:07   ` Anthony Krowiak
2023-01-09 21:07     ` [Intel-gfx] " Anthony Krowiak
2023-01-11 19:54   ` Sean Christopherson
2023-01-11 19:54     ` [Intel-gfx] " Sean Christopherson
2023-01-11 20:05     ` Jason Gunthorpe
2023-01-11 20:05       ` Jason Gunthorpe
2023-01-11 20:53       ` Sean Christopherson
2023-01-11 20:53         ` [Intel-gfx] " Sean Christopherson
2023-01-12 12:45         ` Jason Gunthorpe
2023-01-12 12:45           ` [Intel-gfx] " Jason Gunthorpe
2023-01-12 17:21           ` Matthew Rosato
2023-01-12 17:21             ` Matthew Rosato
2023-01-12 17:27             ` [Intel-gfx] " Jason Gunthorpe
2023-01-12 17:27               ` Jason Gunthorpe
2023-01-09 20:10 ` Matthew Rosato [this message]
2023-01-09 20:10   ` [Intel-gfx] [PATCH 2/2] KVM: s390: pci: use asyncronous kvm put Matthew Rosato
2023-01-09 21:10 ` [Intel-gfx] ✗ Fi.CI.SPARSE: warning for kvm/vfio: fix potential deadlock on vfio group lock Patchwork
2023-01-09 21:38 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2023-01-10  7:08 ` [Intel-gfx] ✓ Fi.CI.IGT: " Patchwork
2023-01-11 20:39 ` [Intel-gfx] ✗ Fi.CI.BUILD: failure for kvm/vfio: fix potential deadlock on vfio group lock (rev2) Patchwork
2023-01-11 21:09 ` [Intel-gfx] ✗ Fi.CI.BUILD: failure for kvm/vfio: fix potential deadlock on vfio group lock (rev3) Patchwork
2023-01-12 19:32 ` [Intel-gfx] ✗ Fi.CI.BUILD: failure for kvm/vfio: fix potential deadlock on vfio group lock (rev4) 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=20230109201037.33051-3-mjrosato@linux.ibm.com \
    --to=mjrosato@linux.ibm.com \
    --cc=akrowiak@linux.ibm.com \
    --cc=alex.williamson@redhat.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=jgg@nvidia.com \
    --cc=jjherne@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=pasic@linux.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=pmorel@linux.ibm.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 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.