From: Paolo Bonzini <pbonzini@redhat.com>
To: Sean Christopherson <seanjc@google.com>
Cc: 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 13:10:12 +0100 [thread overview]
Message-ID: <609de7ff-92e2-f96e-e6f5-127251f6e16d@redhat.com> (raw)
In-Reply-To: <20220225013929.3577699-1-seanjc@google.com>
On 2/25/22 02:39, Sean Christopherson wrote:
> Don't snapshot tsc_khz into max_tsc_khz during KVM initialization if the
> host TSC is constant, in which case the actual TSC frequency will never
> change and thus capturing the "max" TSC during initialization is
> unnecessary, KVM can simply use tsc_khz during VM creation.
>
> On CPUs with constant TSC, but not a hardware-specified TSC frequency,
> snapshotting max_tsc_khz and using that to set a VM's default TSC
> frequency can lead to KVM thinking it needs to manually scale the guest's
> TSC if refining the TSC completes after KVM snapshots tsc_khz. The
> actual frequency never changes, only the kernel's calculation of what
> that frequency is changes. On systems without hardware TSC scaling, this
> either puts KVM into "always catchup" mode (extremely inefficient), or
> prevents creating VMs altogether.
>
> Ideally, KVM would not be able to race with TSC refinement, or would have
> a hook into tsc_refine_calibration_work() to get an alert when refinement
> is complete. Avoiding the race altogether isn't practical as refinement
> takes a relative eternity; it's deliberately put on a work queue outside
> of the normal boot sequence to avoid unnecessarily delaying boot.
>
> Adding a hook is doable, but somewhat gross due to KVM's ability to be
> built as a module. And if the TSC is constant, which is likely the case
> for every VMX/SVM-capable CPU produced in the last decade, the race can
> be hit if and only if userspace is able to create a VM before TSC
> refinement completes; refinement is slow, but not that slow.
>
> For now, punt on a proper fix, as not taking a snapshot can help some
> uses cases and not taking a snapshot is arguably correct irrespective of
> the race with refinement.
>
> Cc: Suleiman Souhlal <suleiman@google.com>
> Cc: Anton Romanov <romanton@google.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
Queued, but I'd rather have a subject that calls out that max_tsc_khz
needs a replacement at vCPU creation time. In fact, the real change
(and bug, and fix) is in kvm_arch_vcpu_create(), while the subject
mentions only the change in kvm_timer_init().
What do you think of "KVM: x86: Use current rather than max TSC
frequency if it is constant"?
Pao
next prev parent reply other threads:[~2022-02-25 12:10 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 [this message]
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
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=609de7ff-92e2-f96e-e6f5-127251f6e16d@redhat.com \
--to=pbonzini@redhat.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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®