]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
KVM: x86: reduce pvclock_gtod_sync_lock critical sections
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 25 Mar 2021 18:05:11 +0000 (14:05 -0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 1 Apr 2021 09:14:19 +0000 (05:14 -0400)
There is no need to include changes to vcpu->requests into
the pvclock_gtod_sync_lock critical section.  The changes to
the shared data structures (in pvclock_update_vm_gtod_copy)
already occur under the lock.

Cc: David Woodhouse <dwmw@amazon.co.uk>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/x86.c

index f7d12fca397b9fde42f36061063b6d276d999493..2301623d3c53e7681b894606eb5ffce8b48912ea 100644 (file)
@@ -2561,10 +2561,12 @@ static void kvm_gen_update_masterclock(struct kvm *kvm)
 
        kvm_hv_invalidate_tsc_page(kvm);
 
-       spin_lock(&ka->pvclock_gtod_sync_lock);
        kvm_make_mclock_inprogress_request(kvm);
+
        /* no guest entries from this point */
+       spin_lock(&ka->pvclock_gtod_sync_lock);
        pvclock_update_vm_gtod_copy(kvm);
+       spin_unlock(&ka->pvclock_gtod_sync_lock);
 
        kvm_for_each_vcpu(i, vcpu, kvm)
                kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu);
@@ -2572,8 +2574,6 @@ static void kvm_gen_update_masterclock(struct kvm *kvm)
        /* guest entries allowed */
        kvm_for_each_vcpu(i, vcpu, kvm)
                kvm_clear_request(KVM_REQ_MCLOCK_INPROGRESS, vcpu);
-
-       spin_unlock(&ka->pvclock_gtod_sync_lock);
 #endif
 }
 
@@ -7739,16 +7739,14 @@ static void kvm_hyperv_tsc_notifier(void)
                struct kvm_arch *ka = &kvm->arch;
 
                spin_lock(&ka->pvclock_gtod_sync_lock);
-
                pvclock_update_vm_gtod_copy(kvm);
+               spin_unlock(&ka->pvclock_gtod_sync_lock);
 
                kvm_for_each_vcpu(cpu, vcpu, kvm)
                        kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu);
 
                kvm_for_each_vcpu(cpu, vcpu, kvm)
                        kvm_clear_request(KVM_REQ_MCLOCK_INPROGRESS, vcpu);
-
-               spin_unlock(&ka->pvclock_gtod_sync_lock);
        }
        mutex_unlock(&kvm_lock);
 }