Skip to contentSkip to conversation

powerpc/kexec: Fix radix to hash kexec

PATCH Applied Balbir Singh 2 participants 2 messages Jun 29, 2017 – Jul 11, 2017 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 powerpc/kexec: Fix radix to hash kexec

This patch fixes a crash seen while doing a kexec from radix mode to hash mode. Key 0 is special in hash and used in the RPN by default, we set the key values to 0 today. In radix mode key 0 is used to control supervisor<->user access. In hash key 0 is used by default, so the first instruction after the switch causes a crash on kexec.

This patch fixes
(3b10d00 powerpc/mm/radix: Prevent kernel execution of user space) The commit above introduced setting of IAMR and AMOR values to prevent execution of user mode instructions from supervisor mode. We need to clean up these SPR's on kexec.

---

Changelog v2:
- Put the code in a feature section for CPU_FTR_ARCH_300

 arch/powerpc/kernel/misc_64.S | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/powerpc/kernel/misc_64.S +12 -0
index c119044..8ac0bd2 100644
@@ -614,6 +614,18 @@ _GLOBAL(kexec_sequence)
 	li	r0,0
 	std	r0,16(r1)
 
+BEGIN_FTR_SECTION
+	/*
+	 * This is the best time to turn AMR/IAMR off.
+	 * key 0 is used in radix for supervisor<->user
+	 * protection, but on hash key 0 is reserved
+	 * ideally we want to enter with a clean state.
+	 * NOTE, we rely on r0 being 0 from above.
+	 */
+	mtspr	SPRN_IAMR,r0
+	mtspr	SPRN_AMOR,r0
+END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
+
 	/* save regs for local vars on new stack.
 	 * yes, we won't go back, but ...
 	 */
Signature · 1 line
2.9.4
#1 lore raw
Quoted 8 lines · Balbir Singh

This patch fixes a crash seen while doing a kexec from radix mode to hash mode. Key 0 is special in hash and used in the RPN by default, we set the key values to 0 today. In radix mode key 0 is used to control supervisor<->user access. In hash key 0 is used by default, so the first instruction after the switch causes a crash on kexec.

Quoted 8 lines

This patch fixes
(3b10d00 powerpc/mm/radix: Prevent kernel execution of user space) The commit above introduced setting of IAMR and AMOR values to prevent execution of user mode instructions from supervisor mode. We need to clean up these SPR's on kexec.

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/1e2a516e89fc412a754327522ab271

cheers