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. This is on github: https://github.com/jgunthorpe/linux/commits/vfio_group_locking v2: - Updated comments and commit messages - Rebased on vfio next - Left the dev_warn in place, will adjust it later - s/singleton_file/opened_file/ v1: https://lore.kernel.org/r/0-v1-c1d14aae2e8f+2f4-vfio_group_locking_jgg@xxxxxxxxxx Cc: Nicolin Chen <nicolinc@xxxxxxxxxx> Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxx> 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 | 266 +++++++++++++++++++++++++++----------------- 1 file changed, 163 insertions(+), 103 deletions(-) base-commit: 6a985ae80befcf2c00e7c889336bfe9e9739e2ef -- 2.36.0