Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

clocksource: hyper-v: Skip unnecessary checks for the root partition

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>

Wei Liu 47691ced 4cd661c2

+19 -2
+10 -1
arch/x86/kernel/cpu/mshyperv.c
··· 565 565 machine_ops.crash_shutdown = hv_machine_crash_shutdown; 566 566 #endif 567 567 #endif 568 + /* 569 + * HV_ACCESS_TSC_INVARIANT is always zero for the root partition. Root 570 + * partition doesn't need to write to synthetic MSR to enable invariant 571 + * TSC feature. It sees what the hardware provides. 572 + */ 568 573 if (ms_hyperv.features & HV_ACCESS_TSC_INVARIANT) { 569 574 /* 570 575 * Writing to synthetic MSR 0x40000118 updates/changes the ··· 641 636 * TSC should be marked as unstable only after Hyper-V 642 637 * clocksource has been initialized. This ensures that the 643 638 * stability of the sched_clock is not altered. 639 + * 640 + * HV_ACCESS_TSC_INVARIANT is always zero for the root partition. No 641 + * need to check for it. 644 642 */ 645 - if (!(ms_hyperv.features & HV_ACCESS_TSC_INVARIANT)) 643 + if (!hv_root_partition() && 644 + !(ms_hyperv.features & HV_ACCESS_TSC_INVARIANT)) 646 645 mark_tsc_unstable("running on Hyper-V"); 647 646 648 647 hardlockup_detector_disable();
+9 -1
drivers/clocksource/hyperv_timer.c
··· 549 549 union hv_reference_tsc_msr tsc_msr; 550 550 551 551 /* 552 + * When running as a guest partition: 553 + * 552 554 * If Hyper-V offers TSC_INVARIANT, then the virtualized TSC correctly 553 555 * handles frequency and offset changes due to live migration, 554 556 * pause/resume, and other VM management operations. So lower the 555 557 * Hyper-V Reference TSC rating, causing the generic TSC to be used. 556 558 * TSC_INVARIANT is not offered on ARM64, so the Hyper-V Reference 557 559 * TSC will be preferred over the virtualized ARM64 arch counter. 560 + * 561 + * When running as the root partition: 562 + * 563 + * There is no HV_ACCESS_TSC_INVARIANT feature. Always lower the rating 564 + * of the Hyper-V Reference TSC. 558 565 */ 559 - if (ms_hyperv.features & HV_ACCESS_TSC_INVARIANT) { 566 + if ((ms_hyperv.features & HV_ACCESS_TSC_INVARIANT) || 567 + hv_root_partition()) { 560 568 hyperv_cs_tsc.rating = 250; 561 569 hyperv_cs_msr.rating = 245; 562 570 }