From: Greg Kroah-Hartman <gregkh@suse.de>
To: linux-kernel@vger.kernel.org
Cc: Arnd Bergmann <arnd@arndb.de>,
Alan Cox <alan@lxorguk.ukuu.org.uk>,
Greg Kroah-Hartman <gregkh@suse.de>
Subject: [PATCH 41/67] tty: untangle locking of wait_until_sent
Date: Thu, 5 Aug 2010 15:23:08 -0700 [thread overview]
Message-ID: <1281047014-23429-41-git-send-email-gregkh@suse.de> (raw)
In-Reply-To: <20100805213528.GA13794@kroah.com>
From: Arnd Bergmann <arnd@arndb.de>
Some wait_until_sent versions require the big
tty mutex, others don't and some callers of
wait_until_sent already hold it while other don't.
That leads to recursive use of the BTM in these
functions, which we're trying to get rid of.
This turns all cleans up the locking there so
that the driver's wait_until_sent function
never takes the BTM itself if it is already
called with that lock held.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
drivers/char/amiserial.c | 11 +++++++++--
drivers/serial/68360serial.c | 2 --
drivers/serial/crisv10.c | 2 --
drivers/serial/serial_core.c | 31 ++++++++++++++++++++++---------
4 files changed, 31 insertions(+), 15 deletions(-)
diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c
index 1b21a7a..8228e61 100644
--- a/drivers/char/amiserial.c
+++ b/drivers/char/amiserial.c
@@ -1528,6 +1528,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
{
struct async_struct * info = tty->driver_data;
unsigned long orig_jiffies, char_time;
+ int tty_was_locked = tty_locked();
int lsr;
if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent"))
@@ -1538,7 +1539,12 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
orig_jiffies = jiffies;
- tty_lock_nested(); /* tty_wait_until_sent is called from lots of places */
+ /*
+ * tty_wait_until_sent is called from lots of places,
+ * with or without the BTM.
+ */
+ if (!tty_was_locked)
+ tty_lock();
/*
* Set the check interval to be 1/5 of the estimated time to
* send a single character, and make it at least 1. The check
@@ -1579,7 +1585,8 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
break;
}
__set_current_state(TASK_RUNNING);
- tty_unlock();
+ if (!tty_was_locked)
+ tty_unlock();
#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
#endif
diff --git a/drivers/serial/68360serial.c b/drivers/serial/68360serial.c
index 16f5f2f..edcf1cc 100644
--- a/drivers/serial/68360serial.c
+++ b/drivers/serial/68360serial.c
@@ -1705,7 +1705,6 @@ static void rs_360_wait_until_sent(struct tty_struct *tty, int timeout)
printk("jiff=%lu...", jiffies);
#endif
- tty_lock_nested(); /* always held already since we come from ->close */
/* We go through the loop at least once because we can't tell
* exactly when the last character exits the shifter. There can
* be at least two characters waiting to be sent after the buffers
@@ -1734,7 +1733,6 @@ static void rs_360_wait_until_sent(struct tty_struct *tty, int timeout)
bdp--;
} while (bdp->status & BD_SC_READY);
current->state = TASK_RUNNING;
- tty_unlock();
#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
#endif
diff --git a/drivers/serial/crisv10.c b/drivers/serial/crisv10.c
index e6a1cb7..0825d4a 100644
--- a/drivers/serial/crisv10.c
+++ b/drivers/serial/crisv10.c
@@ -3924,7 +3924,6 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
* Check R_DMA_CHx_STATUS bit 0-6=number of available bytes in FIFO
* R_DMA_CHx_HWSW bit 31-16=nbr of bytes left in DMA buffer (0=64k)
*/
- tty_lock_nested(); /* locked already when coming from close */
orig_jiffies = jiffies;
while (info->xmit.head != info->xmit.tail || /* More in send queue */
(*info->ostatusadr & 0x007f) || /* more in FIFO */
@@ -3941,7 +3940,6 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
curr_time_usec - info->last_tx_active_usec;
}
set_current_state(TASK_RUNNING);
- tty_unlock();
}
/*
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index 851d7c2..cd85112 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -60,7 +60,7 @@ static struct lock_class_key port_lock_key;
static void uart_change_speed(struct tty_struct *tty, struct uart_state *state,
struct ktermios *old_termios);
-static void uart_wait_until_sent(struct tty_struct *tty, int timeout);
+static void __uart_wait_until_sent(struct uart_port *port, int timeout);
static void uart_change_pm(struct uart_state *state, int pm_state);
/*
@@ -1322,8 +1322,16 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
tty->closing = 1;
spin_unlock_irqrestore(&port->lock, flags);
- if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
- tty_wait_until_sent(tty, msecs_to_jiffies(port->closing_wait));
+ if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) {
+ /*
+ * hack: open-coded tty_wait_until_sent to avoid
+ * recursive tty_lock
+ */
+ long timeout = msecs_to_jiffies(port->closing_wait);
+ if (wait_event_interruptible_timeout(tty->write_wait,
+ !tty_chars_in_buffer(tty), timeout) >= 0)
+ __uart_wait_until_sent(uport, timeout);
+ }
/*
* At this point, we stop accepting input. To do this, we
@@ -1339,7 +1347,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
* has completely drained; this is especially
* important if there is a transmit FIFO!
*/
- uart_wait_until_sent(tty, uport->timeout);
+ __uart_wait_until_sent(uport, uport->timeout);
}
uart_shutdown(tty, state);
@@ -1373,17 +1381,13 @@ done:
mutex_unlock(&port->mutex);
}
-static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
+static void __uart_wait_until_sent(struct uart_port *port, int timeout)
{
- struct uart_state *state = tty->driver_data;
- struct uart_port *port = state->uart_port;
unsigned long char_time, expire;
if (port->type == PORT_UNKNOWN || port->fifosize == 0)
return;
- tty_lock_nested(); /* already locked when coming from close */
-
/*
* Set the check interval to be 1/5 of the estimated time to
* send a single character, and make it at least 1. The check
@@ -1429,6 +1433,15 @@ static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
break;
}
set_current_state(TASK_RUNNING); /* might not be needed */
+}
+
+static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
+{
+ struct uart_state *state = tty->driver_data;
+ struct uart_port *port = state->uart_port;
+
+ tty_lock();
+ __uart_wait_until_sent(port, timeout);
tty_unlock();
}
--
1.7.2
next prev parent reply other threads:[~2010-08-05 22:38 UTC|newest]
Thread overview: 81+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-05 21:35 [GIT PATCH] TTY patches for 2.6.36 Greg KH
2010-08-05 22:22 ` [PATCH 01/67] n_gsm.c: removed duplicated #includes Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 02/67] serial: There's no config CONSOLE Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 03/67] vt: clean up the code - use kernel library Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 04/67] serial: add UART_CAP_EFR and UART_CAP_SLEEP flags to 16C950 UARTs definition Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 05/67] mrst_max3110: add UART driver for Max3110 on Moorestown Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 06/67] max3110 sanity check a register Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 07/67] serial: replace open coded mutex with a real mutex in mrst_max3110.c Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 08/67] serial: fix wakup races in the mrst_max3110 driver Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 09/67] tty: Remove Hayes ESP ioctls Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 10/67] tty: remove remaining " Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 11/67] tty: Add EXTPROC support for LINEMODE Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 12/67] vt/console: try harder to print output when panicing Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 13/67] stallion: prune lock_kernel calls Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 14/67] istallion: use bit ops for the board flags Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 15/67] riscom8: kill use of lock_kernel Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 16/67] isicom: kill off the BKL Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 17/67] rocket: kill BKL Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 18/67] synclink: kill the big kernel lock Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 19/67] cyclades: Kill off BKL usage Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 20/67] epca: Kill the big kernel lock Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 21/67] specialix: Kill the BKL Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 22/67] tty: Fix the digi acceleport driver NULL checks Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 23/67] synclink: reworking locking a bit Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 24/67] tty: serial - fix various misuses/mishandlings of port->tty Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 25/67] tty: serial - fix tty back references in termios Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 26/67] tty: serial - fix tty referencing in set_ldisc Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 27/67] vc: Locking clean up Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 28/67] tty: Make vt's have a tty_port Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 29/67] tty: Move the vt_tty field from the vc_data into the standard tty_port Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 30/67] serial: Change the wait for carrier locking Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 31/67] serial: add port helpers Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 32/67] serial: trim locking on the helpers Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 33/67] serial: Use block_til_ready helper Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 34/67] serial: fix termios settings in open Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 35/67] tty: replace BKL with a new tty_lock Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 36/67] tty: never hold BTM while getting tty_mutex Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 37/67] tty: fix console_sem lock order Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 38/67] cdc-acm: remove dead code Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 39/67] tty: introduce wait_event_interruptible_tty Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 40/67] tty: reorder ldisc locking Greg Kroah-Hartman
2010-08-05 22:23 ` Greg Kroah-Hartman [this message]
2010-08-05 22:23 ` [PATCH 42/67] tty: remove tty_lock_nested Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 43/67] tty: implement BTM as mutex instead of BKL Greg Kroah-Hartman
2010-08-06 19:40 ` [PATCH retry] " Arnd Bergmann
2010-08-05 22:23 ` [PATCH 44/67] tty: release BTM while sleeping in block_til_ready Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 45/67] 8250: fix set_ldisc operation Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 46/67] tty: avoid recursive BTM in pty_close Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 47/67] serial: max3107: introduce a max3107 driver Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 48/67] serial: max3107: Abstract out the platform specific bits Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 49/67] tty_io: remove casts from void* Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 50/67] vt: Fix warning: statement with no effect due to vt_kern.h Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 51/67] serial: crisv10: formatting of pointers in printk() Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 52/67] serial: "altera_uart: simplify altera_uart_console_putc()" checkpatch fixes Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 53/67] serial: fix missing bit coverage of ASYNC_FLAGS Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 54/67] serial: general fixes in the serial_rs485 structure Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 55/67] serial: mcf: don't take spinlocks in already protected functions Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 56/67] serial: MMIO32 support for 8250_early.c Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 57/67] timbuart: use __devinit and __devexit macros for probe and remove Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 58/67] serial: 68328serial.c: remove dead (ALMA_ANS | DRAGONIXVZ | M68EZ328ADS) Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 59/67] serial: add support for OX16PCI958 card Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 60/67] mxser: remove unnesesary NULL check Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 61/67] hsu: driver for Medfield High Speed UART device Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 62/67] hsu: add a periodic timer to check dma rx channel Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 63/67] hsu: some code cleanup Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 64/67] hsu: call PCI pm hooks in suspend/resume function Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 65/67] serial: max3107: Fix gpiolib support Greg Kroah-Hartman
2010-08-06 18:40 ` [GIT PATCH] TTY patches for 2.6.36 Linus Torvalds
2010-08-06 18:51 ` Greg KH
2010-08-06 19:40 ` Arnd Bergmann
2010-08-06 19:45 ` Alan Cox
2010-08-06 19:37 ` Greg KH
2010-08-06 19:38 ` Linus Torvalds
2010-08-06 19:58 ` Arnd Bergmann
2010-08-06 20:11 ` Linus Torvalds
2010-08-06 20:19 ` Arnd Bergmann
2010-08-06 20:22 ` Greg KH
2010-08-09 16:06 ` Andy Whitcroft
2010-08-09 18:38 ` Arnd Bergmann
2010-08-09 19:24 ` Alan Cox
2010-08-10 7:31 ` Andy Whitcroft
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=1281047014-23429-41-git-send-email-gregkh@suse.de \
--to=gregkh@suse.de \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=arnd@arndb.de \
--cc=linux-kernel@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