[PATCH 2/3] kernel/workqueue: Surround work execution with shared lock annotations

From: Bart Van Assche
Date: Thu Oct 25 2018 - 11:07:11 EST


Surround execution of work with a shared lockdep annotation because multiple
work items associated with a work queue may execute concurrently.

Cc: Johannes Berg <johannes.berg@xxxxxxxxx>
Cc: Tejun Heo <tj@xxxxxxxxxx>
Cc: Christoph Hellwig <hch@xxxxxx>
Cc: Sagi Grimberg <sagi@xxxxxxxxxxx>
Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx>
---
kernel/workqueue.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 6755ef21a679..fc9129d5909e 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -2125,8 +2125,8 @@ __acquires(&pool->lock)

spin_unlock_irq(&pool->lock);

- lock_map_acquire(&pwq->wq->lockdep_map);
- lock_map_acquire(&lockdep_map);
+ lock_acquire_shared(&pwq->wq->lockdep_map, 0, 0, NULL, _THIS_IP_);
+ lock_acquire_shared(&lockdep_map, 0, 0, NULL, _THIS_IP_);
/*
* Strictly speaking we should mark the invariant state without holding
* any locks, that is, before these two lock_map_acquire()'s.
@@ -2156,8 +2156,8 @@ __acquires(&pool->lock)
* point will only record its address.
*/
trace_workqueue_execute_end(work);
- lock_map_release(&lockdep_map);
- lock_map_release(&pwq->wq->lockdep_map);
+ lock_release(&lockdep_map, 0, _THIS_IP_);
+ lock_release(&pwq->wq->lockdep_map, 0, _THIS_IP_);

if (unlikely(in_atomic() || lockdep_depth(current) > 0)) {
pr_err("BUG: workqueue leaked lock or atomic: %s/0x%08x/%d\n"
@@ -2652,8 +2652,8 @@ void flush_workqueue(struct workqueue_struct *wq)
if (WARN_ON(!wq_online))
return;

- lock_map_acquire(&wq->lockdep_map);
- lock_map_release(&wq->lockdep_map);
+ lock_acquire_exclusive(&wq->lockdep_map, 0, 0, NULL, _THIS_IP_);
+ lock_release(&wq->lockdep_map, 0, _THIS_IP_);

mutex_lock(&wq->mutex);

@@ -2891,8 +2891,9 @@ static bool start_flush_work(struct work_struct *work, struct wq_barrier *barr,
*/
if (!from_cancel &&
(pwq->wq->saved_max_active == 1 || pwq->wq->rescuer)) {
- lock_map_acquire(&pwq->wq->lockdep_map);
- lock_map_release(&pwq->wq->lockdep_map);
+ lock_acquire_exclusive(&pwq->wq->lockdep_map, 0, 0, NULL,
+ _THIS_IP_);
+ lock_release(&pwq->wq->lockdep_map, 0, _THIS_IP_);
}

return true;
--
2.19.1.568.g152ad8e336-goog