ARM: kexec: Assemble relocate code in ARM mode
RFC PATCH 1/1 ARM: kexec: Assemble relocate code in ARM mode
In Thumb2 kernel (CONFIG_THUMB2_KERNEL) kexec's relocate code is assembled in Thumb2 mode, but cpu_v7_reset() jumps to this code in ARM state, because its address is page aligned and has 0 in LSB.
Assemble this code in ARM mode to fix the issue.
---
Based on v3.12-rc4
--- arch/arm/kernel/relocate_kernel.S | 1 + 1 file changed, 1 insertion(+)
arch/arm/kernel/relocate_kernel.S +1 -0
@@ -5,6 +5,7 @@ #include <asm/kexec.h> .globl relocate_new_kernel + .arm relocate_new_kernel: ldr r0,kexec_indirection_page
Signature · 1 line
1.7.9.5
RFC PATCH 1/1 ARM: kexec: Assemble relocate code in ARM mode
Quoted 3 lines · Taras Kondratiuk
In Thumb2 kernel (
CONFIG_THUMB2_KERNEL) kexec's relocate code is assembled in Thumb2 mode, butcpu_v7_reset()jumps to this code in ARM state, because its address is page aligned and has 0 in LSB.
This used to work, but Dave broken it when he fixed the reset code in 153cd8e839b5 ("ARM: 7553/1: proc-v7: Ensure correct instruction set after cpu_reset").
Quoted 1 line
Assemble this code in ARM mode to fix the issue.
In the interest of keeping kexec a possibility for v7m, it might be better to do something similar to head.S (i.e. switch back to thumb if we're a thumb-2 kernel).
Cheers,
Will
Quoted 29 lines
Signed-off-by Taras Kondratiuk <[email protected]>---
Based on v3.12-rc4Cc Dave Martin <[email protected]>Cc Will Deacon <[email protected]>Cc Russell King <[email protected]>Cc linaro-kernel at lists.linaro.orgCc linux-arm-kernel at lists.infradead.org--- arch/arm/kernel/relocate_kernel.S | 1 + 1 file changed, 1 insertion(+)arch/arm/kernel/relocate_kernel.S +1
-0@@ -5,6 +5,7 @@ #include <asm/kexec.h> .globl relocate_new_kernel + .arm relocate_new_kernel: ldr r0,kexec_indirection_pageSignature · 1 line
1.7.9.5
RFC PATCH 1/1 ARM: kexec: Assemble relocate code in ARM mode
Quoted 9 lines · Will Deacon
Quoted 3 lines · Taras Kondratiuk
In Thumb2 kernel (
CONFIG_THUMB2_KERNEL) kexec's relocate code is assembled in Thumb2 mode, butcpu_v7_reset()jumps to this code in ARM state, because its address is page aligned and has 0 in LSB.This used to work, but Dave broken it when he fixed the reset code in
153cd8e839b5("ARM: 7553/1: proc-v7: Ensure correct instruction set aftercpu_reset").
Quoted 6 lines
Quoted 1 line
Assemble this code in ARM mode to fix the issue.
In the interest of keeping kexec a possibility for v7m, it might be better to do something similar to
head.S(i.e. switch back to thumb if we're a thumb-2 kernel).
Actually only v7 jumps here in ARM, so maybe it worth to wrap the patch with CONFIG_CPU_V7? In this case v7m won't be touched.
I'll update patch with a stub that switches back to Thumb, but honestly I don't see a bit sense of it here. Anyway at the end of this function instruction set is switched again.
Signature · 2 lines
Regards, Taras Kondratiuk
RFC PATCH 1/1 ARM: kexec: Assemble relocate code in ARM mode
In reply to Taras KondratiukQuoted 5 lines · Taras Kondratiuk
In Thumb2 kernel (
CONFIG_THUMB2_KERNEL) kexec's relocate code is assembled in Thumb2 mode, butcpu_v7_reset()jumps to this code in ARM state, because its address is page aligned and has 0 in LSB.Assemble this code in ARM mode to fix the issue.
I think the actual issue here is that relocate_new_kernel is not properly annotated as a function symbol.
Can you remove the explicit label declaration and try the following:
#include <linux/linkage.h> ENTRY(relocate_new_kernel) /* body of relocate_new_kernel */ ENDPROC(relocate_new_kernel)
Without this, the linker will treat it as a random pointer to data and never set the Thumb bit.
This fails in precisely the same was as an ordinary function call would fail if the destination function doesn't have the needed annotation.
There should be no need to switch to ARM if the kernel is just jumping to itself...
Cheers
---Dave
Quoted 29 lines
Signed-off-by Taras Kondratiuk <[email protected]>---
Based on v3.12-rc4Cc Dave Martin <[email protected]>Cc Will Deacon <[email protected]>Cc Russell King <[email protected]>Cc linaro-kernel at lists.linaro.orgCc linux-arm-kernel at lists.infradead.org--- arch/arm/kernel/relocate_kernel.S | 1 + 1 file changed, 1 insertion(+)arch/arm/kernel/relocate_kernel.S +1
-0@@ -5,6 +5,7 @@ #include <asm/kexec.h> .globl relocate_new_kernel + .arm relocate_new_kernel: ldr r0,kexec_indirection_pageSignature · 1 line
1.7.9.5
RFC PATCH 1/1 ARM: kexec: Assemble relocate code in ARM mode
Quoted 24 lines · Dave Martin
Quoted 5 lines · Taras Kondratiuk
In Thumb2 kernel (
CONFIG_THUMB2_KERNEL) kexec's relocate code is assembled in Thumb2 mode, butcpu_v7_reset()jumps to this code in ARM state, because its address is page aligned and has 0 in LSB.Assemble this code in ARM mode to fix the issue.
I think the actual issue here is that
relocate_new_kernelis not properly annotated as a function symbol.Can you remove the explicit label declaration and try the following:
#include <linux/linkage.h> ENTRY(relocate_new_kernel) /* body of relocate_new_kernel */ ENDPROC(relocate_new_kernel)Without this, the linker will treat it as a random pointer to data and never set the Thumb bit.
Quoted 7 lines
This fails in precisely the same was as an ordinary function call would fail if the destination function doesn't have the needed annotation.
There should be no need to switch to ARM if the kernel is just jumping to itself...
I think it won't help, because here is no direct jump to this label. This code gets copied to a new page and jump is done to the beginning of that page.