Peter Hurley
aefceaf453
n_tty: Fix termios_rwsem lockdep false positive
Lockdep reports a circular lock dependency between
atomic_read_lock and termios_rwsem [1]. However, a lock
order deadlock is not possible since CPU1 only holds a
read lock which cannot prevent CPU0 from also acquiring
a read lock on the same r/w semaphore.
Unfortunately, lockdep cannot currently distinguish whether
the locks are read or write for any particular lock graph,
merely that the locks _were_ previously read and/or write.
Until lockdep is fixed, re-order atomic_read_lock so
termios_rwsem can be dropped and reacquired without
triggering lockdep.
Patch based on original posted here https://lkml.org/lkml/2013/8/1/510
by Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
[1] Initial lockdep report from Artem Savkov <artem.savkov@gmail.com>
======================================================
[ INFO: possible circular locking dependency detected ]
3.11.0-rc3-next-20130730+ #140 Tainted: G W
-------------------------------------------------------
bash/1198 is trying to acquire lock:
(&tty->termios_rwsem){++++..}, at: [<ffffffff816aa3bb>] n_tty_read+0x49b/0x660
but task is already holding lock:
(&ldata->atomic_read_lock){+.+...}, at: [<ffffffff816aa0f0>] n_tty_read+0x1d0/0x660
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #1 (&ldata->atomic_read_lock){+.+...}:
[<ffffffff811111cc>] validate_chain+0x73c/0x850
[<ffffffff811117e0>] __lock_acquire+0x500/0x5d0
[<ffffffff81111a29>] lock_acquire+0x179/0x1d0
[<ffffffff81d34b9c>] mutex_lock_interruptible_nested+0x7c/0x540
[<ffffffff816aa0f0>] n_tty_read+0x1d0/0x660
[<ffffffff816a3bb6>] tty_read+0x86/0xf0
[<ffffffff811f21d3>] vfs_read+0xc3/0x130
[<ffffffff811f2702>] SyS_read+0x62/0xa0
[<ffffffff81d45259>] system_call_fastpath+0x16/0x1b
-> #0 (&tty->termios_rwsem){++++..}:
[<ffffffff8111064f>] check_prev_add+0x14f/0x590
[<ffffffff811111cc>] validate_chain+0x73c/0x850
[<ffffffff811117e0>] __lock_acquire+0x500/0x5d0
[<ffffffff81111a29>] lock_acquire+0x179/0x1d0
[<ffffffff81d372c1>] down_read+0x51/0xa0
[<ffffffff816aa3bb>] n_tty_read+0x49b/0x660
[<ffffffff816a3bb6>] tty_read+0x86/0xf0
[<ffffffff811f21d3>] vfs_read+0xc3/0x130
[<ffffffff811f2702>] SyS_read+0x62/0xa0
[<ffffffff81d45259>] system_call_fastpath+0x16/0x1b
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(&ldata->atomic_read_lock);
lock(&tty->termios_rwsem);
lock(&ldata->atomic_read_lock);
lock(&tty->termios_rwsem);
*** DEADLOCK ***
2 locks held by bash/1198:
#0: (&tty->ldisc_sem){.+.+.+}, at: [<ffffffff816ade04>] tty_ldisc_ref_wait+0x24/0x60
#1: (&ldata->atomic_read_lock){+.+...}, at: [<ffffffff816aa0f0>] n_tty_read+0x1d0/0x660
stack backtrace:
CPU: 1 PID: 1198 Comm: bash Tainted: G W 3.11.0-rc3-next-20130730+ #140
Hardware name: Bochs Bochs, BIOS Bochs 01/01/2007
0000000000000000 ffff880019acdb28 ffffffff81d34074 0000000000000002
0000000000000000 ffff880019acdb78 ffffffff8110ed75 ffff880019acdb98
ffff880019fd0000 ffff880019acdb78 ffff880019fd0638 ffff880019fd0670
Call Trace:
[<ffffffff81d34074>] dump_stack+0x59/0x7d
[<ffffffff8110ed75>] print_circular_bug+0x105/0x120
[<ffffffff8111064f>] check_prev_add+0x14f/0x590
[<ffffffff81d3ab5f>] ? _raw_spin_unlock_irq+0x4f/0x70
[<ffffffff811111cc>] validate_chain+0x73c/0x850
[<ffffffff8110ae0f>] ? trace_hardirqs_off_caller+0x1f/0x190
[<ffffffff811117e0>] __lock_acquire+0x500/0x5d0
[<ffffffff81111a29>] lock_acquire+0x179/0x1d0
[<ffffffff816aa3bb>] ? n_tty_read+0x49b/0x660
[<ffffffff81d372c1>] down_read+0x51/0xa0
[<ffffffff816aa3bb>] ? n_tty_read+0x49b/0x660
[<ffffffff816aa3bb>] n_tty_read+0x49b/0x660
[<ffffffff810e4130>] ? try_to_wake_up+0x210/0x210
[<ffffffff816a3bb6>] tty_read+0x86/0xf0
[<ffffffff811f21d3>] vfs_read+0xc3/0x130
[<ffffffff811f2702>] SyS_read+0x62/0xa0
[<ffffffff815e24ee>] ? trace_hardirqs_on_thunk+0x3a/0x3f
[<ffffffff81d45259>] system_call_fastpath+0x16/0x1b
Reported-by: Artem Savkov <artem.savkov@gmail.com>
Reported-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-08-12 11:10:17 -07:00
..
2013-07-31 14:41:03 -07:00
2013-07-30 14:00:42 +02:00
2013-07-26 08:57:56 -04:00
2013-07-18 12:48:40 -07:00
2013-06-27 13:42:16 -04:00
2013-07-22 19:02:52 -07:00
2013-07-31 15:11:50 -04:00
2013-07-02 14:23:01 -07:00
2013-07-03 16:07:25 -07:00
2013-07-31 23:42:00 +02:00
2013-07-03 14:35:40 -07:00
2013-07-14 19:36:57 -04:00
2013-07-30 00:32:00 +02:00
2013-07-29 13:32:29 +02:00
2013-07-24 11:05:18 -07:00
2013-07-03 17:12:13 -07:00
2013-07-28 19:08:33 +05:30
2013-07-23 16:01:28 -07:00
2013-07-03 16:07:41 -07:00
2013-07-27 20:24:36 +02:00
2013-07-31 14:41:02 -07:00
2013-07-31 00:34:31 +02:00
2013-08-04 11:03:14 +10:00
2013-08-02 14:22:15 -07:00
2013-07-03 16:07:41 -07:00
2013-07-16 23:19:19 -07:00
2013-08-03 07:04:50 -07:00
2013-07-13 14:52:21 -07:00
2013-07-10 18:15:41 -07:00
2013-07-16 22:41:38 -07:00
2013-07-31 14:24:06 -07:00
2013-07-13 18:05:13 -07:00
2013-07-10 14:46:40 -07:00
2013-07-14 19:36:57 -04:00
2013-07-09 18:24:39 -07:00
2013-07-02 08:44:02 -07:00
2013-07-04 11:40:58 -07:00
2013-08-01 13:11:47 +10:00
2013-07-26 11:20:10 -07:00
2013-07-15 21:25:14 +02:00
2013-07-03 16:08:06 -07:00
2013-07-03 16:07:41 -07:00
2013-07-10 11:10:27 -07:00
2013-07-26 11:36:12 -07:00
2013-07-23 12:15:15 -07:00
2013-07-05 12:09:48 -07:00
2013-08-05 05:41:03 +08:00
2013-07-09 18:24:39 -07:00
2013-07-22 19:40:38 +01:00
2013-07-14 19:36:59 -04:00
2013-07-31 23:42:32 +02:00
2013-07-03 17:12:13 -07:00
2013-08-02 13:12:52 -07:00
2013-07-02 11:44:19 -07:00
2013-07-25 17:18:36 +02:00
2013-07-10 15:42:51 -04:00
2013-07-18 01:38:59 +02:00
2013-07-10 11:13:00 -07:00
2013-07-03 16:08:06 -07:00
2013-06-26 23:23:54 +02:00
2013-07-31 14:41:02 -07:00
2013-07-10 11:10:27 -07:00
2013-07-11 12:35:09 -07:00
2013-07-31 14:41:03 -07:00
2013-07-19 08:37:39 +02:00
2013-07-24 14:18:12 -07:00
2013-06-28 13:01:40 +02:00
2013-07-15 11:46:16 +01:00
2013-07-13 14:52:21 -07:00
2013-07-29 12:32:30 -07:00
2013-07-11 12:57:19 -07:00
2013-07-22 09:34:46 +08:00
2013-08-12 11:10:17 -07:00
2013-07-03 16:07:26 -07:00
2013-07-29 13:38:38 -07:00
2013-07-03 16:07:41 -07:00
2013-07-24 16:36:41 -06:00
2013-07-23 14:38:20 -07:00
2013-07-31 17:54:24 -07:00
2013-07-10 14:50:58 -07:00
2013-07-03 16:08:06 -07:00
2013-07-13 14:52:21 -07:00
2013-07-31 11:37:43 -07:00
2013-06-29 12:57:28 +04:00
2013-07-10 11:10:27 -07:00
2013-07-10 11:10:27 -07:00