From: Arnd Bergmann <arnd@arndb.de>
To: linux-kernel@vger.kernel.org
Cc: Arnd Bergmann <arnd@arndb.de>,
Alan Cox <alan@lxorguk.ukuu.org.uk>, Greg KH <gregkh@suse.de>,
Frederic Weisbecker <fweisbec@gmail.com>,
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 08/13] tty: release tty lock when blocking
Date: Wed, 5 May 2010 00:33:47 +0200 [thread overview]
Message-ID: <1273012433-6125-9-git-send-email-arnd@arndb.de> (raw)
In-Reply-To: <1273012433-6125-1-git-send-email-arnd@arndb.de>
All wait_event variants and work queue functions
that block on another thread need to release the
tty lock if the thread they are waiting on might
take it.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/char/cyclades.c | 2 +-
drivers/char/istallion.c | 12 ++++++++----
drivers/char/n_r3964.c | 2 +-
drivers/char/tty_buffer.c | 6 +++++-
drivers/char/tty_ioctl.c | 2 +-
drivers/char/tty_ldisc.c | 26 ++++++++++++++++++++++----
drivers/char/tty_port.c | 2 +-
drivers/char/vt_ioctl.c | 2 +-
drivers/serial/crisv10.c | 4 ++--
drivers/usb/class/cdc-acm.c | 2 +-
10 files changed, 43 insertions(+), 17 deletions(-)
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index 5b3b419..c425dbc 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 0618797..ab72858 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -955,7 +955,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;
@@ -990,7 +990,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;
@@ -1021,7 +1021,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;
@@ -1053,7 +1053,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;
@@ -1074,6 +1074,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_buffer.c b/drivers/char/tty_buffer.c
index 7ee5216..57db0a1 100644
--- a/drivers/char/tty_buffer.c
+++ b/drivers/char/tty_buffer.c
@@ -143,7 +143,11 @@ void tty_buffer_flush(struct tty_struct *tty)
if (test_bit(TTY_FLUSHING, &tty->flags)) {
set_bit(TTY_FLUSHPENDING, &tty->flags);
spin_unlock_irqrestore(&tty->buf.lock, flags);
- wait_event(tty->read_wait,
+ if (tty_locked())
+ wait_event_tty(tty->read_wait,
+ test_bit(TTY_FLUSHPENDING, &tty->flags) == 0);
+ else
+ wait_event(tty->read_wait,
test_bit(TTY_FLUSHPENDING, &tty->flags) == 0);
return;
} else
diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c
index 4b57e73..6455434 100644
--- a/drivers/char/tty_ioctl.c
+++ b/drivers/char/tty_ioctl.c
@@ -158,7 +158,7 @@ void tty_wait_until_sent(struct tty_struct *tty, long timeout)
#endif
if (!timeout)
timeout = MAX_SCHEDULE_TIMEOUT;
- if (wait_event_interruptible_timeout(tty->write_wait,
+ if (wait_event_interruptible_timeout_tty(tty->write_wait,
!tty_chars_in_buffer(tty), timeout) >= 0) {
if (tty->ops->wait_until_sent)
tty->ops->wait_until_sent(tty, timeout);
diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c
index 630e1ef..d4259cf 100644
--- a/drivers/char/tty_ldisc.c
+++ b/drivers/char/tty_ldisc.c
@@ -331,8 +331,16 @@ struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty)
{
struct tty_ldisc *ld;
- /* wait_event is a macro */
- wait_event(tty_ldisc_wait, (ld = tty_ldisc_try(tty)) != NULL);
+ ld = tty_ldisc_try(tty);
+ if (ld)
+ return ld;
+
+ if (tty_locked())
+ /* need to give up BTM when coming from paste_selection */
+ wait_event_tty(tty_ldisc_wait, (ld = tty_ldisc_try(tty)) != NULL);
+ else
+ __wait_event(tty_ldisc_wait, (ld = tty_ldisc_try(tty)) != NULL);
+
return ld;
}
EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait);
@@ -527,8 +535,17 @@ static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old)
static int tty_ldisc_halt(struct tty_struct *tty)
{
+ int ret;
clear_bit(TTY_LDISC, &tty->flags);
- return cancel_delayed_work_sync(&tty->buf.work);
+ if (tty_locked()) {
+ __release_tty_lock();
+ ret = cancel_delayed_work_sync(&tty->buf.work);
+ __reacquire_tty_lock();
+ } else {
+ ret = cancel_delayed_work_sync(&tty->buf.work);
+
+ }
+ return ret;
}
/**
@@ -854,8 +871,9 @@ void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty)
*/
tty_ldisc_halt(tty);
+ release_tty_lock(current);
flush_scheduled_work();
-
+ reacquire_tty_lock(current);
mutex_lock_tty_on(&tty->ldisc_mutex);
/*
* Now kill off the ldisc
diff --git a/drivers/char/tty_port.c b/drivers/char/tty_port.c
index dbcfc48..70e1349 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 0ebda0e..d54f73f 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);
diff --git a/drivers/serial/crisv10.c b/drivers/serial/crisv10.c
index d11d898..e6a1cb7 100644
--- a/drivers/serial/crisv10.c
+++ b/drivers/serial/crisv10.c
@@ -3981,7 +3981,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)
@@ -4139,7 +4139,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/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 5e1a253..bdd4bfc 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -645,7 +645,7 @@ static void acm_port_down(struct acm *acm, int drain)
acm_set_control(acm, acm->ctrlout = 0);
/* try letting the last writes drain naturally */
if (drain) {
- wait_event_interruptible_timeout(acm->drain_wait,
+ wait_event_interruptible_timeout_tty(acm->drain_wait,
(ACM_NW == acm_wb_is_avail(acm)) || !acm->dev,
ACM_CLOSE_TIMEOUT * HZ);
}
--
1.7.0.4
next prev parent reply other threads:[~2010-05-04 22:34 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-04 22:33 [PATCH v2 00/13] BKL conversion in tty layer Arnd Bergmann
2010-05-04 22:33 ` [PATCH 01/13] tty: replace BKL with a new tty_lock Arnd Bergmann
2010-05-04 22:33 ` [PATCH 02/13] tty: make atomic_write_lock release tty_lock Arnd Bergmann
2010-05-05 10:57 ` Alan Cox
2010-05-04 22:33 ` [PATCH 03/13] tty: make tty_port->mutex nest under tty_lock Arnd Bergmann
2010-05-04 22:33 ` [PATCH 04/13] tty: make termios mutex " Arnd Bergmann
2010-05-05 16:11 ` Arnd Bergmann
2010-05-04 22:33 ` [PATCH 05/13] tty: make ldisc_mutex " Arnd Bergmann
2010-05-04 22:33 ` [PATCH 06/13] tty: never hold BTM while getting tty_mutex Arnd Bergmann
2010-05-04 22:33 ` [PATCH 07/13] tty: give up BTM in acquire_console_sem Arnd Bergmann
2010-05-04 22:33 ` Arnd Bergmann [this message]
2010-05-04 22:33 ` [PATCH 09/13] tty: implement BTM as mutex instead of BKL Arnd Bergmann
2010-05-04 22:33 ` [PATCH 10/13] tty: untangle locking of wait_until_sent Arnd Bergmann
2010-05-05 19:59 ` Alan Cox
2010-05-05 21:31 ` Arnd Bergmann
2010-05-05 22:51 ` Greg KH
2010-05-05 23:52 ` Alan Cox
2010-05-24 19:00 ` Pavel Machek
2010-05-24 20:27 ` Alan Cox
2010-05-04 22:33 ` [PATCH 11/13] tty: remove tty_lock_nested Arnd Bergmann
2010-05-04 22:33 ` [PATCH 12/13] tty: remove release_tty_lock/reacquire_tty_lock Arnd Bergmann
2010-05-04 22:33 ` [PATCH 13/13] tty: turn ldisc_mutex into a regular mutex Arnd Bergmann
2010-05-05 9:18 ` Arnd Bergmann
2010-05-05 10:52 ` [PATCH v2 00/13] BKL conversion in tty layer Alan Cox
2010-05-05 12:24 ` 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=1273012433-6125-9-git-send-email-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=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
all inboxes | Powered by JetHome®