Skip to content

Commit d9c5ed0

Browse files
committed
KVM: x86: Don't take kvm->lock when iterating over vCPUs in suspend notifier
When queueing vCPU PVCLOCK updates in response to SUSPEND or HIBERNATE, don't take kvm->lock as doing so can trigger a largely theoretical deadlock, it is perfectly safe to iterate over the xarray of vCPUs without holding kvm->lock, and kvm->lock doesn't protect kvm_set_guest_paused() in any way (pv_time.active and pvclock_set_guest_stopped_request are protected by vcpu->mutex, not kvm->lock). Reported-by: [email protected] Closes: https://lore.kernel.org/all/[email protected] Fixes: 7d62874 ("kvm: x86: implement KVM PM-notifier") Reviewed-by: Paul Durrant <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent a64dcfb commit d9c5ed0

File tree

1 file changed

+0
-2
lines changed

1 file changed

+0
-2
lines changed

arch/x86/kvm/x86.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6907,7 +6907,6 @@ static int kvm_arch_suspend_notifier(struct kvm *kvm)
69076907
unsigned long i;
69086908
int ret = 0;
69096909

6910-
mutex_lock(&kvm->lock);
69116910
kvm_for_each_vcpu(i, vcpu, kvm) {
69126911
if (!vcpu->arch.pv_time.active)
69136912
continue;
@@ -6919,7 +6918,6 @@ static int kvm_arch_suspend_notifier(struct kvm *kvm)
69196918
break;
69206919
}
69216920
}
6922-
mutex_unlock(&kvm->lock);
69236921

69246922
return ret ? NOTIFY_BAD : NOTIFY_DONE;
69256923
}

0 commit comments

Comments
 (0)