From: Sean Christopherson <seanjc@google.com>
To: David Woodhouse <dwmw2@infradead.org>
Cc: Paul Durrant <paul@xen.org>, Paolo Bonzini <pbonzini@redhat.com>,
Jonathan Corbet <corbet@lwn.net>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
kvm@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] KVM x86/xen: add an override for PVCLOCK_TSC_STABLE_BIT
Date: Tue, 31 Oct 2023 22:58:48 +0000 [thread overview]
Message-ID: <ZUGGqOCU7TAU6c6p@google.com> (raw)
In-Reply-To: <028f629d16377f9a7e9fd87ef9564846b0ab4ed9.camel@infradead.org>
On Tue, Oct 31, 2023, David Woodhouse wrote:
> On Tue, 2023-10-31 at 15:39 -0700, Sean Christopherson wrote:
> > On Tue, Oct 31, 2023, Paul Durrant wrote:
> > Any reason not to make this a generic "capability" instead of a Xen specific flag?
> > E.g. I assume these problematic guests would mishandle PVCLOCK_TSC_STABLE_BIT if
> > it showed up in kvmclock, but they don't use kvmclock so it's not a problem in
> > practice.
>
> No, those guests are just fine with kvmclock. It's the *Xen* page they
> forgot to map to userspace for the vDSO to use. And it's Xen (true Xen)
> which made you jump through hoops to use the TSC that way, such that it
> would actually expose the PVCLOCK_TSC_STABLE_BIT. We don't expect, and
> have never seen, such issues with native KVM guests.
Hmm, and I suppose theoretically the guest kernel could choose to ignore the Xen
interface for whatever reason. Mostly out of curiosity, is this flag something
that'd be set anytime Xen is advertised to the guest?
> > I doubt there's a real need or use case, but it'd require less churn and IMO is
> > simpler overall, e.g.
> >
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index e3eb608b6692..731b201bfd5a 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -3225,7 +3225,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
> >
> > /* If the host uses TSC clocksource, then it is stable */
> > pvclock_flags = 0;
> > - if (use_master_clock)
> > + if (use_master_clock && !vcpu->kvm.force_tsc_unstable)
> > pvclock_flags |= PVCLOCK_TSC_STABLE_BIT;
> >
> > vcpu->hv_clock.flags = pvclock_flags;
> >
> > I also assume this is a "set and forget" thing? I.e. KVM can require the flag
> > to be set before any vCPUs are created.
>
> Hrm, not sure we have previously required that the KVM_XEN_HVM_CONFIG
> setup be done before any vCPUs were created.
Oh, I was asking in the context of adding a generic capability.
> I tend to prefer *not* to push ordering requirements onto userspace.
For per-VM flags that are consumed by vCPUs, it makes reasoning about correctness
and what is/isn't allowed much, much easier.
> Does it need to be a per-vcpu thing?
Huh? No, I was only asking (again, for a generic capability) if we could do
mutex_lock(&kvm->lock);
if (!kvm->created_vcpus) {
kvm->arch.force_tsc_unstable = true;
r = 0;
}
mutex_unlock(&kvm->lock);
So that it would be blatantly obvious that there's no race with checking a per-VM
flag without any lock/RCU protections.
next prev parent reply other threads:[~2023-10-31 22:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-31 11:57 [PATCH v2] KVM x86/xen: add an override for PVCLOCK_TSC_STABLE_BIT Paul Durrant
2023-10-31 22:39 ` Sean Christopherson
2023-10-31 22:48 ` David Woodhouse
2023-10-31 22:58 ` Sean Christopherson [this message]
2023-10-31 23:06 ` David Woodhouse
2023-11-01 11:06 ` Paul Durrant
2023-11-01 11:02 ` Paul Durrant
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=ZUGGqOCU7TAU6c6p@google.com \
--to=seanjc@google.com \
--cc=bp@alien8.de \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=dwmw2@infradead.org \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=paul@xen.org \
--cc=pbonzini@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).