public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tty: annotate tty_lock() for lockdep
@ 2012-05-28 18:43 Jiri Kosina
  2012-05-31 11:31 ` Srikar Dronamraju
  0 siblings, 1 reply; 5+ messages in thread
From: Jiri Kosina @ 2012-05-28 18:43 UTC (permalink / raw)
  To: Alan Cox, Jiri Slaby; +Cc: linux-kernel, Greg Kroah-Hartman

=============================================
[ INFO: possible recursive locking detected ]
3.4.0-08218-gb48b2c3 #7 Not tainted
---------------------------------------------
blogd/279 is trying to acquire lock:
 (&tty->legacy_mutex){+.+.+.}, at: [<ffffffff8150f51e>] tty_lock+0x3e/0x90

but task is already holding lock:
 (&tty->legacy_mutex){+.+.+.}, at: [<ffffffff8150f51e>] tty_lock+0x3e/0x90

other info that might help us debug this:
 Possible unsafe locking scenario:

       CPU0
       ----
  lock(&tty->legacy_mutex);
  lock(&tty->legacy_mutex);

 *** DEADLOCK ***

[ .. stacktraces removed .. ]

This is a false positive stemming from the fact that lockdep doesn't
understand that proper lock ordering is already achieved in tty_lock_pair()
by ordering by struct tty address.

Introduce tty_lock_nested() to be able to express this explicit
ordering to lockdep and teach tty_lock_pair() to use it.

Signed-off-by: Jiri Kosina <jkosina@suse.cz>
---
 drivers/tty/tty_mutex.c |   22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/tty_mutex.c b/drivers/tty/tty_mutex.c
index 69adc80..90d43ad 100644
--- a/drivers/tty/tty_mutex.c
+++ b/drivers/tty/tty_mutex.c
@@ -10,7 +10,7 @@
  * Getting the big tty mutex.
  */
 
-void __lockfunc tty_lock(struct tty_struct *tty)
+void tty_lock_common(struct tty_struct *tty)
 {
 	if (tty->magic != TTY_MAGIC) {
 		printk(KERN_ERR "L Bad %p\n", tty);
@@ -18,10 +18,22 @@ void __lockfunc tty_lock(struct tty_struct *tty)
 		return;
 	}
 	tty_kref_get(tty);
+}
+
+void __lockfunc tty_lock(struct tty_struct *tty)
+{
+	tty_lock_common(tty);
 	mutex_lock(&tty->legacy_mutex);
 }
 EXPORT_SYMBOL(tty_lock);
 
+void __lockfunc tty_lock_nested(struct tty_struct *tty,
+					unsigned int subclass)
+{
+	tty_lock_common(tty);
+	mutex_lock_nested(&tty->legacy_mutex, subclass);
+}
+
 void __lockfunc tty_unlock(struct tty_struct *tty)
 {
 	if (tty->magic != TTY_MAGIC) {
@@ -42,12 +54,12 @@ void __lockfunc tty_lock_pair(struct tty_struct *tty,
 					struct tty_struct *tty2)
 {
 	if (tty < tty2) {
-		tty_lock(tty);
-		tty_lock(tty2);
+		tty_lock_nested(tty, 1);
+		tty_lock_nested(tty2, 2);
 	} else {
 		if (tty2 && tty2 != tty)
-			tty_lock(tty2);
-		tty_lock(tty);
+			tty_lock_nested(tty2, 2);
+		tty_lock_nested(tty, 1);
 	}
 }
 EXPORT_SYMBOL(tty_lock_pair);

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-05-31 15:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-28 18:43 [PATCH] tty: annotate tty_lock() for lockdep Jiri Kosina
2012-05-31 11:31 ` Srikar Dronamraju
2012-05-31 11:55   ` Eric Dumazet
2012-05-31 13:21     ` Srikar Dronamraju
2012-05-31 15:13       ` Srikar Dronamraju

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox