[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250107175128.GGZ31poPrKk2E_k-H3@fat_crate.local>
Date: Tue, 7 Jan 2025 18:51:28 +0100
From: Borislav Petkov <bp@...en8.de>
To: Nikunj A Dadhania <nikunj@....com>
Cc: linux-kernel@...r.kernel.org, thomas.lendacky@....com, x86@...nel.org,
kvm@...r.kernel.org, mingo@...hat.com, tglx@...utronix.de,
dave.hansen@...ux.intel.com, pgonda@...gle.com, seanjc@...gle.com,
pbonzini@...hat.com, francescolavra.fl@...il.com,
Alexey Makhalov <alexey.makhalov@...adcom.com>,
Juergen Gross <jgross@...e.com>,
Boris Ostrovsky <boris.ostrovsky@...cle.com>
Subject: Re: [PATCH v16 11/13] x86/tsc: Upgrade TSC clocksource rating for
guests
On Mon, Jan 06, 2025 at 06:16:31PM +0530, Nikunj A Dadhania wrote:
> Hypervisor platform setup (x86_hyper_init::init_platform) routines register
> their own PV clock sources (KVM, HyperV, and Xen) at different clock
> ratings, resulting in PV clocksource being selected even when a stable TSC
> clocksource is available. Upgrade the clock rating of the TSC early and
> regular clocksource to prefer TSC over PV clock sources when TSC is
> invariant, non-stop, and stable
>
> Cc: Alexey Makhalov <alexey.makhalov@...adcom.com>
> Cc: Juergen Gross <jgross@...e.com>
> Cc: Boris Ostrovsky <boris.ostrovsky@...cle.com>
> Suggested-by: Thomas Gleixner <tglx@...utronix.de>
> Signed-off-by: Nikunj A Dadhania <nikunj@....com>
> ---
> arch/x86/kernel/tsc.c | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
This needs to make it perfectly clear that it is about virt and not in
general:
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index e98b7e585c1c..3741d097d925 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -276,14 +276,16 @@ bool using_native_sched_clock(void)
/*
* Upgrade the clock rating for TSC early and regular clocksource when the
- * underlying platform provides non-stop, invariant, and stable TSC. TSC
+ * underlying guest is provided a non-stop, invariant, and stable TSC. TSC
* early/regular clocksource will be preferred over other PV clock sources.
*/
-static void __init upgrade_clock_rating(struct clocksource *tsc_early,
- struct clocksource *tsc)
+static void __init virt_upgrade_clock_rating(struct clocksource *tsc_early,
+ struct clocksource *tsc)
{
- if (cpu_feature_enabled(X86_FEATURE_HYPERVISOR) &&
- cpu_feature_enabled(X86_FEATURE_CONSTANT_TSC) &&
+ if (!cpu_feature_enabled(X86_FEATURE_HYPERVISOR))
+ return;
+
+ if (cpu_feature_enabled(X86_FEATURE_CONSTANT_TSC) &&
cpu_feature_enabled(X86_FEATURE_NONSTOP_TSC) &&
!tsc_unstable) {
tsc_early->rating = 449;
@@ -295,7 +297,7 @@ u64 sched_clock_noinstr(void) __attribute__((alias("native_sched_clock")));
bool using_native_sched_clock(void) { return true; }
-static void __init upgrade_clock_rating(struct clocksource *tsc_early, struct clocksource *tsc) { }
+static void __init virt_upgrade_clock_rating(struct clocksource *tsc_early, struct clocksource *tsc) { }
#endif
notrace u64 sched_clock(void)
@@ -1584,7 +1586,7 @@ void __init tsc_init(void)
if (tsc_clocksource_reliable || no_tsc_watchdog)
tsc_disable_clocksource_watchdog();
- upgrade_clock_rating(&clocksource_tsc_early, &clocksource_tsc);
+ virt_upgrade_clock_rating(&clocksource_tsc_early, &clocksource_tsc);
clocksource_register_khz(&clocksource_tsc_early, tsc_khz);
detect_art();
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
Powered by blists - more mailing lists