Skip to content

Commit 2ffc48f

Browse files
atishp04palmer-dabbelt
authored andcommitted
RISC-V: Move spinwait booting method to its own config
The spinwait booting method should only be used for platforms with older firmware without SBI HSM extension or M-mode firmware because spinwait method can't support cpu hotplug, kexec or sparse hartid. It is better to move the entire spinwait implementation to its own config which can be disabled if required. It is enabled by default to maintain backward compatibility and M-mode Linux. Reviewed-by: Anup Patel <[email protected]> Signed-off-by: Atish Patra <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 0b39eb3 commit 2ffc48f

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

arch/riscv/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,20 @@ config RISCV_SBI_V01
374374
This config allows kernel to use SBI v0.1 APIs. This will be
375375
deprecated in future once legacy M-mode software are no longer in use.
376376

377+
config RISCV_BOOT_SPINWAIT
378+
bool "Spinwait booting method"
379+
depends on SMP
380+
default y
381+
help
382+
This enables support for booting Linux via spinwait method. In the
383+
spinwait method, all cores randomly jump to Linux. One of the cores
384+
gets chosen via lottery and all other keep spinning on a percpu
385+
variable. This method cannot support CPU hotplug and sparse hartid
386+
scheme. It should be only enabled for M-mode Linux or platforms relying
387+
on older firmware without SBI HSM extension. All other platforms should
388+
rely on ordered booting via SBI HSM extension which gets chosen
389+
dynamically at runtime if the firmware supports it.
390+
377391
config KEXEC
378392
bool "Kexec system call"
379393
select KEXEC_CORE

arch/riscv/kernel/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ obj-$(CONFIG_FPU) += fpu.o
4343
obj-$(CONFIG_SMP) += smpboot.o
4444
obj-$(CONFIG_SMP) += smp.o
4545
obj-$(CONFIG_SMP) += cpu_ops.o
46-
obj-$(CONFIG_SMP) += cpu_ops_spinwait.o
46+
47+
obj-$(CONFIG_RISCV_BOOT_SPINWAIT) += cpu_ops_spinwait.o
4748
obj-$(CONFIG_MODULES) += module.o
4849
obj-$(CONFIG_MODULE_SECTIONS) += module-sections.o
4950

arch/riscv/kernel/cpu_ops.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@
1515
const struct cpu_operations *cpu_ops[NR_CPUS] __ro_after_init;
1616

1717
extern const struct cpu_operations cpu_ops_sbi;
18+
#ifdef CONFIG_RISCV_BOOT_SPINWAIT
1819
extern const struct cpu_operations cpu_ops_spinwait;
20+
#else
21+
const struct cpu_operations cpu_ops_spinwait = {
22+
.name = "",
23+
.cpu_prepare = NULL,
24+
.cpu_start = NULL,
25+
};
26+
#endif
1927

2028
void __init cpu_set_ops(int cpuid)
2129
{

arch/riscv/kernel/head.S

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ pmp_done:
259259
li t0, SR_FS
260260
csrc CSR_STATUS, t0
261261

262-
#ifdef CONFIG_SMP
262+
#ifdef CONFIG_RISCV_BOOT_SPINWAIT
263263
li t0, CONFIG_NR_CPUS
264264
blt a0, t0, .Lgood_cores
265265
tail .Lsecondary_park
@@ -285,7 +285,7 @@ pmp_done:
285285
beq t0, t1, .Lsecondary_start
286286

287287
#endif /* CONFIG_XIP */
288-
#endif /* CONFIG_SMP */
288+
#endif /* CONFIG_RISCV_BOOT_SPINWAIT */
289289

290290
#ifdef CONFIG_XIP_KERNEL
291291
la sp, _end + THREAD_SIZE
@@ -344,7 +344,7 @@ clear_bss_done:
344344
call soc_early_init
345345
tail start_kernel
346346

347-
#ifdef CONFIG_SMP
347+
#if CONFIG_RISCV_BOOT_SPINWAIT
348348
.Lsecondary_start:
349349
/* Set trap vector to spin forever to help debug */
350350
la a3, .Lsecondary_park
@@ -371,7 +371,7 @@ clear_bss_done:
371371
fence
372372

373373
tail .Lsecondary_start_common
374-
#endif
374+
#endif /* CONFIG_RISCV_BOOT_SPINWAIT */
375375

376376
END(_start_kernel)
377377

arch/riscv/kernel/head.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa);
1616
asmlinkage void __init __copy_data(void);
1717
#endif
1818

19+
#ifdef CONFIG_RISCV_BOOT_SPINWAIT
1920
extern void *__cpu_spinwait_stack_pointer[];
2021
extern void *__cpu_spinwait_task_pointer[];
22+
#endif
2123

2224
#endif /* __ASM_HEAD_H */

0 commit comments

Comments
 (0)