public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Tony Luck <tony.luck@intel.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	linux-kernel@vger.kernel.org, Greg KH <gregkh@suse.de>,
	Thomas Gleixner <tglx@linutronix.de>,
	Andrew Morton <akpm@linux-foundation.org>,
	John Kacur <jkacur@redhat.com>, Al Viro <viro@zeniv.linux.org.uk>,
	Ingo Molnar <mingo@elte.hu>
Subject: [PATCH] serial: revert "Use block_til_ready helper"
Date: Sat, 19 Jun 2010 22:29:21 +0200	[thread overview]
Message-ID: <201006192229.21971.arnd@arndb.de> (raw)
In-Reply-To: <201006191432.04685.arnd@arndb.de>

On Saturday 19 June 2010 14:32:04 Arnd Bergmann wrote:
> > I boot with a "console=uart,io,0x3f8" argument, so I start out using
> > 8250_early.c. Looks like it switched to 8250.c based on seeing
> > this:
> > 
> > Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
> > 
> > on the console log.
> 
> Good, so it's something I should be able to reproduce on a PC.

I could reproduce the problem now and bisected it down to a cleanup
patch that can fortunately get reverted. The symptom that I saw
is that when I open a serial port for the second time (e.g. starting
getty and logging in), the output gets garbled, while the first one
worked fine. This does not rely on the console code at all.

Original commit message:
    Our code now rather closely resembles the helper, so switch to it.

Apparently, the two functions are not really doing the same,
so revert the commit for now. This includes the addition of
a tty_unlock()/tty_lock() pair when blocking on the wait queue.

Greg, do you want to apply this patch on top of the series, or
do you prefer to get a replacement for the original patch, once
we know what's wrong with it?

Tony, can you confirm that with this patch added, everything's
fine for you?

Alan, any idea where the problem may be with the broken patch?

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/serial/serial_core.c |   89 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 88 insertions(+), 1 deletions(-)

diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index 78b1eac..55e5769 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -1539,6 +1539,93 @@ static void uart_dtr_rts(struct tty_port *port, int onoff)
 		uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS);
 }
 
+/*
+ * Block the open until the port is ready.  We must be called with
+ * the per-port semaphore held.
+ */
+static int
+uart_block_til_ready(struct file *filp, struct uart_state *state)
+{
+	DECLARE_WAITQUEUE(wait, current);
+	struct tty_port *port = &state->port;
+	unsigned long flags;
+
+	spin_lock_irqsave(&port->lock, flags);
+	if (!tty_hung_up_p(filp))
+		port->count--;
+	port->blocked_open++;
+	spin_unlock_irqrestore(&port->lock, flags);
+
+	add_wait_queue(&port->open_wait, &wait);
+	while (1) {
+		set_current_state(TASK_INTERRUPTIBLE);
+
+		/*
+		 * If we have been hung up, tell userspace/restart open.
+		 */
+		if (tty_hung_up_p(filp) || port->tty == NULL)
+			break;
+
+		/*
+		 * If the port has been closed, tell userspace/restart open.
+		 */
+		if (!(port->flags & ASYNC_INITIALIZED))
+			break;
+
+		/*
+		 * If non-blocking mode is set, or CLOCAL mode is set,
+		 * we don't want to wait for the modem status lines to
+		 * indicate that the port is ready.
+		 *
+		 * Also, if the port is not enabled/configured, we want
+		 * to allow the open to succeed here.  Note that we will
+		 * have set TTY_IO_ERROR for a non-existant port.
+		 */
+		if ((filp->f_flags & O_NONBLOCK) ||
+		    (port->tty->termios->c_cflag & CLOCAL) ||
+		    (port->tty->flags & (1 << TTY_IO_ERROR)))
+			break;
+
+		/*
+		 * Set DTR to allow modem to know we're waiting.  Do
+		 * not set RTS here - we want to make sure we catch
+		 * the data from the modem.
+		 */
+		if (port->tty->termios->c_cflag & CBAUD)
+			tty_port_raise_dtr_rts(port);
+
+		/*
+		 * and wait for the carrier to indicate that the
+		 * modem is ready for us.
+		 */
+		if (tty_port_carrier_raised(port))
+			break;
+
+		tty_unlock();
+		schedule();
+		tty_lock();
+
+		if (signal_pending(current))
+			break;
+	}
+	set_current_state(TASK_RUNNING);
+	remove_wait_queue(&port->open_wait, &wait);
+
+	spin_lock_irqsave(&port->lock, flags);
+	if (!tty_hung_up_p(filp))
+		port->count++;
+	port->blocked_open--;
+	spin_unlock_irqrestore(&port->lock, flags);
+
+	if (signal_pending(current))
+		return -ERESTARTSYS;
+
+	if (!port->tty || tty_hung_up_p(filp))
+		return -EAGAIN;
+
+	return 0;
+}
+
 static struct uart_state *uart_get(struct uart_driver *drv, int line)
 {
 	struct uart_state *state;
@@ -1647,7 +1734,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
 	 */
 	mutex_unlock(&port->mutex);
 	if (retval == 0)
-		retval = tty_port_block_til_ready(port, tty, filp);
+		retval = uart_block_til_ready(filp, state);
 
 	/*
 	 * If this is the first open to succeed, adjust things to suit.
-- 
1.7.0.4


  reply	other threads:[~2010-06-19 20:30 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-15 20:59 [PATCH v3 00/10] BKL conversion in tty layer Arnd Bergmann
2010-05-15 20:59 ` [PATCH 01/10] tty: replace BKL with a new tty_lock Arnd Bergmann
2010-05-15 20:59 ` [PATCH 02/10] tty: never hold BTM while getting tty_mutex Arnd Bergmann
2010-05-15 20:59 ` [PATCH 03/10] tty: fix console_sem lock order Arnd Bergmann
2010-05-15 20:59 ` [PATCH 04/10] cdc-acm: remove dead code Arnd Bergmann
2010-05-15 20:59 ` [PATCH 05/10] tty: introduce wait_event_interruptible_tty Arnd Bergmann
2010-05-15 20:59 ` [PATCH 06/10] tty: annotate tty_write_lock Arnd Bergmann
2010-05-15 20:59 ` [PATCH 07/10] tty: reorder ldisc locking Arnd Bergmann
2010-05-15 20:59 ` [PATCH 08/10] tty: untangle locking of wait_until_sent Arnd Bergmann
2010-05-16  3:12   ` Daniel K.
2010-05-15 20:59 ` [PATCH 09/10] tty: remove tty_lock_nested Arnd Bergmann
2010-05-15 20:59 ` [PATCH 10/10] tty: implement BTM as mutex instead of BKL Arnd Bergmann
2010-05-16  3:33   ` Daniel K.
2010-05-16 12:58     ` Arnd Bergmann
2010-05-17 13:41 ` [PATCH v3 00/10] BKL conversion in tty layer Alan Cox
2010-05-17 15:30   ` Greg KH
2010-05-17 18:30     ` Arnd Bergmann
2010-05-18  4:27       ` Greg KH
2010-05-18 21:52         ` Arnd Bergmann
2010-05-19  1:50           ` Greg KH
2010-05-22 13:54             ` Arnd Bergmann
2010-05-17 18:49   ` Arnd Bergmann
2010-06-17 19:13   ` Tony Luck
2010-06-17 19:40     ` Arnd Bergmann
2010-06-17 20:15       ` Tony Luck
2010-06-17 21:48         ` Arnd Bergmann
2010-06-17 22:09           ` Frederic Weisbecker
2010-06-18 12:58             ` [PATCH] tty: avoid recursive BTM in pty_close Arnd Bergmann
2010-06-18 16:21               ` Alan Cox
2010-06-18 16:52                 ` Tony Luck
2010-06-18 18:35                   ` Arnd Bergmann
2010-06-18 20:25                     ` Tony Luck
2010-06-19 12:32                       ` Arnd Bergmann
2010-06-19 20:29                         ` Arnd Bergmann [this message]
2010-06-19 21:57                           ` [PATCH] serial: revert "Use block_til_ready helper" Alan Cox
2010-06-20 20:54                             ` Arnd Bergmann
2010-06-21 14:13                               ` Alan Cox
2010-06-21 20:57                                 ` Arnd Bergmann
2010-06-21 20:58                                   ` Arnd Bergmann
2010-06-21 17:11                           ` Tony Luck
2010-06-22 23:01                           ` Greg KH
2010-06-28 17:17                     ` [PATCH] tty: avoid recursive BTM in pty_close Tony Luck
2010-06-28 19:03                       ` Arnd Bergmann

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=201006192229.21971.arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=fweisbec@gmail.com \
    --cc=gregkh@suse.de \
    --cc=jkacur@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=viro@zeniv.linux.org.uk \
    /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