Skip to content

Commit 0441a55

Browse files
Qais YousefKAGA-KOKO
authored andcommitted
cpu/hotplug: Create a new function to shutdown nonboot cpus
This function will be used later in machine_shutdown() for some architectures. disable_nonboot_cpus() is not safe to use when doing machine_down(), because it relies on freeze_secondary_cpus() which in turn is a suspend/resume related freeze and could abort if the logic detects any pending activities that can prevent finishing the offlining process. Signed-off-by: Qais Yousef <qais.yousef@arm.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lkml.kernel.org/r/20200323135110.30522-3-qais.yousef@arm.com
1 parent 93ef142 commit 0441a55

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

‎include/linux/cpu.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ extern void cpu_hotplug_enable(void);
120120
void clear_tasks_mm_cpumask(int cpu);
121121
int cpu_down(unsigned int cpu);
122122
int remove_cpu(unsigned int cpu);
123+
extern void smp_shutdown_nonboot_cpus(unsigned int primary_cpu);
123124

124125
#else /* CONFIG_HOTPLUG_CPU */
125126

@@ -131,6 +132,7 @@ static inline int cpus_read_trylock(void) { return true; }
131132
static inline void lockdep_assert_cpus_held(void) { }
132133
static inline void cpu_hotplug_disable(void) { }
133134
static inline void cpu_hotplug_enable(void) { }
135+
static inline void smp_shutdown_nonboot_cpus(unsigned int primary_cpu) { }
134136
#endif /* !CONFIG_HOTPLUG_CPU */
135137

136138
/* Wrappers which go away once all code is converted */

‎kernel/cpu.c‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,48 @@ int remove_cpu(unsigned int cpu)
10691069
}
10701070
EXPORT_SYMBOL_GPL(remove_cpu);
10711071

1072+
void smp_shutdown_nonboot_cpus(unsigned int primary_cpu)
1073+
{
1074+
unsigned int cpu;
1075+
int error;
1076+
1077+
cpu_maps_update_begin();
1078+
1079+
/*
1080+
* Make certain the cpu I'm about to reboot on is online.
1081+
*
1082+
* This is inline to what migrate_to_reboot_cpu() already do.
1083+
*/
1084+
if (!cpu_online(primary_cpu))
1085+
primary_cpu = cpumask_first(cpu_online_mask);
1086+
1087+
for_each_online_cpu(cpu) {
1088+
if (cpu == primary_cpu)
1089+
continue;
1090+
1091+
error = cpu_down_maps_locked(cpu, CPUHP_OFFLINE);
1092+
if (error) {
1093+
pr_err("Failed to offline CPU%d - error=%d",
1094+
cpu, error);
1095+
break;
1096+
}
1097+
}
1098+
1099+
/*
1100+
* Ensure all but the reboot CPU are offline.
1101+
*/
1102+
BUG_ON(num_online_cpus() > 1);
1103+
1104+
/*
1105+
* Make sure the CPUs won't be enabled by someone else after this
1106+
* point. Kexec will reboot to a new kernel shortly resetting
1107+
* everything along the way.
1108+
*/
1109+
cpu_hotplug_disabled++;
1110+
1111+
cpu_maps_update_done();
1112+
}
1113+
10721114
#else
10731115
#define takedown_cpu NULL
10741116
#endif /*CONFIG_HOTPLUG_CPU*/

0 commit comments

Comments
 (0)