Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The refactoring in `recalibrate_cpu_khz()` introduces a race condition where the global variable `cpu_khz` is temporarily set to 0 for up to 150ms during runtime CPU frequency recalibration. This exposes the system to invalid state reads. --
commit 34cf1b98d726e6c329bdefbd5c9712901d8b4bc8 Author: Sean Christopherson <[email protected]> x86/tsc: Fold native_calibrate_cpu() into recalibrate_cpu_khz() This commit folds the implementation of native_calibrate_cpu() directly into recalibrate_cpu_khz() to remove an extra CONFIG_SMP=n ifdef block. This change aims to clarify the intentional use of early versus late calibration routines. > diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c > index 9764ac758081f..6ed6f8f012ebf 100644 > --- a/arch/x86/kernel/tsc.c > +++ b/arch/x86/kernel/tsc.c [ ... ] > @@ -944,7 +929,9 @@ void recalibrate_cpu_khz(void) > if (WARN_ON_ONCE(cpu_feature_enabled(X86_FEATURE_TSC_KNOWN_FREQ))) > return; > > - cpu_khz = native_calibrate_cpu(); > + cpu_khz = native_calibrate_cpu_early(); > + if (!cpu_khz) > + cpu_khz = native_calibrate_cpu_late(); [Severity: Medium] Does this expose a race condition by temporarily assigning 0 to the global cpu_khz variable? On a UP kernel during cpufreq transitions, if early calibration fails, the global cpu_khz is directly assigned 0. It remains 0 while native_calibrate_cpu_late() executes, which can take ~150ms and enables interrupts. Could this lead to sysfs readers via arch_freq_get_on_cpu() observing a 0 frequency, or the NMI watchdog being misconfigured with a 0 sample period if toggled during this window? The previous implementation used a local variable inside native_calibrate_cpu() to hold the intermediate state, preventing concurrent readers from seeing an invalid 0 value before the slow fallback calibration completes. > tsc_khz = native_calibrate_tsc(); > if (tsc_khz == 0) > tsc_khz = cpu_khz; -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=17
