Skip to content

Commit e15c6e3

Browse files
Atish Patrapalmer-dabbelt
authored andcommitted
RISC-V: Do not wait indefinitely in __cpu_up
In SMP path, __cpu_up waits for other CPU to come online indefinitely. This is wrong as other CPU might be disabled in machine mode and possible CPU is set to the cpus present in DT. Introduce a completion variable and waits only for a second. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
1 parent 79a47ba commit e15c6e3

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎arch/riscv/kernel/smpboot.c‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
void *__cpu_up_stack_pointer[NR_CPUS];
4141
void *__cpu_up_task_pointer[NR_CPUS];
42+
static DECLARE_COMPLETION(cpu_running);
4243

4344
void __init smp_prepare_boot_cpu(void)
4445
{
@@ -77,6 +78,7 @@ void __init setup_smp(void)
7778

7879
int __cpu_up(unsigned int cpu, struct task_struct *tidle)
7980
{
81+
int ret = 0;
8082
int hartid = cpuid_to_hartid_map(cpu);
8183
tidle->thread_info.cpu = cpu;
8284

@@ -92,10 +94,16 @@ int __cpu_up(unsigned int cpu, struct task_struct *tidle)
9294
task_stack_page(tidle) + THREAD_SIZE);
9395
WRITE_ONCE(__cpu_up_task_pointer[hartid], tidle);
9496

95-
while (!cpu_online(cpu))
96-
cpu_relax();
97+
lockdep_assert_held(&cpu_running);
98+
wait_for_completion_timeout(&cpu_running,
99+
msecs_to_jiffies(1000));
97100

98-
return 0;
101+
if (!cpu_online(cpu)) {
102+
pr_crit("CPU%u: failed to come online\n", cpu);
103+
ret = -EIO;
104+
}
105+
106+
return ret;
99107
}
100108

101109
void __init smp_cpus_done(unsigned int max_cpus)
@@ -121,6 +129,7 @@ asmlinkage void __init smp_callin(void)
121129
* a local TLB flush right now just in case.
122130
*/
123131
local_flush_tlb_all();
132+
complete(&cpu_running);
124133
/*
125134
* Disable preemption before enabling interrupts, so we don't try to
126135
* schedule a CPU that hasn't actually started yet.

0 commit comments

Comments
 (0)