[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YhkGkAJtMu0epKiT@google.com>
Date: Fri, 25 Feb 2022 16:40:48 +0000
From: Sean Christopherson <seanjc@...gle.com>
To: David Woodhouse <dwmw2@...radead.org>
Cc: Paolo Bonzini <pbonzini@...hat.com>,
Vitaly Kuznetsov <vkuznets@...hat.com>,
Wanpeng Li <wanpengli@...cent.com>,
Jim Mattson <jmattson@...gle.com>,
Joerg Roedel <joro@...tes.org>, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org,
Suleiman Souhlal <suleiman@...gle.com>,
Anton Romanov <romanton@...gle.com>
Subject: Re: [PATCH] KVM: x86: Don't snapshot "max" TSC if host TSC is
constant
On Fri, Feb 25, 2022, David Woodhouse wrote:
> On Fri, 2022-02-25 at 01:39 +0000, Sean Christopherson wrote:
> > @@ -11160,7 +11162,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
> > vcpu->arch.msr_platform_info = MSR_PLATFORM_INFO_CPUID_FAULT;
> > kvm_vcpu_mtrr_init(vcpu);
> > vcpu_load(vcpu);
> > - kvm_set_tsc_khz(vcpu, max_tsc_khz);
> > + kvm_set_tsc_khz(vcpu, max_tsc_khz ? : tsc_khz);
> > kvm_vcpu_reset(vcpu, false);
> > kvm_init_mmu(vcpu);
> > vcpu_put(vcpu);
> >
>
> Hm, now if you hit that race you end up potentially giving *different*
> frequencies to different vCPUs in a single guest, depending on when
> they were created.
Yep. Though the race is much harder to hit (userspace vs TSC refinement). The
existing race being hit is essentially do_initcalls() vs. TSC refinement.
> How about this... (and as noted, I think I want to add an explicit KVM
> ioctl to set kvm->arch.default_tsc_khz for subsequently created vCPUs).
This wouldn't necessarily help. E.g. assuming userspace knows the actual TSC
frequency, creating a vCPU before refinement completes might put the vCPU in
"always catchup" purgatory.
To really fix the race, KVM needs a notification that refinement completed (or
failed). KVM could simply refuse to create vCPUs until it got the notification.
In the non-constant case, KVM would also need to refresh max_tsc_khz.
Powered by blists - more mailing lists