Skip to content

Commit 87915ad

Browse files
jmberg-intelhtejun
authored andcommitted
workqueue: re-add lockdep dependencies for flushing
In flush_work(), we need to create a lockdep dependency so that the following scenario is appropriately tagged as a problem: work_function() { mutex_lock(&mutex); ... } other_function() { mutex_lock(&mutex); flush_work(&work); // or cancel_work_sync(&work); } This is a problem since the work might be running and be blocked on trying to acquire the mutex. Similarly, in flush_workqueue(). These were removed after cross-release partially caught these problems, but now cross-release was reverted anyway. IMHO the removal was erroneous anyway though, since lockdep should be able to catch potential problems, not just actual ones, and cross-release would only have caught the problem when actually invoking wait_for_completion(). Fixes: fd1a5b0 ("workqueue: Remove now redundant lock acquisitions wrt. workqueue flushes") Signed-off-by: Johannes Berg <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent d6e8978 commit 87915ad

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

kernel/workqueue.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,6 +2652,9 @@ void flush_workqueue(struct workqueue_struct *wq)
26522652
if (WARN_ON(!wq_online))
26532653
return;
26542654

2655+
lock_map_acquire(&wq->lockdep_map);
2656+
lock_map_release(&wq->lockdep_map);
2657+
26552658
mutex_lock(&wq->mutex);
26562659

26572660
/*
@@ -2905,6 +2908,11 @@ static bool __flush_work(struct work_struct *work, bool from_cancel)
29052908
if (WARN_ON(!wq_online))
29062909
return false;
29072910

2911+
if (!from_cancel) {
2912+
lock_map_acquire(&work->lockdep_map);
2913+
lock_map_release(&work->lockdep_map);
2914+
}
2915+
29082916
if (start_flush_work(work, &barr, from_cancel)) {
29092917
wait_for_completion(&barr.done);
29102918
destroy_work_on_stack(&barr.work);

0 commit comments

Comments
 (0)