Skip to content

Commit 38a94c4

Browse files
AndybnACTpalmer-dabbelt
authored andcommitted
riscv: smp: fail booting up smp if inconsistent vlen is detected
Currently we only support Vector for SMP platforms, that is, all SMP cores have the same vlenb. If we happen to detect a mismatching vlen, it is better to just fail bootting it up to prevent further race/scheduling issues. Also, move .Lsecondary_park forward and chage `tail smp_callin` into a regular call in the early assembly. So a core would be parked right after a return from smp_callin. Note that a successful smp_callin does not return. Fixes: 7017858 ("riscv: Introduce riscv_v_vsize to record size of Vector context") Reported-by: Conor Dooley <[email protected]> Closes: https://lore.kernel.org/linux-riscv/20240228-vicinity-cornstalk-4b8eb5fe5730@spud/ Signed-off-by: Andy Chiu <[email protected]> Reviewed-by: Conor Dooley <[email protected]> Reviewed-by: Yunhui Cui <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 77afe3e commit 38a94c4

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

arch/riscv/kernel/head.S

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,20 @@ secondary_start_sbi:
165165
#endif
166166
call .Lsetup_trap_vector
167167
scs_load_current
168-
tail smp_callin
168+
call smp_callin
169169
#endif /* CONFIG_SMP */
170170

171+
.align 2
172+
.Lsecondary_park:
173+
/*
174+
* Park this hart if we:
175+
* - have too many harts on CONFIG_RISCV_BOOT_SPINWAIT
176+
* - receive an early trap, before setup_trap_vector finished
177+
* - fail in smp_callin(), as a successful one wouldn't return
178+
*/
179+
wfi
180+
j .Lsecondary_park
181+
171182
.align 2
172183
.Lsetup_trap_vector:
173184
/* Set trap vector to exception handler */
@@ -181,12 +192,6 @@ secondary_start_sbi:
181192
csrw CSR_SCRATCH, zero
182193
ret
183194

184-
.align 2
185-
.Lsecondary_park:
186-
/* We lack SMP support or have too many harts, so park this hart */
187-
wfi
188-
j .Lsecondary_park
189-
190195
SYM_CODE_END(_start)
191196

192197
SYM_CODE_START(_start_kernel)

arch/riscv/kernel/smpboot.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ asmlinkage __visible void smp_callin(void)
214214
struct mm_struct *mm = &init_mm;
215215
unsigned int curr_cpuid = smp_processor_id();
216216

217+
if (has_vector()) {
218+
/*
219+
* Return as early as possible so the hart with a mismatching
220+
* vlen won't boot.
221+
*/
222+
if (riscv_v_setup_vsize())
223+
return;
224+
}
225+
217226
/* All kernel threads share the same mm context. */
218227
mmgrab(mm);
219228
current->active_mm = mm;
@@ -226,11 +235,6 @@ asmlinkage __visible void smp_callin(void)
226235
numa_add_cpu(curr_cpuid);
227236
set_cpu_online(curr_cpuid, true);
228237

229-
if (has_vector()) {
230-
if (riscv_v_setup_vsize())
231-
elf_hwcap &= ~COMPAT_HWCAP_ISA_V;
232-
}
233-
234238
riscv_user_isa_enable();
235239

236240
/*

0 commit comments

Comments
 (0)