From: Oliver Upton <oliver.upton@linux.dev>
To: Sean Christopherson <seanjc@google.com>
Cc: Like Xu <like.xu.linux@gmail.com>,
Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: x86/tsc: Update guest tsc_offset again before vcpu first runs
Date: Fri, 30 Jun 2023 17:24:19 +0000 [thread overview]
Message-ID: <ZJ8Pw3YMrYbwgcP2@linux.dev> (raw)
In-Reply-To: <ZJ8PIbHfhc0oYB8/@linux.dev>
On Fri, Jun 30, 2023 at 05:21:41PM +0000, Oliver Upton wrote:
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index c30364152fe6..43d40f058a41 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -2721,14 +2721,14 @@ static void kvm_synchronize_tsc(struct kvm_vcpu *vcpu, u64 data)
> > * kvm_clock stable after CPU hotplug
> > */
> > synchronizing = true;
> > - } else {
> > + } else if (kvm_vcpu_has_run(vcpu)) {
> > u64 tsc_exp = kvm->arch.last_tsc_write +
> > nsec_to_cycles(vcpu, elapsed);
> > u64 tsc_hz = vcpu->arch.virtual_tsc_khz * 1000LL;
> > /*
> > * Special case: TSC write with a small delta (1 second)
> > - * of virtual cycle time against real time is
> > - * interpreted as an attempt to synchronize the CPU.
> > + * of virtual cycle time against real time on a running
> > + * vCPU is interpreted as an attempt to synchronize.
> > */
> > synchronizing = data < tsc_exp + tsc_hz &&
> > data + tsc_hz > tsc_exp;
>
> This would break existing save/restore patterns for the TSC. QEMU relies
> on KVM synchronizing the TSCs when restoring a VM, since it cannot
> snapshot the TSC values of all the vCPUs in a single instant. It instead
> tries to save the TSCs at roughly the same time [*], which KVM detects
> on the target and gets everything back in sync. Can't wait to see when
> this heuristic actually breaks :)
Of course, forgot to actually include the link.
[*] https://gitlab.com/qemu-project/qemu/-/blob/408015a97dbe48a9dde8c0d2526c9312691952e7/target/i386/kvm/kvm.c#L249
--
Thanks,
Oliver
next prev parent reply other threads:[~2023-06-30 17:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-29 16:48 [PATCH] KVM: x86/tsc: Update guest tsc_offset again before vcpu first runs Like Xu
2023-06-29 17:19 ` Sean Christopherson
2023-06-30 17:21 ` Oliver Upton
2023-06-30 17:24 ` Oliver Upton [this message]
2023-07-04 8:01 ` Like Xu
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=ZJ8Pw3YMrYbwgcP2@linux.dev \
--to=oliver.upton@linux.dev \
--cc=kvm@vger.kernel.org \
--cc=like.xu.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.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