Skip to content

Commit 7b1f8c6

Browse files
fbqPeter Zijlstra
authored andcommitted
lockding/lockdep: Avoid to find wrong lock dep path in check_irq_usage()
In the step #3 of check_irq_usage(), we seach backwards to find a lock whose usage conflicts the usage of @target_entry1 on safe/unsafe. However, we should only keep the irq-unsafe usage of @target_entry1 into consideration, because it could be a case where a lock is hardirq-unsafe but soft-safe, and in check_irq_usage() we find it because its hardirq-unsafe could result into a hardirq-safe-unsafe deadlock, but currently since we don't filter out the other usage bits, so we may find a lock dependency path softirq-unsafe -> softirq-safe, which in fact doesn't cause a deadlock. And this may cause misleading lockdep splats. Fix this by only keeping LOCKF_ENABLED_IRQ_ALL bits when we try the backwards search. Reported-by: Johannes Berg <johannes@sipsolutions.net> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lore.kernel.org/r/20210618170110.3699115-4-boqun.feng@gmail.com
1 parent d4c157c commit 7b1f8c6

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

kernel/locking/lockdep.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2768,8 +2768,18 @@ static int check_irq_usage(struct task_struct *curr, struct held_lock *prev,
27682768
* Step 3: we found a bad match! Now retrieve a lock from the backward
27692769
* list whose usage mask matches the exclusive usage mask from the
27702770
* lock found on the forward list.
2771+
*
2772+
* Note, we should only keep the LOCKF_ENABLED_IRQ_ALL bits, considering
2773+
* the follow case:
2774+
*
2775+
* When trying to add A -> B to the graph, we find that there is a
2776+
* hardirq-safe L, that L -> ... -> A, and another hardirq-unsafe M,
2777+
* that B -> ... -> M. However M is **softirq-safe**, if we use exact
2778+
* invert bits of M's usage_mask, we will find another lock N that is
2779+
* **softirq-unsafe** and N -> ... -> A, however N -> .. -> M will not
2780+
* cause a inversion deadlock.
27712781
*/
2772-
backward_mask = original_mask(target_entry1->class->usage_mask);
2782+
backward_mask = original_mask(target_entry1->class->usage_mask & LOCKF_ENABLED_IRQ_ALL);
27732783

27742784
ret = find_usage_backwards(&this, backward_mask, &target_entry);
27752785
if (bfs_error(ret)) {

0 commit comments

Comments
 (0)