[PATCH v5 3/6] KVM: add kvm_lock_all_vcpus and kvm_trylock_all_vcpus
Marc Zyngier
maz at kernel.org
Wed May 14 02:33:50 PDT 2025
On Mon, 12 May 2025 19:04:04 +0100,
Maxim Levitsky <mlevitsk at redhat.com> wrote:
>
> 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 at redhat.com>
> Signed-off-by: Maxim Levitsky <mlevitsk at redhat.com>
Acked-by: Marc Zyngier <maz at kernel.org>
M.
--
Without deviation from the norm, progress is not possible.
More information about the kvm-riscv
mailing list