Skip to content

Commit 19ab428

Browse files
Stephen WarrenRussell King
authored andcommitted
ARM: 7759/1: decouple CPU offlining from reboot/shutdown
Add comments to machine_shutdown()/halt()/power_off()/restart() that describe their purpose and/or requirements re: CPUs being active/not. In machine_shutdown(), replace the call to smp_send_stop() with a call to disable_nonboot_cpus(). This completely disables all but one CPU, thus satisfying the requirement that only a single CPU be active for kexec. Adjust Kconfig dependencies for this change. In machine_halt()/power_off()/restart(), call smp_send_stop() directly, rather than via machine_shutdown(); these functions don't need to completely de-activate all CPUs using hotplug, but rather just quiesce them. Remove smp_kill_cpus(), and its call from smp_send_stop(). smp_kill_cpus() was indirectly calling smp_ops.cpu_kill() without calling smp_ops.cpu_die() on the target CPUs first. At least some implementations of smp_ops had issues with this; it caused cpu_kill() to hang on Tegra, for example. Since smp_send_stop() is only used for shutdown, halt, and power-off, there is no need to attempt any kind of CPU hotplug here. Adjust Kconfig to reflect that machine_shutdown() (and hence kexec) relies upon disable_nonboot_cpus(). However, this alone doesn't guarantee that hotplug will work, or even that hotplug is implemented for a particular piece of HW that a multi-platform zImage runs on. Hence, add error-checking to machine_kexec() to determine whether it did work. Suggested-by: Russell King <rmk+kernel@arm.linux.org.uk> Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: Will Deacon <will.deacon@arm.com> Tested-by: Zhangfei Gao <zhangfei.gao@gmail.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent 69f91ff commit 19ab428

4 files changed

Lines changed: 42 additions & 20 deletions

File tree

‎arch/arm/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2016,7 +2016,7 @@ config XIP_PHYS_ADDR
20162016

20172017
config KEXEC
20182018
bool "Kexec system call (EXPERIMENTAL)"
2019-
depends on (!SMP || HOTPLUG_CPU)
2019+
depends on (!SMP || PM_SLEEP_SMP)
20202020
help
20212021
kexec is a system call that implements the ability to shutdown your
20222022
current kernel, and to start another kernel. It is like a reboot

‎arch/arm/kernel/machine_kexec.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ void machine_kexec(struct kimage *image)
134134
unsigned long reboot_code_buffer_phys;
135135
void *reboot_code_buffer;
136136

137+
if (num_online_cpus() > 1) {
138+
pr_err("kexec: error: multiple CPUs still online\n");
139+
return;
140+
}
137141

138142
page_list = image->head & PAGE_MASK;
139143

‎arch/arm/kernel/process.c‎

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,30 +184,61 @@ int __init reboot_setup(char *str)
184184

185185
__setup("reboot=", reboot_setup);
186186

187+
/*
188+
* Called by kexec, immediately prior to machine_kexec().
189+
*
190+
* This must completely disable all secondary CPUs; simply causing those CPUs
191+
* to execute e.g. a RAM-based pin loop is not sufficient. This allows the
192+
* kexec'd kernel to use any and all RAM as it sees fit, without having to
193+
* avoid any code or data used by any SW CPU pin loop. The CPU hotplug
194+
* functionality embodied in disable_nonboot_cpus() to achieve this.
195+
*/
187196
void machine_shutdown(void)
188197
{
189-
#ifdef CONFIG_SMP
190-
smp_send_stop();
191-
#endif
198+
disable_nonboot_cpus();
192199
}
193200

201+
/*
202+
* Halting simply requires that the secondary CPUs stop performing any
203+
* activity (executing tasks, handling interrupts). smp_send_stop()
204+
* achieves this.
205+
*/
194206
void machine_halt(void)
195207
{
196-
machine_shutdown();
208+
smp_send_stop();
209+
197210
local_irq_disable();
198211
while (1);
199212
}
200213

214+
/*
215+
* Power-off simply requires that the secondary CPUs stop performing any
216+
* activity (executing tasks, handling interrupts). smp_send_stop()
217+
* achieves this. When the system power is turned off, it will take all CPUs
218+
* with it.
219+
*/
201220
void machine_power_off(void)
202221
{
203-
machine_shutdown();
222+
smp_send_stop();
223+
204224
if (pm_power_off)
205225
pm_power_off();
206226
}
207227

228+
/*
229+
* Restart requires that the secondary CPUs stop performing any activity
230+
* while the primary CPU resets the system. Systems with a single CPU can
231+
* use soft_restart() as their machine descriptor's .restart hook, since that
232+
* will cause the only available CPU to reset. Systems with multiple CPUs must
233+
* provide a HW restart implementation, to ensure that all CPUs reset at once.
234+
* This is required so that any code running after reset on the primary CPU
235+
* doesn't have to co-ordinate with other CPUs to ensure they aren't still
236+
* executing pre-reset code, and using RAM that the primary CPU's code wishes
237+
* to use. Implementing such co-ordination would be essentially impossible.
238+
*/
208239
void machine_restart(char *cmd)
209240
{
210-
machine_shutdown();
241+
smp_send_stop();
211242

212243
arm_pm_restart(reboot_mode, cmd);
213244

‎arch/arm/kernel/smp.c‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -651,17 +651,6 @@ void smp_send_reschedule(int cpu)
651651
smp_cross_call(cpumask_of(cpu), IPI_RESCHEDULE);
652652
}
653653

654-
#ifdef CONFIG_HOTPLUG_CPU
655-
static void smp_kill_cpus(cpumask_t *mask)
656-
{
657-
unsigned int cpu;
658-
for_each_cpu(cpu, mask)
659-
platform_cpu_kill(cpu);
660-
}
661-
#else
662-
static void smp_kill_cpus(cpumask_t *mask) { }
663-
#endif
664-
665654
void smp_send_stop(void)
666655
{
667656
unsigned long timeout;
@@ -679,8 +668,6 @@ void smp_send_stop(void)
679668

680669
if (num_online_cpus() > 1)
681670
pr_warning("SMP: failed to stop secondary CPUs\n");
682-
683-
smp_kill_cpus(&mask);
684671
}
685672

686673
/*

0 commit comments

Comments
 (0)