lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 6 Oct 2023 08:27:19 -0700
From:   Vishal Annapurve <vannapurve@...gle.com>
To:     Dave Hansen <dave.hansen@...el.com>
Cc:     "Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
        Dave Hansen <dave.hansen@...ux.intel.com>,
        Peter Zijlstra <peterz@...radead.org>,
        Jun Nakajima <jun.nakajima@...el.com>,
        Isaku Yamahata <isaku.yamahata@...el.com>,
        Erdem Aktas <erdemaktas@...gle.com>,
        Sagi Shahar <sagis@...gle.com>,
        Sean Christopherson <seanjc@...gle.com>,
        Nikolay Borisov <nik.borisov@...e.com>,
        "Jason A. Donenfeld" <Jason@...c4.com>,
        Kuppuswamy Sathyanarayanan 
        <sathyanarayanan.kuppuswamy@...ux.intel.com>,
        "H. Peter Anvin" <hpa@...or.com>, x86@...nel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] x86/tdx: Override the tsc calibration for TDX VMs

On Fri, Oct 6, 2023 at 7:03 AM Dave Hansen <dave.hansen@...el.com> wrote:
>
> On 10/5/23 18:12, Vishal Annapurve wrote:
> > +/**
> > + * Determine TSC frequency via CPUID, else return 0.
> > + */
> > +static unsigned long tdx_calibrate_tsc(void)
> > +{
> > +     unsigned int eax_denominator = 0, ebx_numerator = 0, ecx_hz = 0, edx = 0;
> > +     unsigned int crystal_khz;
> > +
> > +     /* CPUID 15H TSC/Crystal ratio, plus optionally Crystal Hz */
> > +     cpuid(0x15, &eax_denominator, &ebx_numerator, &ecx_hz, &edx);
> > +
> > +     if (ebx_numerator == 0 || eax_denominator == 0)
> > +             return 0;
> > +
> > +     crystal_khz = ecx_hz / 1000;
> > +
> > +     /*
> > +      * TSC frequency reported directly by CPUID is a "hardware reported"
> > +      * frequency and is the most accurate one so far we have. This
> > +      * is considered a known frequency.
> > +      */
> > +     if (crystal_khz != 0)
> > +             setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ);
> > +
> > +     return crystal_khz * ebx_numerator / eax_denominator;
> > +}
> > +
>
> Would it be possible to do this by refactoring the existing code and
> calling it directly instead of copying and pasting so much?

One option is to call native_calibrate_tsc from tdx_calibrate_tsc and
undo the lapic_timer_period configuration after the call. Does that
sound reasonable?

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ