mbox series

[v2,0/6] Fully lock the container members of struct vfio_group

Message ID 0-v2-d035a1842d81+1bf-vfio_group_locking_jgg@nvidia.com (mailing list archive)
Headers show
Series Fully lock the container members of struct vfio_group | expand

Message

Jason Gunthorpe May 16, 2022, 11:41 p.m. UTC
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@nvidia.com

Cc: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

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

Comments

Nicolin Chen May 17, 2022, 5:11 a.m. UTC | #1
On Mon, May 16, 2022 at 08:41:16PM -0300, Jason Gunthorpe wrote:
> 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@nvidia.com
> 
> Cc: Nicolin Chen <nicolinc@nvidia.com>

Sanity tested on x86_64 and ARM64.

Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Matthew Rosato May 17, 2022, 3:37 p.m. UTC | #2
On 5/17/22 1:11 AM, Nicolin Chen wrote:
> On Mon, May 16, 2022 at 08:41:16PM -0300, Jason Gunthorpe wrote:
>> 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@nvidia.com
>>
>> Cc: Nicolin Chen <nicolinc@nvidia.com>
> 
> Sanity tested on x86_64 and ARM64.
> 
> Tested-by: Nicolin Chen <nicolinc@nvidia.com>

Also sanity tested this series on s390x (vfio-pci and vfio-ap)

Tested-by: Matthew Rosato <mjrosato@linux.ibm.com>
Alex Williamson May 18, 2022, 5:51 p.m. UTC | #3
On Mon, 16 May 2022 20:41:16 -0300
Jason Gunthorpe <jgg@nvidia.com> wrote:

> 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@nvidia.com
> 
> Cc: Nicolin Chen <nicolinc@nvidia.com>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> 
> 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

Applied to vfio next branch for v5.19.  Thanks!

Alex