Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Jim Mattson <jmattson@google.com>
Cc: sashiko-reviews@lists.linux.dev, kvm@vger.kernel.org
Subject: Re: [PATCH v3 13/21] KVM: selftests: Use KVM's reported TSC KHz as L0's frequency (sanity checked)
Date: Mon, 5 Oct 2026 22:37:04 -0700	[thread overview]
Message-ID: <asSJAJUuvCAXkCwi@google.com> (raw)
In-Reply-To: <CALMp9eRkgiFYeQcTU_aweJQTfrq7ijN5hw+6otKE_RvgGQm=Uw@mail.gmail.com>

On Fri, Oct 02, 2026, Jim Mattson wrote:
> On Wed, Sep 30, 2026 at 11:23 AM Sean Christopherson <seanjc@google.com> wrote:
> >
> > On Wed, Sep 30, 2026, sashiko-bot@kernel.org wrote:
> 
> > > > @@ -212,18 +209,30 @@ static void test_tsc_scaling(u64 l0_tsc_freq, u64 l1_scale_factor, u64 l2_scale_
> > > >  int main(int argc, char *argv[])
> > > >  {
> > > >     u64 l0_tsc_freq, tsc_start, tsc_end, l1_scale, l2_scale;
> > > > +   struct kvm_vm *vm;
> > > >
> > > >     TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX) ||
> > > >                  kvm_cpu_has(X86_FEATURE_SVM));
> > > >     TEST_REQUIRE(kvm_has_cap(KVM_CAP_TSC_CONTROL));
> > > >     TEST_REQUIRE(sys_clocksource_is_based_on_tsc());
> > > >
> > > > +   /*
> > > > +    * Create a dummy VM to get KVM's default TSC frequency.  All CPUs that
> > > > +    * support TSC scaling should have a constant TSC, i.e. there's no need
> > > > +    * to calibrate the "real" TSC.  But do sanity check that the observed
> > > > +    * TSC is within range of KVM's reported TSC frequency.
> > > > +    */
> > > > +   vm = vm_create_barebones();
> > > > +   l0_tsc_freq = (u64)__vm_ioctl(vm, KVM_GET_TSC_KHZ, NULL) * 1000;
> > > > +   TEST_ASSERT(l0_tsc_freq, "vcpu ioctl KVM_GET_TSC_KHZ failed");
> > >
> > > [Severity: Low]
> > > Does this properly catch an ioctl failure? If __vm_ioctl() fails and returns
> > > -1, casting it to a u64 and multiplying by 1000 results in a very large
> > > non-zero value (0xfffffffffffffc18).
> > >
> > > Since TEST_ASSERT only checks if l0_tsc_freq is non-zero, won't this pass
> > > using garbage data instead of failing the test?
> >
> > Eh, yes and no.  KVM_GET_TSC_KHZ existed long before TSC scaling, and while KVM
> > doesn't sanity check tsc_khz, i.e. KVM_GET_TSC_KHZ could return a "legitimate"
> > negative frequency (when those ~2.17PHz CPUs come along), in practice checking
> > for a non-zero value is sufficient because any bogus value will quickly fail the
> > functional checks.
> >
> > Heh, actually, kvm_arch_vm_post_create() *already* validates KVM_GET_TSC_KHZ:
> >
> >         r = __vm_ioctl(vm, KVM_GET_TSC_KHZ, NULL);
> >         TEST_ASSERT(r > 0, "KVM_GET_TSC_KHZ did not provide a valid TSC frequency.");
> >         guest_tsc_khz = r;
> >
> > so this is a non-issue.  I agree it's not the prettiest, I just don't care enough
> > to clean it up.
> 
> In my best Sashiko passive-aggressive tone:
> 
> Is it possible that vm_create_barebones() bypasses that check?

LOL, *sigh*.  I'll send a patch to add a wrapper, having to manually do the
assert is annoying.

  reply	other threads:[~2026-10-06  5:37 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 17:36 [PATCH v3 00/21] KVM: x86: Fix nested TSC scaling edge cases Sean Christopherson
2026-09-30 17:36 ` [PATCH v3 01/21] KVM: x86: Saturate L2's TSC frequency if it exceeds hardware supports Sean Christopherson
2026-09-30 17:36 ` [PATCH v3 02/21] KVM: SVM: Fallback to the default TSC ratio if KVM tries to use a bad multiplier Sean Christopherson
2026-09-30 17:36 ` [PATCH v3 03/21] KVM: x86: Allow userspace to set KVM's max supported guest TSC frequency Sean Christopherson
2026-09-30 17:36 ` [PATCH v3 04/21] KVM: selftests: Use KVM's pRNG to randomize L1's TSC ratio in TSC scaling test Sean Christopherson
2026-09-30 17:36 ` [PATCH v3 05/21] KVM: selftests: Drop redundant VMWRITE of TSC_MULTIPLIER_HIGH Sean Christopherson
2026-09-30 17:36 ` [PATCH v3 06/21] KVM: selftests: Drop unnecessary use of PRIu64 in nested TSC scaling test Sean Christopherson
2026-09-30 17:36 ` [PATCH v3 07/21] KVM: selftests: Randomize L2's scale factor " Sean Christopherson
2026-09-30 17:36 ` [PATCH v3 08/21] KVM: selftests: Rename TSC freq checkers " Sean Christopherson
2026-09-30 17:45   ` sashiko-bot
2026-09-30 18:00     ` Sean Christopherson
2026-09-30 17:36 ` [PATCH v3 09/21] KVM: selftests: Extract guts of nested TSC scaling test to helper function Sean Christopherson
2026-09-30 17:36 ` [PATCH v3 10/21] KVM: selftests: Track L2 multiplier, not scale-up factor, in nested TSC test Sean Christopherson
2026-09-30 17:36 ` [PATCH v3 11/21] KVM: selftests: Print out the failing L{0,1,2} level in nested TSC scaling test Sean Christopherson
2026-09-30 17:36 ` [PATCH v3 12/21] KVM: selftests: Allow +/- 1 tolerance if expected TSC frequency is <100 Sean Christopherson
2026-09-30 17:36 ` [PATCH v3 13/21] KVM: selftests: Use KVM's reported TSC KHz as L0's frequency (sanity checked) Sean Christopherson
2026-09-30 17:52   ` sashiko-bot
2026-09-30 18:08     ` Sean Christopherson
2026-10-02 23:43       ` Jim Mattson
2026-10-06  5:37         ` Sean Christopherson [this message]
2026-10-06 21:57   ` Jim Mattson
2026-10-07  6:04     ` Sean Christopherson
2026-10-07 17:25       ` Jim Mattson
2026-09-30 17:36 ` [PATCH v3 14/21] KVM: selftests: Explicitly pass TSC frequencies to guts of TSC scaling test Sean Christopherson
2026-09-30 17:36 ` [PATCH v3 15/21] KVM: selftests: Sanity check KVM's default TSC freq in nested " Sean Christopherson
2026-09-30 17:36 ` [PATCH v3 16/21] KVM: selftests: Test L1 "up" and L2 "down" " Sean Christopherson
2026-09-30 17:36 ` [PATCH v3 17/21] KVM: selftests: Verify that KVM saturates L2 TSC freq on {under,over}flow Sean Christopherson
2026-09-30 17:36 ` [PATCH v3 18/21] KVM: selftests: Test non-zero TSC offset on SVM in nested TSC scaling test Sean Christopherson
2026-09-30 17:36 ` [PATCH v3 19/21] KVM: selftests: Randomize L2's TSC offset in the " Sean Christopherson
2026-09-30 17:36 ` [PATCH v3 20/21] KVM: selftests: Use GUEST_SYNC2() in " Sean Christopherson
2026-09-30 17:36 ` [PATCH v3 21/21] KVM: selftests: Spell out UCALL in nested TSC scaling test's enums Sean Christopherson
2026-10-02 21:07 ` [PATCH v3 00/21] KVM: x86: Fix nested TSC scaling edge cases 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=asSJAJUuvCAXkCwi@google.com \
    --to=seanjc@google.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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