From: Sean Christopherson <seanjc@google.com>
To: David Woodhouse <dwmw2@infradead.org>
Cc: Paul Durrant <pdurrant@amazon.co.uk>,
Fred Griffoul <fgriffo@amazon.co.uk>,
Colin Percival <cperciva@tarsnap.com>,
Paolo Bonzini <pbonzini@redhat.com>,
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" <x86@kernel.org>,
"H. Peter Anvin" <hpa@zytor.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Graf (AWS), Alexander" <graf@amazon.de>,
Ajay Kaher <ajay.kaher@broadcom.com>,
Alexey Makhalov <alexey.makhalov@broadcom.com>
Subject: Re: [PATCH v2 0/3] Support "generic" CPUID timing leaf as KVM guest and host
Date: Tue, 2 Sep 2025 10:49:16 -0700 [thread overview]
Message-ID: <aLcuHHfxOlaF5htL@google.com> (raw)
In-Reply-To: <d74ff3c1c70f815a10b8743647008bd4081e7625.camel@infradead.org>
On Tue, Sep 02, 2025, David Woodhouse wrote:
> On Fri, 2025-08-29 at 13:36 -0700, Sean Christopherson wrote:
> >
> > > This does mean userspace would have to set the vCPU's TSC frequency and
> > > then query the kernel before setting up its CPUID. And in the absence
> > > of scaling, this KVM API would report the hardware TSC frequency.
> >
> > Reporting the hardware TSC frequency on CPUs without scaling seems all kinds of
> > wrong (which another reason I don't like KVM shoving in the state). Of course,
> > reporting the frequency KVM is trying to provide isn't great either, as the guest
> > will definitely observe something in between those two.
>
> Yes, on CPUs that don't support TSC scaling, we should not attempt to
> advertise a frequency.
>
> Where I said 'in the absence of scaling' I meant modern CPUs but where
> the VMM just didn't ask for TSC scaling.
>
> > > I guess the API would have to return -EHARDWARETOOSTUPID if the TSC frequency
> > > *isn't* the same across all CPUs and all power states, etc.
> >
> > What if KVM advertises the flag in KVM_GET_SUPPORTED_CPUID if and only if the
> > TSC will be constant from the guest's perspective? TSC scaling has been supported
> > by AMD and Intel for ~10 years, it doesn't seem at all unreasonable to restrict
> > the feature to somewhat modern hardware. And if userspace or the admin knows
> > better than KVM, then userspace can always ignore KVM and report the frequency
> > anyways.
>
> I hadn't put it in KVM_GET_SUPPORTED_CPUID; I was following the lead of
> the existing Xen leaf support, where *if* userspace provides that leaf,
> KVM will dynamically correct the values in it.
>
> The problem is that KVM_GET_SUPPORTED_CPUID is a *system* ioctl on the
> bare /dev/kvm device, isn 't it?
Yep.
> So even if a VMM has set the TSC frequency VM-wide with KVM_SET_TSC_KHZ
> instead of doing it the old per- vCPU way, how can it get the results for a
> specific VM?
I don't see any need for userspace to query per-VM support. What I'm proposing
is that KVM advertise the feature if the bare metal TSC is constant and the CPU
supports TSC scaling. Beyond that, _KVM_ doesn't need to do anything to ensure
the guest sees a constant frequency, it's userspace's responsibility to provide
a sane configuration.
And strictly speaking, CPUID is per-CPU, i.e. it's architecturally legal to set
per-vCPU frequencies and then advertise a different frequency in CPUID for each
vCPU. That's all but guaranteed to break guests as most/all kernels assume that
TSC operates at the same frequency on all CPUs, but as above, that's userspace's
responsibility to not screw up.
next prev parent reply other threads:[~2025-09-02 17:49 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-16 10:09 [PATCH v2 0/3] Support "generic" CPUID timing leaf as KVM guest and host David Woodhouse
2025-08-16 10:10 ` [PATCH v2 1/3] KVM: x86: Restore caching of KVM CPUID base David Woodhouse
2025-08-16 10:10 ` [PATCH v2 2/3] KVM: x86: Provide TSC frequency in "generic" timing infomation CPUID leaf David Woodhouse
2025-08-16 10:10 ` [PATCH v2 3/3] x86/kvm: Obtain TSC frequency from CPUID if present David Woodhouse
2025-08-21 16:26 ` [PATCH v2 0/3] Support "generic" CPUID timing leaf as KVM guest and host Sean Christopherson
2025-08-21 17:37 ` David Woodhouse
2025-08-21 19:27 ` Sean Christopherson
2025-08-21 20:42 ` David Woodhouse
2025-08-21 20:48 ` Sean Christopherson
2025-08-21 21:10 ` David Woodhouse
2025-08-22 1:57 ` Colin Percival
[not found] ` <01000198cf7ec03e-dfc78632-42ee-480b-8b51-3446fbb555d1-000000@email.amazonses.com>
2025-08-26 19:30 ` Sean Christopherson
2025-08-27 9:30 ` David Woodhouse
2025-08-28 23:40 ` Sean Christopherson
2025-08-29 9:50 ` David Woodhouse
2025-08-29 11:08 ` Durrant, Paul
2025-08-29 11:19 ` David Woodhouse
2025-08-29 20:36 ` Sean Christopherson
2025-09-02 8:31 ` David Woodhouse
2025-09-02 17:49 ` Sean Christopherson [this message]
2025-09-02 18:23 ` David Woodhouse
2025-09-04 11:59 ` Sean Christopherson
2025-09-04 12:14 ` David Woodhouse
2025-09-04 13:25 ` Sean Christopherson
2025-09-04 13:51 ` David Woodhouse
2025-09-05 7:57 ` Sean Christopherson
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=aLcuHHfxOlaF5htL@google.com \
--to=seanjc@google.com \
--cc=ajay.kaher@broadcom.com \
--cc=alexey.makhalov@broadcom.com \
--cc=bp@alien8.de \
--cc=cperciva@tarsnap.com \
--cc=dave.hansen@linux.intel.com \
--cc=dwmw2@infradead.org \
--cc=fgriffo@amazon.co.uk \
--cc=graf@amazon.de \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=pdurrant@amazon.co.uk \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--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).