cpu/hotplug: CPUHP_BRINGUP_CPU failure exception
authorVincent Donnefort <vincent.donnefort@arm.com>
Tue, 16 Feb 2021 10:35:05 +0000 (10:35 +0000)
committerIngo Molnar <mingo@kernel.org>
Sat, 6 Mar 2021 11:40:22 +0000 (12:40 +0100)
The atomic states (between CPUHP_AP_IDLE_DEAD and CPUHP_AP_ONLINE) are
triggered by the CPUHP_BRINGUP_CPU step. If the latter fails, no atomic
state can be rolled back.

DEAD callbacks too can't fail and disallow recovery. As a consequence,
during hotunplug, the fail injection interface should prohibit all states
from CPUHP_BRINGUP_CPU to CPUHP_ONLINE.

Signed-off-by: Vincent Donnefort <vincent.donnefort@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lkml.kernel.org/r/20210216103506.416286-3-vincent.donnefort@arm.com
kernel/cpu.c

index 9121edf5759a542e182696153030750bbcf31d03..680ed8f427c0c57a8d4d6d4669dfbbf19130caf9 100644 (file)
@@ -1045,9 +1045,13 @@ 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) {
-               cpuhp_reset_state(st, prev_state);
-               __cpuhp_kick_ap(st);
+       if (ret && st->state < prev_state) {
+               if (st->state == CPUHP_TEARDOWN_CPU) {
+                       cpuhp_reset_state(st, prev_state);
+                       __cpuhp_kick_ap(st);
+               } else {
+                       WARN(1, "DEAD callback error for CPU%d", cpu);
+               }
        }
 
 out:
@@ -2221,6 +2225,15 @@ static ssize_t write_cpuhp_fail(struct device *dev,
        if (cpuhp_is_atomic_state(fail))
                return -EINVAL;
 
+       /*
+        * DEAD callbacks cannot fail...
+        * ... neither can CPUHP_BRINGUP_CPU during hotunplug. The latter
+        * triggering STARTING callbacks, a failure in this state would
+        * hinder rollback.
+        */
+       if (fail <= CPUHP_BRINGUP_CPU && st->state > CPUHP_BRINGUP_CPU)
+               return -EINVAL;
+
        /*
         * Cannot fail anything that doesn't have callbacks.
         */