<feed xmlns='http://www.w3.org/2005/Atom'>
<title>user/sven/linux.git/include/linux/tty_ldisc.h, branch v3.16.1</title>
<subtitle>Linux Kernel
</subtitle>
<id>https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v3.16.1</id>
<link rel='self' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v3.16.1'/>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/'/>
<updated>2014-04-24T23:16:33Z</updated>
<entry>
<title>tty_ldisc: add more limits to the @write_wakeup</title>
<updated>2014-04-24T23:16:33Z</updated>
<author>
<name>Huang Shijie</name>
<email>b32955@freescale.com</email>
</author>
<published>2014-04-23T14:58:25Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=879eb9c3f9b854394c5a2014b9243c00eaa329f0'/>
<id>urn:sha1:879eb9c3f9b854394c5a2014b9243c00eaa329f0</id>
<content type='text'>
In the uart_handle_cts_change(), uart_write_wakeup() is called after
we call @uart_port-&gt;ops-&gt;start_tx().

The Documentation/serial/driver tells us:
-----------------------------------------------
  start_tx(port)
	Start transmitting characters.

	Locking: port-&gt;lock taken.
	Interrupts: locally disabled.
-----------------------------------------------

So when the uart_write_wakeup() is called, the port-&gt;lock is taken by
the upper. See the following callstack:

	|_ uart_write_wakeup
	   |_ tty_wakeup
	      |_ ld-&gt;ops-&gt;write_wakeup

With the port-&gt;lock held, we call the @write_wakeup. Some implemetation of
the @write_wakeup does not notice that the port-&gt;lock is held, and it still
tries to send data with uart_write() which will try to grab the prot-&gt;lock.
A dead lock occurs, see the following log caught in the Bluetooth by uart:

--------------------------------------------------------------------
BUG: spinlock lockup suspected on CPU#0, swapper/0/0
 lock: 0xdc3f4410, .magic: dead4ead, .owner: swapper/0/0, .owner_cpu: 0
CPU: 0 PID: 0 Comm: swapper/0 Tainted: G        W    3.10.17-16839-ge4a1bef #1320
[&lt;80014cbc&gt;] (unwind_backtrace+0x0/0x138) from [&lt;8001251c&gt;] (show_stack+0x10/0x14)
[&lt;8001251c&gt;] (show_stack+0x10/0x14) from [&lt;802816ac&gt;] (do_raw_spin_lock+0x108/0x184)
[&lt;802816ac&gt;] (do_raw_spin_lock+0x108/0x184) from [&lt;806a22b0&gt;] (_raw_spin_lock_irqsave+0x54/0x60)
[&lt;806a22b0&gt;] (_raw_spin_lock_irqsave+0x54/0x60) from [&lt;802f5754&gt;] (uart_write+0x38/0xe0)
[&lt;802f5754&gt;] (uart_write+0x38/0xe0) from [&lt;80455270&gt;] (hci_uart_tx_wakeup+0xa4/0x168)
[&lt;80455270&gt;] (hci_uart_tx_wakeup+0xa4/0x168) from [&lt;802dab18&gt;] (tty_wakeup+0x50/0x5c)
[&lt;802dab18&gt;] (tty_wakeup+0x50/0x5c) from [&lt;802f81a4&gt;] (imx_rtsint+0x50/0x80)
[&lt;802f81a4&gt;] (imx_rtsint+0x50/0x80) from [&lt;802f88f4&gt;] (imx_int+0x158/0x17c)
[&lt;802f88f4&gt;] (imx_int+0x158/0x17c) from [&lt;8007abe0&gt;] (handle_irq_event_percpu+0x50/0x194)
[&lt;8007abe0&gt;] (handle_irq_event_percpu+0x50/0x194) from [&lt;8007ad60&gt;] (handle_irq_event+0x3c/0x5c)
--------------------------------------------------------------------

This patch adds more limits to the @write_wakeup, the one who wants to
implemet the @write_wakeup should follow the limits which avoid the deadlock.

Signed-off-by: Huang Shijie &lt;b32955@freescale.com&gt;
Signed-off-by: Felipe Balbi &lt;balbi@ti.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>tty: tty_ldisc.h: Remove duplicate include</title>
<updated>2014-02-18T20:50:26Z</updated>
<author>
<name>Sachin Kamat</name>
<email>sachin.kamat@linaro.org</email>
</author>
<published>2014-02-17T09:49:18Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=c957dd494615ccdb36d4892ef9bfd2287502fbfd'/>
<id>urn:sha1:c957dd494615ccdb36d4892ef9bfd2287502fbfd</id>
<content type='text'>
linux/wait.h was included twice.

Signed-off-by: Sachin Kamat &lt;sachin.kamat@linaro.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>tty: Always handle NULL flag ptr</title>
<updated>2013-12-09T00:56:05Z</updated>
<author>
<name>Peter Hurley</name>
<email>peter@hurleysoftware.com</email>
</author>
<published>2013-12-02T18:56:03Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=82f91fe092b6eacd82e976b8955443f9fd97d07e'/>
<id>urn:sha1:82f91fe092b6eacd82e976b8955443f9fd97d07e</id>
<content type='text'>
Most line disciplines already handle the undocumented NULL flag
ptr in their .receive_buf method; however, several don't.

Document the NULL flag ptr, and correct handling in the
N_MOUSE, N_GSM0710 and N_R394 line disciplines.

Signed-off-by: Peter Hurley &lt;peter@hurleysoftware.com&gt;
Acked-by: Dmitry Torokhov &lt;dmitry.torokhov@gmail.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>tty: Make ldisc input flow control concurrency-friendly</title>
<updated>2013-07-23T23:42:59Z</updated>
<author>
<name>Peter Hurley</name>
<email>peter@hurleysoftware.com</email>
</author>
<published>2013-06-15T13:14:15Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=24a89d1cb69b6c488cf16d98dd02e7820f62b40c'/>
<id>urn:sha1:24a89d1cb69b6c488cf16d98dd02e7820f62b40c</id>
<content type='text'>
Although line discipline receiving is single-producer/single-consumer,
using tty-&gt;receive_room to manage flow control creates unnecessary
critical regions requiring additional lock use.

Instead, introduce the optional .receive_buf2() ldisc method which
returns the # of bytes actually received. Serialization is guaranteed
by the caller.

In turn, the line discipline should schedule the buffer work item
whenever space becomes available; ie., when there is room to receive
data and receive_room() previously returned 0 (the buffer work
item stops processing if receive_buf2() returns 0). Note the
'no room' state need not be atomic despite concurrent use by two
threads because only the buffer work thread can set the state and
only the read() thread can clear the state.

Add n_tty_receive_buf2() as the receive_buf2() method for N_TTY.
Provide a public helper function, tty_ldisc_receive_buf(), to use
when directly accessing the receive_buf() methods.

Line disciplines not using input flow control can continue to set
tty-&gt;receive_room to a fixed value and only provide the receive_buf()
method.

Signed-off-by: Peter Hurley &lt;peter@hurleysoftware.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>tty: Replace ldisc locking with ldisc_sem</title>
<updated>2013-07-23T23:38:34Z</updated>
<author>
<name>Peter Hurley</name>
<email>peter@hurleysoftware.com</email>
</author>
<published>2013-06-15T11:04:48Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=36697529b5bbe36911e39a6309e7a7c9250d280a'/>
<id>urn:sha1:36697529b5bbe36911e39a6309e7a7c9250d280a</id>
<content type='text'>
Line discipline locking was performed with a combination of
a mutex, a status bit, a count, and a waitqueue -- basically,
a rw semaphore.

Replace the existing combination with an ld_semaphore.

Fixes:
 1) the 'reference acquire after ldisc locked' bug
 2) the over-complicated halt mechanism
 3) lock order wrt. tty_lock()
 4) dropping locks while changing ldisc
 5) previously unidentified deadlock while locking ldisc from
    both linked ttys concurrently
 6) previously unidentified recursive deadlocks

Adds much-needed lockdep diagnostics.

Signed-off-by: Peter Hurley &lt;peter@hurleysoftware.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>n_tty: Encapsulate minimum_to_wake within N_TTY</title>
<updated>2013-06-17T19:55:11Z</updated>
<author>
<name>Peter Hurley</name>
<email>peter@hurleysoftware.com</email>
</author>
<published>2013-06-15T11:28:28Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=f6c8dbe6e50c6e5121d7b6644718207daa008221'/>
<id>urn:sha1:f6c8dbe6e50c6e5121d7b6644718207daa008221</id>
<content type='text'>
minimum_to_wake is unique to N_TTY processing, and belongs in
per-ldisc data.

Add the ldisc method, ldisc_ops::fasync(), to notify line disciplines
when signal-driven I/O is enabled or disabled. When enabled for N_TTY
(by fcntl(F_SETFL, O_ASYNC)), blocking reader/polls will be woken
for any readable input. When disabled, blocking reader/polls are not
woken until the read buffer is full.

Canonical mode (L_ICANON(tty), n_tty_data::icanon) is not affected by
the minimum_to_wake setting.

Signed-off-by: Peter Hurley &lt;peter@hurleysoftware.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>tty: Add timed, writer-prioritized rw semaphore</title>
<updated>2013-05-20T19:30:32Z</updated>
<author>
<name>Peter Hurley</name>
<email>peter@hurleysoftware.com</email>
</author>
<published>2013-04-16T10:15:50Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=4898e640caf03fdbaf2122d5a33949bf3e4a5b34'/>
<id>urn:sha1:4898e640caf03fdbaf2122d5a33949bf3e4a5b34</id>
<content type='text'>
The semantics of a rw semaphore are almost ideally suited
for tty line discipline lifetime management;  multiple active
threads obtain "references" (read locks) while performing i/o
to prevent the loss or change of the current line discipline
(write lock).

Unfortunately, the existing rw_semaphore is ill-suited in other
ways;
1) TIOCSETD ioctl (change line discipline) expects to return an
   error if the line discipline cannot be exclusively locked within
   5 secs. Lock wait timeouts are not supported by rwsem.
2) A tty hangup is expected to halt and scrap pending i/o, so
   exclusive locking must be prioritized.
   Writer priority is not supported by rwsem.

Add ld_semaphore which implements these requirements in a
semantically similar way to rw_semaphore.

Writer priority is handled by separate wait lists for readers and
writers. Pending write waits are priortized before existing read
waits and prevent further read locks.

Wait timeouts are trivially added, but obviously change the lock
semantics as lock attempts can fail (but only due to timeout).

This implementation incorporates the write-lock stealing work of
Michel Lespinasse &lt;walken@google.com&gt;.

Cc: Michel Lespinasse &lt;walken@google.com&gt;
Signed-off-by: Peter Hurley &lt;peter@hurleysoftware.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>tty: Fix checkpatch errors in tty_ldisc.h</title>
<updated>2013-03-18T23:14:55Z</updated>
<author>
<name>Peter Hurley</name>
<email>peter@hurleysoftware.com</email>
</author>
<published>2013-03-06T13:38:21Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=6be06e7273c4682a15ca1f4adf1aeae510823530'/>
<id>urn:sha1:6be06e7273c4682a15ca1f4adf1aeae510823530</id>
<content type='text'>
Signed-off-by: Peter Hurley &lt;peter@hurleysoftware.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>pps: Move timestamp read into PPS code proper</title>
<updated>2013-02-13T18:13:58Z</updated>
<author>
<name>George Spelvin</name>
<email>linux@horizon.com</email>
</author>
<published>2013-02-12T07:00:43Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=593fb1ae457aab28b392ac114f6e3358788da985'/>
<id>urn:sha1:593fb1ae457aab28b392ac114f6e3358788da985</id>
<content type='text'>
The PPS (Pulse-Per-Second) line discipline has developed a number of
unhealthy attachments to core tty data and functions, ultimately leading
to its breakage.

The previous patches fixed the crashing.  This one reduces coupling further
by eliminating the timestamp parameter from the dcd_change ldisc method.
This reduces header file linkage and makes the extension more generic,
and the timestamp read is delayed only slightly, from just before the
ldisc-&gt;ops-&gt;dcd_change method call to just after.

Fix attendant build breakage in
    drivers/tty/n_tty.c
    drivers/tty/tty_buffer.c
    drivers/staging/speakup/selection.c
    drivers/staging/dgrp/dgrp_*.c

Cc: William Hubbs &lt;w.d.hubbs@gmail.com&gt;
Cc: Chris Brannon &lt;chris@the-brannons.com&gt;
Cc: Kirk Reiser &lt;kirk@braille.uwo.ca&gt;
Cc: Samuel Thibault &lt;samuel.thibault@ens-lyon.org&gt;
Signed-off-by: Peter Hurley &lt;peter@hurleysoftware.com&gt;
Signed-off-by: George Spelvin &lt;linux@horizon.com&gt;
Acked-by: Rodolfo Giometti &lt;giometti@enneenne.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>tty: move global ldisc idle waitqueue to the individual ldisc</title>
<updated>2012-05-10T18:24:03Z</updated>
<author>
<name>Ivo Sieben</name>
<email>meltedpianoman@gmail.com</email>
</author>
<published>2012-05-03T12:37:43Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=1541f845d123a48fbca3cee32b2963b3fb3da83a'/>
<id>urn:sha1:1541f845d123a48fbca3cee32b2963b3fb3da83a</id>
<content type='text'>
The global wait_queue that is used for line discipline idle handling is
moved to a separate wait_queue for each line instance. This prevents
unnecessary blocking on one line, because of idle handling on another
line.

Signed-off-by: Ivo Sieben &lt;meltedpianoman@gmail.com&gt;
Acked-by: Alan Cox &lt;alan@linux.intel.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
</feed>
