From: Sean Christopherson <seanjc@google.com>
To: David Woodhouse <dwmw2@infradead.org>
Cc: Like Xu <like.xu.linux@gmail.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Oliver Upton <oliver.upton@linux.dev>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4] KVM: x86/tsc: Don't sync user changes to TSC with KVM-initiated change
Date: Wed, 13 Sep 2023 07:50:27 -0700 [thread overview]
Message-ID: <ZQHMM8/7xXReZHdD@google.com> (raw)
In-Reply-To: <055482bec09cae1ea56f979893c6b67e9d6b26a2.camel@infradead.org>
On Wed, Sep 13, 2023, David Woodhouse wrote:
> On Fri, 2023-08-11 at 15:59 -0700, Sean Christopherson wrote:
> > On Tue, Aug 01, 2023, Like Xu wrote:
> > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > > index 278dbd37dab2..eeaf4ad9174d 100644
> > > --- a/arch/x86/kvm/x86.c
> > > +++ b/arch/x86/kvm/x86.c
> > > @@ -2713,7 +2713,7 @@ static void __kvm_synchronize_tsc(struct kvm_vcpu *vcpu, u64 offset, u64 tsc,
> > > kvm_track_tsc_matching(vcpu);
> > > }
> > >
> > > -static void kvm_synchronize_tsc(struct kvm_vcpu *vcpu, u64 data)
> > > +static void kvm_synchronize_tsc(struct kvm_vcpu *vcpu, u64 data, bool user_initiated)
> >
> > Rather than pass two somewhat magic values for the KVM-internal call, what about
> > making @data a pointer and passing NULL?
>
> Why change that at all?
>
> Userspace used to be able to force a sync by writing zero. You are
> removing that from the ABI without any explanation about why;
No, my suggestion did not remove that from the ABI. A @user_value of '0' would
still force synchronization.
-static void kvm_synchronize_tsc(struct kvm_vcpu *vcpu, u64 data)
+static void kvm_synchronize_tsc(struct kvm_vcpu *vcpu, u64 *user_value)
{
+ u64 data = user_value ? *user_value : 0; <=== "*user_value" is '0'
struct kvm *kvm = vcpu->kvm;
u64 offset, ns, elapsed;
unsigned long flags;
@@ -2712,14 +2713,17 @@ static void kvm_synchronize_tsc(struct kvm_vcpu *vcpu, u64 data)
elapsed = ns - kvm->arch.last_tsc_nsec;
if (vcpu->arch.virtual_tsc_khz) {
+ /*
+ * Force synchronization when creating or hotplugging a vCPU,
+ * i.e. when the TSC value is '0', to help keep clocks stable.
+ * If this is NOT a hotplug/creation case, skip synchronization
+ * on the first write from userspace so as not to misconstrue
+ * state restoration after live migration as an attempt from
+ * userspace to synchronize.
+ */
if (data == 0) { <== "data" still '0', still forces synchronization
- /*
- * detection of vcpu initialization -- need to sync
- * with other vCPUs. This particularly helps to keep
- * kvm_clock stable after CPU hotplug
- */
synchronizing = true;
> it doesn't seem necessary for fixing the original issue.
It's necessary for "user_set_tsc" to be an accurate name. The code in v6 yields
"user_set_tsc_to_non_zero_value". And I don't think it's just a naming issue,
e.g. if userspace writes '0' immediately after creating, and then later writes a
small delta, the v6 code wouldn't trigger synchronization because "user_set_tsc"
would be left unseft by the write of '0'.
next prev parent reply other threads:[~2023-09-13 14:50 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-01 3:45 [PATCH v4] KVM: x86/tsc: Don't sync user changes to TSC with KVM-initiated change Like Xu
2023-08-11 22:59 ` Sean Christopherson
2023-09-13 8:10 ` David Woodhouse
2023-09-13 8:41 ` Like Xu
2023-09-13 8:44 ` David Woodhouse
2023-09-13 8:31 ` David Woodhouse
2023-09-13 14:50 ` Sean Christopherson [this message]
2023-09-13 15:05 ` David Woodhouse
2023-09-13 15:15 ` Sean Christopherson
2023-09-13 15:24 ` David Woodhouse
2023-09-14 3:24 ` 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=ZQHMM8/7xXReZHdD@google.com \
--to=seanjc@google.com \
--cc=dwmw2@infradead.org \
--cc=kvm@vger.kernel.org \
--cc=like.xu.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oliver.upton@linux.dev \
--cc=pbonzini@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.