Skip to contentSkip to conversation

locking: Giving mutex warning more precisely in case of !lock->owner

PATCH New Chuansheng Liu 2 participants 2 messages Dec 4, 2013 – Dec 18, 2013 Locking primitives

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 locking: Giving mutex warning more precisely in case of !lock->owner

When enabling mutex debugging, in case the imbalanced mutex_unlock() is called, we still get the warning like below:

[  364.208284] DEBUG_LOCKS_WARN_ON(lock->owner != current)

But in that case, it is due to imbalanced mutex_unlock calling, and the lock->owner is NULL.

Here we can enhance the case to give the warning as below:
DEBUG_LOCKS_WARN_ON(lock->owner == NULL)

---
 kernel/locking/mutex-debug.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/locking/mutex-debug.c +6 -1
index 7e3443f..b2a1b96 100644
@@ -75,7 +75,12 @@ void debug_mutex_unlock(struct mutex *lock)
 		return;
 
 	DEBUG_LOCKS_WARN_ON(lock->magic != lock);
-	DEBUG_LOCKS_WARN_ON(lock->owner != current);
+
+	if (!lock->owner)
+		DEBUG_LOCKS_WARN_ON(lock->owner == NULL);
+	else
+		DEBUG_LOCKS_WARN_ON(lock->owner != current);
+
 	DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
 	mutex_clear_owner(lock);
 }
Signature · 1 line
1.7.9.5
#1 lore raw

[tip:core/locking] mutexes: Give more informative mutex warning in the !lock->owner case

mutexes: Give more informative mutex warning in the !lock->owner case
Commit-ID:  91f30a17024ff0d8345e11228af33ee938b13426
Gitweb:     http://git.kernel.org/tip/91f30a17024ff0d8345e11228af33ee938b13426
Author:     Chuansheng Liu <[email protected]>
AuthorDate: Wed, 4 Dec 2013 13:58:13 +0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 17 Dec 2013 15:35:10 +0100

mutexes: Give more informative mutex warning in the !lock->owner case

When mutex debugging is enabled and an imbalanced mutex_unlock() is called, we get the following, slightly confusing warning:

  [  364.208284] DEBUG_LOCKS_WARN_ON(lock->owner != current)

But in that case the warning is due to an imbalanced mutex_unlock() call, and the lock->owner is NULL - so the message is misleading.

So improve the message by testing for this case specifically:

DEBUG_LOCKS_WARN_ON(!lock->owner)

Cc Linus Torvalds <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Paul E. McKenney <[email protected]>
[ Improved the changelog, changed the patch to use !lock->owner consistently. ]
---
 kernel/locking/mutex-debug.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/locking/mutex-debug.c +6 -1
index 7e3443f..faf6f5b 100644
@@ -75,7 +75,12 @@ void debug_mutex_unlock(struct mutex *lock)
 		return;
 
 	DEBUG_LOCKS_WARN_ON(lock->magic != lock);
-	DEBUG_LOCKS_WARN_ON(lock->owner != current);
+
+	if (!lock->owner)
+		DEBUG_LOCKS_WARN_ON(!lock->owner);
+	else
+		DEBUG_LOCKS_WARN_ON(lock->owner != current);
+
 	DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
 	mutex_clear_owner(lock);
 }