Re: [Intel-gfx] [PATCH v2] vfio: fix deadlock between group lock and kvm lock

2023-02-02 Thread Matthew Rosato
On 2/1/23 11:10 PM, Tian, Kevin wrote: >> From: Alex Williamson >> Sent: Thursday, February 2, 2023 7:28 AM >>> >>> +#ifdef CONFIG_HAVE_KVM >>> +static bool vfio_kvm_get_kvm_safe(struct vfio_device *device, struct kvm >> *kvm) >> >> I'm tempted to name these vfio_device_get_kvm_safe() and only

Re: [Intel-gfx] [PATCH v2] vfio: fix deadlock between group lock and kvm lock

2023-02-01 Thread Liu, Yi L
> -Original Message- > From: Alex Williamson > Sent: Thursday, February 2, 2023 12:15 PM > To: Liu, Yi L > Cc: Matthew Rosato ; pbonz...@redhat.com; > j...@nvidia.com; coh...@redhat.com; far...@linux.ibm.com; > pmo...@linux.ibm.com; borntrae...@linux.ibm.com; > fran...@linux.ibm.com;

Re: [Intel-gfx] [PATCH v2] vfio: fix deadlock between group lock and kvm lock

2023-02-01 Thread Alex Williamson
On Thu, 2 Feb 2023 03:46:59 + "Liu, Yi L" wrote: > > From: Alex Williamson > > Sent: Thursday, February 2, 2023 7:28 AM > > > > On Wed, 1 Feb 2023 14:20:10 -0500 > > Matthew Rosato wrote: > > > > > After 51cdc8bc120e, we have another deadlock scenario between the > > > kvm->lock and

Re: [Intel-gfx] [PATCH v2] vfio: fix deadlock between group lock and kvm lock

2023-02-01 Thread Tian, Kevin
> From: Alex Williamson > Sent: Thursday, February 2, 2023 7:28 AM > > > > +#ifdef CONFIG_HAVE_KVM > > +static bool vfio_kvm_get_kvm_safe(struct vfio_device *device, struct kvm > *kvm) > > I'm tempted to name these vfio_device_get_kvm_safe() and only pass the > vfio_device, where of course we

Re: [Intel-gfx] [PATCH v2] vfio: fix deadlock between group lock and kvm lock

2023-02-01 Thread Tian, Kevin
> From: Liu, Yi L > Sent: Thursday, February 2, 2023 11:47 AM > > > ret = vfio_device_open(device, device->group->iommufd, > > > device->group->kvm); > > > > We're using device->group->kvm outside of kvm_ref_lock here, it should > > be using device->kvm. > > Existing

Re: [Intel-gfx] [PATCH v2] vfio: fix deadlock between group lock and kvm lock

2023-02-01 Thread Liu, Yi L
> From: Alex Williamson > Sent: Thursday, February 2, 2023 7:28 AM > > On Wed, 1 Feb 2023 14:20:10 -0500 > Matthew Rosato wrote: > > > After 51cdc8bc120e, we have another deadlock scenario between the > > kvm->lock and the vfio group_lock with two different codepaths acquiring > > the locks

Re: [Intel-gfx] [PATCH v2] vfio: fix deadlock between group lock and kvm lock

2023-02-01 Thread Alex Williamson
On Wed, 1 Feb 2023 14:20:10 -0500 Matthew Rosato wrote: > After 51cdc8bc120e, we have another deadlock scenario between the > kvm->lock and the vfio group_lock with two different codepaths acquiring > the locks in different order. Specifically in vfio_open_device, vfio > holds the vfio

[Intel-gfx] [PATCH v2] vfio: fix deadlock between group lock and kvm lock

2023-02-01 Thread Matthew Rosato
After 51cdc8bc120e, we have another deadlock scenario between the kvm->lock and the vfio group_lock with two different codepaths acquiring the locks in different order. Specifically in vfio_open_device, vfio holds the vfio group_lock when issuing device->ops->open_device but some drivers (like