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 <gshan@redhat.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Mark Rutland <mark.rutland@arm.com>
This commit is contained in:
Gavin Shan 2020-03-02 13:03:40 +11:00 committed by Catalin Marinas
parent 24b2cce91f
commit d22b115cbf

View File

@ -115,33 +115,27 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle)
update_cpu_boot_status(CPU_MMU_OFF); update_cpu_boot_status(CPU_MMU_OFF);
__flush_dcache_area(&secondary_data, sizeof(secondary_data)); __flush_dcache_area(&secondary_data, sizeof(secondary_data));
/* /* Now bring the CPU into our world */
* Now bring the CPU into our world.
*/
ret = boot_secondary(cpu, idle); ret = boot_secondary(cpu, idle);
if (ret == 0) { if (ret) {
pr_err("CPU%u: failed to boot: %d\n", cpu, ret);
return ret;
}
/* /*
* CPU was successfully started, wait for it to come online or * CPU was successfully started, wait for it to come online or
* time out. * time out.
*/ */
wait_for_completion_timeout(&cpu_running, wait_for_completion_timeout(&cpu_running,
msecs_to_jiffies(5000)); msecs_to_jiffies(5000));
if (cpu_online(cpu))
return 0;
if (!cpu_online(cpu)) {
pr_crit("CPU%u: failed to come online\n", cpu); pr_crit("CPU%u: failed to come online\n", cpu);
ret = -EIO;
}
} else {
pr_err("CPU%u: failed to boot: %d\n", cpu, ret);
return ret;
}
secondary_data.task = NULL; secondary_data.task = NULL;
secondary_data.stack = NULL; secondary_data.stack = NULL;
__flush_dcache_area(&secondary_data, sizeof(secondary_data)); __flush_dcache_area(&secondary_data, sizeof(secondary_data));
status = READ_ONCE(secondary_data.status); status = READ_ONCE(secondary_data.status);
if (ret && status) {
if (status == CPU_MMU_OFF) if (status == CPU_MMU_OFF)
status = READ_ONCE(__early_cpu_boot_status); status = READ_ONCE(__early_cpu_boot_status);
@ -162,14 +156,15 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle)
pr_crit("CPU%u: is stuck in kernel\n", cpu); pr_crit("CPU%u: is stuck in kernel\n", cpu);
if (status & CPU_STUCK_REASON_52_BIT_VA) if (status & CPU_STUCK_REASON_52_BIT_VA)
pr_crit("CPU%u: does not support 52-bit VAs\n", cpu); pr_crit("CPU%u: does not support 52-bit VAs\n", cpu);
if (status & CPU_STUCK_REASON_NO_GRAN) if (status & CPU_STUCK_REASON_NO_GRAN) {
pr_crit("CPU%u: does not support %luK granule \n", cpu, PAGE_SIZE / SZ_1K); pr_crit("CPU%u: does not support %luK granule\n",
cpu, PAGE_SIZE / SZ_1K);
}
cpus_stuck_in_kernel++; cpus_stuck_in_kernel++;
break; break;
case CPU_PANIC_KERNEL: case CPU_PANIC_KERNEL:
panic("CPU%u detected unsupported configuration\n", cpu); panic("CPU%u detected unsupported configuration\n", cpu);
} }
}
return ret; return ret;
} }