]> www.infradead.org Git - users/jedix/linux-maple.git/commit
KVM: add kvm_lock_all_vcpus and kvm_trylock_all_vcpus
authorMaxim Levitsky <mlevitsk@redhat.com>
Mon, 12 May 2025 18:04:04 +0000 (14:04 -0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 27 May 2025 16:16:41 +0000 (12:16 -0400)
commite4a454ced74c0ac97c8bd32f086ee3ad74528780
treea5ddf1057901f18d3479e7c245d54420a4ebbdaa
parentfb49f07ba1d9d8c9bd8854878ae6b5b21ff9ac45
KVM: add kvm_lock_all_vcpus and kvm_trylock_all_vcpus

In a few cases, usually in the initialization code, KVM locks all vCPUs
of a VM to ensure that userspace doesn't do funny things while KVM performs
an operation that affects the whole VM.

Until now, all these operations were implemented using custom code,
and all of them share the same problem:

Lockdep can't cope with simultaneous locking of a large number of locks of
the same class.

However if these locks are taken while another lock is already held,
which is luckily the case, it is possible to take advantage of little known
_nest_lock feature of lockdep which allows in this case to have an
unlimited number of locks of same class to be taken.

To implement this, create two functions:
kvm_lock_all_vcpus() and kvm_trylock_all_vcpus()

Both functions are needed because some code that will be replaced in
the subsequent patches, uses mutex_trylock, instead of regular mutex_lock.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Acked-by: Marc Zyngier <maz@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Message-ID: <20250512180407.659015-4-mlevitsk@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
include/linux/kvm_host.h
virt/kvm/kvm_main.c