From: David Woodhouse <dwmw2@infradead.org>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Suleiman Souhlal <suleiman@google.com>,
Anton Romanov <romanton@google.com>
Subject: Re: [PATCH] KVM: x86: Don't snapshot "max" TSC if host TSC is constant
Date: Fri, 25 Feb 2022 16:51:57 +0000 [thread overview]
Message-ID: <95aecbfae5ecad47cf06b30bb415f273b67ed3a3.camel@infradead.org> (raw)
In-Reply-To: <YhkGkAJtMu0epKiT@google.com>
[-- Attachment #1: Type: text/plain, Size: 2095 bytes --]
On Fri, 2022-02-25 at 16:40 +0000, Sean Christopherson wrote:
> 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.
Right. But at least they'd be *consistent*.
I was actually making that change anyway, for the benefit of VMs where
we are intentionally scaling to a known, different, TSC frequency —
which is currently completely hosed when all the vCPUs set it for
themselves because the TSC sync then fails.
> 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.
Hm, would the world be a better place if we knew that the delta between
the unrefined and refined TSC values was always within the tolerance of
tsc_tolerance_ppm for which we wouldn't bother scaling anyway?
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5965 bytes --]
prev parent reply other threads:[~2022-02-25 16:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-25 1:39 Sean Christopherson
2022-02-25 12:10 ` Paolo Bonzini
2022-02-25 12:20 ` David Woodhouse
2022-02-25 16:21 ` Sean Christopherson
2022-02-25 16:34 ` David Woodhouse
2022-04-12 17:38 ` Anton Romanov
2022-04-13 8:31 ` Paolo Bonzini
2022-02-25 12:52 ` David Woodhouse
2022-02-25 16:40 ` Sean Christopherson
2022-02-25 16:51 ` David Woodhouse [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=95aecbfae5ecad47cf06b30bb415f273b67ed3a3.camel@infradead.org \
--to=dwmw2@infradead.org \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=romanton@google.com \
--cc=seanjc@google.com \
--cc=suleiman@google.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®