* [PATCH 0/2] powerpc/64: Fix some snafus in head_64.S
@ 2026-11-20 17:29 Bradley Morgan
2026-11-20 17:29 ` [PATCH 1/2] powerpc/64e: Pass entry point in r4 to book3e_start_thread() Bradley Morgan
2026-11-20 17:29 ` [PATCH 2/2] powerpc/64: Set r3 to physical CPU ID before kexec_wait on !SMP Bradley Morgan
0 siblings, 2 replies; 3+ messages in thread
From: Bradley Morgan @ 2026-11-20 17:29 UTC (permalink / raw)
To: Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy
Cc: Ritesh Harjani, Shrikanth Hegde, linuxppc-dev, linux-kernel,
stable, Bradley Morgan
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(-)
--
2.53.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] powerpc/64e: Pass entry point in r4 to book3e_start_thread()
2026-11-20 17:29 [PATCH 0/2] powerpc/64: Fix some snafus in head_64.S Bradley Morgan
@ 2026-11-20 17:29 ` Bradley Morgan
2026-11-20 17:29 ` [PATCH 2/2] powerpc/64: Set r3 to physical CPU ID before kexec_wait on !SMP Bradley Morgan
1 sibling, 0 replies; 3+ messages in thread
From: Bradley Morgan @ 2026-11-20 17:29 UTC (permalink / raw)
To: Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy
Cc: Ritesh Harjani, Shrikanth Hegde, linuxppc-dev, linux-kernel,
stable, Bradley Morgan
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")
Cc: stable@vger.kernel.org # v6.6+
Signed-off-by: Bradley Morgan <bradley.morgan@linux.dev>
---
arch/powerpc/kernel/head_64.S | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S
index a54f6f9791731..0077ce148a5a6 100644
--- a/arch/powerpc/kernel/head_64.S
+++ b/arch/powerpc/kernel/head_64.S
@@ -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 */
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 2/2] powerpc/64: Set r3 to physical CPU ID before kexec_wait on !SMP
2026-11-20 17:29 [PATCH 0/2] powerpc/64: Fix some snafus in head_64.S Bradley Morgan
2026-11-20 17:29 ` [PATCH 1/2] powerpc/64e: Pass entry point in r4 to book3e_start_thread() Bradley Morgan
@ 2026-11-20 17:29 ` Bradley Morgan
1 sibling, 0 replies; 3+ messages in thread
From: Bradley Morgan @ 2026-11-20 17:29 UTC (permalink / raw)
To: Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy
Cc: Ritesh Harjani, Shrikanth Hegde, linuxppc-dev, linux-kernel,
stable, 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")
Cc: stable@vger.kernel.org
Signed-off-by: Bradley Morgan <bradley.morgan@linux.dev>
---
arch/powerpc/kernel/head_64.S | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S
index 0077ce148a5a6..6219f474d00bd 100644
--- a/arch/powerpc/kernel/head_64.S
+++ b/arch/powerpc/kernel/head_64.S
@@ -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 */
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-20 17:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 17:29 [PATCH 0/2] powerpc/64: Fix some snafus in head_64.S Bradley Morgan
2026-11-20 17:29 ` [PATCH 1/2] powerpc/64e: Pass entry point in r4 to book3e_start_thread() Bradley Morgan
2026-11-20 17:29 ` [PATCH 2/2] powerpc/64: Set r3 to physical CPU ID before kexec_wait on !SMP Bradley Morgan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox