From: Arnd Bergmann <arnd@arndb.de>
To: Greg KH <gregkh@suse.de>
Cc: linux-kernel@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>,
Alan Cox <alan@lxorguk.ukuu.org.uk>,
Frederic Weisbecker <fweisbec@gmail.com>,
John Kacur <jkacur@redhat.com>
Subject: [PATCH 28/31] tty: remove tty_lock_nested
Date: Tue, 1 Jun 2010 22:53:08 +0200 [thread overview]
Message-ID: <1275425591-8803-29-git-send-email-arnd@arndb.de> (raw)
In-Reply-To: <1275425591-8803-1-git-send-email-arnd@arndb.de>
This changes all remaining users of tty_lock_nested
to be non-recursive, which lets us kill this function.
As a consequence, we won't need to keep the lock count
any more, which allows more simplifications later.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/char/pty.c | 2 +-
drivers/char/selection.c | 4 ++--
drivers/char/tty_io.c | 41 ++++++++++++++++++++---------------------
drivers/char/tty_ldisc.c | 3 +--
include/linux/tty.h | 16 +---------------
5 files changed, 25 insertions(+), 41 deletions(-)
diff --git a/drivers/char/pty.c b/drivers/char/pty.c
index d9c1407..c9af9ff 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -62,7 +62,7 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
if (tty->driver == ptm_driver)
devpts_pty_kill(tty->link);
#endif
- tty_vhangup(tty->link);
+ tty_vhangup_locked(tty->link);
}
}
diff --git a/drivers/char/selection.c b/drivers/char/selection.c
index 75889cd..ebae344 100644
--- a/drivers/char/selection.c
+++ b/drivers/char/selection.c
@@ -313,7 +313,8 @@ int paste_selection(struct tty_struct *tty)
struct tty_ldisc *ld;
DECLARE_WAITQUEUE(wait, current);
- tty_lock_nested(); /* always called with BTM from vt_ioctl */
+ /* always called with BTM from vt_ioctl */
+ WARN_ON(!tty_locked());
acquire_console_sem();
poke_blanked_console();
@@ -343,6 +344,5 @@ int paste_selection(struct tty_struct *tty)
__set_current_state(TASK_RUNNING);
tty_ldisc_deref(ld);
- tty_unlock();
return 0;
}
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index d51993b..5db354d 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -492,10 +492,8 @@ EXPORT_SYMBOL_GPL(tty_wakeup);
* tasklist_lock to walk task list for hangup event
* ->siglock to protect ->signal/->sighand
*/
-static void do_tty_hangup(struct work_struct *work)
+void tty_vhangup_locked(struct tty_struct *tty)
{
- struct tty_struct *tty =
- container_of(work, struct tty_struct, hangup_work);
struct file *cons_filp = NULL;
struct file *filp, *f = NULL;
struct task_struct *p;
@@ -517,8 +515,6 @@ static void do_tty_hangup(struct work_struct *work)
/* inuse_filps is protected by the single tty lock,
this really needs to change if we want to flush the
workqueue with the lock held */
- tty_lock_nested(); /* called with BTM held from pty_close and
- others */
check_tty_count(tty, "do_tty_hangup");
file_list_lock();
@@ -598,11 +594,20 @@ static void do_tty_hangup(struct work_struct *work)
*/
set_bit(TTY_HUPPED, &tty->flags);
tty_ldisc_enable(tty);
- tty_unlock();
if (f)
fput(f);
}
+static void do_tty_hangup(struct work_struct *work)
+{
+ struct tty_struct *tty =
+ container_of(work, struct tty_struct, hangup_work);
+
+ tty_lock();
+ tty_vhangup_locked(tty);
+ tty_unlock();
+}
+
/**
* tty_hangup - trigger a hangup event
* @tty: tty to hangup
@@ -638,7 +643,9 @@ void tty_vhangup(struct tty_struct *tty)
printk(KERN_DEBUG "%s vhangup...\n", tty_name(tty, buf));
#endif
- do_tty_hangup(&tty->hangup_work);
+ tty_lock();
+ tty_vhangup_locked(tty);
+ tty_unlock();
}
EXPORT_SYMBOL(tty_vhangup);
@@ -719,10 +726,12 @@ void disassociate_ctty(int on_exit)
tty = get_current_tty();
if (tty) {
tty_pgrp = get_pid(tty->pgrp);
- tty_lock_nested(); /* see above */
- if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY)
- tty_vhangup(tty);
- tty_unlock();
+ if (on_exit) {
+ tty_lock();
+ if (tty->driver->type != TTY_DRIVER_TYPE_PTY)
+ tty_vhangup_locked(tty);
+ tty_unlock();
+ }
tty_kref_put(tty);
} else if (on_exit) {
struct pid *old_pgrp;
@@ -1213,18 +1222,14 @@ static int tty_driver_install_tty(struct tty_driver *driver,
int ret;
if (driver->ops->install) {
- tty_lock_nested(); /* already called with BTM held */
ret = driver->ops->install(driver, tty);
- tty_unlock();
return ret;
}
if (tty_init_termios(tty) == 0) {
- tty_lock_nested();
tty_driver_kref_get(driver);
tty->count++;
driver->ttys[idx] = tty;
- tty_unlock();
return 0;
}
return -ENOMEM;
@@ -1317,15 +1322,11 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
struct tty_struct *tty;
int retval;
- tty_lock_nested(); /* always called with tty lock held already */
-
/* Check if pty master is being opened multiple times */
if (driver->subtype == PTY_TYPE_MASTER &&
(driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok) {
- tty_unlock();
return ERR_PTR(-EIO);
}
- tty_unlock();
/*
* First time open is complex, especially for PTY devices.
@@ -1369,9 +1370,7 @@ release_mem_out:
if (printk_ratelimit())
printk(KERN_INFO "tty_init_dev: ldisc open failed, "
"clearing slot %d\n", idx);
- tty_lock_nested();
release_tty(tty, idx);
- tty_unlock();
return ERR_PTR(retval);
}
diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c
index 0f49479..412f977 100644
--- a/drivers/char/tty_ldisc.c
+++ b/drivers/char/tty_ldisc.c
@@ -450,9 +450,8 @@ static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld)
if (ld->ops->open) {
int ret;
/* BTM here locks versus a hangup event */
- tty_lock_nested(); /* always held here already */
+ WARN_ON(!tty_locked());
ret = ld->ops->open(tty);
- tty_unlock();
return ret;
}
return 0;
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 18a7955..21a6de2 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -416,6 +416,7 @@ extern int is_ignored(int sig);
extern int tty_signal(int sig, struct tty_struct *tty);
extern void tty_hangup(struct tty_struct *tty);
extern void tty_vhangup(struct tty_struct *tty);
+extern void tty_vhangup_locked(struct tty_struct *tty);
extern void tty_vhangup_self(void);
extern void tty_unhangup(struct file *filp);
extern int tty_hung_up_p(struct file *filp);
@@ -574,21 +575,6 @@ extern long vt_compat_ioctl(struct tty_struct *tty, struct file * file,
unsigned int cmd, unsigned long arg);
/* functions for preparation of BKL removal */
-
-/*
- * tty_lock_nested get the tty_lock while potentially holding it
- *
- * The Big TTY Mutex is a recursive lock, meaning you can take it
- * from a thread that is already holding it.
- * This is bad for a number of reasons, so tty_lock_nested should
- * really be used as rarely as possible. If a code location can
- * be shown to never get called with this held already, it should
- * use tty_lock() instead.
- */
-static inline void __lockfunc tty_lock_nested(void) __acquires(kernel_lock)
-{
- lock_kernel();
-}
static inline void tty_lock(void) __acquires(kernel_lock)
{
#ifdef CONFIG_LOCK_KERNEL
--
1.7.0.4
next prev parent reply other threads:[~2010-06-01 20:53 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-01 20:52 [PATCH 00/31] tty: BKL removal Arnd Bergmann
2010-06-01 20:52 ` [PATCH 01/31] stallion: prune lock_kernel calls Arnd Bergmann
2010-06-01 20:52 ` [PATCH 02/31] istallion: use bit ops for the board flags Arnd Bergmann
2010-06-01 20:52 ` [PATCH 03/31] riscom8: kill use of lock_kernel Arnd Bergmann
2010-06-01 20:52 ` [PATCH 04/31] isicom: kill off the BKL Arnd Bergmann
2010-06-01 20:52 ` [PATCH 05/31] rocket: kill BKL Arnd Bergmann
2010-06-01 20:52 ` [PATCH 06/31] synclink: kill the big kernel lock Arnd Bergmann
2010-06-01 20:52 ` [PATCH 07/31] cyclades: Kill off BKL usage Arnd Bergmann
2010-06-01 20:52 ` [PATCH 08/31] epca: Kill the big kernel lock Arnd Bergmann
2010-06-01 20:52 ` [PATCH 09/31] specialix; Kill the BKL Arnd Bergmann
2010-06-01 20:52 ` [PATCH 10/31] synclink: reworking locking a bit Arnd Bergmann
2010-06-01 20:52 ` [PATCH 11/31] tty: serial - fix various misuses/mishandlings of port->tty Arnd Bergmann
2010-06-01 20:52 ` [PATCH 12/31] tty: serial - fix tty back references in termios Arnd Bergmann
2010-06-17 18:50 ` Tony Luck
2010-06-17 20:21 ` Greg KH
2010-06-01 20:52 ` [PATCH 13/31] tty: serial - fix tty referencing in set_ldisc Arnd Bergmann
2010-06-01 20:52 ` [PATCH 14/31] vc: Locking clean up Arnd Bergmann
2010-06-01 20:52 ` [PATCH 15/31] tty: Make vt's have a tty_port Arnd Bergmann
2010-06-01 20:52 ` [PATCH 16/31] tty: Move the vt_tty field from the vc_data into the standard tty_port Arnd Bergmann
2010-06-01 20:52 ` [PATCH 17/31] serial: Change the wait for carrier locking Arnd Bergmann
2010-06-01 20:52 ` [PATCH 18/31] serial: add port helpers Arnd Bergmann
2010-06-01 20:52 ` [PATCH 19/31] serial: trim locking on the helpers Arnd Bergmann
2010-06-01 20:53 ` [PATCH 20/31] serial: Use block_til_ready helper Arnd Bergmann
2010-06-01 20:53 ` [PATCH 21/31] tty: replace BKL with a new tty_lock Arnd Bergmann
2010-06-01 20:53 ` [PATCH 22/31] tty: never hold BTM while getting tty_mutex Arnd Bergmann
2010-06-01 20:53 ` [PATCH 23/31] tty: fix console_sem lock order Arnd Bergmann
2010-06-01 20:53 ` [PATCH 24/31] cdc-acm: remove dead code Arnd Bergmann
2010-06-01 20:53 ` [PATCH 25/31] tty: introduce wait_event_interruptible_tty Arnd Bergmann
2010-06-01 20:53 ` [PATCH 26/31] tty: reorder ldisc locking Arnd Bergmann
2010-06-01 20:53 ` [PATCH 27/31] tty: untangle locking of wait_until_sent Arnd Bergmann
2010-06-01 20:53 ` Arnd Bergmann [this message]
2010-06-01 20:53 ` [PATCH 29/31] tty: implement BTM as mutex instead of BKL Arnd Bergmann
2010-06-01 20:53 ` [PATCH 30/31] tty: release BTM while sleeping in block_til_ready Arnd Bergmann
2010-06-01 20:53 ` [PATCH 31/31] 8250: fix set_ldisc operation Arnd Bergmann
2010-06-02 22:16 ` [PATCH 00/31] tty: BKL removal Arnd Bergmann
2010-06-02 23:10 ` Greg KH
2010-06-16 20:49 ` Greg KH
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=1275425591-8803-29-git-send-email-arnd@arndb.de \
--to=arnd@arndb.de \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=fweisbec@gmail.com \
--cc=gregkh@suse.de \
--cc=jkacur@redhat.com \
--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
all inboxes | Powered by JetHome®