linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Prarit Bhargava <prarit@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Prarit Bhargava <prarit@redhat.com>,
	Patrick Geary <patrickg@supermicro.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	"H. Peter Anvin" <hpa@zytor.com>,
	x86@kernel.org,
	Mauro Carvalho Chehab <mchehab+samsung@kernel.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Pawan Gupta <pawan.kumar.gupta@linux.intel.com>,
	Juergen Gross <jgross@suse.com>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	Daniel Drake <drake@endlessm.com>,
	Michael Zhivich <mzhivich@akamai.com>,
	Peter Zijlstra <peterz@infradead.org>,
	linux-doc@vger.kernel.org
Subject: [PATCH] x86/tsc: Add kernel options to disable CPUID and MSR calibrations
Date: Wed, 26 Feb 2020 11:43:08 -0500	[thread overview]
Message-ID: <20200226164308.14468-1-prarit@redhat.com> (raw)

I have had to debug a few unstable x86 systems that required me to block
the CPUID and MSR calibrations and only use the PIT calibration.  After
blocking the calibrations I was able to debug and find bugs in firmware
that were eventually fixed and resulted in stable systems.

Patrick Geary also posted a similar patch (see link below) that would have
allowed him to boot overclocked CPUs by skipping the CPUID calibration
which resulted in unstable boots due to timing issues.

Add kernel options to disable the CPUID and MSR calibrations.

Also allow for comma-separated TSC options, for example,

	tsc=no_cpuid_calibration,no_msr_calibration,reliable

Link: https://lore.kernel.org/lkml/fdf96605-a4a0-049b-51c9-1e68cc2a9b93@supermicro.com/#r
Co-developed-by: Patrick Geary <patrickg@supermicro.com>
Signed-off-by: Patrick Geary <patrickg@supermicro.com>
Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Cc: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Daniel Drake <drake@endlessm.com>
Cc: Michael Zhivich <mzhivich@akamai.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linux-doc@vger.kernel.org
---
 .../admin-guide/kernel-parameters.txt         |  8 +++-
 arch/x86/kernel/tsc.c                         | 44 ++++++++++++++-----
 2 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index dbc22d684627..0316aadfff08 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -4942,7 +4942,7 @@
 			See Documentation/admin-guide/mm/transhuge.rst
 			for more details.
 
-	tsc=		Disable clocksource stability checks for TSC.
+	tsc=option[,option...]	Various TSC options.
 			Format: <string>
 			[x86] reliable: mark tsc clocksource as reliable, this
 			disables clocksource verification at runtime, as well
@@ -4960,6 +4960,12 @@
 			in situations with strict latency requirements (where
 			interruptions from clocksource watchdog are not
 			acceptable).
+			[x86] no_cpuid_calibration: Disable the CPUID TSC
+			calibration.  Used in situations where the CPUID
+			TSC khz does not match the actual CPU TSC khz
+			[x86] no_msr_calibration: Disable the MSR TSC
+			calibration.  Used in situations where the MSR
+			TSC khz does not match the actual CPU TSC khz.
 
 	tsx=		[X86] Control Transactional Synchronization
 			Extensions (TSX) feature in Intel processors that
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 7e322e2daaf5..c949cb833d05 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -45,6 +45,11 @@ static int __read_mostly tsc_unstable;
 static DEFINE_STATIC_KEY_FALSE(__use_tsc);
 
 int tsc_clocksource_reliable;
+/*
+ * TSC calibration sequence disablement
+ */
+int calibrate_cpuid_khz_enabled = 1;
+int calibrate_msr_enabled = 1;
 
 static u32 art_to_tsc_numerator;
 static u32 art_to_tsc_denominator;
@@ -287,14 +292,30 @@ static int no_tsc_watchdog;
 
 static int __init tsc_setup(char *str)
 {
-	if (!strcmp(str, "reliable"))
-		tsc_clocksource_reliable = 1;
-	if (!strncmp(str, "noirqtime", 9))
-		no_sched_irq_time = 1;
-	if (!strcmp(str, "unstable"))
-		mark_tsc_unstable("boot parameter");
-	if (!strcmp(str, "nowatchdog"))
-		no_tsc_watchdog = 1;
+	while (str) {
+		char *k = strchr(str, ',');
+
+		if (k)
+			*k++ = 0;
+
+		if (!strcmp(str, "reliable"))
+			tsc_clocksource_reliable = 1;
+		if (!strcmp(str, "noirqtime"))
+			no_sched_irq_time = 1;
+		if (!strcmp(str, "unstable"))
+			mark_tsc_unstable("boot parameter");
+		if (!strcmp(str, "nowatchdog"))
+			no_tsc_watchdog = 1;
+		if (!strcmp(str, "no_cpuid_calibration")) {
+			calibrate_cpuid_khz_enabled = 0;
+			pr_info("CPUID khz calibration disabled\n");
+		}
+		if (!strcmp(str, "no_msr_calibration")) {
+			calibrate_cpuid_khz_enabled = 0;
+			pr_info("msr calibration disabled\n");
+		}
+		str = k;
+	}
 	return 1;
 }
 
@@ -860,9 +881,12 @@ static unsigned long pit_hpet_ptimer_calibrate_cpu(void)
  */
 unsigned long native_calibrate_cpu_early(void)
 {
-	unsigned long flags, fast_calibrate = cpu_khz_from_cpuid();
+	unsigned long flags, fast_calibrate = 0;
+
+	if (calibrate_cpuid_khz_enabled)
+		fast_calibrate = cpu_khz_from_cpuid();
 
-	if (!fast_calibrate)
+	if (!fast_calibrate && calibrate_msr_enabled)
 		fast_calibrate = cpu_khz_from_msr();
 	if (!fast_calibrate) {
 		local_irq_save(flags);
-- 
2.21.1


             reply	other threads:[~2020-02-26 16:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-26 16:43 Prarit Bhargava [this message]
2020-02-26 16:54 ` [PATCH] x86/tsc: Add kernel options to disable CPUID and MSR calibrations Peter Zijlstra
2020-02-26 23:27   ` Thomas Gleixner
2020-02-27 12:58     ` Prarit Bhargava

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200226164308.14468-1-prarit@redhat.com \
    --to=prarit@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=bp@alien8.de \
    --cc=corbet@lwn.net \
    --cc=drake@endlessm.com \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab+samsung@kernel.org \
    --cc=mingo@redhat.com \
    --cc=mzhivich@akamai.com \
    --cc=patrickg@supermicro.com \
    --cc=pawan.kumar.gupta@linux.intel.com \
    --cc=peterz@infradead.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=tglx@linutronix.de \
    --cc=viresh.kumar@linaro.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).