Skip to content

Commit 891e465

Browse files
skoralahsuryasaimadhu
authored andcommitted
x86/mce: Check whether writes to MCA_STATUS are getting ignored
The platform can sometimes - depending on its settings - cause writes to MCA_STATUS MSRs to get ignored, regardless of HWCR[McStatusWrEn]'s value. For further info see PPR for AMD Family 19h, Model 01h, Revision B1 Processors, doc ID 55898 at https://bugzilla.kernel.org/show_bug.cgi?id=206537. Therefore, probe for ignored writes to MCA_STATUS to determine if hardware error injection is at all possible. [ bp: Heavily massage commit message and patch. ] Signed-off-by: Smita Koralahalli <Smita.KoralahalliChannabasappa@amd.com> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://lore.kernel.org/r/20220214233640.70510-2-Smita.KoralahalliChannabasappa@amd.com
1 parent a111daf commit 891e465

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
#include "internal.h"
3535

36+
static bool hw_injection_possible = true;
37+
3638
/*
3739
* Collect all the MCi_XXX settings
3840
*/
@@ -339,6 +341,8 @@ static int __set_inj(const char *buf)
339341

340342
for (i = 0; i < N_INJ_TYPES; i++) {
341343
if (!strncmp(flags_options[i], buf, strlen(flags_options[i]))) {
344+
if (i > SW_INJ && !hw_injection_possible)
345+
continue;
342346
inj_type = i;
343347
return 0;
344348
}
@@ -717,11 +721,54 @@ static void __init debugfs_init(void)
717721
&i_mce, dfs_fls[i].fops);
718722
}
719723

724+
static void check_hw_inj_possible(void)
725+
{
726+
int cpu;
727+
u8 bank;
728+
729+
/*
730+
* This behavior exists only on SMCA systems though its not directly
731+
* related to SMCA.
732+
*/
733+
if (!cpu_feature_enabled(X86_FEATURE_SMCA))
734+
return;
735+
736+
cpu = get_cpu();
737+
738+
for (bank = 0; bank < MAX_NR_BANKS; ++bank) {
739+
u64 status = MCI_STATUS_VAL, ipid;
740+
741+
/* Check whether bank is populated */
742+
rdmsrl(MSR_AMD64_SMCA_MCx_IPID(bank), ipid);
743+
if (!ipid)
744+
continue;
745+
746+
toggle_hw_mce_inject(cpu, true);
747+
748+
wrmsrl_safe(mca_msr_reg(bank, MCA_STATUS), status);
749+
rdmsrl_safe(mca_msr_reg(bank, MCA_STATUS), &status);
750+
751+
if (!status) {
752+
hw_injection_possible = false;
753+
pr_warn("Platform does not allow *hardware* error injection."
754+
"Try using APEI EINJ instead.\n");
755+
}
756+
757+
toggle_hw_mce_inject(cpu, false);
758+
759+
break;
760+
}
761+
762+
put_cpu();
763+
}
764+
720765
static int __init inject_init(void)
721766
{
722767
if (!alloc_cpumask_var(&mce_inject_cpumask, GFP_KERNEL))
723768
return -ENOMEM;
724769

770+
check_hw_inj_possible();
771+
725772
debugfs_init();
726773

727774
register_nmi_handler(NMI_LOCAL, mce_raise_notify, 0, "mce_notify");

arch/x86/kernel/cpu/mce/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ noinstr u64 mce_rdmsrl(u32 msr);
211211

212212
static __always_inline u32 mca_msr_reg(int bank, enum mca_msr reg)
213213
{
214-
if (mce_flags.smca) {
214+
if (cpu_feature_enabled(X86_FEATURE_SMCA)) {
215215
switch (reg) {
216216
case MCA_CTL: return MSR_AMD64_SMCA_MCx_CTL(bank);
217217
case MCA_ADDR: return MSR_AMD64_SMCA_MCx_ADDR(bank);

0 commit comments

Comments
 (0)