diff --git a/arch/arm64/include/asm/cpu_ops.h b/arch/arm64/include/asm/cpu_ops.h index 765f7754cebc5..7239e79798f3d 100644 --- a/arch/arm64/include/asm/cpu_ops.h +++ b/arch/arm64/include/asm/cpu_ops.h @@ -68,12 +68,15 @@ struct spin_table_power_ops { int (*cpu_on)(u64 mpidr); }; +struct cpumask; + #ifdef CONFIG_HOTPLUG_CPU int spin_table_set_power_ops(const struct spin_table_power_ops *ops); int spin_table_hold_parked(void); void spin_table_unhold_parked(void); int spin_table_stop_parked(void); void spin_table_release_stopped(void); +void spin_table_release_cpus(const struct cpumask *cpus); void spin_table_stop_finished(void); bool spin_table_cpus_stuck(void); #else @@ -90,6 +93,7 @@ static inline int spin_table_stop_parked(void) } static inline void spin_table_release_stopped(void) {} +static inline void spin_table_release_cpus(const struct cpumask *cpus) {} static inline void spin_table_stop_finished(void) {} static inline int spin_table_set_power_ops(const struct spin_table_power_ops *ops) diff --git a/arch/arm64/kernel/smp_spin_table.c b/arch/arm64/kernel/smp_spin_table.c index a2a08f4e2c1e9..5c5096a6608df 100644 --- a/arch/arm64/kernel/smp_spin_table.c +++ b/arch/arm64/kernel/smp_spin_table.c @@ -162,6 +162,8 @@ static u32 spin_table_hold_generation, spin_table_held_generation[NR_CPUS]; static bool spin_table_hold_requested; static bool spin_table_stop_requested; static bool spin_table_stop_released; +/* Stopped CPUs released to their last WFI ahead of the others: spin_table_release_cpus() */ +static struct cpumask spin_table_cpus_early; #define SPIN_TABLE_WAIT_US 100000 @@ -265,6 +267,17 @@ int spin_table_stop_parked(void) return -ETIMEDOUT; } +/* + * At the commit, after spin_table_stop_parked(): the stopped CPUs in @cpus take their last WFI + * now, ahead of the others, which wait for spin_table_release_stopped(). + */ +void spin_table_release_cpus(const struct cpumask *cpus) +{ + cpumask_or(&spin_table_cpus_early, &spin_table_cpus_early, cpus); + dsb(ish); + sev(); +} + /* After the commit: the stopped CPUs take their last WFI. */ void spin_table_release_stopped(void) { @@ -282,6 +295,7 @@ void spin_table_stop_finished(void) WRITE_ONCE(spin_table_hold_requested, false); WRITE_ONCE(spin_table_stop_requested, false); WRITE_ONCE(spin_table_stop_released, false); + cpumask_clear(&spin_table_cpus_early); cpumask_or(&spin_table_cpus_off, &spin_table_cpus_off, &spin_table_cpus_parked); cpumask_clear(&spin_table_cpus_parked); cpumask_clear(&spin_table_cpus_held); @@ -363,7 +377,8 @@ static void smp_rvbar_spin_table_hold(unsigned int cpu, u64 mpidr) cpumask_clear_cpu(cpu, &spin_table_cpus_held); cpumask_clear_cpu(cpu, &spin_table_cpus_parked); - while (!READ_ONCE(spin_table_stop_released)) + while (!READ_ONCE(spin_table_stop_released) && + !cpumask_test_cpu(cpu, &spin_table_cpus_early)) wfe(); spin_table_power->cpu_off(mpidr); }