cpu: Make atomic callbacks run on UP with disabled interrupts
PATCH v2 1/1 cpu: Make atomic callbacks run on UP with disabled interrupts
On SMP callbacks in the "starting" range are invoked while the CPU is brought up and interrupts are still disabled. Callbacks which are added later ar invoked via the hotplug-thread on the target CPU and interrupts are explicitly disabled.
In the UP case callbacks which are added later are invoked "directly" without the thread. This is okay since there is just one CPU but with enabled interrupts debug code, such as smp_processor_id(), will issue warnings.
Disable interrupts before invoking the calback on UP if the state is atomic and interrupts are expected to be disabled.
The "save" part is required because this is also invoked early in the boot process while interrupts are disabled and must not be enabled.
---
Not in -next, repost of
https://lore.kernel.org/all/[email protected]/
kernel/cpu.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-)
kernel/cpu.c +18 -9
@@ -249,6 +249,14 @@ static int cpuhp_invoke_callback(unsigned int cpu, enum cpuhp_state state,return ret; } +/* +* The former STARTING/DYING states, ran with IRQs disabled and must not fail. +*/ +static bool cpuhp_is_atomic_state (enum cpuhp_state state) +{ +return CPUHP_AP_IDLE_DEAD <= state && state <CPUHP_AP_ONLINE ; +} +#ifdef CONFIG_SMP static bool cpuhp_is_ap_state (enum cpuhp_state state) {
@@ -271,14 +279,6 @@ static inline void complete_ap_thread(struct cpuhp_cpu_state *st, bool bringup)complete (done); } -/* -* The former STARTING/DYING states, ran with IRQs disabled and must not fail. -*/ -static bool cpuhp_is_atomic_state (enum cpuhp_state state) -{ -return CPUHP_AP_IDLE_DEAD <= state && state <CPUHP_AP_ONLINE ; -} -/* Synchronization state management */ enum cpuhp_sync_state {SYNC_STATE_DEAD ,
@@ -2364,7 +2364,16 @@ static int cpuhp_issue_call(int cpu, enum cpuhp_state state, bool bringup, else ret =cpuhp_invoke_callback (cpu, state, bringup, node,NULL );#else - ret =cpuhp_invoke_callback (cpu, state, bringup, node,NULL ); +if (cpuhp_is_atomic_state (state)) { +guard (irqsave)(); + ret =cpuhp_invoke_callback (cpu, state, bringup, node,NULL ); +/* +* STARTING/DYING must not fail! +*/ +WARN_ON_ONCE (ret); + }else { + ret =cpuhp_invoke_callback (cpu, state, bringup, node,NULL ); + }#endif BUG_ON (ret && !bringup);return ret;
Signature · 1 line
2.51.0
[tip: smp/urgent] cpu: Make atomic hotplug callbacks run with interrupts disabled on UP
The following commit has been merged into the smp/urgent branch of tip:
The following commit has been merged into the smp/urgent branch of tip:
Commit-ID: c94291914b200e10c72cef23c8e4c67eb4fdbcd9 Gitweb: https://git.kernel.org/tip/c94291914b200e10c72cef23c8e4c67eb4fdbcd9 Author: Sebastian Andrzej Siewior <[email protected]> AuthorDate: Thu, 27 Nov 2025 15:47:23 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 10 Dec 2025 15:49:11 +09:00
cpu: Make atomic hotplug callbacks run with interrupts disabled on UP
On SMP systems the CPU hotplug callbacks in the "starting" range are invoked while the CPU is brought up and interrupts are still disabled. Callbacks which are added later are invoked via the hotplug-thread on the target CPU and interrupts are explicitly disabled.
In the UP case callbacks which are added later are invoked directly without the thread indirection. This is in principle okay since there is just one CPU but those callbacks are invoked with interrupt disabled code. That's incorrect as those callbacks assume interrupt disabled context.
Disable interrupts before invoking the callbacks on UP if the state is atomic and interrupts are expected to be disabled. The "save" part is required because this is also invoked early in the boot process while interrupts are disabled and must not be enabled prematurely.
--- kernel/cpu.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
kernel/cpu.c +16 -9
@@ -249,6 +249,14 @@ err:return ret; } +/* +* The former STARTING/DYING states, ran with IRQs disabled and must not fail. +*/ +static bool cpuhp_is_atomic_state (enum cpuhp_state state) +{ +return CPUHP_AP_IDLE_DEAD <= state && state <CPUHP_AP_ONLINE ; +} +#ifdef CONFIG_SMP static bool cpuhp_is_ap_state (enum cpuhp_state state) {
@@ -271,14 +279,6 @@ static inline void complete_ap_thread(struct cpuhp_cpu_state *st, bool bringup)complete (done); } -/* -* The former STARTING/DYING states, ran with IRQs disabled and must not fail. -*/ -static bool cpuhp_is_atomic_state (enum cpuhp_state state) -{ -return CPUHP_AP_IDLE_DEAD <= state && state <CPUHP_AP_ONLINE ; -} -/* Synchronization state management */ enum cpuhp_sync_state {SYNC_STATE_DEAD ,
@@ -2364,7 +2364,14 @@ static int cpuhp_issue_call(int cpu, enum cpuhp_state state, bool bringup, else ret =cpuhp_invoke_callback (cpu, state, bringup, node,NULL );#else - ret =cpuhp_invoke_callback (cpu, state, bringup, node,NULL ); +if (cpuhp_is_atomic_state (state)) { +guard (irqsave)(); + ret =cpuhp_invoke_callback (cpu, state, bringup, node,NULL ); +/* STARTING/DYING must not fail! */ +WARN_ON_ONCE (ret); + }else { + ret =cpuhp_invoke_callback (cpu, state, bringup, node,NULL ); + }#endif BUG_ON (ret && !bringup);return ret;