]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
clocksource: hyper-v: Skip unnecessary checks for the root partition
authorWei Liu <wei.liu@kernel.org>
Tue, 12 Aug 2025 19:48:45 +0000 (19:48 +0000)
committerWei Liu <wei.liu@kernel.org>
Mon, 8 Sep 2025 22:10:46 +0000 (22:10 +0000)
The HV_ACCESS_TSC_INVARIANT bit is always zero when Linux runs as the
root partition. The root partition will see directly what the hardware
provides.

The old logic in ms_hyperv_init_platform caused the native TSC clock
source to be incorrectly marked as unstable on x86. Fix it.

Skip the unnecessary checks in code for the root partition. Add one
extra comment in code to clarify the behavior.

Reviewed-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
Signed-off-by: Wei Liu <wei.liu@kernel.org>
arch/x86/kernel/cpu/mshyperv.c
drivers/clocksource/hyperv_timer.c

index c78f860419d697c91349b28853c288fb6b2e41f6..25773af116bc41837b8bfd4333c5b40e7ef7a518 100644 (file)
@@ -565,6 +565,11 @@ static void __init ms_hyperv_init_platform(void)
        machine_ops.crash_shutdown = hv_machine_crash_shutdown;
 #endif
 #endif
+       /*
+        * HV_ACCESS_TSC_INVARIANT is always zero for the root partition. Root
+        * partition doesn't need to write to synthetic MSR to enable invariant
+        * TSC feature. It sees what the hardware provides.
+        */
        if (ms_hyperv.features & HV_ACCESS_TSC_INVARIANT) {
                /*
                 * Writing to synthetic MSR 0x40000118 updates/changes the
@@ -636,8 +641,12 @@ static void __init ms_hyperv_init_platform(void)
         * TSC should be marked as unstable only after Hyper-V
         * clocksource has been initialized. This ensures that the
         * stability of the sched_clock is not altered.
+        *
+        * HV_ACCESS_TSC_INVARIANT is always zero for the root partition. No
+        * need to check for it.
         */
-       if (!(ms_hyperv.features & HV_ACCESS_TSC_INVARIANT))
+       if (!hv_root_partition() &&
+           !(ms_hyperv.features & HV_ACCESS_TSC_INVARIANT))
                mark_tsc_unstable("running on Hyper-V");
 
        hardlockup_detector_disable();
index 2edc13ca184e0d4168a8d03347c7e07e6406d13f..10356d4ec55c3ed5e54176042b7f11993ef0ee97 100644 (file)
@@ -549,14 +549,22 @@ static void __init hv_init_tsc_clocksource(void)
        union hv_reference_tsc_msr tsc_msr;
 
        /*
+        * When running as a guest partition:
+        *
         * If Hyper-V offers TSC_INVARIANT, then the virtualized TSC correctly
         * handles frequency and offset changes due to live migration,
         * pause/resume, and other VM management operations.  So lower the
         * Hyper-V Reference TSC rating, causing the generic TSC to be used.
         * TSC_INVARIANT is not offered on ARM64, so the Hyper-V Reference
         * TSC will be preferred over the virtualized ARM64 arch counter.
+        *
+        * When running as the root partition:
+        *
+        * There is no HV_ACCESS_TSC_INVARIANT feature. Always lower the rating
+        * of the Hyper-V Reference TSC.
         */
-       if (ms_hyperv.features & HV_ACCESS_TSC_INVARIANT) {
+       if ((ms_hyperv.features & HV_ACCESS_TSC_INVARIANT) ||
+           hv_root_partition()) {
                hyperv_cs_tsc.rating = 250;
                hyperv_cs_msr.rating = 245;
        }