Skip to contentSkip to conversation

smp/hotplug: Fix last minute wreckage

PATCH In review Thomas Gleixner 2 participants 4 messages Dec 26, 2016 – Dec 27, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover smp/hotplug: Fix last minute wreckage

The last minute changes to the hotplug core code wreckaged the dynamically allocated states. The AMD mce code crashes as a result.

Fix the brainfart and make the AMD code more robust.

Thanks,

tglx

#1 lore raw

PATCH 1/2 smp/hotplug: Undo tglxs brainfart

The attempt to prevent overwriting an active state resulted in a disaster which effectively disables all dynamically allocated hotplug states.

Cleanup the mess.

Fixes dc280d936239 ("cpu/hotplug: Prevent overwriting of callbacks")
---
 kernel/cpu.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/cpu.c +8 -1
@@ -1471,6 +1471,7 @@ int __cpuhp_setup_state(enum cpuhp_state
 			bool multi_instance)
 {
 	int cpu, ret = 0;
+	bool dynstate;
 
 	if (cpuhp_cb_check(state) || !name)
 		return -EINVAL;
@@ -1480,6 +1481,12 @@ int __cpuhp_setup_state(enum cpuhp_state
 	ret = cpuhp_store_callbacks(state, name, startup, teardown,
 				    multi_instance);
 
+	dynstate = state == CPUHP_AP_ONLINE_DYN;
+	if (ret > 0 && dynstate) {
+		state = ret;
+		ret = 0;
+	}
+
 	if (ret || !invoke || !startup)
 		goto out;
 
@@ -1508,7 +1515,7 @@ int __cpuhp_setup_state(enum cpuhp_state
 	 * If the requested state is CPUHP_AP_ONLINE_DYN, return the
 	 * dynamically allocated state in case of success.
 	 */
-	if (!ret && state == CPUHP_AP_ONLINE_DYN)
+	if (!ret && dynstate)
 		return state;
 	return ret;
 }
#2 lore raw

PATCH 2/2 x86/mce/AMD: Make the init code more robust

In reply to Thomas Gleixner

If mce_device_init() fails then the mce device pointer is NULL and the AMD mce code happily dereferences it.

Add a sanity check.

---
 arch/x86/kernel/cpu/mcheck/mce_amd.c |    3 +++
 1 file changed, 3 insertions(+)
arch/x86/kernel/cpu/mcheck/mce_amd.c +3 -0
@@ -1182,6 +1182,9 @@ static int threshold_create_bank(unsigne
 	const char *name = get_name(bank, NULL);
 	int err = 0;
 
+	if (!dev)
+		return -ENODEV;
+
 	if (is_shared_bank(bank)) {
 		nb = node_to_amd_nb(amd_get_nb_id(cpu));
 
maintainer Acked-by on v1 2/2
#3 lore raw

Re: [patch 2/2] x86/mce/AMD: Make the init code more robust

Quoted 15 lines · Thomas Gleixner

If mce_device_init() fails then the mce device pointer is NULL and the AMD mce code happily dereferences it.

Add a sanity check.

---
 arch/x86/kernel/cpu/mcheck/mce_amd.c |    3 +++
 1 file changed, 3 insertions(+)

arch/x86/kernel/cpu/mcheck/mce_amd.c static int threshold_create_bank(unsigne · line 1189

Quoted 8 lines
arch/x86/kernel/cpu/mcheck/mce_amd.c +3 -0
@@ -1182,6 +1182,9 @@ static int threshold_create_bank(unsigne
 	const char *name = get_name(bank, NULL);
 	int err = 0;
 
+	if (!dev)
+		return -ENODEV;
+
 	if (is_shared_bank(bank)) {
 		nb = node_to_amd_nb(amd_get_nb_id(cpu));
Quoted 1 line

From looking at that code, though, it could use some more involved

straightening later.

/me puts it on TODO list.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--