Skip to content

Commit e2ccba4

Browse files
Dave MartinRussell King
authored andcommitted
ARM: 7897/1: kexec: Use the right ISA for relocate_new_kernel
Copying a function with memcpy() and then trying to execute the result isn't trivially portable to Thumb. This patch modifies the kexec soft restart code to copy its assembler trampoline relocate_new_kernel() using fncpy() instead, so that relocate_new_kernel can be in the same ISA as the rest of the kernel without problems. Signed-off-by: Dave Martin <Dave.Martin@arm.com> Acked-by: Will Deacon <will.deacon@arm.com> Reported-by: Taras Kondratiuk <taras.kondratiuk@linaro.org> Tested-by: Taras Kondratiuk <taras.kondratiuk@linaro.org> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent 5091333 commit e2ccba4

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

‎arch/arm/kernel/machine_kexec.c‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
#include <asm/pgalloc.h>
1515
#include <asm/mmu_context.h>
1616
#include <asm/cacheflush.h>
17+
#include <asm/fncpy.h>
1718
#include <asm/mach-types.h>
1819
#include <asm/smp_plat.h>
1920
#include <asm/system_misc.h>
2021

21-
extern const unsigned char relocate_new_kernel[];
22+
extern void relocate_new_kernel(void);
2223
extern const unsigned int relocate_new_kernel_size;
2324

2425
extern unsigned long kexec_start_address;
@@ -142,6 +143,8 @@ void machine_kexec(struct kimage *image)
142143
{
143144
unsigned long page_list;
144145
unsigned long reboot_code_buffer_phys;
146+
unsigned long reboot_entry = (unsigned long)relocate_new_kernel;
147+
unsigned long reboot_entry_phys;
145148
void *reboot_code_buffer;
146149

147150
/*
@@ -168,16 +171,16 @@ void machine_kexec(struct kimage *image)
168171

169172

170173
/* copy our kernel relocation code to the control code page */
171-
memcpy(reboot_code_buffer,
172-
relocate_new_kernel, relocate_new_kernel_size);
174+
reboot_entry = fncpy(reboot_code_buffer,
175+
reboot_entry,
176+
relocate_new_kernel_size);
177+
reboot_entry_phys = (unsigned long)reboot_entry +
178+
(reboot_code_buffer_phys - (unsigned long)reboot_code_buffer);
173179

174-
175-
flush_icache_range((unsigned long) reboot_code_buffer,
176-
(unsigned long) reboot_code_buffer + KEXEC_CONTROL_PAGE_SIZE);
177180
printk(KERN_INFO "Bye!\n");
178181

179182
if (kexec_reinit)
180183
kexec_reinit();
181184

182-
soft_restart(reboot_code_buffer_phys);
185+
soft_restart(reboot_entry_phys);
183186
}

‎arch/arm/kernel/relocate_kernel.S‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
* relocate_kernel.S - put the kernel image in place to boot
33
*/
44

5+
#include <linux/linkage.h>
56
#include <asm/kexec.h>
67

7-
.globl relocate_new_kernel
8-
relocate_new_kernel:
8+
.align 3 /* not needed for this code, but keeps fncpy() happy */
9+
10+
ENTRY(relocate_new_kernel)
911

1012
ldr r0,kexec_indirection_page
1113
ldr r1,kexec_start_address
@@ -79,6 +81,8 @@ kexec_mach_type:
7981
kexec_boot_atags:
8082
.long 0x0
8183

84+
ENDPROC(relocate_new_kernel)
85+
8286
relocate_new_kernel_end:
8387

8488
.globl relocate_new_kernel_size

0 commit comments

Comments
 (0)