public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH] riscv: Fix smp_boot_secondary
@ 2024-09-04 12:08 Andrew Jones
  0 siblings, 0 replies; only message in thread
From: Andrew Jones @ 2024-09-04 12:08 UTC (permalink / raw)
  To: kvm, kvm-riscv; +Cc: atishp, cade.richard, jamestiotio

The last few instructions of secondary_entry had the right concept,
but were the totally wrong implementation. Without setting ra, then,
when the boot function doesn't stay in an infinite loop, like
do_idle() would, we'd go off into the weeds when trying to return
from it. Make sure we set ra to come back to where we can then call
do_idle() instead. The bug was found by inspection since nobody is
calling smp_boot_secondary() with anything other than do_idle() at
this time.

Fixes: 9c92b28e6b7b ("riscv: Add SMP support")
Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
---
 riscv/cstart.S | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/riscv/cstart.S b/riscv/cstart.S
index a9ac72df4dd2..8f26999759da 100644
--- a/riscv/cstart.S
+++ b/riscv/cstart.S
@@ -130,9 +130,9 @@ secondary_entry:
 	mv	a0, sp
 	call	secondary_cinit
 	addi	sp, sp, SECONDARY_DATA_SIZE
-	jr	a0
-	la	a0, do_idle
-	jr	a0
+	jalr	ra, a0
+	call	do_idle
+	j	.	/* unreachable */
 
 /*
  * Save context to address in a0.
-- 
2.46.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-09-04 12:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-04 12:08 [kvm-unit-tests PATCH] riscv: Fix smp_boot_secondary Andrew Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox