x86/tsc: Do feature check as the very first thing
authorBorislav Petkov (AMD) <bp@alien8.de>
Sun, 18 Dec 2022 20:53:36 +0000 (21:53 +0100)
committerBorislav Petkov (AMD) <bp@alien8.de>
Sat, 11 Feb 2023 09:44:07 +0000 (10:44 +0100)
Do the feature check as the very first thing in the function. Everything
else comes after that and is meaningless work if the TSC CPUID bit is
not even set. Switch to cpu_feature_enabled() too, while at it.

No functional changes.

Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/Y5990CUCuWd5jfBH@zn.tnic
arch/x86/kernel/tsc.c

index eaeffef93a12a918771e74b99f077473a8c14471..aff1d79dd6ba20864c51a91068bf292b330a4674 100644 (file)
@@ -1509,6 +1509,11 @@ void __init tsc_early_init(void)
 
 void __init tsc_init(void)
 {
+       if (!cpu_feature_enabled(X86_FEATURE_TSC)) {
+               setup_clear_cpu_cap(X86_FEATURE_TSC_DEADLINE_TIMER);
+               return;
+       }
+
        /*
         * native_calibrate_cpu_early can only calibrate using methods that are
         * available early in boot.
@@ -1516,11 +1521,6 @@ void __init tsc_init(void)
        if (x86_platform.calibrate_cpu == native_calibrate_cpu_early)
                x86_platform.calibrate_cpu = native_calibrate_cpu;
 
-       if (!boot_cpu_has(X86_FEATURE_TSC)) {
-               setup_clear_cpu_cap(X86_FEATURE_TSC_DEADLINE_TIMER);
-               return;
-       }
-
        if (!tsc_khz) {
                /* We failed to determine frequencies earlier, try again */
                if (!determine_cpu_tsc_frequencies(false)) {