Skip to contentSkip to conversation

powerpc/64: Fix some snafus in head_64.S

PATCH New Bradley Morgan 1 participant 3 messages Nov 20

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover powerpc/64: Fix some snafus in head_64.S

While reading through head_64.S, I noticed two bugs in early secondary processor startup.

The first patch fixes a register mismatch on Book3E where the secondary thread entry point was loaded into r5 instead of r4 when thread switching is required, which jumps to data and traps immediately.

The second patch fixes non SMP kernels where secondary processors jump to kexec_wait without copying their physical CPU ID into r3, leaving the next kernel with garbage during kexec.

Tested on ppc64.

Bradley Morgan (2):
powerpc/64e: Pass entry point in r4 to book3e_start_thread() powerpc/64: Set r3 to physical CPU ID before kexec_wait on !SMP

 arch/powerpc/kernel/head_64.S | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/2 powerpc/64e: Pass entry point in r4 to book3e_start_thread()

In generic_secondary_smp_init(), when switching to the target hardware thread on Book3E, the entry point for the secondary thread was loaded into r5 instead of r4.

book3e_start_thread() expects the entry point in r4 and immediately wipes r5 with MSR_KERNEL, which left r4 pointing to booting_thread_hwid. This is bad because the started thread jumps straight into data and traps on an invalid opcode, hanging the core.

To fix this, load DOTSYM(fsl_secondary_thread_init) into r4 so the secondary thread starts at the real entry point.

Fixes 2dc0bc1138ee ("powerpc/64e: Fix secondary thread bringup for ELFv2 kernels")
---
 arch/powerpc/kernel/head_64.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/head_64.S +1 -1
index a54f6f9791731..0077ce148a5a6 100644
@@ -374,7 +374,7 @@ _GLOBAL(generic_secondary_smp_init)
 	beq	20f
 
 	/* start the specified thread */
-	LOAD_REG_ADDR(r5, DOTSYM(fsl_secondary_thread_init))
+	LOAD_REG_ADDR(r4, DOTSYM(fsl_secondary_thread_init))
 	bl	book3e_start_thread
 
 	/* stop the current thread */
Signature · 1 line
2.53.0
#2 lore raw

PATCH 2/2 powerpc/64: Set r3 to physical CPU ID before kexec_wait on !SMP

In reply to Bradley Morgan

In generic_secondary_common_init(), secondary processors on non SMP kernels branch directly to kexec_wait without copying their physical CPU ID from r24 into r3.

kexec_wait() assumes r3 contains the physical CPU ID and passes it along to __secondary_hold at 0x60 once the next kernel starts. This is bad because secondary processors end up acknowledging the next kernel with garbage, which can hang the boot or report the wrong CPU number.

To fix this, copy r24 into r3 before branching to kexec_wait, matching what the PACA lookup failure path already does.

Fixes 768d18ad6d5e ("powerpc: Don't search for paca in freed memory")
---
 arch/powerpc/kernel/head_64.S | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/kernel/head_64.S +1 -0
index 0077ce148a5a6..6219f474d00bd 100644
@@ -401,6 +401,7 @@ generic_secondary_common_init:
 	 * which logical id maps to our physical one.
 	 */
 #ifndef CONFIG_SMP
+	mr	r3,r24
 	b	kexec_wait		/* wait for next kernel if !SMP	 */
 #else
 	LOAD_REG_ADDR(r8, paca_ptrs)	/* Load paca_ptrs pointe	 */
Signature · 1 line
2.53.0