> From: Liu, Yi L <yi.l.liu@xxxxxxxxx> > Sent: Monday, June 27, 2022 3:41 PM > > We do not protect the vfio_device::open_count with group_rwsem > elsewhere (see > vfio_device_fops_release as a comparison, where we already drop > group_rwsem > before open_count--). So move the group_rwsem unlock prior to > open_count--. > > This change now also drops group_rswem before setting device->kvm = NULL, > but that's also OK (again, just like vfio_device_fops_release). The setting > of device->kvm before open_device is technically done while holding the > group_rwsem, this is done to protect the group kvm value we are copying > from, > and we should not be relying on that to protect the contents of device->kvm; > instead we assume this value will not change until after the device is closed > and while under the dev_set->lock. > > Cc: Matthew Rosato <mjrosato@xxxxxxxxxxxxx> > Cc: Jason Gunthorpe <jgg@xxxxxxxxxx> > Signed-off-by: Yi Liu <yi.l.liu@xxxxxxxxx> > Reviewed-by: Matthew Rosato <mjrosato@xxxxxxxxxxxxx> Reviewed-by: Kevin Tian <kevin.tian@xxxxxxxxx>