With the new lockdep crossrelease feature, which checks completions usage, a false positive is reported in the workqueue code: > Worker A : acquired of wfc.work -> wait for cpu_hotplug_lock to be released > Task B : acquired of cpu_hotplug_lock -> wait for lock#3 to be released > Task C : acquired of lock#3 -> wait for completion of barr->done > (Task C is in lru_add_drain_all_cpuslocked()) > Worker D : wait for wfc.work to be released -> will complete barr->done Such a dead lock can not happen because Task C's barr->done and Worker D's barr->done can not be the same instance. The reason of this false positive is we initialize all wq_barrier::done at insert_wq_barrier() via init_completion(), which makes them belong to the same lock class, therefore, impossible circles are reported. To fix this, explicitly initialize the lockdep map for wq_barrier::done in insert_wq_barrier(), so that the lock class key of wq_barrier::done is a subkey of the corresponding work_struct, as a result we won't build a dependency between a wq_barrier with a unrelated work, and we can differ wq barriers based on the related works, so the false positive above is avoided. Also define the empty lockdep_init_map_crosslock() for !CROSSRELEASE to make the code simple and away from unnecessary #ifdefs.
Showing the changes to kernel/workqueue.c (1 of 2 files). Show all
Unified · Split
| @@ -2476,7 +2476,16 @@ static void insert_wq_barrier(struct pool_workqueue *pwq, · 2475 unmodified lines | |||
| 2476 | */ | 2476 | */ |
| 2477 | INIT_WORK_ONSTACK(&barr->work, wq_barrier_func); | 2477 | INIT_WORK_ONSTACK(&barr->work, wq_barrier_func); |
| 2478 | __set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(&barr->work)); | 2478 | __set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(&barr->work)); |
| 2479 | init_completion(&barr->done); | 2479 | |
| 2480 | /* | ||
| 2481 | * Explicitly init the crosslock for wq_barrier::done, make its lock | ||
| 2482 | * key a subkey of the corresponding work. As a result we won't | ||
| 2483 | * build a dependency between wq_barrier::done and unrelated work. | ||
| 2484 | */ | ||
| 2485 | lockdep_init_map_crosslock((struct lockdep_map *)&barr->done.map, | ||
| 2486 | "(complete)wq_barr::done", | ||
| 2487 | target->lockdep_map.key, 1); | ||
| 2488 | __init_completion(&barr->done); | ||
| 2480 | barr->task = current; | 2489 | barr->task = current; |
| 2481 | 2490 | ||
| 2482 | /* | 2491 | /* |