public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: "Greg Kroah-Hartman" <gregkh@suse.de>
Cc: linux-kernel@vger.kernel.org, Alan Cox <alan@lxorguk.ukuu.org.uk>
Subject: [PATCH retry] tty: implement BTM as mutex instead of BKL
Date: Fri, 6 Aug 2010 21:40:30 +0200	[thread overview]
Message-ID: <201008062140.30555.arnd@arndb.de> (raw)
In-Reply-To: <1281047014-23429-43-git-send-email-gregkh@suse.de>

The tty locking now follows the rules for mutexes, so
we can replace the BKL usage with a new subsystem
wide mutex.

Using a regular mutex here will change the behaviour
when blocked on the BTM from spinning to sleeping,
but that should not be visible to the user.

Using the mutex also means that all the BTM is now
covered by lockdep.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: Greg Kroah-Hartman <gregkh@suse.de>

diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 88d6eac..82d05cc 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -9,6 +9,7 @@ FONTMAPFILE = cp437.uni
 
 obj-y	 += mem.o random.o tty_io.o n_tty.o tty_ioctl.o tty_ldisc.o tty_buffer.o tty_port.o
 
+obj-y				+= tty_mutex.o
 obj-$(CONFIG_LEGACY_PTYS)	+= pty.o
 obj-$(CONFIG_UNIX98_PTYS)	+= pty.o
 obj-y				+= misc.o
diff --git a/drivers/char/tty_mutex.c b/drivers/char/tty_mutex.c
new file mode 100644
index 0000000..1336975
--- /dev/null
+++ b/drivers/char/tty_mutex.c
@@ -0,0 +1,47 @@
+/*
+ * drivers/char/tty_lock.c
+ */
+#include <linux/tty.h>
+#include <linux/module.h>
+#include <linux/kallsyms.h>
+#include <linux/semaphore.h>
+#include <linux/sched.h>
+
+/*
+ * The 'big tty mutex'
+ *
+ * This mutex is taken and released by tty_lock() and tty_unlock(),
+ * replacing the older big kernel lock.
+ * It can no longer be taken recursively, and does not get
+ * released implicitly while sleeping.
+ *
+ * Don't use in new code.
+ */
+static DEFINE_MUTEX(big_tty_mutex);
+struct task_struct *__big_tty_mutex_owner;
+EXPORT_SYMBOL_GPL(__big_tty_mutex_owner);
+
+/*
+ * Getting the big tty mutex.
+ */
+void __lockfunc tty_lock(void)
+{
+	struct task_struct *task = current;
+
+	WARN_ON(__big_tty_mutex_owner == task);
+
+	mutex_lock(&big_tty_mutex);
+	__big_tty_mutex_owner = task;
+}
+EXPORT_SYMBOL(tty_lock);
+
+void __lockfunc tty_unlock(void)
+{
+	struct task_struct *task = current;
+
+	WARN_ON(__big_tty_mutex_owner != task);
+	__big_tty_mutex_owner = NULL;
+
+	mutex_unlock(&big_tty_mutex);
+}
+EXPORT_SYMBOL(tty_unlock);
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 98c90df..95526cb 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -575,20 +575,12 @@ extern int vt_ioctl(struct tty_struct *tty, struct file *file,
 extern long vt_compat_ioctl(struct tty_struct *tty, struct file * file,
 		     unsigned int cmd, unsigned long arg);
 
+/* tty_mutex.c */
 /* functions for preparation of BKL removal */
-static inline void tty_lock(void) __acquires(kernel_lock)
-{
-#ifdef CONFIG_LOCK_KERNEL
-	/* kernel_locked is 1 for !CONFIG_LOCK_KERNEL */
-	WARN_ON(kernel_locked());
-#endif
-	lock_kernel();
-}
-static inline void tty_unlock(void) __releases(kernel_lock)
-{
-	unlock_kernel();
-}
-#define tty_locked()		(kernel_locked())
+extern void __lockfunc tty_lock(void) __acquires(tty_lock);
+extern void __lockfunc tty_unlock(void) __releases(tty_lock);
+extern struct task_struct *__big_tty_mutex_owner;
+#define tty_locked()		(current == __big_tty_mutex_owner)
 
 /*
  * wait_event_interruptible_tty -- wait for a condition with the tty lock held

  reply	other threads:[~2010-08-06 19:41 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 ` [PATCH 41/67] tty: untangle locking of wait_until_sent Greg Kroah-Hartman
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   ` Arnd Bergmann [this message]
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=201008062140.30555.arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=gregkh@suse.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