]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.4.172/tty-ldsem-wake-up-readers-after-timed-out-down_write.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.4.172 / tty-ldsem-wake-up-readers-after-timed-out-down_write.patch
CommitLineData
99cc4e5f
GKH
1From 231f8fd0cca078bd4396dd7e380db813ac5736e2 Mon Sep 17 00:00:00 2001
2From: Dmitry Safonov <dima@arista.com>
3Date: Thu, 1 Nov 2018 00:24:46 +0000
4Subject: tty/ldsem: Wake up readers after timed out down_write()
5
6From: Dmitry Safonov <dima@arista.com>
7
8commit 231f8fd0cca078bd4396dd7e380db813ac5736e2 upstream.
9
10ldsem_down_read() will sleep if there is pending writer in the queue.
11If the writer times out, readers in the queue should be woken up,
12otherwise they may miss a chance to acquire the semaphore until the last
13active reader will do ldsem_up_read().
14
15There was a couple of reports where there was one active reader and
16other readers soft locked up:
17 Showing all locks held in the system:
18 2 locks held by khungtaskd/17:
19 #0: (rcu_read_lock){......}, at: watchdog+0x124/0x6d1
20 #1: (tasklist_lock){.+.+..}, at: debug_show_all_locks+0x72/0x2d3
21 2 locks held by askfirst/123:
22 #0: (&tty->ldisc_sem){.+.+.+}, at: ldsem_down_read+0x46/0x58
23 #1: (&ldata->atomic_read_lock){+.+...}, at: n_tty_read+0x115/0xbe4
24
25Prevent readers wait for active readers to release ldisc semaphore.
26
27Link: lkml.kernel.org/r/20171121132855.ajdv4k6swzhvktl6@wfg-t540p.sh.intel.com
28Link: lkml.kernel.org/r/20180907045041.GF1110@shao2-debian
29Cc: Jiri Slaby <jslaby@suse.com>
30Cc: Peter Zijlstra <peterz@infradead.org>
31Cc: stable@vger.kernel.org
32Reported-by: kernel test robot <rong.a.chen@intel.com>
33Signed-off-by: Dmitry Safonov <dima@arista.com>
34Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
35
36---
37 drivers/tty/tty_ldsem.c | 10 ++++++++++
38 1 file changed, 10 insertions(+)
39
40--- a/drivers/tty/tty_ldsem.c
41+++ b/drivers/tty/tty_ldsem.c
42@@ -307,6 +307,16 @@ down_write_failed(struct ld_semaphore *s
43 if (!locked)
44 ldsem_atomic_update(-LDSEM_WAIT_BIAS, sem);
45 list_del(&waiter.list);
46+
47+ /*
48+ * In case of timeout, wake up every reader who gave the right of way
49+ * to writer. Prevent separation readers into two groups:
50+ * one that helds semaphore and another that sleeps.
51+ * (in case of no contention with a writer)
52+ */
53+ if (!locked && list_empty(&sem->write_wait))
54+ __ldsem_wake_readers(sem);
55+
56 raw_spin_unlock_irq(&sem->wait_lock);
57
58 __set_task_state(tsk, TASK_RUNNING);