Technical Root Cause Analysis
1. Involved Functions, Structs, and Files
2. Triggering Mechanism and Race Lifecycle
smp_call_function_single_async() allows callers to queue an asynchronous cross-CPU IPI callback using a caller-managed, preallocated call_single_data_t (csd). As documented in its function header (kernel/smp.c:805-812), the caller is responsible for synchronizing submissions on the given csd object so that calls are serialized among submitters. If a previously submitted call is still in progress on the target CPU, smp_call_function_single_async() returns -EBUSY.
In this report, the shared csd is &rq->hrtick_csd belonging to CPU 0:
-
Submitter Context (CPU 1):
- CPU 1 activates or wakes a task belonging to CPU 0 (
try_to_wake_up() $\rightarrow$ ttwu_queue() $\rightarrow$ ttwu_do_activate() $\rightarrow$ activate_task() $\rightarrow$ enqueue_task() $\rightarrow$ enqueue_task_fair() $\rightarrow$ hrtick_update() $\rightarrow$ hrtick_start_fair() $\rightarrow$ hrtick_start()).
- Callers of
hrtick_start() hold CPU 0's runqueue lock (rq->__lock), strictly serializing submissions on rq->hrtick_csd.
- In
hrtick_start(), because rq != this_rq(), it calls:
smp_call_function_single_async(cpu_of(rq), &rq->hrtick_csd);
- In
smp_call_function_single_async() (kernel/smp.c:825):
if (csd->node.u_flags & CSD_FLAG_LOCK) {
err = -EBUSY;
goto out;
}
csd->node.u_flags = CSD_FLAG_LOCK;
smp_wmb();
err = generic_exec_single(cpu, csd);
Line 825 performs a plain, unmarked memory read of csd->node.u_flags.
-
IPI Handler Context (CPU 0):
3. Violated Synchronization and Memory Invariant
While submitters serialize with each other using external locks (rq->__lock), they cannot hold locks that serialize against __flush_smp_call_function_queue(), which runs asynchronously in interrupt context on the target CPU. Checking whether the previous async request has finished requires inspecting csd->node.u_flags.
csd_unlock() writes 0 using smp_store_release(&csd->node.u_flags, 0) so that prior reads of csd->func, csd->info, and list nodes are ordered before clearing CSD_FLAG_LOCK.
- Conversely,
smp_call_function_single_async() reads csd->node.u_flags with a plain, unmarked load at line 825, followed by a plain store at line 830 (csd->node.u_flags = CSD_FLAG_LOCK).
- The plain load constitutes an unsynchronized, unmarked read concurrent with a marked write (
smp_store_release), directly violating LKMM rules and triggering KCSAN. Furthermore, it lacks acquire semantics (such as smp_load_acquire(&csd->node.u_flags) or try_cmpxchg_acquire()), failing to establish a formal acquire-release pairing with csd_unlock() before reusing the csd node.