linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kvm/vfio: Fix potential deadlock problem in vfio
@ 2022-05-17  2:34 Wan Jiabing
  2022-05-17 18:58 ` Jason Gunthorpe
  2022-05-18 17:51 ` Alex Williamson
  0 siblings, 2 replies; 3+ messages in thread
From: Wan Jiabing @ 2022-05-17  2:34 UTC (permalink / raw)
  To: Paolo Bonzini, Alex Williamson, Yi Liu, Kevin Tian,
	Jason Gunthorpe, kvm, linux-kernel
  Cc: Wan Jiabing

Fix following coccicheck warning:
./virt/kvm/vfio.c:258:1-7: preceding lock on line 236

If kvm_vfio_file_iommu_group() failed, code would goto err_fdput with
mutex_lock acquired and then return ret. It might cause potential
deadlock. Move mutex_unlock bellow err_fdput tag to fix it. 

Fixes: d55d9e7a45721 ("kvm/vfio: Store the struct file in the kvm_vfio_group")
Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
---
 virt/kvm/vfio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
index 8f9f7fffb96a..ce1b01d02c51 100644
--- a/virt/kvm/vfio.c
+++ b/virt/kvm/vfio.c
@@ -252,8 +252,8 @@ static int kvm_vfio_group_set_spapr_tce(struct kvm_device *dev,
 		break;
 	}
 
-	mutex_unlock(&kv->lock);
 err_fdput:
+	mutex_unlock(&kv->lock);
 	fdput(f);
 	return ret;
 }
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-18 17:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-17  2:34 [PATCH] kvm/vfio: Fix potential deadlock problem in vfio Wan Jiabing
2022-05-17 18:58 ` Jason Gunthorpe
2022-05-18 17:51 ` Alex Williamson

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).