locking/mutex: implement mutex_lock_killable_nest_lock
authorMaxim Levitsky <mlevitsk@redhat.com>
Mon, 12 May 2025 18:04:03 +0000 (14:04 -0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 27 May 2025 16:16:41 +0000 (12:16 -0400)
commitfb49f07ba1d9d8c9bd8854878ae6b5b21ff9ac45
tree62d4f79d9b829d884245ee9187a1c905201866e9
parentc5b6ababd21ab6bb251e5a2b4db110e76fb00a26
locking/mutex: implement mutex_lock_killable_nest_lock

KVM's SEV intra-host migration code needs to lock all vCPUs
of the source and the target VM, before it proceeds with the migration.

The number of vCPUs that belong to each VM is not bounded by anything
except a self-imposed KVM limit of CONFIG_KVM_MAX_NR_VCPUS vCPUs which is
significantly larger than the depth of lockdep's lock stack.

Luckily, the locks in both of the cases mentioned above, are held under
the 'kvm->lock' of each VM, which means that we can use the little
known lockdep feature called a "nest_lock" to support this use case in
a cleaner way, compared to the way it's currently done.

Implement and expose 'mutex_lock_killable_nest_lock' for this
purpose.

Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Message-ID: <20250512180407.659015-3-mlevitsk@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
include/linux/mutex.h
kernel/locking/mutex.c