Skip to content

Commit fd1a5b0

Browse files
lgebyungchulparkIngo Molnar
authored andcommitted
workqueue: Remove now redundant lock acquisitions wrt. workqueue flushes
The workqueue code added manual lock acquisition annotations to catch deadlocks. After lockdepcrossrelease was introduced, some of those became redundant, since wait_for_completion() already does the acquisition and tracking. Remove the duplicate annotations. Signed-off-by: Byungchul Park <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent a7967bc commit fd1a5b0

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

include/linux/workqueue.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ static inline unsigned int work_static(struct work_struct *work) { return 0; }
218218
\
219219
__init_work((_work), _onstack); \
220220
(_work)->data = (atomic_long_t) WORK_DATA_INIT(); \
221-
lockdep_init_map(&(_work)->lockdep_map, #_work, &__key, 0); \
221+
lockdep_init_map(&(_work)->lockdep_map, "(work_completion)"#_work, &__key, 0); \
222222
INIT_LIST_HEAD(&(_work)->entry); \
223223
(_work)->func = (_func); \
224224
} while (0)
@@ -398,7 +398,7 @@ __alloc_workqueue_key(const char *fmt, unsigned int flags, int max_active,
398398
static struct lock_class_key __key; \
399399
const char *__lock_name; \
400400
\
401-
__lock_name = #fmt#args; \
401+
__lock_name = "(wq_completion)"#fmt#args; \
402402
\
403403
__alloc_workqueue_key((fmt), (flags), (max_active), \
404404
&__key, __lock_name, ##args); \

kernel/workqueue.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,15 +2497,8 @@ static void insert_wq_barrier(struct pool_workqueue *pwq,
24972497
INIT_WORK_ONSTACK(&barr->work, wq_barrier_func);
24982498
__set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(&barr->work));
24992499

2500-
/*
2501-
* Explicitly init the crosslock for wq_barrier::done, make its lock
2502-
* key a subkey of the corresponding work. As a result we won't
2503-
* build a dependency between wq_barrier::done and unrelated work.
2504-
*/
2505-
lockdep_init_map_crosslock((struct lockdep_map *)&barr->done.map,
2506-
"(complete)wq_barr::done",
2507-
target->lockdep_map.key, 1);
2508-
__init_completion(&barr->done);
2500+
init_completion_map(&barr->done, &target->lockdep_map);
2501+
25092502
barr->task = current;
25102503

25112504
/*
@@ -2611,16 +2604,13 @@ void flush_workqueue(struct workqueue_struct *wq)
26112604
struct wq_flusher this_flusher = {
26122605
.list = LIST_HEAD_INIT(this_flusher.list),
26132606
.flush_color = -1,
2614-
.done = COMPLETION_INITIALIZER_ONSTACK(this_flusher.done),
2607+
.done = COMPLETION_INITIALIZER_ONSTACK_MAP(this_flusher.done, wq->lockdep_map),
26152608
};
26162609
int next_color;
26172610

26182611
if (WARN_ON(!wq_online))
26192612
return;
26202613

2621-
lock_map_acquire(&wq->lockdep_map);
2622-
lock_map_release(&wq->lockdep_map);
2623-
26242614
mutex_lock(&wq->mutex);
26252615

26262616
/*
@@ -2883,9 +2873,6 @@ bool flush_work(struct work_struct *work)
28832873
if (WARN_ON(!wq_online))
28842874
return false;
28852875

2886-
lock_map_acquire(&work->lockdep_map);
2887-
lock_map_release(&work->lockdep_map);
2888-
28892876
if (start_flush_work(work, &barr)) {
28902877
wait_for_completion(&barr.done);
28912878
destroy_work_on_stack(&barr.work);

0 commit comments

Comments
 (0)