diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index f6b5decff53da..f383d15a104cf 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -139,8 +139,17 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle) */ wait_for_completion_timeout(&cpu_running, msecs_to_jiffies(5000)); - if (cpu_online(cpu)) + if (cpu_online(cpu)) { + /* + * The CPU has taken its task. Cleared, as kernels before 5.x did, so a core that + * reaches __secondary_switched without a bring-up of its own waits in + * __secondary_too_slow instead of running as this CPU a second time. + */ + WRITE_ONCE(secondary_data.task, NULL); + dcache_clean_inval_poc((unsigned long)&secondary_data, + (unsigned long)&secondary_data + sizeof(secondary_data)); return 0; + } pr_crit("CPU%u: failed to come online\n", cpu); secondary_data.task = NULL; diff --git a/arch/arm64/kernel/smp_spin_table.c b/arch/arm64/kernel/smp_spin_table.c index e66806dbbf9c5..0d0f200e3de6a 100644 --- a/arch/arm64/kernel/smp_spin_table.c +++ b/arch/arm64/kernel/smp_spin_table.c @@ -222,6 +222,9 @@ int spin_table_hold_parked(void) int us, ret; unsigned int cpu; + /* No CPU restarted from here to the wake may pass the pen without its own bring-up. */ + write_pen_release(INVALID_HWID); + for_each_present_cpu(cpu) WRITE_ONCE(spin_table_hold_error[cpu], 0); WRITE_ONCE(spin_table_hold_generation, READ_ONCE(spin_table_hold_generation) + 1); @@ -331,6 +334,8 @@ void spin_table_stop_finished(void) /* Before any CPU is started again: the pen must let them boot. */ if (secondary_pen_deep) spin_table_pen_deep_set(0); + /* ...but only the one its bring-up releases (cores started early wait in the pen). */ + write_pen_release(INVALID_HWID); WRITE_ONCE(spin_table_hold_requested, false); WRITE_ONCE(spin_table_stop_requested, false); WRITE_ONCE(spin_table_stop_released, false); @@ -473,6 +478,14 @@ static int smp_rvbar_spin_table_cpu_kill(unsigned int cpu) static void smp_rvbar_spin_table_postboot(void) { + /* + * Close the pen behind this CPU. Left at its MPIDR, the next restart at the reset vector + * (after a sleep's commit, or a platform that starts every core at once at the wake) + * lets it straight through the pen into secondary_startup ahead of its own bring-up, + * with the secondary_data of its last boot: it then runs as that CPU with no STARTING + * callbacks run, e.g. without a tick device. + */ + write_pen_release(INVALID_HWID); cpumask_clear_cpu(smp_processor_id(), &spin_table_cpus_off); if (READ_ONCE(spin_table_power) && spin_table_power->cpu_restore) spin_table_power->cpu_restore(read_cpuid_mpidr() & MPIDR_HWID_BITMASK);