[PATCH 39/68] tty: introduce wait_event_interruptible_tty

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Greg Kroah-Hartman
Date: Tuesday, August 10, 2010 - 2:59 pm

From: Arnd Bergmann <arnd@arndb.de>

Calling wait_event_interruptible implicitly
releases the BKL when it sleeps, but we need
to do this explcitly when we have converted
it to a mutex.

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/cyclades.c  |    2 +-
 drivers/char/istallion.c |   12 ++++++++----
 drivers/char/n_r3964.c   |    2 +-
 drivers/char/tty_port.c  |    2 +-
 drivers/char/vt_ioctl.c  |    5 ++++-
 drivers/serial/crisv10.c |    4 ++--
 include/linux/tty.h      |   42 ++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 59 insertions(+), 10 deletions(-)

diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index 51acfe3..27aad94 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -1607,7 +1607,7 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
 	 * If the port is the middle of closing, bail out now
 	 */
 	if (tty_hung_up_p(filp) || (info->port.flags & ASYNC_CLOSING)) {
-		wait_event_interruptible(info->port.close_wait,
+		wait_event_interruptible_tty(info->port.close_wait,
 				!(info->port.flags & ASYNC_CLOSING));
 		return (info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS;
 	}
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index 5e9a81d..be28391 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -954,7 +954,7 @@ static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned l
  *	order of opens and closes may not be preserved across shared
  *	memory, so we must wait until it is complete.
  */
-	wait_event_interruptible(portp->raw_wait,
+	wait_event_interruptible_tty(portp->raw_wait,
 			!test_bit(ST_CLOSING, &portp->state));
 	if (signal_pending(current)) {
 		return -ERESTARTSYS;
@@ -989,7 +989,7 @@ static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned l
 	set_bit(ST_OPENING, &portp->state);
 	spin_unlock_irqrestore(&brd_lock, flags);
 
-	wait_event_interruptible(portp->raw_wait,
+	wait_event_interruptible_tty(portp->raw_wait,
 			!test_bit(ST_OPENING, &portp->state));
 	if (signal_pending(current))
 		rc = -ERESTARTSYS;
@@ -1020,7 +1020,7 @@ static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned
  *	occurs on this port.
  */
 	if (wait) {
-		wait_event_interruptible(portp->raw_wait,
+		wait_event_interruptible_tty(portp->raw_wait,
 				!test_bit(ST_CLOSING, &portp->state));
 		if (signal_pending(current)) {
 			return -ERESTARTSYS;
@@ -1052,7 +1052,7 @@ static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned
  *	to come back.
  */
 	rc = 0;
-	wait_event_interruptible(portp->raw_wait,
+	wait_event_interruptible_tty(portp->raw_wait,
 			!test_bit(ST_CLOSING, &portp->state));
 	if (signal_pending(current))
 		rc = -ERESTARTSYS;
@@ -1073,6 +1073,10 @@ static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned
 
 static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback)
 {
+	/*
+	 * no need for wait_event_tty because clearing ST_CMDING cannot block
+	 * on BTM
+	 */
 	wait_event_interruptible(portp->raw_wait,
 			!test_bit(ST_CMDING, &portp->state));
 	if (signal_pending(current))
diff --git a/drivers/char/n_r3964.c b/drivers/char/n_r3964.c
index f4bd259..a98290d 100644
--- a/drivers/char/n_r3964.c
+++ b/drivers/char/n_r3964.c
@@ -1079,7 +1079,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
 				goto unlock;
 			}
 			/* block until there is a message: */
-			wait_event_interruptible(pInfo->read_wait,
+			wait_event_interruptible_tty(pInfo->read_wait,
 					(pMsg = remove_msg(pInfo, pClient)));
 		}
 
diff --git a/drivers/char/tty_port.c b/drivers/char/tty_port.c
index a3bd1d0..35eb304 100644
--- a/drivers/char/tty_port.c
+++ b/drivers/char/tty_port.c
@@ -231,7 +231,7 @@ int tty_port_block_til_ready(struct tty_port *port,
 
 	/* block if port is in the process of being closed */
 	if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
-		wait_event_interruptible(port->close_wait,
+		wait_event_interruptible_tty(port->close_wait,
 				!(port->flags & ASYNC_CLOSING));
 		if (port->flags & ASYNC_HUP_NOTIFY)
 			return -EAGAIN;
diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
index cf87c53..2bbeaae 100644
--- a/drivers/char/vt_ioctl.c
+++ b/drivers/char/vt_ioctl.c
@@ -133,7 +133,7 @@ static void vt_event_wait(struct vt_event_wait *vw)
 	list_add(&vw->list, &vt_events);
 	spin_unlock_irqrestore(&vt_event_lock, flags);
 	/* Wait for it to pass */
-	wait_event_interruptible(vt_event_waitqueue, vw->done);
+	wait_event_interruptible_tty(vt_event_waitqueue, vw->done);
 	/* Dequeue it */
 	spin_lock_irqsave(&vt_event_lock, flags);
 	list_del(&vw->list);
@@ -1761,10 +1761,13 @@ int vt_move_to_console(unsigned int vt, int alloc)
 		return -EIO;
 	}
 	release_console_sem();
+	tty_lock();
 	if (vt_waitactive(vt + 1)) {
 		pr_debug("Suspend: Can't switch VCs.");
+		tty_unlock();
 		return -EINTR;
 	}
+	tty_unlock();
 	return prev;
 }
 
diff --git a/drivers/serial/crisv10.c b/drivers/serial/crisv10.c
index f848e18..94bfb9f 100644
--- a/drivers/serial/crisv10.c
+++ b/drivers/serial/crisv10.c
@@ -3992,7 +3992,7 @@ block_til_ready(struct tty_struct *tty, struct file * filp,
 	 */
 	if (tty_hung_up_p(filp) ||
 	    (info->flags & ASYNC_CLOSING)) {
-		wait_event_interruptible(info->close_wait,
+		wait_event_interruptible_tty(info->close_wait,
 			!(info->flags & ASYNC_CLOSING));
 #ifdef SERIAL_DO_RESTART
 		if (info->flags & ASYNC_HUP_NOTIFY)
@@ -4150,7 +4150,7 @@ rs_open(struct tty_struct *tty, struct file * filp)
 	 */
 	if (tty_hung_up_p(filp) ||
 	    (info->flags & ASYNC_CLOSING)) {
-		wait_event_interruptible(info->close_wait,
+		wait_event_interruptible_tty(info->close_wait,
 			!(info->flags & ASYNC_CLOSING));
 #ifdef SERIAL_DO_RESTART
 		return ((info->flags & ASYNC_HUP_NOTIFY) ?
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 6ead6b6..955d72e 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -607,5 +607,47 @@ static inline void tty_unlock(void) __releases(kernel_lock)
 }
 #define tty_locked()		(kernel_locked())
 
+/*
+ * wait_event_interruptible_tty -- wait for a condition with the tty lock held
+ *
+ * The condition we are waiting for might take a long time to
+ * become true, or might depend on another thread taking the
+ * BTM. In either case, we need to drop the BTM to guarantee
+ * forward progress. This is a leftover from the conversion
+ * from the BKL and should eventually get removed as the BTM
+ * falls out of use.
+ *
+ * Do not use in new code.
+ */
+#define wait_event_interruptible_tty(wq, condition)			\
+({									\
+	int __ret = 0;							\
+	if (!(condition)) {						\
+		__wait_event_interruptible_tty(wq, condition, __ret);	\
+	}								\
+	__ret;								\
+})
+
+#define __wait_event_interruptible_tty(wq, condition, ret)		\
+do {									\
+	DEFINE_WAIT(__wait);						\
+									\
+	for (;;) {							\
+		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
+		if (condition)						\
+			break;						\
+		if (!signal_pending(current)) {				\
+			tty_unlock();					\
+			schedule();					\
+			tty_lock();					\
+			continue;					\
+		}							\
+		ret = -ERESTARTSYS;					\
+		break;							\
+	}								\
+	finish_wait(&wq, &__wait);					\
+} while (0)
+
+
 #endif /* __KERNEL__ */
 #endif
-- 
1.7.2

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[GIT PATCH] TTY patches for 2.6.36, try 2, Greg KH, (Tue Aug 10, 2:44 pm)
[PATCH 01/68] n_gsm.c: removed duplicated #includes, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 02/68] serial: There's no config CONSOLE, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 03/68] vt: clean up the code - use kernel library, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 04/68] serial: add UART_CAP_EFR and UART_CAP_SLEEP ..., Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 05/68] mrst_max3110: add UART driver for Max3110 on ..., Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 06/68] max3110 sanity check a register, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 07/68] serial: replace open coded mutex with a real ..., Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 08/68] serial: fix wakup races in the mrst_max3110 ..., Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 09/68] tty: Remove Hayes ESP ioctls, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 10/68] tty: remove remaining Hayes ESP ioctls, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 11/68] tty: Add EXTPROC support for LINEMODE, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 12/68] vt/console: try harder to print output when ..., Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 13/68] stallion: prune lock_kernel calls, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 14/68] istallion: use bit ops for the board flags, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 15/68] riscom8: kill use of lock_kernel, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 16/68] isicom: kill off the BKL, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 17/68] rocket: kill BKL, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 18/68] synclink: kill the big kernel lock, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 19/68] cyclades: Kill off BKL usage, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 20/68] epca: Kill the big kernel lock, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 21/68] specialix: Kill the BKL, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 22/68] tty: Fix the digi acceleport driver NULL checks, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 23/68] synclink: reworking locking a bit, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 24/68] tty: serial - fix various misuses/mishandlin ..., Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 25/68] tty: serial - fix tty back references in termios, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 26/68] tty: serial - fix tty referencing in set_ldisc, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 27/68] vc: Locking clean up, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 28/68] tty: Make vt's have a tty_port, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 29/68] tty: Move the vt_tty field from the vc_data ..., Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 30/68] serial: Change the wait for carrier locking, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 31/68] serial: add port helpers, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 32/68] serial: trim locking on the helpers, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 33/68] serial: Use block_til_ready helper, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 34/68] serial: fix termios settings in open, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 35/68] tty: replace BKL with a new tty_lock, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 36/68] tty: never hold BTM while getting tty_mutex, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 37/68] tty: fix console_sem lock order, Greg Kroah-Hartman, (Tue Aug 10, 2:58 pm)
[PATCH 38/68] cdc-acm: remove dead code, Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 39/68] tty: introduce wait_event_interruptible_tty, Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 40/68] tty: reorder ldisc locking, Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 41/68] tty: untangle locking of wait_until_sent, Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 42/68] tty: remove tty_lock_nested, Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 43/68] tty: implement BTM as mutex instead of BKL, Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 44/68] tty: release BTM while sleeping in block_til ..., Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 45/68] 8250: fix set_ldisc operation, Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 46/68] tty: avoid recursive BTM in pty_close, Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 47/68] serial: max3107: introduce a max3107 driver, Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 48/68] serial: max3107: Abstract out the platform s ..., Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 49/68] tty_io: remove casts from void*, Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 50/68] vt: Fix warning: statement with no effect du ..., Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 51/68] serial: crisv10: formatting of pointers in p ..., Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 53/68] serial: fix missing bit coverage of ASYNC_FLAGS, Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 54/68] serial: general fixes in the serial_rs485 st ..., Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 55/68] serial: mcf: don't take spinlocks in already ..., Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 56/68] serial: MMIO32 support for 8250_early.c, Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 57/68] timbuart: use __devinit and __devexit macros ..., Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 58/68] serial: 68328serial.c: remove dead (ALMA_ANS ..., Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 59/68] serial: add support for OX16PCI958 card, Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 60/68] mxser: remove unnesesary NULL check, Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 61/68] hsu: driver for Medfield High Speed UART device, Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 62/68] hsu: add a periodic timer to check dma rx ch ..., Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 63/68] hsu: some code cleanup, Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 64/68] hsu: call PCI pm hooks in suspend/resume fun ..., Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 65/68] serial: max3107: Fix gpiolib support, Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)
[PATCH 68/68] U6715 16550A serial driver support, Greg Kroah-Hartman, (Tue Aug 10, 2:59 pm)