From: Tony W Wang-oc <TonyWWang-oc@zhaoxin.com>
To: <tglx@linutronix.de>, <mingo@redhat.com>, <bp@alien8.de>,
<dave.hansen@linux.intel.com>, <x86@kernel.org>, <hpa@zytor.com>,
<tony.luck@intel.com>, <linux-kernel@vger.kernel.org>,
<linux-edac@vger.kernel.org>, <qiuxu.zhuo@intel.com>
Cc: <CobeChen@zhaoxin.com>, <TimGuo@zhaoxin.com>,
<LeoLiu-oc@zhaoxin.com>, Lyle Li <LyleLi@zhaoxin.com>
Subject: [PATCH v5 4/4] x86/mce: Add CMCI storm switching support for Zhaoxin
Date: Mon, 14 Oct 2024 15:53:18 +0800 [thread overview]
Message-ID: <20241014075318.1936-5-TonyWWang-oc@zhaoxin.com> (raw)
In-Reply-To: <20241014075318.1936-1-TonyWWang-oc@zhaoxin.com>
From: Lyle Li <LyleLi@zhaoxin.com>
Zhaoxin CPUs support CMCI which is compatible with Intel, but
their UCR errors are not reported through CMCI like Intel's. To
be compatible with intel's CMCI code, add Zhaoxin's specific
CMCI storm toggle.
Signed-off-by: Lyle Li <LyleLi@zhaoxin.com>
Signed-off-by: Tony W Wang-oc <TonyWWang-oc@zhaoxin.com>
Reviewed-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com>
---
arch/x86/kernel/cpu/mce/intel.c | 5 ++---
arch/x86/kernel/cpu/mce/internal.h | 7 +++++++
arch/x86/kernel/cpu/mce/threshold.c | 4 ++++
arch/x86/kernel/cpu/mce/zhaoxin.c | 18 ++++++++++++++++++
4 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kernel/cpu/mce/intel.c b/arch/x86/kernel/cpu/mce/intel.c
index b7e67f4f7edd..aa75e28486c3 100644
--- a/arch/x86/kernel/cpu/mce/intel.c
+++ b/arch/x86/kernel/cpu/mce/intel.c
@@ -45,7 +45,7 @@ static DEFINE_PER_CPU(mce_banks_t, mce_banks_owned);
* cmci_discover_lock protects against parallel discovery attempts
* which could race against each other.
*/
-static DEFINE_RAW_SPINLOCK(cmci_discover_lock);
+DEFINE_RAW_SPINLOCK(cmci_discover_lock);
/*
* On systems that do support CMCI but it's disabled, polling for MCEs can
@@ -61,7 +61,7 @@ static DEFINE_SPINLOCK(cmci_poll_lock);
* MCi_CTL2 threshold for each bank when there is no storm.
* Default value for each bank may have been set by BIOS.
*/
-static u16 cmci_threshold[MAX_NR_BANKS];
+u16 cmci_threshold[MAX_NR_BANKS];
/*
* High threshold to limit CMCI rate during storms. Max supported is
@@ -73,7 +73,6 @@ static u16 cmci_threshold[MAX_NR_BANKS];
* to corrected errors, so keeping CMCI enabled means that uncorrected
* errors will still be processed in a timely fashion.
*/
-#define CMCI_STORM_THRESHOLD 32749
static int cmci_supported(int *banks)
{
diff --git a/arch/x86/kernel/cpu/mce/internal.h b/arch/x86/kernel/cpu/mce/internal.h
index fb9d8b5b3b75..69377664bacf 100644
--- a/arch/x86/kernel/cpu/mce/internal.h
+++ b/arch/x86/kernel/cpu/mce/internal.h
@@ -6,6 +6,8 @@
#define pr_fmt(fmt) "mce: " fmt
#include <linux/device.h>
+#include <linux/spinlock.h>
+
#include <asm/mce.h>
enum severity_level {
@@ -336,11 +338,16 @@ static __always_inline u32 mca_msr_reg(int bank, enum mca_msr reg)
}
extern void (*mc_poll_banks)(void);
+#define CMCI_STORM_THRESHOLD 32749
+extern raw_spinlock_t cmci_discover_lock;
+extern u16 cmci_threshold[MAX_NR_BANKS];
#ifdef CONFIG_X86_MCE_ZHAOXIN
void mce_zhaoxin_feature_init(struct cpuinfo_x86 *c);
void mce_zhaoxin_feature_clear(struct cpuinfo_x86 *c);
+void mce_zhaoxin_handle_storm(int bank, bool on);
#else
static inline void mce_zhaoxin_feature_init(struct cpuinfo_x86 *c) { }
static inline void mce_zhaoxin_feature_clear(struct cpuinfo_x86 *c) { }
+static inline void mce_zhaoxin_handle_storm(int bank, bool on) { }
#endif
#endif /* __X86_MCE_INTERNAL_H__ */
diff --git a/arch/x86/kernel/cpu/mce/threshold.c b/arch/x86/kernel/cpu/mce/threshold.c
index 89e31e1e5c9c..200280387f04 100644
--- a/arch/x86/kernel/cpu/mce/threshold.c
+++ b/arch/x86/kernel/cpu/mce/threshold.c
@@ -63,6 +63,10 @@ static void mce_handle_storm(unsigned int bank, bool on)
case X86_VENDOR_INTEL:
mce_intel_handle_storm(bank, on);
break;
+ case X86_VENDOR_ZHAOXIN:
+ case X86_VENDOR_CENTAUR:
+ mce_zhaoxin_handle_storm(bank, on);
+ break;
}
}
diff --git a/arch/x86/kernel/cpu/mce/zhaoxin.c b/arch/x86/kernel/cpu/mce/zhaoxin.c
index 6fdef2d24f31..6e38e2b8af20 100644
--- a/arch/x86/kernel/cpu/mce/zhaoxin.c
+++ b/arch/x86/kernel/cpu/mce/zhaoxin.c
@@ -62,3 +62,21 @@ void mce_zhaoxin_feature_clear(struct cpuinfo_x86 *c)
{
intel_clear_lmce();
}
+
+void mce_zhaoxin_handle_storm(int bank, bool on)
+{
+ unsigned long flags;
+ u64 val;
+
+ raw_spin_lock_irqsave(&cmci_discover_lock, flags);
+ rdmsrl(MSR_IA32_MCx_CTL2(bank), val);
+ if (on) {
+ val &= ~(MCI_CTL2_CMCI_EN | MCI_CTL2_CMCI_THRESHOLD_MASK);
+ val |= CMCI_STORM_THRESHOLD;
+ } else {
+ val &= ~MCI_CTL2_CMCI_THRESHOLD_MASK;
+ val |= (MCI_CTL2_CMCI_EN | cmci_threshold[bank]);
+ }
+ wrmsrl(MSR_IA32_MCx_CTL2(bank), val);
+ raw_spin_unlock_irqrestore(&cmci_discover_lock, flags);
+}
--
2.34.1
prev parent reply other threads:[~2024-10-14 8:09 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <2024090910439.3349-1-TonyWWang-oc@zhaoxin.com>
2024-09-10 9:26 ` [PATCH v2 0/3] x86/mce: Add Zhaoxin MCE support Tony W Wang-oc
2024-09-10 9:26 ` [PATCH v2 1/3] x86/mce: Add centaur vendor to support Zhaoxin MCA Tony W Wang-oc
2024-09-10 9:26 ` [PATCH v2 2/3] x86/mce: Add zhaoxin.c " Tony W Wang-oc
2024-09-10 9:26 ` [PATCH v2 3/3] x86/mce: Add CMCI storm switching support for Zhaoxin Tony W Wang-oc
2024-09-18 5:54 ` [PATCH v3 0/3] x86/mce: Add Zhaoxin MCE support Tony W Wang-oc
2024-09-18 5:54 ` [PATCH v3 1/3] x86/mce: Add centaur vendor to support Zhaoxin MCA Tony W Wang-oc
2024-09-19 13:55 ` Yazen Ghannam
2024-09-20 10:41 ` Tony W Wang-oc
2024-09-18 5:54 ` [PATCH v3 2/3] x86/mce: Add zhaoxin.c " Tony W Wang-oc
2024-09-18 5:54 ` [PATCH v3 3/3] x86/mce: Add CMCI storm switching support for Zhaoxin Tony W Wang-oc
2024-09-19 14:06 ` Yazen Ghannam
2024-09-20 10:42 ` Tony W Wang-oc
2024-09-20 13:23 ` Yazen Ghannam
2024-09-20 9:17 ` Zhuo, Qiuxu
2024-09-20 10:42 ` Tony W Wang-oc
2024-09-20 11:44 ` Zhuo, Qiuxu
2024-09-20 13:36 ` Yazen Ghannam
2024-09-21 5:39 ` Zhuo, Qiuxu
[not found] ` <acf35354-ab97-4441-828f-daf7affa20ac@zhaoxin.com>
2024-09-23 3:23 ` Tony W Wang-oc
2024-09-23 7:33 ` [PATCH v4 0/4] x86/mce: Add Zhaoxin MCE support and remove Tony W Wang-oc
2024-09-23 7:33 ` [PATCH v4 1/4] x86/mce: Add centaur vendor to support Zhaoxin MCA Tony W Wang-oc
2024-10-12 3:34 ` Zhuo, Qiuxu
2024-09-23 7:33 ` [PATCH v4 2/4] x86/mce: Remove functions that disable error reporting Tony W Wang-oc
2024-10-12 5:37 ` Zhuo, Qiuxu
2024-09-23 7:33 ` [PATCH v4 3/4] x86/mce: Add zhaoxin.c to support Zhaoxin MCA Tony W Wang-oc
2024-10-12 6:41 ` Zhuo, Qiuxu
2024-10-12 9:06 ` Tony W Wang-oc
2024-10-12 11:27 ` Zhuo, Qiuxu
2024-09-23 7:33 ` [PATCH v4 4/4] x86/mce: Add CMCI storm switching support for Zhaoxin Tony W Wang-oc
2024-10-12 7:13 ` Zhuo, Qiuxu
2024-10-12 7:56 ` Tony W Wang-oc
2024-10-14 7:53 ` [PATCH v5 0/4] x86/mce: Add Zhaoxin MCE support and remove functions that disable error reporting Tony W Wang-oc
2024-10-14 7:53 ` [PATCH v5 1/4] x86/mce: Add Centaur vendor to support Zhaoxin MCA Tony W Wang-oc
2024-10-14 7:53 ` [PATCH v5 2/4] x86/mce: Remove functions that disable error reporting Tony W Wang-oc
2024-10-14 7:53 ` [PATCH v5 3/4] x86/mce: Add zhaoxin.c to support Zhaoxin MCA Tony W Wang-oc
2024-10-14 7:53 ` Tony W Wang-oc [this message]
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=20241014075318.1936-5-TonyWWang-oc@zhaoxin.com \
--to=tonywwang-oc@zhaoxin.com \
--cc=CobeChen@zhaoxin.com \
--cc=LeoLiu-oc@zhaoxin.com \
--cc=LyleLi@zhaoxin.com \
--cc=TimGuo@zhaoxin.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=qiuxu.zhuo@intel.com \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--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