Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp59890ybf; Wed, 26 Feb 2020 08:48:43 -0800 (PST) X-Google-Smtp-Source: APXvYqzAKfLf5cjjIOAdbNsrDzKO/kfFcNLlUBb2lgNP5jJwLf+cA89LE/Yfx1G5cnczvC1W6mQ6 X-Received: by 2002:a05:6830:1f1c:: with SMTP id u28mr4065165otg.143.1582735723085; Wed, 26 Feb 2020 08:48:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582735723; cv=none; d=google.com; s=arc-20160816; b=neSw8e4+gNo1w4oTYm/dyt0n3k+R4O4i1s8pAi/NVOHCrfFZm+anvciP65EjRwf+Wq LbqK0FdqcKAt069uIEs9md4HvfJ1RTu6hE9uJESRm51KCG/ML3otTVsRqmGnqhLIKo6Z xzSbIaI5PRBCHUGcannZfwwk50uYZ48/wgMC4DR/E341uUM8LwcQRCXDeQQOY/rDBt7Z QdMhzcxhZ6CSdfv4vxkxIpY2x4HmxGdLvbw9Itr9F8W4g3K1mO3FVR6xrFCoFlsmcMDq siPOm/HEnmlfpY+5YMpHmxwy17EeIeNEmfWPugw+xsQBSO8XPI4QNtNh4cV/QZw356m5 z5Cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=sE1NdjxwrRYWFMPfmNxlgM+W5OTCkbL8wxbNxVCasR8=; b=fbgE0KodpXByIRZu/gUAjHT7Sa2s1/oCXAn1pJki9EIBuhHwbR2brKHaSGE+yBcaof lnTGnLlLCAEhCx5JqwyaWXRUJxQ+UnGEi+lfou+9yITWg9HYaRTO8P10NH8MxZpw1IFF 12+juGlueOK8+89tsfcddmI+a5cPIFvoIAHBEb1TjXV+mhXYl19oXSlqZZjSBsUlCBL8 +dVTc4K2sB1EXvNMB9kNxcJeZ/HWYrbHl/J0fh9voaDqAs+H3Z9x/+8QbHvlCkEy5ALo O17i0do5iejQTKN2StRAlMR7KawWkc6QIgRqFDQyMB35GPEyfTBZygLJjvTv/fC7tima O11w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JaZGoS9c; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q189si1383526oic.235.2020.02.26.08.48.30; Wed, 26 Feb 2020 08:48:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JaZGoS9c; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727069AbgBZQn3 (ORCPT + 99 others); Wed, 26 Feb 2020 11:43:29 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:32558 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726214AbgBZQn3 (ORCPT ); Wed, 26 Feb 2020 11:43:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582735407; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=sE1NdjxwrRYWFMPfmNxlgM+W5OTCkbL8wxbNxVCasR8=; b=JaZGoS9cQ8pjYWyQO34U4kUUsITvz4ozxaiodR9Nhon0KzBVqNWHdUfZGdKcPISDJOMHGc yMrzLubSiGOAn+hXmwR5shdoCKSXrW9t4n+wdfU1L5fdecP73Kt8BD7UMD4YuhqPbK6KCa m9hbA7HnH/Q/+vxO+Ue27xqIlOfCE6A= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-267-rWs9osVYPC2teGR0nCK1RQ-1; Wed, 26 Feb 2020 11:43:22 -0500 X-MC-Unique: rWs9osVYPC2teGR0nCK1RQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5DEC710937BA; Wed, 26 Feb 2020 16:43:19 +0000 (UTC) Received: from prarit.bos.redhat.com (prarit-guest.7a2m.lab.eng.bos.redhat.com [10.16.222.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id A93C15C102; Wed, 26 Feb 2020 16:43:16 +0000 (UTC) From: Prarit Bhargava To: linux-kernel@vger.kernel.org Cc: Prarit Bhargava , Patrick Geary , Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, Mauro Carvalho Chehab , Josh Poimboeuf , Andrew Morton , Pawan Gupta , Juergen Gross , "Rafael J. Wysocki" , Viresh Kumar , Daniel Drake , Michael Zhivich , Peter Zijlstra , 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 Message-Id: <20200226164308.14468-1-prarit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 hav= e 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=3Dno_cpuid_calibration,no_msr_calibration,reliable Link: https://lore.kernel.org/lkml/fdf96605-a4a0-049b-51c9-1e68cc2a9b93@s= upermicro.com/#r Co-developed-by: Patrick Geary Signed-off-by: Patrick Geary Signed-off-by: Prarit Bhargava Cc: Jonathan Corbet Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: "H. Peter Anvin" Cc: x86@kernel.org Cc: Mauro Carvalho Chehab Cc: Josh Poimboeuf Cc: Andrew Morton Cc: Pawan Gupta Cc: Juergen Gross Cc: "Rafael J. Wysocki" Cc: Viresh Kumar Cc: Daniel Drake Cc: Michael Zhivich Cc: Peter Zijlstra 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/Documentat= ion/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. =20 - tsc=3D Disable clocksource stability checks for TSC. + tsc=3Doption[,option...] Various TSC options. Format: [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. =20 tsx=3D [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); =20 int tsc_clocksource_reliable; +/* + * TSC calibration sequence disablement + */ +int calibrate_cpuid_khz_enabled =3D 1; +int calibrate_msr_enabled =3D 1; =20 static u32 art_to_tsc_numerator; static u32 art_to_tsc_denominator; @@ -287,14 +292,30 @@ static int no_tsc_watchdog; =20 static int __init tsc_setup(char *str) { - if (!strcmp(str, "reliable")) - tsc_clocksource_reliable =3D 1; - if (!strncmp(str, "noirqtime", 9)) - no_sched_irq_time =3D 1; - if (!strcmp(str, "unstable")) - mark_tsc_unstable("boot parameter"); - if (!strcmp(str, "nowatchdog")) - no_tsc_watchdog =3D 1; + while (str) { + char *k =3D strchr(str, ','); + + if (k) + *k++ =3D 0; + + if (!strcmp(str, "reliable")) + tsc_clocksource_reliable =3D 1; + if (!strcmp(str, "noirqtime")) + no_sched_irq_time =3D 1; + if (!strcmp(str, "unstable")) + mark_tsc_unstable("boot parameter"); + if (!strcmp(str, "nowatchdog")) + no_tsc_watchdog =3D 1; + if (!strcmp(str, "no_cpuid_calibration")) { + calibrate_cpuid_khz_enabled =3D 0; + pr_info("CPUID khz calibration disabled\n"); + } + if (!strcmp(str, "no_msr_calibration")) { + calibrate_cpuid_khz_enabled =3D 0; + pr_info("msr calibration disabled\n"); + } + str =3D k; + } return 1; } =20 @@ -860,9 +881,12 @@ static unsigned long pit_hpet_ptimer_calibrate_cpu(v= oid) */ unsigned long native_calibrate_cpu_early(void) { - unsigned long flags, fast_calibrate =3D cpu_khz_from_cpuid(); + unsigned long flags, fast_calibrate =3D 0; + + if (calibrate_cpuid_khz_enabled) + fast_calibrate =3D cpu_khz_from_cpuid(); =20 - if (!fast_calibrate) + if (!fast_calibrate && calibrate_msr_enabled) fast_calibrate =3D cpu_khz_from_msr(); if (!fast_calibrate) { local_irq_save(flags); --=20 2.21.1