Commit 1d92a611 authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Greg Kroah-Hartman

cpu/hotplug: Prevent state corruption on error rollback

commit 69fa6eb7 upstream.

When a teardown callback fails, the CPU hotplug code brings the CPU back to
the previous state. The previous state becomes the new target state. The
rollback happens in undo_cpu_down() which increments the state
unconditionally even if the state is already the same as the target.

As a consequence the next CPU hotplug operation will start at the wrong
state. This is easily to observe when __cpu_disable() fails.

Prevent the unconditional undo by checking the state vs. target before
incrementing state and fix up the consequently wrong conditional in the
unplug code which handles the failure of the final CPU take down on the
control CPU side.

Fixes: 4dddfb5f ("smp/hotplug: Rewrite AP state machine core")
Reported-by: default avatarNeeraj Upadhyay <>
Signed-off-by: default avatarThomas Gleixner <>
Tested-by: default avatarGeert Uytterhoeven <>
Tested-by: default avatarSudeep Holla <>
Tested-by: default avatarNeeraj Upadhyay <>
Link: default avatarGreg Kroah-Hartman <>

parent cb262585
......@@ -932,7 +932,8 @@ static int cpuhp_down_callbacks(unsigned int cpu, struct cpuhp_cpu_state *st,
ret = cpuhp_invoke_callback(cpu, st->state, false, NULL, NULL);
if (ret) {
st->target = prev_state;
undo_cpu_down(cpu, st);
if (st->state < prev_state)
undo_cpu_down(cpu, st);
......@@ -985,7 +986,7 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
* to do the further cleanups.
ret = cpuhp_down_callbacks(cpu, st, target);
if (ret && st->state > CPUHP_TEARDOWN_CPU && st->state < prev_state) {
if (ret && st->state == CPUHP_TEARDOWN_CPU && st->state < prev_state) {
cpuhp_reset_state(st, prev_state);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment