Skip to contentSkip to conversation

x86/mce/AMD: Make sure banks were initialized before accessing them

PATCH Borislav Petkov 1 participant 1 message Nov 27, 2018

Subsystems (2)
lore
Share & tools
lore

Borislav Petkov

author maintainer
#0 lore raw
Quoted 8 lines · Borislav Petkov
Quoted 5 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

It may happen amd_threshold_interrupt() fires before banks get setup as part of the threshold_init_device() call. Such a case requires a proper check to avoid NULL pointer dereference.

Yeah, and this code is wrong as hell. :-\

John, does the below hunk help booting?

You might still see

"Unexpected threshold interrupt at vector f9"

or so but you should still be able to boot.

@Yazen, btw look at the bugzilla entry - dmesg has a bunch of MCEs during boot:

[    2.001178] mce: [Hardware Error]: Machine check events logged
[    2.001302] mce: [Hardware Error]: CPU 4: Machine Check: 0 Bank 1: d8200000000a0151
[    2.001309] mce: [Hardware Error]: TSC e45ee7124 MISC d01b0fff00000000 SYND 4a000000 IPID 100b000000000
[    2.001317] mce: [Hardware Error]: PROCESSOR 2:810f10 TIME 1538271297 SOCKET 0 APIC 4 microcode 810100b

how do we decode those new ones if the EDAC decoder is not loaded? I.e., by hand? We probably need some IPID mapping or so...

And also, why is his box spewing so many of those, it is trying to tell us something. :-)

Thx.

arch/x86/kernel/cpu/mcheck/mce_amd.c +6 -13
index dd33c357548f..e12454e21b8a 100644
@@ -56,7 +56,7 @@
 /* Threshold LVT offset is at MSR0xC0000410[15:12] */
 #define SMCA_THR_LVT_OFF	0xF000
 
-static bool thresholding_en;
+static bool thresholding_irq_en;
 
 static const char * const th_names[] = {
 	"load_store",
@@ -534,9 +534,8 @@ prepare_threshold_block(unsigned int bank, unsigned int block, u32 addr,
 
 set_offset:
 	offset = setup_APIC_mce_threshold(offset, new);
-
-	if ((offset == new) && (mce_threshold_vector != amd_threshold_interrupt))
-		mce_threshold_vector = amd_threshold_interrupt;
+	if (offset == new)
+		thresholding_irq_en = true;
 
 done:
 	mce_threshold_block_init(&b, offset);
@@ -1357,9 +1356,6 @@ int mce_threshold_remove_device(unsigned int cpu)
 {
 	unsigned int bank;
 
-	if (!thresholding_en)
-		return 0;
-
 	for (bank = 0; bank < mca_cfg.banks; ++bank) {
 		if (!(per_cpu(bank_map, cpu) & (1 << bank)))
 			continue;
@@ -1377,9 +1373,6 @@ int mce_threshold_create_device(unsigned int cpu)
 	struct threshold_bank **bp;
 	int err = 0;
 
-	if (!thresholding_en)
-		return 0;
-
 	bp = per_cpu(threshold_banks, cpu);
 	if (bp)
 		return 0;
@@ -1408,9 +1401,6 @@ static __init int threshold_init_device(void)
 {
 	unsigned lcpu = 0;
 
-	if (mce_threshold_vector == amd_threshold_interrupt)
-		thresholding_en = true;
-
 	/* to hit CPUs online before the notifier is up */
 	for_each_online_cpu(lcpu) {
 		int err = mce_threshold_create_device(lcpu);
@@ -1419,6 +1409,9 @@ static __init int threshold_init_device(void)
 			return err;
 	}
 
+	if (thresholding_irq_en)
+		mce_threshold_vector = amd_threshold_interrupt;
+
 	return 0;
 }
 /*