Skip to content

Commit c445535

Browse files
ani-sinhaliuw
authored andcommitted
x86/hyperv: fix for unwanted manipulation of sched_clock when TSC marked unstable
Marking TSC as unstable has a side effect of marking sched_clock as unstable when TSC is still being used as the sched_clock. This is not desirable. Hyper-V ultimately uses a paravirtualized clock source that provides a stable scheduler clock even on systems without TscInvariant CPU capability. Hence, mark_tsc_unstable() call should be called _after_ scheduler clock has been changed to the paravirtualized clocksource. This will prevent any unwanted manipulation of the sched_clock. Only TSC will be correctly marked as unstable. Signed-off-by: Ani Sinha <ani@anisinha.ca> Reviewed-by: Michael Kelley <mikelley@microsoft.com> Tested-by: Michael Kelley <mikelley@microsoft.com> Link: https://lore.kernel.org/r/20210713030522.1714803-1-ani@anisinha.ca Signed-off-by: Wei Liu <wei.liu@kernel.org>
1 parent ba3f583 commit c445535

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

arch/x86/kernel/cpu/mshyperv.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,6 @@ static void __init ms_hyperv_init_platform(void)
375375
if (ms_hyperv.features & HV_ACCESS_TSC_INVARIANT) {
376376
wrmsrl(HV_X64_MSR_TSC_INVARIANT_CONTROL, 0x1);
377377
setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE);
378-
} else {
379-
mark_tsc_unstable("running on Hyper-V");
380378
}
381379

382380
/*
@@ -437,6 +435,13 @@ static void __init ms_hyperv_init_platform(void)
437435
/* Register Hyper-V specific clocksource */
438436
hv_init_clocksource();
439437
#endif
438+
/*
439+
* TSC should be marked as unstable only after Hyper-V
440+
* clocksource has been initialized. This ensures that the
441+
* stability of the sched_clock is not altered.
442+
*/
443+
if (!(ms_hyperv.features & HV_ACCESS_TSC_INVARIANT))
444+
mark_tsc_unstable("running on Hyper-V");
440445
}
441446

442447
static bool __init ms_hyperv_x2apic_available(void)

0 commit comments

Comments
 (0)