[PATCH v2 13/17] locking/lockdep: Add nest lock type

Yuyang Du
2019-05-16T08:01:14Z

Add a macro LOCK_TYPE_NEST for nest lock type and mark the nested lock in
check_deadlock_current(). Unlike the other LOCK_TYPE_* enums, this lock type
is used only in lockdep.

No functional change.

Signed-off-by: Yuyang Du <duyuyang@gmail.com>
---
kernel/locking/lockdep.c | 7 +++++--
kernel/locking/lockdep_internals.h | 1 +
2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index ce79b5a..d8e484d 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -2527,6 +2527,7 @@ static inline void inc_chains(void)
* 0: on deadlock detected;
* 1: on OK;
* 3: LOCK_TYPE_RECURSIVE on recursive read
+ * 4: LOCK_TYPE_NEST on nest lock
*/
static int
check_deadlock_current(struct task_struct *curr, struct held_lock *next)
@@ -2556,7 +2557,7 @@ static inline void inc_chains(void)
* nesting behaviour.
*/
if (nest)
- return LOCK_TYPE_RECURSIVE;
+ return LOCK_TYPE_NEST;

print_deadlock_bug(curr, prev, next);
return 0;
@@ -3131,11 +3132,13 @@ static int validate_chain(struct task_struct *curr,

if (!ret)
return 0;
+
/*
* Add dependency only if this lock is not the head
* of the chain, and if it's not a secondary read-lock:
*/
- if (!chain_head && ret != LOCK_TYPE_RECURSIVE) {
+ if (!chain_head && ret != LOCK_TYPE_RECURSIVE &&
+ ret != LOCK_TYPE_NEST) {
if (!check_prevs_add(curr, hlock))
return 0;
}
diff --git a/kernel/locking/lockdep_internals.h b/kernel/locking/lockdep_internals.h
index c287bcb..759e740 100644
--- a/kernel/locking/lockdep_internals.h
+++ b/kernel/locking/lockdep_internals.h
@@ -28,6 +28,7 @@ enum lock_usage_bit {

#define LOCK_TYPE_BITS 16
#define LOCK_TYPE_MASK 0xFFFF
+#define LOCK_TYPE_NEST (LOCK_TYPE_RECURSIVE + 1)

/*
* Usage-state bitmasks:
--
1.8.3.1