From: Peter Hurley <peter@hurleysoftware.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jslaby@suse.cz>,
One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk>,
linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
Peter Hurley <peter@hurleysoftware.com>
Subject: [PATCH 23/26] tty: Move packet mode flow control notifications to pty driver
Date: Tue, 2 Sep 2014 17:39:32 -0400 [thread overview]
Message-ID: <1409693975-1028-24-git-send-email-peter@hurleysoftware.com> (raw)
In-Reply-To: <1409693975-1028-1-git-send-email-peter@hurleysoftware.com>
When a master pty is set to packet mode, flow control changes to
the slave pty cause notifications to the master pty via reads and
polls. However, these tests are occurring for all ttys, not
just ptys.
Implement flow control packet mode notifications in the pty driver.
Only the slave side implements the flow control handlers since
packet mode is asymmetric; the master pty receives notifications
for slave-side changes, but not vice versa.
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
---
drivers/tty/pty.c | 41 +++++++++++++++++++++++++++++++++++++++++
drivers/tty/tty_io.c | 31 ++++---------------------------
2 files changed, 45 insertions(+), 27 deletions(-)
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index 25c9bc7..c344de0 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -24,6 +24,7 @@
#include <linux/devpts_fs.h>
#include <linux/slab.h>
#include <linux/mutex.h>
+#include <linux/poll.h>
#ifdef CONFIG_UNIX98_PTYS
@@ -313,6 +314,42 @@ done:
}
/**
+ * pty_start - start() handler
+ * pty_stop - stop() handler
+ * @tty: tty being flow-controlled
+ *
+ * Propagates the TIOCPKT status to the master pty.
+ *
+ * NB: only the master pty can be in packet mode so only the slave
+ * needs start()/stop() handlers
+ */
+static void pty_start(struct tty_struct *tty)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&tty->ctrl_lock, flags);
+ if (tty->link && tty->link->packet) {
+ tty->ctrl_status &= ~TIOCPKT_STOP;
+ tty->ctrl_status |= TIOCPKT_START;
+ wake_up_interruptible_poll(&tty->link->read_wait, POLLIN);
+ }
+ spin_unlock_irqrestore(&tty->ctrl_lock, flags);
+}
+
+static void pty_stop(struct tty_struct *tty)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&tty->ctrl_lock, flags);
+ if (tty->link && tty->link->packet) {
+ tty->ctrl_status &= ~TIOCPKT_START;
+ tty->ctrl_status |= TIOCPKT_STOP;
+ wake_up_interruptible_poll(&tty->link->read_wait, POLLIN);
+ }
+ spin_unlock_irqrestore(&tty->ctrl_lock, flags);
+}
+
+/**
* pty_common_install - set up the pty pair
* @driver: the pty driver
* @tty: the tty being instantiated
@@ -472,6 +509,8 @@ static const struct tty_operations slave_pty_ops_bsd = {
.set_termios = pty_set_termios,
.cleanup = pty_cleanup,
.resize = pty_resize,
+ .start = pty_start,
+ .stop = pty_stop,
.remove = pty_remove
};
@@ -647,6 +686,8 @@ static const struct tty_operations pty_unix98_ops = {
.chars_in_buffer = pty_chars_in_buffer,
.unthrottle = pty_unthrottle,
.set_termios = pty_set_termios,
+ .start = pty_start,
+ .stop = pty_stop,
.shutdown = pty_unix98_shutdown,
.cleanup = pty_cleanup,
};
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index b898e29..55b9103 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -922,8 +922,7 @@ void no_tty(void)
* stop_tty - propagate flow control
* @tty: tty to stop
*
- * Perform flow control to the driver. For PTY/TTY pairs we
- * must also propagate the TIOCKPKT status. May be called
+ * Perform flow control to the driver. May be called
* on an already stopped device and will not re-call the driver
* method.
*
@@ -933,24 +932,14 @@ void no_tty(void)
* but not always.
*
* Locking:
- * ctrl_lock
* flow_lock
*/
void __stop_tty(struct tty_struct *tty)
{
- unsigned long flags;
-
if (tty->stopped)
return;
tty->stopped = 1;
- spin_lock_irqsave(&tty->ctrl_lock, flags);
- if (tty->link && tty->link->packet) {
- tty->ctrl_status &= ~TIOCPKT_START;
- tty->ctrl_status |= TIOCPKT_STOP;
- wake_up_interruptible_poll(&tty->link->read_wait, POLLIN);
- }
- spin_unlock_irqrestore(&tty->ctrl_lock, flags);
if (tty->ops->stop)
(tty->ops->stop)(tty);
}
@@ -969,33 +958,21 @@ EXPORT_SYMBOL(stop_tty);
* start_tty - propagate flow control
* @tty: tty to start
*
- * Start a tty that has been stopped if at all possible. Perform
- * any necessary wakeups and propagate the TIOCPKT status. If this
- * is the tty was previous stopped and is being started then the
- * driver start method is invoked and the line discipline woken.
+ * Start a tty that has been stopped if at all possible. If this
+ * tty was previous stopped and is now being started, the driver
+ * start method is invoked and the line discipline woken.
*
* Locking:
- * ctrl_lock
* flow_lock
*/
void __start_tty(struct tty_struct *tty)
{
- unsigned long flags;
-
if (!tty->stopped || tty->flow_stopped)
return;
tty->stopped = 0;
- spin_lock_irqsave(&tty->ctrl_lock, flags);
- if (tty->link && tty->link->packet) {
- tty->ctrl_status &= ~TIOCPKT_STOP;
- tty->ctrl_status |= TIOCPKT_START;
- wake_up_interruptible_poll(&tty->link->read_wait, POLLIN);
- }
- spin_unlock_irqrestore(&tty->ctrl_lock, flags);
if (tty->ops->start)
(tty->ops->start)(tty);
- /* If we have a running line discipline it may need kicking */
tty_wakeup(tty);
}
--
2.1.0
next prev parent reply other threads:[~2014-09-02 22:11 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-02 21:39 [PATCH 00/26] tty/serial flow control fixes Peter Hurley
2014-09-02 21:39 ` [PATCH 01/26] Revert "serial: uart: add hw flow control support configuration" Peter Hurley
2014-09-02 21:50 ` Murali Karicheri
2014-09-02 21:58 ` Peter Hurley
2014-09-02 22:17 ` Murali Karicheri
2014-09-02 21:39 ` [PATCH 02/26] serial: Style fix Peter Hurley
2014-09-02 21:39 ` [PATCH 03/26] serial: imx: Fix x_char handling and tx flow control Peter Hurley
2014-09-02 21:39 ` [PATCH 04/26] serial: core: Fix x_char race Peter Hurley
2014-09-02 21:39 ` [PATCH 05/26] serial: core: Remove unsafe x_char optimization Peter Hurley
2014-09-02 21:39 ` [PATCH 06/26] serial: Fix send_xchar() handlers Peter Hurley
2014-09-02 21:39 ` [PATCH 07/26] serial: mpc52xx: Use default serial core x_char handler Peter Hurley
2014-09-02 21:39 ` [PATCH 08/26] serial: sunsab: Don't enable tx if tx stopped Peter Hurley
2014-09-02 21:39 ` [PATCH 09/26] serial: blackfin: Fix missing gpio.h Peter Hurley
2014-09-02 21:39 ` [PATCH 10/26] serial: core: Document lock requirement for UPF_* flags updates Peter Hurley
2014-09-02 21:39 ` [PATCH 11/26] serial: 8250: Document serial8250_modem_status() locking Peter Hurley
2014-09-02 21:39 ` [PATCH 12/26] serial: core: Unwrap tertiary assignment in uart_handle_dcd_change() Peter Hurley
2014-09-02 21:39 ` [PATCH 13/26] locking: Add non-fatal spin lock assert Peter Hurley
2014-09-03 9:27 ` Peter Zijlstra
2014-09-03 11:20 ` Peter Hurley
2014-09-03 14:40 ` Peter Zijlstra
2014-09-03 14:50 ` Peter Hurley
2014-09-03 15:07 ` Peter Zijlstra
2014-09-04 5:14 ` Ingo Molnar
2014-09-10 11:02 ` Peter Hurley
2014-09-10 13:08 ` Peter Zijlstra
2014-09-10 14:45 ` Peter Hurley
2014-09-10 18:34 ` Greg Kroah-Hartman
2014-09-02 21:39 ` [PATCH 14/26] serial: core: Document and assert lock requirements for irq helpers Peter Hurley
2014-09-02 21:39 ` [PATCH 15/26] serial: core: Privatize modem status enable flags Peter Hurley
2014-09-02 21:39 ` [PATCH 16/26] isdn: i4l: Remove ASYNC_CTS_FLOW Peter Hurley
2014-09-02 21:39 ` [PATCH 17/26] serial: core: Privatize tty->hw_stopped Peter Hurley
2014-09-09 0:29 ` Peter Hurley
2014-09-02 21:39 ` [PATCH 18/26] usb: serial: Remove unused tty->hw_stopped Peter Hurley
2014-09-02 21:39 ` [PATCH 19/26] serial: bfin-uart: Fix auto CTS Peter Hurley
2014-09-02 21:39 ` [PATCH 20/26] serial: core: Use spin_lock_irq() in uart_set_termios() Peter Hurley
2014-09-02 21:39 ` [PATCH 21/26] tty: Convert tty_struct bitfield to bools Peter Hurley
2014-09-03 10:58 ` One Thousand Gnomes
2014-09-03 12:14 ` Peter Hurley
2014-09-03 12:19 ` One Thousand Gnomes
2014-09-03 15:10 ` Peter Hurley
2014-09-03 17:56 ` Greg Kroah-Hartman
2014-09-04 16:08 ` Peter Hurley
2014-09-02 21:39 ` [PATCH 22/26] tty: Serialize tty flow control changes with flow_lock Peter Hurley
2014-09-02 21:39 ` Peter Hurley [this message]
2014-09-02 21:39 ` [PATCH 24/26] tty: Serialize tcflow() with other tty flow control changes Peter Hurley
2014-09-02 21:39 ` [PATCH 25/26] tty: Move and rename send_prio_char() as tty_send_xchar() Peter Hurley
2014-09-02 21:39 ` [PATCH 26/26] tty: Hold termios_rwsem for tcflow(TCIxxx) Peter Hurley
2014-09-08 23:24 ` [PATCH 00/26] tty/serial flow control fixes Greg Kroah-Hartman
2014-09-08 23:33 ` Peter Hurley
2014-09-08 23:43 ` Greg Kroah-Hartman
2014-09-08 23:46 ` Peter Hurley
2014-09-09 0:01 ` Greg Kroah-Hartman
2014-09-10 19:06 ` [PATCH v2 00/14] " Peter Hurley
2014-09-10 19:06 ` [PATCH v2 01/14] serial: core: Document and assert lock requirements for irq helpers Peter Hurley
2014-09-10 19:06 ` [PATCH v2 02/14] serial: core: Privatize modem status enable flags Peter Hurley
2014-09-10 19:06 ` [PATCH v2 03/14] isdn: i4l: Remove ASYNC_CTS_FLOW Peter Hurley
2014-09-10 19:06 ` [PATCH v2 04/14] serial: core: Privatize tty->hw_stopped Peter Hurley
2014-09-10 19:06 ` [PATCH v2 05/14] usb: serial: Remove unused tty->hw_stopped Peter Hurley
2014-09-23 15:33 ` Johan Hovold
2014-09-10 19:06 ` [PATCH v2 06/14] serial: bfin-uart: Fix auto CTS Peter Hurley
2014-09-10 19:06 ` [PATCH v2 07/14] serial: core: Use spin_lock_irq() in uart_set_termios() Peter Hurley
2014-09-10 19:06 ` [PATCH v2 08/14] tty: Convert tty_struct bitfield to ints Peter Hurley
2014-09-10 19:06 ` [PATCH v2 09/14] tty: Serialize tty flow control changes with flow_lock Peter Hurley
2014-09-10 19:06 ` [PATCH v2 10/14] tty: Move packet mode flow control notifications to pty driver Peter Hurley
2014-09-10 19:06 ` [PATCH v2 11/14] tty: Serialize tcflow() with other tty flow control changes Peter Hurley
2014-09-10 19:06 ` [PATCH v2 12/14] tty: Move and rename send_prio_char() as tty_send_xchar() Peter Hurley
2014-09-10 19:06 ` [PATCH v2 13/14] tty: Hold termios_rwsem for tcflow(TCIxxx) Peter Hurley
2014-09-10 19:06 ` [PATCH v2 14/14] tty: Workaround Alpha non-atomic byte storage in tty_struct Peter Hurley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1409693975-1028-24-git-send-email-peter@hurleysoftware.com \
--to=peter@hurleysoftware.com \
--cc=gnomes@lxorguk.ukuu.org.uk \
--cc=gregkh@linuxfoundation.org \
--cc=jslaby@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).