The atomic based scheme for tracking the group->container and group->kvm has two race conditions, simplify it by adding a rwsem to protect those values and related and remove the atomics. It is based on top of all the series thus far: - rc3 - vfio_mdev_no_group - vfio_kvm_no_group - vfio_get_from_dev - iommu series To make all this work removing alot of the container_users cases was necessary, which was accomplished in prior series. This is on github: https://github.com/jgunthorpe/linux/commits/vfio_group_locking (which also has all 82 patches listed above) This has been rebased far too many times, I've checked this version and so has Nicolin, but it could use a careful 3rd look. Jason Gunthorpe (6): vfio: Add missing locking for struct vfio_group::kvm vfio: Change struct vfio_group::opened from an atomic to bool vfio: Split up vfio_group_get_device_fd() vfio: Fully lock struct vfio_group::container vfio: Simplify the life cycle of the group FD vfio: Change struct vfio_group::container_users to a non-atomic int drivers/vfio/vfio.c | 273 +++++++++++++++++++++++++++----------------- 1 file changed, 166 insertions(+), 107 deletions(-) base-commit: e50abb9a762947bd0b9ffc73b7e28e5523f6eab8 -- 2.36.0