[PATCH] cpu/hotplug: mark concurrent accesses to should_run
From: Zhu Jun
Date: Wed Nov 11 2026 - 01:29:09 EST
The boot processor sets should_run to wake the application processor's
hotplug thread. cpuhp_should_run() reads that flag without a common lock.
The existing memory barriers order the associated state, but do not mark
the flag accesses themselves, which KCSAN reports as a data race.
Use READ_ONCE() and WRITE_ONCE() for should_run accesses while preserving
the existing barriers and completion protocol.
Fixes: 4cb28ced23c4 ("cpu/hotplug: Create hotplug threads")
Signed-off-by: Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
---
kernel/cpu.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 376d297a6292..ab8dae116e0e 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -774,7 +774,7 @@ static void __cpuhp_kick_ap(struct cpuhp_cpu_state *st)
* true. Paired with the mb() above in cpuhp_thread_fun()
*/
smp_mb();
- st->should_run = true;
+ WRITE_ONCE(st->should_run, true);
wake_up_process(st->thread);
wait_for_ap_thread(st, st->bringup);
}
@@ -1045,7 +1045,7 @@ static int cpuhp_should_run(unsigned int cpu)
{
struct cpuhp_cpu_state *st = this_cpu_ptr(&cpuhp_state);
- return st->should_run;
+ return READ_ONCE(st->should_run);
}
/*
@@ -1068,7 +1068,7 @@ static void cpuhp_thread_fun(unsigned int cpu)
bool bringup = st->bringup;
enum cpuhp_state state;
- if (WARN_ON_ONCE(!st->should_run))
+ if (WARN_ON_ONCE(!READ_ONCE(st->should_run)))
return;
/*
@@ -1087,10 +1087,11 @@ static void cpuhp_thread_fun(unsigned int cpu)
if (st->single) {
state = st->cb_state;
- st->should_run = false;
+ WRITE_ONCE(st->should_run, false);
} else {
- st->should_run = cpuhp_next_state(bringup, &state, st, st->target);
- if (!st->should_run)
+ WRITE_ONCE(st->should_run,
+ cpuhp_next_state(bringup, &state, st, st->target));
+ if (!READ_ONCE(st->should_run))
goto end;
}
@@ -1116,14 +1117,14 @@ static void cpuhp_thread_fun(unsigned int cpu)
* playing.
*/
WARN_ON_ONCE(st->rollback);
- st->should_run = false;
+ WRITE_ONCE(st->should_run, false);
}
end:
cpuhp_lock_release(bringup);
lockdep_release_cpus_lock();
- if (!st->should_run)
+ if (!READ_ONCE(st->should_run))
complete_ap_thread(st, bringup);
}
--
2.51.0