Skip to content

Commit 0f134c5

Browse files
suryasaimadhubp3tk0v
authored andcommitted
x86/mce: Cleanup bank processing on init
Unify the bank preparation into __mcheck_cpu_init_clear_banks(), rename that function to what it does now - prepares banks. Do this so that generic and vendor banks init goes first so that settings done during that init can take effect before the first bank polling takes place. Move __mcheck_cpu_check_banks() into __mcheck_cpu_init_prepare_banks() as it already loops over the banks. The MCP_DONTLOG flag is no longer needed, since the MCA polling function is now called only if boot-time logging should be done. Signed-off-by: Borislav Petkov <bp@suse.de> Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Yazen Ghannam <yazen.ghannam@amd.com> Reviewed-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com> Reviewed-by: Tony Luck <tony.luck@intel.com> Tested-by: Tony Luck <tony.luck@intel.com> Link: https://lore.kernel.org/20250825-wip-mca-updates-v5-5-865768a2eef8@amd.com
1 parent c4bac5c commit 0f134c5

2 files changed

Lines changed: 19 additions & 47 deletions

File tree

arch/x86/include/asm/mce.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,7 @@ DECLARE_PER_CPU(mce_banks_t, mce_poll_banks);
290290
enum mcp_flags {
291291
MCP_TIMESTAMP = BIT(0), /* log time stamp */
292292
MCP_UC = BIT(1), /* log uncorrected errors */
293-
MCP_DONTLOG = BIT(2), /* only clear, don't log */
294-
MCP_QUEUE_LOG = BIT(3), /* only queue to genpool */
293+
MCP_QUEUE_LOG = BIT(2), /* only queue to genpool */
295294
};
296295

297296
void machine_check_poll(enum mcp_flags flags, mce_banks_t *b);

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

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -807,9 +807,6 @@ void machine_check_poll(enum mcp_flags flags, mce_banks_t *b)
807807
continue;
808808

809809
log_it:
810-
if (flags & MCP_DONTLOG)
811-
goto clear_it;
812-
813810
mce_read_aux(&err, i);
814811
m->severity = mce_severity(m, NULL, NULL, false);
815812
/*
@@ -1812,7 +1809,7 @@ static void __mcheck_cpu_mce_banks_init(void)
18121809
/*
18131810
* Init them all, __mcheck_cpu_apply_quirks() is going to apply
18141811
* the required vendor quirks before
1815-
* __mcheck_cpu_init_clear_banks() does the final bank setup.
1812+
* __mcheck_cpu_init_prepare_banks() does the final bank setup.
18161813
*/
18171814
b->ctl = -1ULL;
18181815
b->init = true;
@@ -1851,65 +1848,42 @@ static void __mcheck_cpu_cap_init(void)
18511848

18521849
static void __mcheck_cpu_init_generic(void)
18531850
{
1854-
enum mcp_flags m_fl = 0;
1855-
mce_banks_t all_banks;
18561851
u64 cap;
18571852

1858-
if (!mca_cfg.bootlog)
1859-
m_fl = MCP_DONTLOG;
1860-
1861-
/*
1862-
* Log the machine checks left over from the previous reset. Log them
1863-
* only, do not start processing them. That will happen in mcheck_late_init()
1864-
* when all consumers have been registered on the notifier chain.
1865-
*/
1866-
bitmap_fill(all_banks, MAX_NR_BANKS);
1867-
machine_check_poll(MCP_UC | MCP_QUEUE_LOG | m_fl, &all_banks);
1868-
18691853
cr4_set_bits(X86_CR4_MCE);
18701854

18711855
rdmsrq(MSR_IA32_MCG_CAP, cap);
18721856
if (cap & MCG_CTL_P)
18731857
wrmsr(MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff);
18741858
}
18751859

1876-
static void __mcheck_cpu_init_clear_banks(void)
1860+
static void __mcheck_cpu_init_prepare_banks(void)
18771861
{
18781862
struct mce_bank *mce_banks = this_cpu_ptr(mce_banks_array);
1863+
u64 msrval;
18791864
int i;
18801865

1881-
for (i = 0; i < this_cpu_read(mce_num_banks); i++) {
1882-
struct mce_bank *b = &mce_banks[i];
1866+
/*
1867+
* Log the machine checks left over from the previous reset. Log them
1868+
* only, do not start processing them. That will happen in mcheck_late_init()
1869+
* when all consumers have been registered on the notifier chain.
1870+
*/
1871+
if (mca_cfg.bootlog) {
1872+
mce_banks_t all_banks;
18831873

1884-
if (!b->init)
1885-
continue;
1886-
wrmsrq(mca_msr_reg(i, MCA_CTL), b->ctl);
1887-
wrmsrq(mca_msr_reg(i, MCA_STATUS), 0);
1874+
bitmap_fill(all_banks, MAX_NR_BANKS);
1875+
machine_check_poll(MCP_UC | MCP_QUEUE_LOG, &all_banks);
18881876
}
1889-
}
1890-
1891-
/*
1892-
* Do a final check to see if there are any unused/RAZ banks.
1893-
*
1894-
* This must be done after the banks have been initialized and any quirks have
1895-
* been applied.
1896-
*
1897-
* Do not call this from any user-initiated flows, e.g. CPU hotplug or sysfs.
1898-
* Otherwise, a user who disables a bank will not be able to re-enable it
1899-
* without a system reboot.
1900-
*/
1901-
static void __mcheck_cpu_check_banks(void)
1902-
{
1903-
struct mce_bank *mce_banks = this_cpu_ptr(mce_banks_array);
1904-
u64 msrval;
1905-
int i;
19061877

19071878
for (i = 0; i < this_cpu_read(mce_num_banks); i++) {
19081879
struct mce_bank *b = &mce_banks[i];
19091880

19101881
if (!b->init)
19111882
continue;
19121883

1884+
wrmsrq(mca_msr_reg(i, MCA_CTL), b->ctl);
1885+
wrmsrq(mca_msr_reg(i, MCA_STATUS), 0);
1886+
19131887
rdmsrq(mca_msr_reg(i, MCA_CTL), msrval);
19141888
b->init = !!msrval;
19151889
}
@@ -2314,8 +2288,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
23142288
__mcheck_cpu_init_early(c);
23152289
__mcheck_cpu_init_generic();
23162290
__mcheck_cpu_init_vendor(c);
2317-
__mcheck_cpu_init_clear_banks();
2318-
__mcheck_cpu_check_banks();
2291+
__mcheck_cpu_init_prepare_banks();
23192292
__mcheck_cpu_setup_timer();
23202293
}
23212294

@@ -2483,7 +2456,7 @@ static void mce_syscore_resume(void)
24832456
{
24842457
__mcheck_cpu_init_generic();
24852458
__mcheck_cpu_init_vendor(raw_cpu_ptr(&cpu_info));
2486-
__mcheck_cpu_init_clear_banks();
2459+
__mcheck_cpu_init_prepare_banks();
24872460
}
24882461

24892462
static struct syscore_ops mce_syscore_ops = {
@@ -2501,7 +2474,7 @@ static void mce_cpu_restart(void *data)
25012474
if (!mce_available(raw_cpu_ptr(&cpu_info)))
25022475
return;
25032476
__mcheck_cpu_init_generic();
2504-
__mcheck_cpu_init_clear_banks();
2477+
__mcheck_cpu_init_prepare_banks();
25052478
__mcheck_cpu_init_timer();
25062479
}
25072480

0 commit comments

Comments
 (0)