lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 26 Feb 2020 11:43:08 -0500
From:   Prarit Bhargava <prarit@...hat.com>
To:     linux-kernel@...r.kernel.org
Cc:     Prarit Bhargava <prarit@...hat.com>,
        Patrick Geary <patrickg@...ermicro.com>,
        Jonathan Corbet <corbet@....net>,
        Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
        "H. Peter Anvin" <hpa@...or.com>, x86@...nel.org,
        Mauro Carvalho Chehab <mchehab+samsung@...nel.org>,
        Josh Poimboeuf <jpoimboe@...hat.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Pawan Gupta <pawan.kumar.gupta@...ux.intel.com>,
        Juergen Gross <jgross@...e.com>,
        "Rafael J. Wysocki" <rafael.j.wysocki@...el.com>,
        Viresh Kumar <viresh.kumar@...aro.org>,
        Daniel Drake <drake@...lessm.com>,
        Michael Zhivich <mzhivich@...mai.com>,
        Peter Zijlstra <peterz@...radead.org>,
        linux-doc@...r.kernel.org
Subject: [PATCH] x86/tsc: Add kernel options to disable CPUID and MSR calibrations

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@...ermicro.com>
Signed-off-by: Patrick Geary <patrickg@...ermicro.com>
Signed-off-by: Prarit Bhargava <prarit@...hat.com>
Cc: Jonathan Corbet <corbet@....net>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Ingo Molnar <mingo@...hat.com>
Cc: Borislav Petkov <bp@...en8.de>
Cc: "H. Peter Anvin" <hpa@...or.com>
Cc: x86@...nel.org
Cc: Mauro Carvalho Chehab <mchehab+samsung@...nel.org>
Cc: Josh Poimboeuf <jpoimboe@...hat.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: Pawan Gupta <pawan.kumar.gupta@...ux.intel.com>
Cc: Juergen Gross <jgross@...e.com>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@...el.com>
Cc: Viresh Kumar <viresh.kumar@...aro.org>
Cc: Daniel Drake <drake@...lessm.com>
Cc: Michael Zhivich <mzhivich@...mai.com>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: linux-doc@...r.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ