* [PATCH v2] workqueue: Fix race condition in wq->stats incrementation
@ 2025-04-23 16:17 Jiayuan Chen
2025-04-23 16:59 ` Tejun Heo
0 siblings, 1 reply; 2+ messages in thread
From: Jiayuan Chen @ 2025-04-23 16:17 UTC (permalink / raw)
To: linux-kernel
Cc: mrpre, mkoutny, Jiayuan Chen, syzbot+01affb1491750534256d,
Tejun Heo, Lai Jiangshan
Fixed a race condition in incrementing wq->stats[PWQ_STAT_COMPLETED] by
moving the operation under pool->lock.
Reported-by: syzbot+01affb1491750534256d@syzkaller.appspotmail.com
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
---
kernel/workqueue.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index cf6203282737..1ea62b8c76b3 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3241,7 +3241,7 @@ __acquires(&pool->lock)
* point will only record its address.
*/
trace_workqueue_execute_end(work, worker->current_func);
- pwq->stats[PWQ_STAT_COMPLETED]++;
+
lock_map_release(&lockdep_map);
if (!bh_draining)
lock_map_release(pwq->wq->lockdep_map);
@@ -3272,6 +3272,8 @@ __acquires(&pool->lock)
raw_spin_lock_irq(&pool->lock);
+ pwq->stats[PWQ_STAT_COMPLETED]++;
+
/*
* In addition to %WQ_CPU_INTENSIVE, @worker may also have been marked
* CPU intensive by wq_worker_tick() if @work hogged CPU longer than
--
2.47.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-04-23 16:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-23 16:17 [PATCH v2] workqueue: Fix race condition in wq->stats incrementation Jiayuan Chen
2025-04-23 16:59 ` Tejun Heo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox