Re: [PATCH v3] KVM: SEV: Mark nested locking of vcpu->lock

From: Paolo Bonzini
Date: Sat Apr 30 2022 - 04:12:10 EST

On 4/30/22 03:50, Hillf Danton wrote:
lock for migration
kvm_for_each_vcpu(i, vcpu, kvm) {
if (mutex_lock_killable(&vcpu->mutex))
goto out_unlock;
lockdep_copy_map(&vcpu->v_dep_map, &vcpu->mutex.dep_map);
mutex_release(&vcpu->mutex.dep_map, ip);

unlock for migration
kvm_for_each_vcpu(i, vcpu, kvm) {
lockdep_copy_map(&vcpu->mutex.dep_map, &vcpu->v_dep_map);
* Or directly acquire without v_dep_map added
mutex_acquire(&vcpu->mutex.dep_map, 0, 1,_RET_IP_);

Yes this is exactly what Peter is doing, except that we're trying to keep one lock taken. Thanks for pointing to lock_sock_nested().