* [PATCH v2] clocksource: hyper-v: Use lapic timer in a TDX VM without paravisor
@ 2024-06-21 6:16 Dexuan Cui
2024-06-21 15:18 ` Michael Kelley
2024-06-24 7:06 ` Wei Liu
0 siblings, 2 replies; 3+ messages in thread
From: Dexuan Cui @ 2024-06-21 6:16 UTC (permalink / raw)
To: mhklinux, K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui,
Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), H. Peter Anvin,
Daniel Lezcano, open list:Hyper-V/Azure CORE AND DRIVERS,
open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)
Cc: stable, Roman Kisel
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>
---
Changes in v2:
Improved the comments in ms_hyperv_init_platform() [Michael Kelley]
Added "print a warning in case Invariant TSC unavailable" in the changelog.
Added Roman's Reviewed-by.
arch/x86/kernel/cpu/mshyperv.c | 16 +++++++++++++++-
drivers/clocksource/hyperv_timer.c | 16 +++++++++++++++-
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index e0fd57a8ba840..954b7cbfa2f02 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -449,9 +449,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_MSR_CRASH_CTL is unsupported. */
ms_hyperv.misc_features &= ~HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE;
diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c
index b2a080647e413..99177835cadec 100644
--- a/drivers/clocksource/hyperv_timer.c
+++ b/drivers/clocksource/hyperv_timer.c
@@ -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;
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [PATCH v2] clocksource: hyper-v: Use lapic timer in a TDX VM without paravisor
2024-06-21 6:16 [PATCH v2] clocksource: hyper-v: Use lapic timer in a TDX VM without paravisor Dexuan Cui
@ 2024-06-21 15:18 ` Michael Kelley
2024-06-24 7:06 ` Wei Liu
1 sibling, 0 replies; 3+ messages in thread
From: Michael Kelley @ 2024-06-21 15:18 UTC (permalink / raw)
To: Dexuan Cui, K. Y. Srinivasan, Haiyang Zhang, Wei Liu,
Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), H. Peter Anvin,
Daniel Lezcano, open list:Hyper-V/Azure CORE AND DRIVERS,
open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)
Cc: stable@vger.kernel.org, Roman Kisel
From: Dexuan Cui <decui@microsoft.com> Sent: Thursday, June 20, 2024 11:16 PM
>
> 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>
> ---
>
> Changes in v2:
> Improved the comments in ms_hyperv_init_platform() [Michael Kelley]
> Added "print a warning in case Invariant TSC unavailable" in the changelog.
> Added Roman's Reviewed-by.
>
> arch/x86/kernel/cpu/mshyperv.c | 16 +++++++++++++++-
> drivers/clocksource/hyperv_timer.c | 16 +++++++++++++++-
> 2 files changed, 30 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
> index e0fd57a8ba840..954b7cbfa2f02 100644
> --- a/arch/x86/kernel/cpu/mshyperv.c
> +++ b/arch/x86/kernel/cpu/mshyperv.c
> @@ -449,9 +449,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_MSR_CRASH_CTL is unsupported. */
> ms_hyperv.misc_features &= ~HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE;
>
> diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c
> index b2a080647e413..99177835cadec 100644
> --- a/drivers/clocksource/hyperv_timer.c
> +++ b/drivers/clocksource/hyperv_timer.c
> @@ -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;
> --
> 2.25.1
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] clocksource: hyper-v: Use lapic timer in a TDX VM without paravisor
2024-06-21 6:16 [PATCH v2] clocksource: hyper-v: Use lapic timer in a TDX VM without paravisor Dexuan Cui
2024-06-21 15:18 ` Michael Kelley
@ 2024-06-24 7:06 ` Wei Liu
1 sibling, 0 replies; 3+ messages in thread
From: Wei Liu @ 2024-06-24 7:06 UTC (permalink / raw)
To: Dexuan Cui
Cc: mhklinux, K. Y. Srinivasan, Haiyang Zhang, Wei Liu,
Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), H. Peter Anvin,
Daniel Lezcano, open list:Hyper-V/Azure CORE AND DRIVERS,
open list:X86 ARCHITECTURE (32-BIT AND 64-BIT), stable,
Roman Kisel
On Thu, Jun 20, 2024 at 11:16:14PM -0700, Dexuan Cui wrote:
> 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>
Applied to hyperv-fixes. Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-06-24 7:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-21 6:16 [PATCH v2] clocksource: hyper-v: Use lapic timer in a TDX VM without paravisor Dexuan Cui
2024-06-21 15:18 ` Michael Kelley
2024-06-24 7:06 ` Wei Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).