Skip to content

Commit 42a9000

Browse files
dwmw2bonzini
authored andcommitted
KVM: Ensure lockdep knows about kvm->lock vs. vcpu->mutex ordering rule
Documentation/virt/kvm/locking.rst tells us that kvm->lock is taken outside vcpu->mutex. But that doesn't actually happen very often; it's only in some esoteric cases like migration with AMD SEV. This means that lockdep usually doesn't notice, and doesn't do its job of keeping us honest. Ensure that lockdep *always* knows about the ordering of these two locks, by briefly taking vcpu->mutex in kvm_vm_ioctl_create_vcpu() while kvm->lock is held. Signed-off-by: David Woodhouse <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent bbe17c6 commit 42a9000

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

virt/kvm/kvm_main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3954,6 +3954,13 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
39543954
}
39553955

39563956
mutex_lock(&kvm->lock);
3957+
3958+
#ifdef CONFIG_LOCKDEP
3959+
/* Ensure that lockdep knows vcpu->mutex is taken *inside* kvm->lock */
3960+
mutex_lock(&vcpu->mutex);
3961+
mutex_unlock(&vcpu->mutex);
3962+
#endif
3963+
39573964
if (kvm_get_vcpu_by_id(kvm, id)) {
39583965
r = -EEXIST;
39593966
goto unlock_vcpu_destroy;

0 commit comments

Comments
 (0)