Skip to contentSkip to conversation

ARM: kexec: Assemble relocate code in ARM mode

RFC PATCH New Taras Kondratiuk 3 participants 5 messages Oct 9, 2013 – Oct 10, 2013 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

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

Cc Dave Martin <[email protected]>
Cc Will Deacon <[email protected]>
Cc Russell King <[email protected]>
Cc linaro-kernel at lists.linaro.org
Cc 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
index d0cdedf..a3af323 100644
@@ -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
#1 lore raw

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, but cpu_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

---
Based on v3.12-rc4

Cc Dave Martin <[email protected]>
Cc Will Deacon <[email protected]>
Cc Russell King <[email protected]>
Cc linaro-kernel at lists.linaro.org
Cc 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
index d0cdedf..a3af323 100644
@@ -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
#2 lore raw

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, but cpu_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 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
#3 lore raw

RFC PATCH 1/1 ARM: kexec: Assemble relocate code in ARM mode

In reply to Taras Kondratiuk
Quoted 5 lines · Taras Kondratiuk

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.

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

---
Based on v3.12-rc4

Cc Dave Martin <[email protected]>
Cc Will Deacon <[email protected]>
Cc Russell King <[email protected]>
Cc linaro-kernel at lists.linaro.org
Cc 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
index d0cdedf..a3af323 100644
@@ -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
#4 lore raw

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, 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.

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.

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.