kvm/vfio: avoid bouncing the mutex when adding and deleting groups
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Fri, 14 Jul 2023 22:45:33 +0000 (15:45 -0700)
committerAlex Williamson <alex.williamson@redhat.com>
Thu, 3 Aug 2023 18:01:56 +0000 (12:01 -0600)
commit73e2f19da50857a3488f44a7c9d874fed6fae533
tree1fada3117e1a97eabf0eef97d35ab43b962fae8a
parent9e0f4f2918c2ff145d3dedee862d9919a6ed5812
kvm/vfio: avoid bouncing the mutex when adding and deleting groups

Stop taking kv->lock mutex in kvm_vfio_update_coherency() and instead
call it with this mutex held: the callers of the function usually
already have it taken (and released) before calling
kvm_vfio_update_coherency(). This avoid bouncing the lock up and down.

The exception is kvm_vfio_release() where we do not take the lock, but
it is being executed when the very last reference to kvm_device is being
dropped, so there are no concerns about concurrency.

Suggested-by: Alex Williamson <alex.williamson@redhat.com>
Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Link: https://lore.kernel.org/r/20230714224538.404793-2-dmitry.torokhov@gmail.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
virt/kvm/vfio.c