]>
Commit | Line | Data |
---|---|---|
99cc4e5f GKH |
1 | From 231f8fd0cca078bd4396dd7e380db813ac5736e2 Mon Sep 17 00:00:00 2001 |
2 | From: Dmitry Safonov <dima@arista.com> | |
3 | Date: Thu, 1 Nov 2018 00:24:46 +0000 | |
4 | Subject: tty/ldsem: Wake up readers after timed out down_write() | |
5 | ||
6 | From: Dmitry Safonov <dima@arista.com> | |
7 | ||
8 | commit 231f8fd0cca078bd4396dd7e380db813ac5736e2 upstream. | |
9 | ||
10 | ldsem_down_read() will sleep if there is pending writer in the queue. | |
11 | If the writer times out, readers in the queue should be woken up, | |
12 | otherwise they may miss a chance to acquire the semaphore until the last | |
13 | active reader will do ldsem_up_read(). | |
14 | ||
15 | There was a couple of reports where there was one active reader and | |
16 | other 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 | ||
25 | Prevent readers wait for active readers to release ldisc semaphore. | |
26 | ||
27 | Link: lkml.kernel.org/r/20171121132855.ajdv4k6swzhvktl6@wfg-t540p.sh.intel.com | |
28 | Link: lkml.kernel.org/r/20180907045041.GF1110@shao2-debian | |
29 | Cc: Jiri Slaby <jslaby@suse.com> | |
30 | Cc: Peter Zijlstra <peterz@infradead.org> | |
31 | Cc: stable@vger.kernel.org | |
32 | Reported-by: kernel test robot <rong.a.chen@intel.com> | |
33 | Signed-off-by: Dmitry Safonov <dima@arista.com> | |
34 | Signed-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); |