The automatic CPU-intensive work item detection reads the worker task's se.sum_exec_runtime without a lock in wq_worker_running(), wq_worker_tick() and process_one_work(). The scheduler updates that field under the rq lock (from the tick via update_curr(), or cross-CPU via task_sched_runtime()), raising: BUG: KCSAN: data-race in wq_worker_running+0xa8/0xe8 race at unknown origin, with read to 0xffff0009a11d1df8 of 8 bytes by task 238535 on cpu 68: wq_worker_running schedule schedule_preempt_disabled __mutex_lock mutex_lock_nested cgroup_bpf_release process_one_work worker_thread kthread ret_from_fork value changed: 0x0000000088482ba0 -> 0x00000000884893c0 The value only feeds a heuristic, so the race is benign-ish. Unlike commit ecf5aad9a441 ("workqueue: annotate racy PWQ_STAT_CPU_TIME update in wq_worker_tick()") that only needs data_race(), these are plain reads whose result drives a subtraction and comparison, so use READ_ONCE() for a single, non-torn load, which also silences KCSAN.
Showing the changes to kernel/workqueue.c (1 of 1 file). Show all
Unified · Split
| @@ -1468,7 +1468,7 @@ void wq_worker_running(struct task_struct *task) · 1467 unmodified lines | |||
| 1468 | * CPU intensive auto-detection cares about how long a work item hogged | 1468 | * CPU intensive auto-detection cares about how long a work item hogged |
| 1469 | * CPU without sleeping. Reset the starting timestamp on wakeup. | 1469 | * CPU without sleeping. Reset the starting timestamp on wakeup. |
| 1470 | */ | 1470 | */ |
| 1471 | worker->current_at = worker->task->se.sum_exec_runtime; | 1471 | worker->current_at = READ_ONCE(worker->task->se.sum_exec_runtime); |
| 1472 | 1472 | ||
| 1473 | WRITE_ONCE(worker->sleeping, 0); | 1473 | WRITE_ONCE(worker->sleeping, 0); |
| 1474 | } | 1474 | } |
| @@ -1557,7 +1557,7 @@ void wq_worker_tick(struct task_struct *task) · 82 unmodified lines | |||
| 1557 | * We probably want to make this prettier in the future. | 1557 | * We probably want to make this prettier in the future. |
| 1558 | */ | 1558 | */ |
| 1559 | if ((worker->flags & WORKER_NOT_RUNNING) || READ_ONCE(worker->sleeping) || | 1559 | if ((worker->flags & WORKER_NOT_RUNNING) || READ_ONCE(worker->sleeping) || |
| 1560 | worker->task->se.sum_exec_runtime - worker->current_at < | 1560 | READ_ONCE(worker->task->se.sum_exec_runtime) - worker->current_at < |
| 1561 | wq_cpu_intensive_thresh_us * NSEC_PER_USEC) | 1561 | wq_cpu_intensive_thresh_us * NSEC_PER_USEC) |
| 1562 | return; | 1562 | return; |
| 1563 | 1563 | ||
| @@ -3294,7 +3294,7 @@ __acquires(&pool->lock) · 1730 unmodified lines | |||
| 3294 | worker->current_func = work->func; | 3294 | worker->current_func = work->func; |
| 3295 | worker->current_pwq = pwq; | 3295 | worker->current_pwq = pwq; |
| 3296 | if (worker->task) | 3296 | if (worker->task) |
| 3297 | worker->current_at = worker->task->se.sum_exec_runtime; | 3297 | worker->current_at = READ_ONCE(worker->task->se.sum_exec_runtime); |
| 3298 | worker->current_start = jiffies; | 3298 | worker->current_start = jiffies; |
| 3299 | work_data = *work_data_bits(work); | 3299 | work_data = *work_data_bits(work); |
| 3300 | worker->current_color = get_work_color(work_data); | 3300 | worker->current_color = get_work_color(work_data); |