clocksource: hyper-v: Use lapic timer in a TDX VM without paravisor
BugLink: https://bugs.launchpad.net/bugs/2086138 commit 7f828d5fff7d24752e1ecf6bebb6617a81f97b93 upstream. In a TDX VM without paravisor, currently the default timer is the Hyper-V timer, which depends on the slow VM Reference Counter MSR: the Hyper-V TSC page is not enabled in such a VM because the VM uses Invariant TSC as a better clocksource and it's challenging to mark the Hyper-V TSC page shared in very early boot. Lower the rating of the Hyper-V timer so the local APIC timer becomes the the default timer in such a VM, and print a warning in case Invariant TSC is unavailable in such a VM. This change should cause no perceivable performance difference. Cc: stable@vger.kernel.org # 6.6+ Reviewed-by: Roman Kisel <romank@linux.microsoft.com> Signed-off-by: Dexuan Cui <decui@microsoft.com> Reviewed-by: Michael Kelley <mhklinux@outlook.com> Link: https://lore.kernel.org/r/20240621061614.8339-1-decui@microsoft.com Signed-off-by: Wei Liu <wei.liu@kernel.org> Message-ID: <20240621061614.8339-1-decui@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> [koichiroden: adjusted context due to missing commit: b967df629351 ("hyperv-tlfs: Rename some HV_REGISTER_* defines for consistency")] Signed-off-by: Koichiro Den <koichiro.den@canonical.com> Signed-off-by: Roxana Nicolescu <roxana.nicolescu@canonical.com>
This commit is contained in:
committed by
Mehmet Basaran
parent
d8e0e1f4e6
commit
c68e3cd882
@@ -451,9 +451,23 @@ static void __init ms_hyperv_init_platform(void)
|
||||
ms_hyperv.hints &= ~HV_X64_APIC_ACCESS_RECOMMENDED;
|
||||
|
||||
if (!ms_hyperv.paravisor_present) {
|
||||
/* To be supported: more work is required. */
|
||||
/*
|
||||
* Mark the Hyper-V TSC page feature as disabled
|
||||
* in a TDX VM without paravisor so that the
|
||||
* Invariant TSC, which is a better clocksource
|
||||
* anyway, is used instead.
|
||||
*/
|
||||
ms_hyperv.features &= ~HV_MSR_REFERENCE_TSC_AVAILABLE;
|
||||
|
||||
/*
|
||||
* The Invariant TSC is expected to be available
|
||||
* in a TDX VM without paravisor, but if not,
|
||||
* print a warning message. The slower Hyper-V MSR-based
|
||||
* Ref Counter should end up being the clocksource.
|
||||
*/
|
||||
if (!(ms_hyperv.features & HV_ACCESS_TSC_INVARIANT))
|
||||
pr_warn("Hyper-V: Invariant TSC is unavailable\n");
|
||||
|
||||
/* HV_REGISTER_CRASH_CTL is unsupported. */
|
||||
ms_hyperv.misc_features &= ~HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE;
|
||||
|
||||
|
||||
@@ -137,7 +137,21 @@ static int hv_stimer_init(unsigned int cpu)
|
||||
ce->name = "Hyper-V clockevent";
|
||||
ce->features = CLOCK_EVT_FEAT_ONESHOT;
|
||||
ce->cpumask = cpumask_of(cpu);
|
||||
ce->rating = 1000;
|
||||
|
||||
/*
|
||||
* Lower the rating of the Hyper-V timer in a TDX VM without paravisor,
|
||||
* so the local APIC timer (lapic_clockevent) is the default timer in
|
||||
* such a VM. The Hyper-V timer is not preferred in such a VM because
|
||||
* it depends on the slow VM Reference Counter MSR (the Hyper-V TSC
|
||||
* page is not enbled in such a VM because the VM uses Invariant TSC
|
||||
* as a better clocksource and it's challenging to mark the Hyper-V
|
||||
* TSC page shared in very early boot).
|
||||
*/
|
||||
if (!ms_hyperv.paravisor_present && hv_isolation_type_tdx())
|
||||
ce->rating = 90;
|
||||
else
|
||||
ce->rating = 1000;
|
||||
|
||||
ce->set_state_shutdown = hv_ce_shutdown;
|
||||
ce->set_state_oneshot = hv_ce_set_oneshot;
|
||||
ce->set_next_event = hv_ce_set_next_event;
|
||||
|
||||
Reference in New Issue
Block a user