Skip to content

Commit dce7cd6

Browse files
andrea-parriKAGA-KOKO
authored andcommitted
x86/hyperv: Allow guests to enable InvariantTSC
If the hardware supports TSC scaling, Hyper-V will set bit 15 of the HV_PARTITION_PRIVILEGE_MASK in guest VMs with a compatible Hyper-V configuration version. Bit 15 corresponds to the AccessTscInvariantControls privilege. If this privilege bit is set, guests can access the HvSyntheticInvariantTscControl MSR: guests can set bit 0 of this synthetic MSR to enable the InvariantTSC feature. After setting the synthetic MSR, CPUID will enumerate support for InvariantTSC. Signed-off-by: Andrea Parri <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Michael Kelley <[email protected]> Reviewed-by: Vitaly Kuznetsov <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent b264f57 commit dce7cd6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

arch/x86/include/asm/hyperv-tlfs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686
#define HV_X64_ACCESS_FREQUENCY_MSRS BIT(11)
8787
/* AccessReenlightenmentControls privilege */
8888
#define HV_X64_ACCESS_REENLIGHTENMENT BIT(13)
89+
/* AccessTscInvariantControls privilege */
90+
#define HV_X64_ACCESS_TSC_INVARIANT BIT(15)
8991

9092
/*
9193
* Feature identification: indicates which flags were specified at partition
@@ -270,6 +272,9 @@
270272
#define HV_X64_MSR_TSC_EMULATION_CONTROL 0x40000107
271273
#define HV_X64_MSR_TSC_EMULATION_STATUS 0x40000108
272274

275+
/* TSC invariant control */
276+
#define HV_X64_MSR_TSC_INVARIANT_CONTROL 0x40000118
277+
273278
/*
274279
* Declare the MSR used to setup pages used to communicate with the hypervisor.
275280
*/

arch/x86/kernel/cpu/mshyperv.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,12 @@ static void __init ms_hyperv_init_platform(void)
285285
machine_ops.shutdown = hv_machine_shutdown;
286286
machine_ops.crash_shutdown = hv_machine_crash_shutdown;
287287
#endif
288-
mark_tsc_unstable("running on Hyper-V");
288+
if (ms_hyperv.features & HV_X64_ACCESS_TSC_INVARIANT) {
289+
wrmsrl(HV_X64_MSR_TSC_INVARIANT_CONTROL, 0x1);
290+
setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE);
291+
} else {
292+
mark_tsc_unstable("running on Hyper-V");
293+
}
289294

290295
/*
291296
* Generation 2 instances don't support reading the NMI status from

0 commit comments

Comments
 (0)