]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: x86: Don't take kvm->lock when iterating over vCPUs in suspend notifier
authorSean Christopherson <seanjc@google.com>
Sat, 1 Feb 2025 01:38:17 +0000 (17:38 -0800)
committerSean Christopherson <seanjc@google.com>
Wed, 12 Feb 2025 18:45:54 +0000 (10:45 -0800)
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: syzbot+352e553a86e0d75f5120@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/677c0f36.050a0220.3b3668.0014.GAE@google.com
Fixes: 7d62874f69d7 ("kvm: x86: implement KVM PM-notifier")
Reviewed-by: Paul Durrant <paul@xen.org>
Link: https://lore.kernel.org/r/20250201013827.680235-2-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/x86.c

index 8e77e61d4fbd4dc0de7bfd900270e887ff81296c..b83d58f9f0b42db0e3b2291735ecdf4efdc75f95 100644 (file)
@@ -6907,7 +6907,6 @@ static int kvm_arch_suspend_notifier(struct kvm *kvm)
        unsigned long i;
        int ret = 0;
 
-       mutex_lock(&kvm->lock);
        kvm_for_each_vcpu(i, vcpu, kvm) {
                if (!vcpu->arch.pv_time.active)
                        continue;
@@ -6919,7 +6918,6 @@ static int kvm_arch_suspend_notifier(struct kvm *kvm)
                        break;
                }
        }
-       mutex_unlock(&kvm->lock);
 
        return ret ? NOTIFY_BAD : NOTIFY_DONE;
 }