Skip to content

Commit d22b115

Browse files
Gavin Shanctmarinas
authored andcommitted
arm64/kernel: Simplify __cpu_up() by bailing out early
The function __cpu_up() is invoked to bring up the target CPU through the backend, PSCI for example. The nested if statements won't be needed if we bail out early on the following two conditions where the status won't be checked. The code looks simplified in that case. * Error returned from the backend (e.g. PSCI) * The target CPU has been marked as onlined Signed-off-by: Gavin Shan <[email protected]> Signed-off-by: Catalin Marinas <[email protected]> Reviewed-by: Mark Rutland <[email protected]>
1 parent 24b2cce commit d22b115

File tree

1 file changed

+37
-42
lines changed

1 file changed

+37
-42
lines changed

arch/arm64/kernel/smp.c

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -115,60 +115,55 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle)
115115
update_cpu_boot_status(CPU_MMU_OFF);
116116
__flush_dcache_area(&secondary_data, sizeof(secondary_data));
117117

118-
/*
119-
* Now bring the CPU into our world.
120-
*/
118+
/* Now bring the CPU into our world */
121119
ret = boot_secondary(cpu, idle);
122-
if (ret == 0) {
123-
/*
124-
* CPU was successfully started, wait for it to come online or
125-
* time out.
126-
*/
127-
wait_for_completion_timeout(&cpu_running,
128-
msecs_to_jiffies(5000));
129-
130-
if (!cpu_online(cpu)) {
131-
pr_crit("CPU%u: failed to come online\n", cpu);
132-
ret = -EIO;
133-
}
134-
} else {
120+
if (ret) {
135121
pr_err("CPU%u: failed to boot: %d\n", cpu, ret);
136122
return ret;
137123
}
138124

125+
/*
126+
* CPU was successfully started, wait for it to come online or
127+
* time out.
128+
*/
129+
wait_for_completion_timeout(&cpu_running,
130+
msecs_to_jiffies(5000));
131+
if (cpu_online(cpu))
132+
return 0;
133+
134+
pr_crit("CPU%u: failed to come online\n", cpu);
139135
secondary_data.task = NULL;
140136
secondary_data.stack = NULL;
141137
__flush_dcache_area(&secondary_data, sizeof(secondary_data));
142138
status = READ_ONCE(secondary_data.status);
143-
if (ret && status) {
144-
145-
if (status == CPU_MMU_OFF)
146-
status = READ_ONCE(__early_cpu_boot_status);
139+
if (status == CPU_MMU_OFF)
140+
status = READ_ONCE(__early_cpu_boot_status);
147141

148-
switch (status & CPU_BOOT_STATUS_MASK) {
149-
default:
150-
pr_err("CPU%u: failed in unknown state : 0x%lx\n",
151-
cpu, status);
152-
cpus_stuck_in_kernel++;
153-
break;
154-
case CPU_KILL_ME:
155-
if (!op_cpu_kill(cpu)) {
156-
pr_crit("CPU%u: died during early boot\n", cpu);
157-
break;
158-
}
159-
pr_crit("CPU%u: may not have shut down cleanly\n", cpu);
160-
/* Fall through */
161-
case CPU_STUCK_IN_KERNEL:
162-
pr_crit("CPU%u: is stuck in kernel\n", cpu);
163-
if (status & CPU_STUCK_REASON_52_BIT_VA)
164-
pr_crit("CPU%u: does not support 52-bit VAs\n", cpu);
165-
if (status & CPU_STUCK_REASON_NO_GRAN)
166-
pr_crit("CPU%u: does not support %luK granule \n", cpu, PAGE_SIZE / SZ_1K);
167-
cpus_stuck_in_kernel++;
142+
switch (status & CPU_BOOT_STATUS_MASK) {
143+
default:
144+
pr_err("CPU%u: failed in unknown state : 0x%lx\n",
145+
cpu, status);
146+
cpus_stuck_in_kernel++;
147+
break;
148+
case CPU_KILL_ME:
149+
if (!op_cpu_kill(cpu)) {
150+
pr_crit("CPU%u: died during early boot\n", cpu);
168151
break;
169-
case CPU_PANIC_KERNEL:
170-
panic("CPU%u detected unsupported configuration\n", cpu);
171152
}
153+
pr_crit("CPU%u: may not have shut down cleanly\n", cpu);
154+
/* Fall through */
155+
case CPU_STUCK_IN_KERNEL:
156+
pr_crit("CPU%u: is stuck in kernel\n", cpu);
157+
if (status & CPU_STUCK_REASON_52_BIT_VA)
158+
pr_crit("CPU%u: does not support 52-bit VAs\n", cpu);
159+
if (status & CPU_STUCK_REASON_NO_GRAN) {
160+
pr_crit("CPU%u: does not support %luK granule\n",
161+
cpu, PAGE_SIZE / SZ_1K);
162+
}
163+
cpus_stuck_in_kernel++;
164+
break;
165+
case CPU_PANIC_KERNEL:
166+
panic("CPU%u detected unsupported configuration\n", cpu);
172167
}
173168

174169
return ret;

0 commit comments

Comments
 (0)