Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [Medium] Spurious WARN_ON stack trace on every boot for CoCo (SEV-SNP/TDX) 
guests under KVM.
--

commit e57255e4d076143a67d0e6e44f914aec31aed8c7
Author: Sean Christopherson <[email protected]>

x86/tsc: Rejects attempts to override TSC calibration with lesser routine

This commit adds a sanity check when registering a TSC frequency calibration
routine to ensure the incoming routine is as robust as the outgoing one,
rejecting it with a warning if it is not. This prevents replacing a trusted
calibration source with a less trusted one.

> diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
> index 98bef1d06fa9d..7a261214fa3ef 100644
> --- a/arch/x86/kernel/tsc.c
> +++ b/arch/x86/kernel/tsc.c
> @@ -1319,8 +1319,13 @@ void tsc_register_calibration_routines(unsigned long 
> (*calibrate_tsc)(void),
>  
>       if (properties & TSC_FREQUENCY_KNOWN)
>               setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ);
> +     else if (WARN_ON(boot_cpu_has(X86_FEATURE_TSC_KNOWN_FREQ)))
> +             return;
> +
>       if (properties & TSC_RELIABLE)
>               setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE);
> +     else if (WARN_ON(boot_cpu_has(X86_FEATURE_TSC_RELIABLE)))
> +             return;

Will this cause a spurious warning stack trace on every boot for CoCo
(SEV-SNP/TDX) guests under KVM?

For KVM CoCo guests, CoCo registers first via tsc_early_init(), setting both
TSC_FREQUENCY_KNOWN and X86_FEATURE_TSC_RELIABLE.

KVM then registers second via kvmclock_init(). At this point in the patch
series, KVM only passes TSC_FREQUENCY_KNOWN, so the properties & TSC_RELIABLE
check is false, and it falls through to this WARN_ON. Since CoCo already set
the capability, the condition evaluates to true.

I see this is fixed later in the series by the commit "x86/kvmclock: Mark TSC
as reliable when it's constant and nonstop", which modifies KVM to pass
TSC_FREQ_KNOWN_AND_RELIABLE on modern hardware, preventing this warning.

Could the patch ordering be adjusted to prevent this intermediate regression?

>  
>       x86_platform.calibrate_tsc = calibrate_tsc;
>       if (calibrate_cpu)

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=32

Reply via email to