[PATCH v3 25/30] locking/lockdep: Add nest lock type

From: Yuyang Du
Date: Fri Jun 28 2019 - 05:17:38 EST


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@xxxxxxxxx>
---
kernel/locking/lockdep.c | 7 +++++--
kernel/locking/lockdep_internals.h | 2 ++
2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index e7610d2..cb3a1d3 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -2517,6 +2517,7 @@ static inline void inc_chains(void)
* 0: on deadlock detected;
* 1: on OK;
* LOCK_TYPE_RECURSIVE: on recursive read
+ * LOCK_TYPE_NEST: on nest lock
*/
static int
check_deadlock_current(struct task_struct *curr, struct held_lock *next)
@@ -2546,7 +2547,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;
@@ -3049,12 +3050,14 @@ static int validate_chain(struct task_struct *curr, struct held_lock *next,

if (!ret)
return 0;
+
/*
* Add dependency only if this lock is not the head of the
* chain, and if it's not a second recursive-read lock. If
* not, there is no need to check further.
*/
- if (!(chain->depth > 1 && ret != LOCK_TYPE_RECURSIVE))
+ if (!(chain->depth > 1 && ret != LOCK_TYPE_RECURSIVE &&
+ ret != LOCK_TYPE_NEST))
goto out_unlock;
}

diff --git a/kernel/locking/lockdep_internals.h b/kernel/locking/lockdep_internals.h
index e9a8ed6..56fac83 100644
--- a/kernel/locking/lockdep_internals.h
+++ b/kernel/locking/lockdep_internals.h
@@ -26,6 +26,8 @@ enum lock_usage_bit {
#define LOCK_USAGE_DIR_MASK 2
#define LOCK_USAGE_STATE_MASK (~(LOCK_USAGE_READ_MASK | LOCK_USAGE_DIR_MASK))

+#define LOCK_TYPE_NEST NR_LOCK_TYPE
+
/*
* Usage-state bitmasks:
*/
--
1.8.3.1