Skip to content

Commit

Permalink
x86/hyperv: Don’t enable TSCInvariant on some older Hyper-V hosts
Browse files Browse the repository at this point in the history
Hyper-V host builds earlier than 22621 (Windows 11 22H2) have a bug in
the TSC Invariant feature that may result in the guest seeing a "slow"
TSC after the Hyper-V host resumes from hiberation. As a result, time
advances more slowly in the guest than in the host. When Linux programs
the Hyper-V synthetic timer, the timer interrupt can occur sooner than
expected or even immediately. As the guest time falls further and
further behind, a timer interrupt storm and unresponsive Linux guest can
result, along with excessive load on the host. Since the problem occurs
only after a Hyper-V host resumes from hibernation, the scenario is
primarily on Windows client devices that are running Linux guests such
as WSLv2.

Avoid the bug by assuming the TSC Invariant feature is not present when
WSLv2 is running on these builds.

Closes: microsoft/WSL#6982

Signed-off-by: Michael Kelley <[email protected]>
Signed-off-by: Mitchell Levy <[email protected]>
  • Loading branch information
mhklinux authored and Nevuly committed Feb 17, 2025
1 parent 2b6a7b2 commit 066c314
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions arch/x86/kernel/cpu/mshyperv.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ int hv_get_hypervisor_version(union hv_hypervisor_version_info *info)

static void __init ms_hyperv_init_platform(void)
{
union hv_hypervisor_version_info version;
unsigned int build = 0;
int hv_max_functions_eax;

#ifdef CONFIG_PARAVIRT
Expand All @@ -451,6 +453,18 @@ static void __init ms_hyperv_init_platform(void)
pr_debug("Hyper-V: max %u virtual processors, %u logical processors\n",
ms_hyperv.max_vp_index, ms_hyperv.max_lp_index);

/*
* Host builds earlier than 22621 (Win 11 22H2) have a bug in the
* invariant TSC feature that may result in the guest seeing a "slow"
* TSC after host hibernation. This causes problems with synthetic
* timer interrupts. In such a case, avoid the bug by assuming the
* feature is not present.
*/
if (!hv_get_hypervisor_version(&version))
build = version.build_number;
if (build < 22621)
ms_hyperv.features &= ~HV_ACCESS_TSC_INVARIANT;

/*
* Check CPU management privilege.
*
Expand Down

0 comments on commit 066c314

Please sign in to comment.