Skip to content

Commit 2103f6c

Browse files
nvswarrenRussell King
authored andcommitted
ARM: 7807/1: kexec: validate CPU hotplug support
Architectures should fully validate whether kexec is possible as part of machine_kexec_prepare(), so that user-space's kexec_load() operation can report any problems. Performing validation in machine_kexec() itself is too late, since it is not allowed to return. Prior to this patch, ARM's machine_kexec() was testing after-the-fact whether machine_kexec_prepare() was able to disable all but one CPU. Instead, modify machine_kexec_prepare() to validate all conditions necessary for machine_kexec_prepare()'s to succeed. BUG if the validation succeeded, yet disabling the CPUs didn't actually work. Signed-off-by: Stephen Warren <[email protected]> Acked-by: "Eric W. Biederman" <[email protected]> Signed-off-by: Russell King <[email protected]>
1 parent 00efaa0 commit 2103f6c

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

arch/arm/include/asm/smp_plat.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,7 @@ static inline u32 mpidr_hash_size(void)
8888
{
8989
return 1 << mpidr_hash.bits;
9090
}
91+
92+
extern int platform_can_cpu_hotplug(void);
93+
9194
#endif

arch/arm/kernel/machine_kexec.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <asm/mmu_context.h>
1616
#include <asm/cacheflush.h>
1717
#include <asm/mach-types.h>
18+
#include <asm/smp_plat.h>
1819
#include <asm/system_misc.h>
1920

2021
extern const unsigned char relocate_new_kernel[];
@@ -38,6 +39,14 @@ int machine_kexec_prepare(struct kimage *image)
3839
__be32 header;
3940
int i, err;
4041

42+
/*
43+
* Validate that if the current HW supports SMP, then the SW supports
44+
* and implements CPU hotplug for the current HW. If not, we won't be
45+
* able to kexec reliably, so fail the prepare operation.
46+
*/
47+
if (num_possible_cpus() > 1 && !platform_can_cpu_hotplug())
48+
return -EINVAL;
49+
4150
/*
4251
* No segment at default ATAGs address. try to locate
4352
* a dtb using magic.
@@ -134,10 +143,13 @@ void machine_kexec(struct kimage *image)
134143
unsigned long reboot_code_buffer_phys;
135144
void *reboot_code_buffer;
136145

137-
if (num_online_cpus() > 1) {
138-
pr_err("kexec: error: multiple CPUs still online\n");
139-
return;
140-
}
146+
/*
147+
* This can only happen if machine_shutdown() failed to disable some
148+
* CPU, and that can only happen if the checks in
149+
* machine_kexec_prepare() were not correct. If this fails, we can't
150+
* reliably kexec anyway, so BUG_ON is appropriate.
151+
*/
152+
BUG_ON(num_online_cpus() > 1);
141153

142154
page_list = image->head & PAGE_MASK;
143155

arch/arm/kernel/smp.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ int boot_secondary(unsigned int cpu, struct task_struct *idle)
145145
return -ENOSYS;
146146
}
147147

148+
int platform_can_cpu_hotplug(void)
149+
{
150+
#ifdef CONFIG_HOTPLUG_CPU
151+
if (smp_ops.cpu_kill)
152+
return 1;
153+
#endif
154+
155+
return 0;
156+
}
157+
148158
#ifdef CONFIG_HOTPLUG_CPU
149159
static void percpu_timer_stop(void);
150160

0 commit comments

Comments
 (0)