Skip to content

Commit 01528db

Browse files
committed
KVM: Drop hack that "manually" informs lockdep of kvm->lock vs. vcpu->mutex
Now that KVM takes vcpu->mutex inside kvm->lock when creating a vCPU, drop the hack to manually inform lockdep of the kvm->lock => vcpu->mutex ordering. This effectively reverts commit 42a9000 ("KVM: Ensure lockdep knows about kvm->lock vs. vcpu->mutex ordering rule"). Cc: Oliver Upton <oliver.upton@linux.dev> Acked-by: Will Deacon <will@kernel.org> Link: https://lore.kernel.org/r/20241009150455.1057573-7-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent e53dc37 commit 01528db

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

virt/kvm/kvm_main.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4116,12 +4116,6 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, unsigned long id)
41164116

41174117
mutex_lock(&kvm->lock);
41184118

4119-
#ifdef CONFIG_LOCKDEP
4120-
/* Ensure that lockdep knows vcpu->mutex is taken *inside* kvm->lock */
4121-
mutex_lock(&vcpu->mutex);
4122-
mutex_unlock(&vcpu->mutex);
4123-
#endif
4124-
41254119
if (kvm_get_vcpu_by_id(kvm, id)) {
41264120
r = -EEXIST;
41274121
goto unlock_vcpu_destroy;
@@ -4138,7 +4132,8 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, unsigned long id)
41384132
* so that userspace can't invoke vCPU ioctl()s until the vCPU is fully
41394133
* visible (per online_vcpus), e.g. so that KVM doesn't get tricked
41404134
* into a NULL-pointer dereference because KVM thinks the _current_
4141-
* vCPU doesn't exist.
4135+
* vCPU doesn't exist. As a bonus, taking vcpu->mutex ensures lockdep
4136+
* knows it's taken *inside* kvm->lock.
41424137
*/
41434138
mutex_lock(&vcpu->mutex);
41444139
kvm_get_kvm(kvm);

0 commit comments

Comments
 (0)