All of
 help / color / mirror / Atom feed
From: Yuyang Du <>
	Yuyang Du <>
Subject: [PATCH v3 18/18] locking/lockdep: Add explanation to lock usage rules in lockdep design doc
Date: Thu, 21 Mar 2019 15:57:25 +0800	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

The rules that if violated a deacklock may happen are explained in more
detail concerning both irqs and circular dependencies.

Signed-off-by: Yuyang Du <>
 Documentation/locking/lockdep-design.txt | 35 +++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 10 deletions(-)

diff --git a/Documentation/locking/lockdep-design.txt b/Documentation/locking/lockdep-design.txt
index 1dcceaa..83803c6 100644
--- a/Documentation/locking/lockdep-design.txt
+++ b/Documentation/locking/lockdep-design.txt
@@ -105,14 +105,24 @@ Unused locks (e.g., mutexes) cannot be part of the cause of an error.
 Single-lock state rules:
+A lock is irq-safe means it was ever used in an irq context, while a lock
+is irq-unsafe means it was ever acquired with irq enabled.
 A softirq-unsafe lock-class is automatically hardirq-unsafe as well. The
-following states are exclusive, and only one of them is allowed to be
-set for any lock-class:
+following states must be exclusive: only one of them is allowed to be set
+for any lock-class based on its usage:
+ <hardirq-safe> or <hardirq-unsafe>
+ <softirq-safe> or <softirq-unsafe>
- <hardirq-safe> and <hardirq-unsafe>
- <softirq-safe> and <softirq-unsafe>
+This is because if a lock can be used in irq (safe) then it cannot be ever
+acquired with irq enabled (unsafe). Otherwise, a deadlock may happen. For
+example, in the scenario that after this lock was acquired but before
+released, if the context is interrupted this lock will be attempted to
+acquire twice, which creates a deadlock, sometimes referred to as lock
+recursion deadlock.
-The validator detects and reports lock usage that violate these
+The validator detects and reports lock usage that violates these
 single-lock state rules.
 Multi-lock dependency rules:
@@ -121,15 +131,20 @@ Multi-lock dependency rules:
 The same lock-class must not be acquired twice, because this could lead
 to lock recursion deadlocks.
-Furthermore, two locks may not be taken in different order:
+Furthermore, two locks can not be taken in inverse order:
  <L1> -> <L2>
  <L2> -> <L1>
-because this could lead to lock inversion deadlocks. (The validator
-finds such dependencies in arbitrary complexity, i.e. there can be any
-other locking sequence between the acquire-lock operations, the
-validator will still track all dependencies between locks.)
+because it could lead to a deadlock - sometimes referred to as lock
+inversion deadlock - as attempts to acquire the two locks form a circle
+which could lead to two contexts waiting for each other permanently, namely
+the two contexts are holding one lock while waiting for acquiring the other
+in an inverse order. The validator will find such circle in arbitrary
+complexity. In other words, there can be any number of locking sequences
+between two acquire-lock operations (holding one lock while acquiring
+another); the validator will still find whether these locks can be acquired
+in a circular fashion.
 Furthermore, the following usage based lock dependencies are not allowed
 between any two lock-classes:

  parent reply	other threads:[~2019-03-21  7:58 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-21  7:57 [PATCH v3 00/18] locking/lockdep: Add comments and make some code Yuyang Du
2019-03-21  7:57 ` [PATCH v3 01/18] locking/lockdep: Change all print_*() return type to void Yuyang Du
2019-03-21  7:57 ` [PATCH v3 02/18] locking/lockdep: Add description and explanation in lockdep design doc Yuyang Du
2019-03-21  7:57 ` [PATCH v3 03/18] locking/lockdep: Adjust lock usage bit character checks Yuyang Du
2019-03-21  7:57 ` [PATCH v3 04/18] locking/lockdep: Remove useless conditional macro Yuyang Du
2019-03-21  7:57 ` [PATCH v3 05/18] locking/lockdep: Print the right depth for chain key colission Yuyang Du
2019-03-21  7:57 ` [PATCH v3 06/18] locking/lockdep: Update obsolete struct field description Yuyang Du
2019-03-21  7:57 ` [PATCH v3 07/18] locking/lockdep: Use lockdep_init_task for task initiation consistently Yuyang Du
2019-03-21  7:57 ` [PATCH v3 08/18] locking/lockdep: Define INITIAL_CHAIN_KEY for chain keys to start with Yuyang Du
2019-03-21  7:57 ` [PATCH v3 09/18] locking/lockdep: Change the range of class_idx in held_lock struct Yuyang Du
2019-03-21  7:57 ` [PATCH v3 10/18] locking/lockdep: Remove unused argument in validate_chain() and check_deadlock() Yuyang Du
2019-03-21  7:57 ` [PATCH v3 11/18] locking/lockdep: Update comment Yuyang Du
2019-03-21  7:57 ` [PATCH v3 12/18] locking/lockdep: Remove unnecessary function pointer argument Yuyang Du
2019-03-21  7:57 ` [PATCH v3 13/18] locking/lockdep: Change type of the element field in circular_queue Yuyang Du
2019-03-21  7:57 ` [PATCH v3 14/18] locking/lockdep: Change the return type of __cq_dequeue() Yuyang Du
2019-03-21  7:57 ` [PATCH v3 15/18] locking/lockdep: Avoid constant checks in __bfs by using offset reference Yuyang Du
2019-03-21  7:57 ` [PATCH v3 16/18] locking/lockdep: Combine check_noncircular and check_redundant Yuyang Du
2019-03-21  7:57 ` [PATCH v3 17/18] locking/lockdep: Update comments on dependency search Yuyang Du
2019-03-21  7:57 ` Yuyang Du [this message]
2019-04-04  5:03   ` Question on a lockdep test case about mixed read-write ABBA Yuyang Du

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.