Skip to content

Commit 669ce49

Browse files
yghannambp3tk0v
authored andcommitted
x86/mce: Define BSP-only init
Currently, MCA initialization is executed identically on each CPU as they are brought online. However, a number of MCA initialization tasks only need to be done once. Define a function to collect all 'global' init tasks and call this from the BSP only. Start with CPU features. Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com> Reviewed-by: Tony Luck <tony.luck@intel.com> Reviewed-by: Nikolay Borisov <nik.borisov@suse.com> Tested-by: Tony Luck <tony.luck@intel.com> Link: https://lore.kernel.org/20250908-wip-mca-updates-v6-0-eef5d6c74b9c@amd.com
1 parent cfffcf9 commit 669ce49

4 files changed

Lines changed: 24 additions & 10 deletions

File tree

arch/x86/include/asm/mce.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,14 @@ struct cper_ia_proc_ctx;
241241

242242
#ifdef CONFIG_X86_MCE
243243
int mcheck_init(void);
244+
void mca_bsp_init(struct cpuinfo_x86 *c);
244245
void mcheck_cpu_init(struct cpuinfo_x86 *c);
245246
void mcheck_cpu_clear(struct cpuinfo_x86 *c);
246247
int apei_smca_report_x86_error(struct cper_ia_proc_ctx *ctx_info,
247248
u64 lapic_id);
248249
#else
249250
static inline int mcheck_init(void) { return 0; }
251+
static inline void mca_bsp_init(struct cpuinfo_x86 *c) {}
250252
static inline void mcheck_cpu_init(struct cpuinfo_x86 *c) {}
251253
static inline void mcheck_cpu_clear(struct cpuinfo_x86 *c) {}
252254
static inline int apei_smca_report_x86_error(struct cper_ia_proc_ctx *ctx_info,

arch/x86/kernel/cpu/common.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,6 +1784,7 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)
17841784
setup_clear_cpu_cap(X86_FEATURE_LA57);
17851785

17861786
detect_nopl();
1787+
mca_bsp_init(c);
17871788
}
17881789

17891790
void __init init_cpu_devs(void)

arch/x86/kernel/cpu/mce/amd.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,6 @@ void mce_amd_feature_init(struct cpuinfo_x86 *c)
653653
u32 low = 0, high = 0, address = 0;
654654
int offset = -1;
655655

656-
mce_flags.overflow_recov = cpu_feature_enabled(X86_FEATURE_OVERFLOW_RECOV);
657-
mce_flags.succor = cpu_feature_enabled(X86_FEATURE_SUCCOR);
658-
mce_flags.smca = cpu_feature_enabled(X86_FEATURE_SMCA);
659656
mce_flags.amd_threshold = 1;
660657

661658
for (bank = 0; bank < this_cpu_read(mce_num_banks); ++bank) {

arch/x86/kernel/cpu/mce/core.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,13 +1837,6 @@ static void __mcheck_cpu_cap_init(void)
18371837
this_cpu_write(mce_num_banks, b);
18381838

18391839
__mcheck_cpu_mce_banks_init();
1840-
1841-
/* Use accurate RIP reporting if available. */
1842-
if ((cap & MCG_EXT_P) && MCG_EXT_CNT(cap) >= 9)
1843-
mca_cfg.rip_msr = MSR_IA32_MCG_EIP;
1844-
1845-
if (cap & MCG_SER_P)
1846-
mca_cfg.ser = 1;
18471840
}
18481841

18491842
static void __mcheck_cpu_init_generic(void)
@@ -2240,6 +2233,27 @@ DEFINE_IDTENTRY_RAW(exc_machine_check)
22402233
}
22412234
#endif
22422235

2236+
void mca_bsp_init(struct cpuinfo_x86 *c)
2237+
{
2238+
u64 cap;
2239+
2240+
if (!mce_available(c))
2241+
return;
2242+
2243+
mce_flags.overflow_recov = cpu_feature_enabled(X86_FEATURE_OVERFLOW_RECOV);
2244+
mce_flags.succor = cpu_feature_enabled(X86_FEATURE_SUCCOR);
2245+
mce_flags.smca = cpu_feature_enabled(X86_FEATURE_SMCA);
2246+
2247+
rdmsrq(MSR_IA32_MCG_CAP, cap);
2248+
2249+
/* Use accurate RIP reporting if available. */
2250+
if ((cap & MCG_EXT_P) && MCG_EXT_CNT(cap) >= 9)
2251+
mca_cfg.rip_msr = MSR_IA32_MCG_EIP;
2252+
2253+
if (cap & MCG_SER_P)
2254+
mca_cfg.ser = 1;
2255+
}
2256+
22432257
/*
22442258
* Called for each booted CPU to set up machine checks.
22452259
* Must be called with preempt off:

0 commit comments

Comments
 (0)