Skip to contentSkip to conversation

x86/MCE/AMD: Fix thinko about thresholding_en

PATCH New Borislav Petkov 2 participants 2 messages Nov 19, 2016 – Nov 21, 2016 x86

lore
Share & tools
lore

Borislav Petkov

author maintainer
#0 lore raw

PATCH 1/1 x86/MCE/AMD: Fix thinko about thresholding_en

From: Borislav Petkov <[email protected]>

So adding thresholding_en et al was a good thing for removing the per-CPU thresholding callback, i.e., threshold_cpu_callback.

But, in order for it to work and especially that test in mce_threshold_create_device() so that all thresholding banks get properly created and not the whole thing to fail with a NULL ptr dereference at mce_cpu_pre_down() when we offline the CPUs, we need to set the thresholding_en flag *before* we start creating the devices.

Yap, it failed because thresholding_en wasn't set at the time we were creating the banks so we didn't create any and then at mce_cpu_pre_down() -> mce_threshold_remove_device() time, we would blow up.

And the fix is actually easy: we have thresholding on the system when we have managed to set the thresholding vector to amd_threshold_interrupt() earlier in mce_amd_feature_init() while we were picking apart the thresholding banks and what is set and what not.

So let's do that.

Cc Sebastian Andrzej Siewior <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Yazen Ghannam <[email protected]>
Fixes 4d7b02d58c40 ("x86/mcheck: Split threshold_cpu_callback into two callbacks")
---
 arch/x86/kernel/cpu/mcheck/mce_amd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/mcheck/mce_amd.c +3 -2
index 5c181610af58..bffc4253008b 100644
@@ -1160,6 +1160,9 @@ 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);
@@ -1168,8 +1171,6 @@ static __init int threshold_init_device(void)
 			return err;
 	}
 
-	thresholding_en = true;
-
 	return 0;
 }
 /*
Signature · 1 line
2.10.0
#1 lore raw
x86/MCE/AMD: Fix thinko about thresholding_en
Commit-ID:  254fe9c7a4187ebf5ce23e0ca0e9ba98b1dbef18
Gitweb:     http://git.kernel.org/tip/254fe9c7a4187ebf5ce23e0ca0e9ba98b1dbef18
Author:     Borislav Petkov <[email protected]>
AuthorDate: Sat, 19 Nov 2016 11:34:02 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 21 Nov 2016 11:02:12 +0100

x86/MCE/AMD: Fix thinko about thresholding_en

So adding thresholding_en et al was a good thing for removing the per-CPU thresholding callback, i.e., threshold_cpu_callback.

But, in order for it to work and especially that test in mce_threshold_create_device() so that all thresholding banks get properly created and not the whole thing to fail with a NULL ptr dereference at mce_cpu_pre_down() when we offline the CPUs, we need to set the thresholding_en flag *before* we start creating the devices.

Yap, it failed because thresholding_en wasn't set at the time we were creating the banks so we didn't create any and then at mce_cpu_pre_down() -> mce_threshold_remove_device() time, we would blow up.

And the fix is actually easy: we have thresholding on the system when we have managed to set the thresholding vector to amd_threshold_interrupt() earlier in mce_amd_feature_init() while we were picking apart the thresholding banks and what is set and what not.

So let's do that.

Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Sebastian Andrzej Siewior <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Yazen Ghannam <[email protected]>
Fixes 4d7b02d58c40 ("x86/mcheck: Split threshold_cpu_callback into two callbacks")
---
 arch/x86/kernel/cpu/mcheck/mce_amd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/mcheck/mce_amd.c +3 -2
index c33a3ee..4e82e53 100644
@@ -1134,6 +1134,9 @@ 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);
@@ -1142,8 +1145,6 @@ static __init int threshold_init_device(void)
 			return err;
 	}
 
-	thresholding_en = true;
-
 	return 0;
 }
 /*