RE: [PATCH v4] vfio: fix potential deadlock on vfio group lock

From: Tian, Kevin
Date: Tue Jan 17 2023 - 04:14:25 EST


> From: Matthew Rosato <mjrosato@xxxxxxxxxxxxx>
> Sent: Saturday, January 14, 2023 8:04 AM
>
> void vfio_device_group_close(struct vfio_device *device)
> {
> + void (*put_kvm)(struct kvm *kvm);
> + struct kvm *kvm;
> +
> mutex_lock(&device->group->group_lock);
> + kvm = device->kvm;
> + put_kvm = device->put_kvm;
> vfio_device_close(device, device->group->iommufd);
> + if (kvm == device->kvm)
> + kvm = NULL;

Add a simple comment that this check is to detect the last close

> +void vfio_kvm_put_kvm(void (*put)(struct kvm *kvm), struct kvm *kvm)
> +{
> + if (WARN_ON(!put))
> + return;

also WARN_ON(!kvm)?

otherwise this looks good to me:

Reviewed-by: Kevin Tian <kevin.tian@xxxxxxxxx>