Linux EDAC development
 help / color / mirror / Atom feed
From: Qiuxu Zhuo <qiuxu.zhuo@intel.com>
To: bp@alien8.de, tony.luck@intel.com
Cc: tglx@linutronix.de, dave.hansen@linux.intel.com,
	mingo@redhat.com, hpa@zytor.com, yazen.ghannam@amd.com,
	sohil.mehta@intel.com, nik.borisov@suse.com, x86@kernel.org,
	linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org,
	qiuxu.zhuo@intel.com
Subject: [PATCH v4 4/8] x86/mce: Break up __mcheck_cpu_apply_quirks()
Date: Mon, 11 Nov 2024 14:04:24 +0800	[thread overview]
Message-ID: <20241111060428.44258-5-qiuxu.zhuo@intel.com> (raw)
In-Reply-To: <20241111060428.44258-1-qiuxu.zhuo@intel.com>

From: Tony Luck <tony.luck@intel.com>

Split each vendor specific part into its own helper function.

Tested-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com>
Signed-off-by: Tony Luck <tony.luck@intel.com>
Signed-off-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com>
---
Changes in v4:
  - Add necessary blank lines in apply_quirks_amd() (Yazen).
  - Use 'mca_cfg' instead of 'cfg' in apply_quirks_*(). (Yazen).

Changes in v3:
  - New patch.

 arch/x86/kernel/cpu/mce/core.c | 192 ++++++++++++++++++---------------
 1 file changed, 104 insertions(+), 88 deletions(-)

diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c
index ce6fe5e20805..3855ec2ed0e0 100644
--- a/arch/x86/kernel/cpu/mce/core.c
+++ b/arch/x86/kernel/cpu/mce/core.c
@@ -1910,101 +1910,117 @@ static void __mcheck_cpu_check_banks(void)
 	}
 }
 
+static void apply_quirks_amd(struct cpuinfo_x86 *c)
+{
+	struct mce_bank *mce_banks = this_cpu_ptr(mce_banks_array);
+
+	/* This should be disabled by the BIOS, but isn't always */
+	if (c->x86 == 15 && this_cpu_read(mce_num_banks) > 4) {
+		/*
+		 * disable GART TBL walk error reporting, which
+		 * trips off incorrectly with the IOMMU & 3ware
+		 * & Cerberus:
+		 */
+		clear_bit(10, (unsigned long *)&mce_banks[4].ctl);
+	}
+
+	if (c->x86 < 0x11 && mca_cfg.bootlog < 0) {
+		/*
+		 * Lots of broken BIOS around that don't clear them
+		 * by default and leave crap in there. Don't log:
+		 */
+		mca_cfg.bootlog = 0;
+	}
+
+	/*
+	 * Various K7s with broken bank 0 around. Always disable
+	 * by default.
+	 */
+	if (c->x86 == 6 && this_cpu_read(mce_num_banks) > 0)
+		mce_banks[0].ctl = 0;
+
+	/*
+	 * overflow_recov is supported for F15h Models 00h-0fh
+	 * even though we don't have a CPUID bit for it.
+	 */
+	if (c->x86 == 0x15 && c->x86_model <= 0xf)
+		mce_flags.overflow_recov = 1;
+
+	if (c->x86 >= 0x17 && c->x86 <= 0x1A)
+		mce_flags.zen_ifu_quirk = 1;
+}
+
+static void apply_quirks_intel(struct cpuinfo_x86 *c)
+{
+	struct mce_bank *mce_banks = this_cpu_ptr(mce_banks_array);
+
+	/*
+	 * SDM documents that on family 6 bank 0 should not be written
+	 * because it aliases to another special BIOS controlled
+	 * register.
+	 * But it's not aliased anymore on model 0x1a+
+	 * Don't ignore bank 0 completely because there could be a
+	 * valid event later, merely don't write CTL0.
+	 */
+	if (c->x86 == 6 && c->x86_model < 0x1A && this_cpu_read(mce_num_banks) > 0)
+		mce_banks[0].init = false;
+
+	/*
+	 * All newer Intel systems support MCE broadcasting. Enable
+	 * synchronization with a one second timeout.
+	 */
+	if ((c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xe)) &&
+	    mca_cfg.monarch_timeout < 0)
+		mca_cfg.monarch_timeout = USEC_PER_SEC;
+
+	/*
+	 * There are also broken BIOSes on some Pentium M and
+	 * earlier systems:
+	 */
+	if (c->x86 == 6 && c->x86_model <= 13 && mca_cfg.bootlog < 0)
+		mca_cfg.bootlog = 0;
+
+	if (c->x86_vfm == INTEL_SANDYBRIDGE_X)
+		mce_flags.snb_ifu_quirk = 1;
+
+	/*
+	 * Skylake, Cascacde Lake and Cooper Lake require a quirk on
+	 * rep movs.
+	 */
+	if (c->x86_vfm == INTEL_SKYLAKE_X)
+		mce_flags.skx_repmov_quirk = 1;
+}
+
+static void apply_quirks_zhaoxin(struct cpuinfo_x86 *c)
+{
+	/*
+	 * All newer Zhaoxin CPUs support MCE broadcasting. Enable
+	 * synchronization with a one second timeout.
+	 */
+	if (c->x86 > 6 || (c->x86_model == 0x19 || c->x86_model == 0x1f)) {
+		if (mca_cfg.monarch_timeout < 0)
+			mca_cfg.monarch_timeout = USEC_PER_SEC;
+	}
+}
+
 /* Add per CPU specific workarounds here */
 static bool __mcheck_cpu_apply_quirks(struct cpuinfo_x86 *c)
 {
-	struct mce_bank *mce_banks = this_cpu_ptr(mce_banks_array);
 	struct mca_config *cfg = &mca_cfg;
 
-	if (c->x86_vendor == X86_VENDOR_UNKNOWN) {
+	switch (c->x86_vendor) {
+	case X86_VENDOR_UNKNOWN:
 		pr_info("unknown CPU type - not enabling MCE support\n");
 		return false;
-	}
-
-	/* This should be disabled by the BIOS, but isn't always */
-	if (c->x86_vendor == X86_VENDOR_AMD) {
-		if (c->x86 == 15 && this_cpu_read(mce_num_banks) > 4) {
-			/*
-			 * disable GART TBL walk error reporting, which
-			 * trips off incorrectly with the IOMMU & 3ware
-			 * & Cerberus:
-			 */
-			clear_bit(10, (unsigned long *)&mce_banks[4].ctl);
-		}
-		if (c->x86 < 0x11 && cfg->bootlog < 0) {
-			/*
-			 * Lots of broken BIOS around that don't clear them
-			 * by default and leave crap in there. Don't log:
-			 */
-			cfg->bootlog = 0;
-		}
-		/*
-		 * Various K7s with broken bank 0 around. Always disable
-		 * by default.
-		 */
-		if (c->x86 == 6 && this_cpu_read(mce_num_banks) > 0)
-			mce_banks[0].ctl = 0;
-
-		/*
-		 * overflow_recov is supported for F15h Models 00h-0fh
-		 * even though we don't have a CPUID bit for it.
-		 */
-		if (c->x86 == 0x15 && c->x86_model <= 0xf)
-			mce_flags.overflow_recov = 1;
-
-		if (c->x86 >= 0x17 && c->x86 <= 0x1A)
-			mce_flags.zen_ifu_quirk = 1;
-
-	}
-
-	if (c->x86_vendor == X86_VENDOR_INTEL) {
-		/*
-		 * SDM documents that on family 6 bank 0 should not be written
-		 * because it aliases to another special BIOS controlled
-		 * register.
-		 * But it's not aliased anymore on model 0x1a+
-		 * Don't ignore bank 0 completely because there could be a
-		 * valid event later, merely don't write CTL0.
-		 */
-
-		if (c->x86 == 6 && c->x86_model < 0x1A && this_cpu_read(mce_num_banks) > 0)
-			mce_banks[0].init = false;
-
-		/*
-		 * All newer Intel systems support MCE broadcasting. Enable
-		 * synchronization with a one second timeout.
-		 */
-		if ((c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xe)) &&
-			cfg->monarch_timeout < 0)
-			cfg->monarch_timeout = USEC_PER_SEC;
-
-		/*
-		 * There are also broken BIOSes on some Pentium M and
-		 * earlier systems:
-		 */
-		if (c->x86 == 6 && c->x86_model <= 13 && cfg->bootlog < 0)
-			cfg->bootlog = 0;
-
-		if (c->x86_vfm == INTEL_SANDYBRIDGE_X)
-			mce_flags.snb_ifu_quirk = 1;
-
-		/*
-		 * Skylake, Cascacde Lake and Cooper Lake require a quirk on
-		 * rep movs.
-		 */
-		if (c->x86_vfm == INTEL_SKYLAKE_X)
-			mce_flags.skx_repmov_quirk = 1;
-	}
-
-	if (c->x86_vendor == X86_VENDOR_ZHAOXIN) {
-		/*
-		 * All newer Zhaoxin CPUs support MCE broadcasting. Enable
-		 * synchronization with a one second timeout.
-		 */
-		if (c->x86 > 6 || (c->x86_model == 0x19 || c->x86_model == 0x1f)) {
-			if (cfg->monarch_timeout < 0)
-				cfg->monarch_timeout = USEC_PER_SEC;
-		}
+	case X86_VENDOR_AMD:
+		apply_quirks_amd(c);
+		break;
+	case X86_VENDOR_INTEL:
+		apply_quirks_intel(c);
+		break;
+	case X86_VENDOR_ZHAOXIN:
+		apply_quirks_zhaoxin(c);
+		break;
 	}
 
 	if (cfg->monarch_timeout < 0)
-- 
2.17.1


  parent reply	other threads:[~2024-11-11  6:33 UTC|newest]

Thread overview: 132+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-10 15:31 [PATCH 00/10] Clean up some x86/mce code Qiuxu Zhuo
2024-10-10 15:31 ` [PATCH 01/10] x86/mce/dev-mcelog: Use xchg() to get and clear the flags Qiuxu Zhuo
2024-10-10 15:31 ` [PATCH 02/10] x86/mce/intel: Use MCG_BANKCNT_MASK instead of 0xff Qiuxu Zhuo
2024-10-10 15:31 ` [PATCH 03/10] x86/mce: Make several functions return bool Qiuxu Zhuo
2024-10-10 15:31 ` [PATCH 04/10] x86/mce/threshold: Remove the redundant this_cpu_dec_return() Qiuxu Zhuo
2024-10-10 15:31 ` [PATCH 05/10] x86/mce/genpool: Make mce_gen_pool_create() return explicit error codes Qiuxu Zhuo
2024-11-02 14:31   ` Thomas Gleixner
2024-11-03  0:42     ` Zhuo, Qiuxu
2024-10-10 15:31 ` [PATCH 06/10] x86/mce: Convert multiple if () statements into a switch() statement Qiuxu Zhuo
2024-10-10 15:31 ` [PATCH 07/10] x86/mce: Remove the unnecessary {} Qiuxu Zhuo
2024-10-10 15:32 ` [PATCH 08/10] x86/mce: Remove the redundant zeroing assignments Qiuxu Zhuo
2024-10-10 15:32 ` [PATCH 09/10] x86/mce/amd: Remove unnecessary NULL pointer initializations Qiuxu Zhuo
2024-10-11 20:55   ` Luck, Tony
2024-10-10 15:32 ` [PATCH 10/10] x86/mce: Fix typos in comments Qiuxu Zhuo
2024-10-11 20:57 ` [PATCH 00/10] Clean up some x86/mce code Luck, Tony
2024-10-16 12:30 ` [PATCH v2 00/10] x86/mce: " Qiuxu Zhuo
2024-10-16 12:30   ` [PATCH v2 01/10] x86/mce/dev-mcelog: Use xchg() to get and clear the flags Qiuxu Zhuo
2024-10-16 12:30   ` [PATCH v2 02/10] x86/mce/intel: Use MCG_BANKCNT_MASK instead of 0xff Qiuxu Zhuo
2024-10-16 12:30   ` [PATCH v2 03/10] x86/mce: Make several functions return bool Qiuxu Zhuo
2024-10-18 19:02     ` Sohil Mehta
2024-10-19  3:00       ` Zhuo, Qiuxu
2024-10-16 12:30   ` [PATCH v2 04/10] x86/mce/threshold: Remove the redundant this_cpu_dec_return() Qiuxu Zhuo
2024-10-16 12:30   ` [PATCH v2 05/10] x86/mce/genpool: Make mce_gen_pool_create() return explicit error codes Qiuxu Zhuo
2024-10-18 19:20     ` Sohil Mehta
2024-10-19  3:29       ` Zhuo, Qiuxu
2024-10-16 12:30   ` [PATCH v2 06/10] x86/mce: Convert multiple if () statements into a switch() statement Qiuxu Zhuo
2024-10-18 19:44     ` Sohil Mehta
2024-10-18 20:14       ` Tony Luck
2024-10-19  0:04         ` Sohil Mehta
2024-10-19  5:46           ` Zhuo, Qiuxu
2024-10-21 16:06             ` Luck, Tony
2024-10-21 16:31               ` Dave Hansen
2024-10-23  8:20                 ` Zhuo, Qiuxu
2024-10-24 13:05                   ` Zhuo, Qiuxu
2024-10-24 16:42                     ` Luck, Tony
2024-10-24 21:31                       ` Sohil Mehta
2024-10-24 21:41                         ` Luck, Tony
2024-10-24 22:18                         ` Dave Hansen
2024-10-21 17:38               ` Sohil Mehta
2024-10-21 17:51                 ` Luck, Tony
2024-10-21 18:26                   ` Sohil Mehta
2024-10-21 18:40                     ` Luck, Tony
2024-10-21 22:57                       ` Sohil Mehta
2024-10-21 23:31                         ` Luck, Tony
2024-10-22  0:07                           ` Sohil Mehta
2024-10-22  0:17                         ` Dave Hansen
2024-10-22 18:12                           ` Sohil Mehta
2024-10-23  2:08                 ` Zhuo, Qiuxu
2024-10-23  6:48                   ` Sohil Mehta
2024-10-23  7:57                     ` Zhuo, Qiuxu
2024-10-23  6:47             ` Sohil Mehta
2024-10-23  7:43               ` Zhuo, Qiuxu
2024-10-19  4:39         ` Zhuo, Qiuxu
2024-10-16 12:30   ` [PATCH v2 07/10] x86/mce: Remove the unnecessary {} Qiuxu Zhuo
2024-10-16 12:30   ` [PATCH v2 08/10] x86/mce: Remove the redundant zeroing assignments Qiuxu Zhuo
2024-10-18 20:25     ` Sohil Mehta
2024-10-19  7:37       ` Zhuo, Qiuxu
2024-10-19  7:40         ` H. Peter Anvin
2024-10-19  8:30           ` Zhuo, Qiuxu
2024-10-20  0:25             ` H. Peter Anvin
2024-10-21  6:29               ` Zhuo, Qiuxu
2024-10-16 12:30   ` [PATCH v2 09/10] x86/mce/amd: Remove unnecessary NULL pointer initializations Qiuxu Zhuo
2024-10-18 20:34     ` Sohil Mehta
2024-10-19  7:40       ` Zhuo, Qiuxu
2024-10-16 12:30   ` [PATCH v2 10/10] x86/mce: Fix typos in comments Qiuxu Zhuo
2024-10-18 20:36     ` Sohil Mehta
2024-10-19  8:02       ` Zhuo, Qiuxu
2024-10-17 15:30   ` [PATCH v2 00/10] x86/mce: Clean up some x86/mce code Nikolay Borisov
2024-10-18 20:40   ` Sohil Mehta
2024-10-25  2:45   ` [PATCH v3 " Qiuxu Zhuo
2024-10-25  2:45     ` [PATCH v3 01/10] x86/mce/dev-mcelog: Use xchg() to get and clear the flags Qiuxu Zhuo
2024-10-25  2:45     ` [PATCH v3 02/10] x86/mce/intel: Use MCG_BANKCNT_MASK instead of 0xff Qiuxu Zhuo
2024-10-25  2:45     ` [PATCH v3 03/10] x86/mce: Make several functions return bool and rename a function Qiuxu Zhuo
2024-10-28 13:06       ` Borislav Petkov
2024-10-29  3:32         ` Zhuo, Qiuxu
2024-10-30 10:24           ` Borislav Petkov
2024-10-31  3:23             ` Zhuo, Qiuxu
2024-10-25  2:45     ` [PATCH v3 04/10] x86/mce/threshold: Remove the redundant this_cpu_dec_return() Qiuxu Zhuo
2024-10-25  2:45     ` [PATCH v3 05/10] x86/mce/genpool: Make mce_gen_pool_create() return explicit error codes Qiuxu Zhuo
2024-11-02 13:13       ` Borislav Petkov
2024-10-25  2:45     ` [PATCH v3 06/10] x86/mce: Break up __mcheck_cpu_apply_quirks() Qiuxu Zhuo
2024-10-29 21:39       ` Yazen Ghannam
2024-10-30  1:39         ` Zhuo, Qiuxu
2024-10-30 14:16           ` Yazen Ghannam
2024-10-31  5:18             ` Zhuo, Qiuxu
2024-10-25  2:45     ` [PATCH v3 07/10] x86/mce: Convert family/model mixed checks to VFM-based checks Qiuxu Zhuo
2024-10-25  2:46     ` [PATCH v3 08/10] x86/mce: Remove the unnecessary {} Qiuxu Zhuo
2024-10-25  2:46     ` [PATCH v3 09/10] x86/mce/amd: Remove unnecessary NULL pointer initializations Qiuxu Zhuo
2024-10-25  2:46     ` [PATCH v3 10/10] x86/mce: Fix typos Qiuxu Zhuo
2024-11-11  6:04     ` [PATCH v4 0/8] x86/mce: Clean up some x86/mce code Qiuxu Zhuo
2024-11-11  6:04       ` [PATCH v4 1/8] x86/mce: Make several functions return bool Qiuxu Zhuo
2024-11-11  6:04       ` [PATCH v4 2/8] x86/mce/threshold: Remove the redundant this_cpu_dec_return() Qiuxu Zhuo
2024-11-11  6:04       ` [PATCH v4 3/8] x86/mce: Make four functions return bool Qiuxu Zhuo
2024-11-12  2:30         ` Sohil Mehta
2024-11-11  6:04       ` Qiuxu Zhuo [this message]
2024-11-12  2:31         ` [PATCH v4 4/8] x86/mce: Break up __mcheck_cpu_apply_quirks() Sohil Mehta
2024-11-11  6:04       ` [PATCH v4 5/8] x86/mce: Convert family/model mixed checks to VFM-based checks Qiuxu Zhuo
2024-11-12  2:31         ` Sohil Mehta
2024-11-12 15:27         ` Yazen Ghannam
2024-11-13 12:10           ` Zhuo, Qiuxu
2024-11-13 14:25             ` Yazen Ghannam
2024-11-14  1:11               ` Zhuo, Qiuxu
2024-11-11  6:04       ` [PATCH v4 6/8] x86/mce: Remove the unnecessary {} Qiuxu Zhuo
2024-11-12 15:43         ` Yazen Ghannam
2024-11-13 13:32           ` Zhuo, Qiuxu
2024-11-13 14:26             ` Yazen Ghannam
2024-11-13 16:11             ` Borislav Petkov
2024-11-14  1:23               ` Zhuo, Qiuxu
2024-11-11  6:04       ` [PATCH v4 7/8] x86/mce/amd: Remove unnecessary NULL pointer initializations Qiuxu Zhuo
2024-11-12 15:48         ` Yazen Ghannam
2024-11-11  6:04       ` [PATCH v4 8/8] x86/mce: Fix typos Qiuxu Zhuo
2024-11-12  2:36         ` Sohil Mehta
2024-11-12 15:38         ` Yazen Ghannam
2024-11-12 22:35           ` Sohil Mehta
2024-11-13 14:31             ` Yazen Ghannam
2024-11-14  1:20               ` Zhuo, Qiuxu
2024-11-13 14:48           ` Zhuo, Qiuxu
2024-12-12 14:00       ` [PATCH v5 0/7] Clean up some x86/mce code Qiuxu Zhuo
2024-12-12 14:00         ` [PATCH v5 1/7] x86/mce: Make several functions return bool Qiuxu Zhuo
2024-12-18 15:20           ` Yazen Ghannam
2024-12-19 15:19             ` Zhuo, Qiuxu
2024-12-12 14:00         ` [PATCH v5 2/7] x86/mce/threshold: Remove the redundant this_cpu_dec_return() Qiuxu Zhuo
2024-12-18 15:36           ` Yazen Ghannam
2024-12-12 14:00         ` [PATCH v5 3/7] x86/mce: Make four functions return bool Qiuxu Zhuo
2024-12-18 15:48           ` Yazen Ghannam
2024-12-12 14:01         ` [PATCH v5 4/7] x86/mce: Break up __mcheck_cpu_apply_quirks() Qiuxu Zhuo
2024-12-18 15:54           ` Yazen Ghannam
2024-12-12 14:01         ` [PATCH v5 5/7] x86/mce: Convert family/model mixed checks to VFM-based checks Qiuxu Zhuo
2024-12-12 14:01         ` [PATCH v5 6/7] x86/mce: Remove the redundant mce_hygon_feature_init() Qiuxu Zhuo
2024-12-12 18:08           ` Sohil Mehta
2024-12-18 16:02           ` Yazen Ghannam
2024-12-12 14:01         ` [PATCH v5 7/7] x86/mce/amd: Remove unnecessary NULL pointer initializations Qiuxu Zhuo

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=20241111060428.44258-5-qiuxu.zhuo@intel.com \
    --to=qiuxu.zhuo@intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-edac@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nik.borisov@suse.com \
    --cc=sohil.mehta@intel.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=x86@kernel.org \
    --cc=yazen.ghannam@amd.com \
    /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