Commit f309532bf3e1cc1b787403d84e3039812a7dbe50

Authored by Linus Torvalds
1 parent 233e562eac

tty: Revert the tty locking series, it needs more work

This reverts the tty layer change to use per-tty locking, because it's
not correct yet, and fixing it will require some more deep surgery.

The main revert is d29f3ef39be4 ("tty_lock: Localise the lock"), but
there are several smaller commits that built upon it, they also get
reverted here. The list of reverted commits is:

  fde86d310886 - tty: add lockdep annotations
  8f6576ad476b - tty: fix ldisc lock inversion trace
  d3ca8b64b97e - pty: Fix lock inversion
  b1d679afd766 - tty: drop the pty lock during hangup
  abcefe5fc357 - tty/amiserial: Add missing argument for tty_unlock()
  fd11b42e3598 - cris: fix missing tty arg in wait_event_interruptible_tty call
  d29f3ef39be4 - tty_lock: Localise the lock

The revert had a trivial conflict in the 68360serial.c staging driver
that got removed in the meantime.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 14 changed files with 119 additions and 191 deletions Side-by-side Diff

drivers/tty/amiserial.c
... ... @@ -1033,7 +1033,7 @@
1033 1033 if (!retinfo)
1034 1034 return -EFAULT;
1035 1035 memset(&tmp, 0, sizeof(tmp));
1036   - tty_lock(tty);
  1036 + tty_lock();
1037 1037 tmp.line = tty->index;
1038 1038 tmp.port = state->port;
1039 1039 tmp.flags = state->tport.flags;
... ... @@ -1042,7 +1042,7 @@
1042 1042 tmp.close_delay = state->tport.close_delay;
1043 1043 tmp.closing_wait = state->tport.closing_wait;
1044 1044 tmp.custom_divisor = state->custom_divisor;
1045   - tty_unlock(tty);
  1045 + tty_unlock();
1046 1046 if (copy_to_user(retinfo,&tmp,sizeof(*retinfo)))
1047 1047 return -EFAULT;
1048 1048 return 0;
1049 1049  
... ... @@ -1059,12 +1059,12 @@
1059 1059 if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
1060 1060 return -EFAULT;
1061 1061  
1062   - tty_lock(tty);
  1062 + tty_lock();
1063 1063 change_spd = ((new_serial.flags ^ port->flags) & ASYNC_SPD_MASK) ||
1064 1064 new_serial.custom_divisor != state->custom_divisor;
1065 1065 if (new_serial.irq || new_serial.port != state->port ||
1066 1066 new_serial.xmit_fifo_size != state->xmit_fifo_size) {
1067   - tty_unlock(tty);
  1067 + tty_unlock();
1068 1068 return -EINVAL;
1069 1069 }
1070 1070  
... ... @@ -1074,7 +1074,7 @@
1074 1074 (new_serial.xmit_fifo_size != state->xmit_fifo_size) ||
1075 1075 ((new_serial.flags & ~ASYNC_USR_MASK) !=
1076 1076 (port->flags & ~ASYNC_USR_MASK))) {
1077   - tty_unlock(tty);
  1077 + tty_unlock();
1078 1078 return -EPERM;
1079 1079 }
1080 1080 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
... ... @@ -1084,7 +1084,7 @@
1084 1084 }
1085 1085  
1086 1086 if (new_serial.baud_base < 9600) {
1087   - tty_unlock(tty);
  1087 + tty_unlock();
1088 1088 return -EINVAL;
1089 1089 }
1090 1090  
... ... @@ -1116,7 +1116,7 @@
1116 1116 }
1117 1117 } else
1118 1118 retval = startup(tty, state);
1119   - tty_unlock(tty);
  1119 + tty_unlock();
1120 1120 return retval;
1121 1121 }
1122 1122  
drivers/tty/cyclades.c
... ... @@ -1599,7 +1599,7 @@
1599 1599 * If the port is the middle of closing, bail out now
1600 1600 */
1601 1601 if (tty_hung_up_p(filp) || (info->port.flags & ASYNC_CLOSING)) {
1602   - wait_event_interruptible_tty(tty, info->port.close_wait,
  1602 + wait_event_interruptible_tty(info->port.close_wait,
1603 1603 !(info->port.flags & ASYNC_CLOSING));
1604 1604 return (info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS;
1605 1605 }
drivers/tty/n_r3964.c
... ... @@ -1065,8 +1065,7 @@
1065 1065  
1066 1066 TRACE_L("read()");
1067 1067  
1068   - /* FIXME: should use a private lock */
1069   - tty_lock(tty);
  1068 + tty_lock();
1070 1069  
1071 1070 pClient = findClient(pInfo, task_pid(current));
1072 1071 if (pClient) {
... ... @@ -1078,7 +1077,7 @@
1078 1077 goto unlock;
1079 1078 }
1080 1079 /* block until there is a message: */
1081   - wait_event_interruptible_tty(tty, pInfo->read_wait,
  1080 + wait_event_interruptible_tty(pInfo->read_wait,
1082 1081 (pMsg = remove_msg(pInfo, pClient)));
1083 1082 }
1084 1083  
... ... @@ -1108,7 +1107,7 @@
1108 1107 }
1109 1108 ret = -EPERM;
1110 1109 unlock:
1111   - tty_unlock(tty);
  1110 + tty_unlock();
1112 1111 return ret;
1113 1112 }
1114 1113  
... ... @@ -1157,7 +1156,7 @@
1157 1156 pHeader->locks = 0;
1158 1157 pHeader->owner = NULL;
1159 1158  
1160   - tty_lock(tty);
  1159 + tty_lock();
1161 1160  
1162 1161 pClient = findClient(pInfo, task_pid(current));
1163 1162 if (pClient) {
... ... @@ -1176,7 +1175,7 @@
1176 1175 add_tx_queue(pInfo, pHeader);
1177 1176 trigger_transmit(pInfo);
1178 1177  
1179   - tty_unlock(tty);
  1178 + tty_unlock();
1180 1179  
1181 1180 return 0;
1182 1181 }
... ... @@ -47,7 +47,6 @@
47 47 wake_up_interruptible(&tty->read_wait);
48 48 wake_up_interruptible(&tty->write_wait);
49 49 tty->packet = 0;
50   - /* Review - krefs on tty_link ?? */
51 50 if (!tty->link)
52 51 return;
53 52 tty->link->packet = 0;
54 53  
... ... @@ -63,9 +62,9 @@
63 62 mutex_unlock(&devpts_mutex);
64 63 }
65 64 #endif
66   - tty_unlock(tty);
  65 + tty_unlock();
67 66 tty_vhangup(tty->link);
68   - tty_lock(tty);
  67 + tty_lock();
69 68 }
70 69 }
71 70  
72 71  
73 72  
74 73  
75 74  
76 75  
... ... @@ -623,27 +622,26 @@
623 622 return retval;
624 623  
625 624 /* find a device that is not in use. */
626   - mutex_lock(&devpts_mutex);
  625 + tty_lock();
627 626 index = devpts_new_index(inode);
  627 + tty_unlock();
628 628 if (index < 0) {
629 629 retval = index;
630 630 goto err_file;
631 631 }
632 632  
633   - mutex_unlock(&devpts_mutex);
634   -
635 633 mutex_lock(&tty_mutex);
  634 + mutex_lock(&devpts_mutex);
636 635 tty = tty_init_dev(ptm_driver, index);
  636 + mutex_unlock(&devpts_mutex);
  637 + tty_lock();
  638 + mutex_unlock(&tty_mutex);
637 639  
638 640 if (IS_ERR(tty)) {
639 641 retval = PTR_ERR(tty);
640 642 goto out;
641 643 }
642 644  
643   - /* The tty returned here is locked so we can safely
644   - drop the mutex */
645   - mutex_unlock(&tty_mutex);
646   -
647 645 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
648 646  
649 647 tty_add_file(tty, filp);
650 648  
651 649  
652 650  
653 651  
... ... @@ -656,17 +654,16 @@
656 654 if (retval)
657 655 goto err_release;
658 656  
659   - tty_unlock(tty);
  657 + tty_unlock();
660 658 return 0;
661 659 err_release:
662   - tty_unlock(tty);
  660 + tty_unlock();
663 661 tty_release(inode, filp);
664 662 return retval;
665 663 out:
666   - mutex_unlock(&tty_mutex);
667 664 devpts_kill_index(inode, index);
  665 + tty_unlock();
668 666 err_file:
669   - mutex_unlock(&devpts_mutex);
670 667 tty_free_file(filp);
671 668 return retval;
672 669 }
drivers/tty/serial/crisv10.c
... ... @@ -3976,7 +3976,7 @@
3976 3976 */
3977 3977 if (tty_hung_up_p(filp) ||
3978 3978 (info->flags & ASYNC_CLOSING)) {
3979   - wait_event_interruptible_tty(tty, info->close_wait,
  3979 + wait_event_interruptible_tty(info->close_wait,
3980 3980 !(info->flags & ASYNC_CLOSING));
3981 3981 #ifdef SERIAL_DO_RESTART
3982 3982 if (info->flags & ASYNC_HUP_NOTIFY)
3983 3983  
... ... @@ -4052,9 +4052,9 @@
4052 4052 printk("block_til_ready blocking: ttyS%d, count = %d\n",
4053 4053 info->line, info->count);
4054 4054 #endif
4055   - tty_unlock(tty);
  4055 + tty_unlock();
4056 4056 schedule();
4057   - tty_lock(tty);
  4057 + tty_lock();
4058 4058 }
4059 4059 set_current_state(TASK_RUNNING);
4060 4060 remove_wait_queue(&info->open_wait, &wait);
... ... @@ -4115,7 +4115,7 @@
4115 4115 */
4116 4116 if (tty_hung_up_p(filp) ||
4117 4117 (info->flags & ASYNC_CLOSING)) {
4118   - wait_event_interruptible_tty(tty, info->close_wait,
  4118 + wait_event_interruptible_tty(info->close_wait,
4119 4119 !(info->flags & ASYNC_CLOSING));
4120 4120 #ifdef SERIAL_DO_RESTART
4121 4121 return ((info->flags & ASYNC_HUP_NOTIFY) ?
drivers/tty/synclink.c
... ... @@ -3338,9 +3338,9 @@
3338 3338 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
3339 3339 __FILE__,__LINE__, tty->driver->name, port->count );
3340 3340  
3341   - tty_unlock(tty);
  3341 + tty_unlock();
3342 3342 schedule();
3343   - tty_lock(tty);
  3343 + tty_lock();
3344 3344 }
3345 3345  
3346 3346 set_current_state(TASK_RUNNING);
drivers/tty/synclink_gt.c
... ... @@ -3336,9 +3336,9 @@
3336 3336 }
3337 3337  
3338 3338 DBGINFO(("%s block_til_ready wait\n", tty->driver->name));
3339   - tty_unlock(tty);
  3339 + tty_unlock();
3340 3340 schedule();
3341   - tty_lock(tty);
  3341 + tty_lock();
3342 3342 }
3343 3343  
3344 3344 set_current_state(TASK_RUNNING);
drivers/tty/synclinkmp.c
... ... @@ -3357,9 +3357,9 @@
3357 3357 printk("%s(%d):%s block_til_ready() count=%d\n",
3358 3358 __FILE__,__LINE__, tty->driver->name, port->count );
3359 3359  
3360   - tty_unlock(tty);
  3360 + tty_unlock();
3361 3361 schedule();
3362   - tty_lock(tty);
  3362 + tty_lock();
3363 3363 }
3364 3364  
3365 3365 set_current_state(TASK_RUNNING);
drivers/tty/tty_io.c
... ... @@ -185,7 +185,6 @@
185 185 put_device(tty->dev);
186 186 kfree(tty->write_buf);
187 187 tty_buffer_free_all(tty);
188   - tty->magic = 0xDEADDEAD;
189 188 kfree(tty);
190 189 }
191 190  
... ... @@ -574,7 +573,7 @@
574 573 }
575 574 spin_unlock(&redirect_lock);
576 575  
577   - tty_lock(tty);
  576 + tty_lock();
578 577  
579 578 /* some functions below drop BTM, so we need this bit */
580 579 set_bit(TTY_HUPPING, &tty->flags);
... ... @@ -667,7 +666,7 @@
667 666 clear_bit(TTY_HUPPING, &tty->flags);
668 667 tty_ldisc_enable(tty);
669 668  
670   - tty_unlock(tty);
  669 + tty_unlock();
671 670  
672 671 if (f)
673 672 fput(f);
674 673  
675 674  
... ... @@ -1104,12 +1103,12 @@
1104 1103 {
1105 1104 if (tty) {
1106 1105 mutex_lock(&tty->atomic_write_lock);
1107   - tty_lock(tty);
  1106 + tty_lock();
1108 1107 if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) {
1109   - tty_unlock(tty);
  1108 + tty_unlock();
1110 1109 tty->ops->write(tty, msg, strlen(msg));
1111 1110 } else
1112   - tty_unlock(tty);
  1111 + tty_unlock();
1113 1112 tty_write_unlock(tty);
1114 1113 }
1115 1114 return;
... ... @@ -1404,7 +1403,6 @@
1404 1403 }
1405 1404 initialize_tty_struct(tty, driver, idx);
1406 1405  
1407   - tty_lock(tty);
1408 1406 retval = tty_driver_install_tty(driver, tty);
1409 1407 if (retval < 0)
1410 1408 goto err_deinit_tty;
1411 1409  
... ... @@ -1417,11 +1415,9 @@
1417 1415 retval = tty_ldisc_setup(tty, tty->link);
1418 1416 if (retval)
1419 1417 goto err_release_tty;
1420   - /* Return the tty locked so that it cannot vanish under the caller */
1421 1418 return tty;
1422 1419  
1423 1420 err_deinit_tty:
1424   - tty_unlock(tty);
1425 1421 deinitialize_tty_struct(tty);
1426 1422 free_tty_struct(tty);
1427 1423 err_module_put:
... ... @@ -1430,7 +1426,6 @@
1430 1426  
1431 1427 /* call the tty release_tty routine to clean out this slot */
1432 1428 err_release_tty:
1433   - tty_unlock(tty);
1434 1429 printk_ratelimited(KERN_INFO "tty_init_dev: ldisc open failed, "
1435 1430 "clearing slot %d\n", idx);
1436 1431 release_tty(tty, idx);
... ... @@ -1633,7 +1628,7 @@
1633 1628 if (tty_paranoia_check(tty, inode, __func__))
1634 1629 return 0;
1635 1630  
1636   - tty_lock(tty);
  1631 + tty_lock();
1637 1632 check_tty_count(tty, __func__);
1638 1633  
1639 1634 __tty_fasync(-1, filp, 0);
1640 1635  
... ... @@ -1642,11 +1637,10 @@
1642 1637 pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
1643 1638 tty->driver->subtype == PTY_TYPE_MASTER);
1644 1639 devpts = (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) != 0;
1645   - /* Review: parallel close */
1646 1640 o_tty = tty->link;
1647 1641  
1648 1642 if (tty_release_checks(tty, o_tty, idx)) {
1649   - tty_unlock(tty);
  1643 + tty_unlock();
1650 1644 return 0;
1651 1645 }
1652 1646  
... ... @@ -1658,7 +1652,7 @@
1658 1652 if (tty->ops->close)
1659 1653 tty->ops->close(tty, filp);
1660 1654  
1661   - tty_unlock(tty);
  1655 + tty_unlock();
1662 1656 /*
1663 1657 * Sanity check: if tty->count is going to zero, there shouldn't be
1664 1658 * any waiters on tty->read_wait or tty->write_wait. We test the
... ... @@ -1681,7 +1675,7 @@
1681 1675 opens on /dev/tty */
1682 1676  
1683 1677 mutex_lock(&tty_mutex);
1684   - tty_lock_pair(tty, o_tty);
  1678 + tty_lock();
1685 1679 tty_closing = tty->count <= 1;
1686 1680 o_tty_closing = o_tty &&
1687 1681 (o_tty->count <= (pty_master ? 1 : 0));
... ... @@ -1712,7 +1706,7 @@
1712 1706  
1713 1707 printk(KERN_WARNING "%s: %s: read/write wait queue active!\n",
1714 1708 __func__, tty_name(tty, buf));
1715   - tty_unlock_pair(tty, o_tty);
  1709 + tty_unlock();
1716 1710 mutex_unlock(&tty_mutex);
1717 1711 schedule();
1718 1712 }
... ... @@ -1775,7 +1769,7 @@
1775 1769  
1776 1770 /* check whether both sides are closing ... */
1777 1771 if (!tty_closing || (o_tty && !o_tty_closing)) {
1778   - tty_unlock_pair(tty, o_tty);
  1772 + tty_unlock();
1779 1773 return 0;
1780 1774 }
1781 1775  
1782 1776  
1783 1777  
... ... @@ -1788,16 +1782,14 @@
1788 1782 tty_ldisc_release(tty, o_tty);
1789 1783 /*
1790 1784 * The release_tty function takes care of the details of clearing
1791   - * the slots and preserving the termios structure. The tty_unlock_pair
1792   - * should be safe as we keep a kref while the tty is locked (so the
1793   - * unlock never unlocks a freed tty).
  1785 + * the slots and preserving the termios structure.
1794 1786 */
1795 1787 release_tty(tty, idx);
1796   - tty_unlock_pair(tty, o_tty);
1797 1788  
1798 1789 /* Make this pty number available for reallocation */
1799 1790 if (devpts)
1800 1791 devpts_kill_index(inode, idx);
  1792 + tty_unlock();
1801 1793 return 0;
1802 1794 }
1803 1795  
... ... @@ -1901,9 +1893,6 @@
1901 1893 * Locking: tty_mutex protects tty, tty_lookup_driver and tty_init_dev.
1902 1894 * tty->count should protect the rest.
1903 1895 * ->siglock protects ->signal/->sighand
1904   - *
1905   - * Note: the tty_unlock/lock cases without a ref are only safe due to
1906   - * tty_mutex
1907 1896 */
1908 1897  
1909 1898 static int tty_open(struct inode *inode, struct file *filp)
... ... @@ -1927,7 +1916,8 @@
1927 1916 retval = 0;
1928 1917  
1929 1918 mutex_lock(&tty_mutex);
1930   - /* This is protected by the tty_mutex */
  1919 + tty_lock();
  1920 +
1931 1921 tty = tty_open_current_tty(device, filp);
1932 1922 if (IS_ERR(tty)) {
1933 1923 retval = PTR_ERR(tty);
1934 1924  
1935 1925  
1936 1926  
... ... @@ -1948,19 +1938,17 @@
1948 1938 }
1949 1939  
1950 1940 if (tty) {
1951   - tty_lock(tty);
1952 1941 retval = tty_reopen(tty);
1953   - if (retval < 0) {
1954   - tty_unlock(tty);
  1942 + if (retval)
1955 1943 tty = ERR_PTR(retval);
1956   - }
1957   - } else /* Returns with the tty_lock held for now */
  1944 + } else
1958 1945 tty = tty_init_dev(driver, index);
1959 1946  
1960 1947 mutex_unlock(&tty_mutex);
1961 1948 if (driver)
1962 1949 tty_driver_kref_put(driver);
1963 1950 if (IS_ERR(tty)) {
  1951 + tty_unlock();
1964 1952 retval = PTR_ERR(tty);
1965 1953 goto err_file;
1966 1954 }
... ... @@ -1989,7 +1977,7 @@
1989 1977 printk(KERN_DEBUG "%s: error %d in opening %s...\n", __func__,
1990 1978 retval, tty->name);
1991 1979 #endif
1992   - tty_unlock(tty); /* need to call tty_release without BTM */
  1980 + tty_unlock(); /* need to call tty_release without BTM */
1993 1981 tty_release(inode, filp);
1994 1982 if (retval != -ERESTARTSYS)
1995 1983 return retval;
1996 1984  
1997 1985  
1998 1986  
... ... @@ -2001,15 +1989,17 @@
2001 1989 /*
2002 1990 * Need to reset f_op in case a hangup happened.
2003 1991 */
  1992 + tty_lock();
2004 1993 if (filp->f_op == &hung_up_tty_fops)
2005 1994 filp->f_op = &tty_fops;
  1995 + tty_unlock();
2006 1996 goto retry_open;
2007 1997 }
2008   - tty_unlock(tty);
  1998 + tty_unlock();
2009 1999  
2010 2000  
2011 2001 mutex_lock(&tty_mutex);
2012   - tty_lock(tty);
  2002 + tty_lock();
2013 2003 spin_lock_irq(&current->sighand->siglock);
2014 2004 if (!noctty &&
2015 2005 current->signal->leader &&
2016 2006  
... ... @@ -2017,10 +2007,11 @@
2017 2007 tty->session == NULL)
2018 2008 __proc_set_tty(current, tty);
2019 2009 spin_unlock_irq(&current->sighand->siglock);
2020   - tty_unlock(tty);
  2010 + tty_unlock();
2021 2011 mutex_unlock(&tty_mutex);
2022 2012 return 0;
2023 2013 err_unlock:
  2014 + tty_unlock();
2024 2015 mutex_unlock(&tty_mutex);
2025 2016 /* after locks to avoid deadlock */
2026 2017 if (!IS_ERR_OR_NULL(driver))
2027 2018  
2028 2019  
... ... @@ -2103,13 +2094,10 @@
2103 2094  
2104 2095 static int tty_fasync(int fd, struct file *filp, int on)
2105 2096 {
2106   - struct tty_struct *tty = file_tty(filp);
2107 2097 int retval;
2108   -
2109   - tty_lock(tty);
  2098 + tty_lock();
2110 2099 retval = __tty_fasync(fd, filp, on);
2111   - tty_unlock(tty);
2112   -
  2100 + tty_unlock();
2113 2101 return retval;
2114 2102 }
2115 2103  
... ... @@ -2946,7 +2934,6 @@
2946 2934 tty->pgrp = NULL;
2947 2935 tty->overrun_time = jiffies;
2948 2936 tty_buffer_init(tty);
2949   - mutex_init(&tty->legacy_mutex);
2950 2937 mutex_init(&tty->termios_mutex);
2951 2938 mutex_init(&tty->ldisc_mutex);
2952 2939 init_waitqueue_head(&tty->write_wait);
drivers/tty/tty_ldisc.c
... ... @@ -568,7 +568,7 @@
568 568 if (IS_ERR(new_ldisc))
569 569 return PTR_ERR(new_ldisc);
570 570  
571   - tty_lock(tty);
  571 + tty_lock();
572 572 /*
573 573 * We need to look at the tty locking here for pty/tty pairs
574 574 * when both sides try to change in parallel.
575 575  
... ... @@ -582,12 +582,12 @@
582 582 */
583 583  
584 584 if (tty->ldisc->ops->num == ldisc) {
585   - tty_unlock(tty);
  585 + tty_unlock();
586 586 tty_ldisc_put(new_ldisc);
587 587 return 0;
588 588 }
589 589  
590   - tty_unlock(tty);
  590 + tty_unlock();
591 591 /*
592 592 * Problem: What do we do if this blocks ?
593 593 * We could deadlock here
... ... @@ -595,7 +595,7 @@
595 595  
596 596 tty_wait_until_sent(tty, 0);
597 597  
598   - tty_lock(tty);
  598 + tty_lock();
599 599 mutex_lock(&tty->ldisc_mutex);
600 600  
601 601 /*
602 602  
... ... @@ -605,10 +605,10 @@
605 605  
606 606 while (test_bit(TTY_LDISC_CHANGING, &tty->flags)) {
607 607 mutex_unlock(&tty->ldisc_mutex);
608   - tty_unlock(tty);
  608 + tty_unlock();
609 609 wait_event(tty_ldisc_wait,
610 610 test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0);
611   - tty_lock(tty);
  611 + tty_lock();
612 612 mutex_lock(&tty->ldisc_mutex);
613 613 }
614 614  
... ... @@ -623,7 +623,7 @@
623 623  
624 624 o_ldisc = tty->ldisc;
625 625  
626   - tty_unlock(tty);
  626 + tty_unlock();
627 627 /*
628 628 * Make sure we don't change while someone holds a
629 629 * reference to the line discipline. The TTY_LDISC bit
... ... @@ -650,7 +650,7 @@
650 650  
651 651 retval = tty_ldisc_wait_idle(tty, 5 * HZ);
652 652  
653   - tty_lock(tty);
  653 + tty_lock();
654 654 mutex_lock(&tty->ldisc_mutex);
655 655  
656 656 /* handle wait idle failure locked */
... ... @@ -665,7 +665,7 @@
665 665 clear_bit(TTY_LDISC_CHANGING, &tty->flags);
666 666 mutex_unlock(&tty->ldisc_mutex);
667 667 tty_ldisc_put(new_ldisc);
668   - tty_unlock(tty);
  668 + tty_unlock();
669 669 return -EIO;
670 670 }
671 671  
... ... @@ -708,7 +708,7 @@
708 708 if (o_work)
709 709 schedule_work(&o_tty->buf.work);
710 710 mutex_unlock(&tty->ldisc_mutex);
711   - tty_unlock(tty);
  711 + tty_unlock();
712 712 return retval;
713 713 }
714 714  
715 715  
... ... @@ -816,11 +816,11 @@
816 816 * need to wait for another function taking the BTM
817 817 */
818 818 clear_bit(TTY_LDISC, &tty->flags);
819   - tty_unlock(tty);
  819 + tty_unlock();
820 820 cancel_work_sync(&tty->buf.work);
821 821 mutex_unlock(&tty->ldisc_mutex);
822 822 retry:
823   - tty_lock(tty);
  823 + tty_lock();
824 824 mutex_lock(&tty->ldisc_mutex);
825 825  
826 826 /* At this point we have a closed ldisc and we want to
... ... @@ -831,7 +831,7 @@
831 831 if (atomic_read(&tty->ldisc->users) != 1) {
832 832 char cur_n[TASK_COMM_LEN], tty_n[64];
833 833 long timeout = 3 * HZ;
834   - tty_unlock(tty);
  834 + tty_unlock();
835 835  
836 836 while (tty_ldisc_wait_idle(tty, timeout) == -EBUSY) {
837 837 timeout = MAX_SCHEDULE_TIMEOUT;
... ... @@ -894,23 +894,6 @@
894 894 tty_ldisc_enable(tty);
895 895 return 0;
896 896 }
897   -
898   -static void tty_ldisc_kill(struct tty_struct *tty)
899   -{
900   - mutex_lock(&tty->ldisc_mutex);
901   - /*
902   - * Now kill off the ldisc
903   - */
904   - tty_ldisc_close(tty, tty->ldisc);
905   - tty_ldisc_put(tty->ldisc);
906   - /* Force an oops if we mess this up */
907   - tty->ldisc = NULL;
908   -
909   - /* Ensure the next open requests the N_TTY ldisc */
910   - tty_set_termios_ldisc(tty, N_TTY);
911   - mutex_unlock(&tty->ldisc_mutex);
912   -}
913   -
914 897 /**
915 898 * tty_ldisc_release - release line discipline
916 899 * @tty: tty being shut down
917 900  
918 901  
919 902  
920 903  
... ... @@ -929,19 +912,27 @@
929 912 * race with the set_ldisc code path.
930 913 */
931 914  
932   - tty_unlock_pair(tty, o_tty);
  915 + tty_unlock();
933 916 tty_ldisc_halt(tty);
934 917 tty_ldisc_flush_works(tty);
935   - if (o_tty) {
936   - tty_ldisc_halt(o_tty);
937   - tty_ldisc_flush_works(o_tty);
938   - }
939   - tty_lock_pair(tty, o_tty);
  918 + tty_lock();
940 919  
  920 + mutex_lock(&tty->ldisc_mutex);
  921 + /*
  922 + * Now kill off the ldisc
  923 + */
  924 + tty_ldisc_close(tty, tty->ldisc);
  925 + tty_ldisc_put(tty->ldisc);
  926 + /* Force an oops if we mess this up */
  927 + tty->ldisc = NULL;
941 928  
942   - tty_ldisc_kill(tty);
  929 + /* Ensure the next open requests the N_TTY ldisc */
  930 + tty_set_termios_ldisc(tty, N_TTY);
  931 + mutex_unlock(&tty->ldisc_mutex);
  932 +
  933 + /* This will need doing differently if we need to lock */
943 934 if (o_tty)
944   - tty_ldisc_kill(o_tty);
  935 + tty_ldisc_release(o_tty, NULL);
945 936  
946 937 /* And the memory resources remaining (buffers, termios) will be
947 938 disposed of when the kref hits zero */
drivers/tty/tty_mutex.c
... ... @@ -4,71 +4,30 @@
4 4 #include <linux/semaphore.h>
5 5 #include <linux/sched.h>
6 6  
7   -/* Legacy tty mutex glue */
  7 +/*
  8 + * The 'big tty mutex'
  9 + *
  10 + * This mutex is taken and released by tty_lock() and tty_unlock(),
  11 + * replacing the older big kernel lock.
  12 + * It can no longer be taken recursively, and does not get
  13 + * released implicitly while sleeping.
  14 + *
  15 + * Don't use in new code.
  16 + */
  17 +static DEFINE_MUTEX(big_tty_mutex);
8 18  
9   -enum {
10   - TTY_MUTEX_NORMAL,
11   - TTY_MUTEX_NESTED,
12   -};
13   -
14 19 /*
15 20 * Getting the big tty mutex.
16 21 */
17   -
18   -static void __lockfunc tty_lock_nested(struct tty_struct *tty,
19   - unsigned int subclass)
  22 +void __lockfunc tty_lock(void)
20 23 {
21   - if (tty->magic != TTY_MAGIC) {
22   - printk(KERN_ERR "L Bad %p\n", tty);
23   - WARN_ON(1);
24   - return;
25   - }
26   - tty_kref_get(tty);
27   - mutex_lock_nested(&tty->legacy_mutex, subclass);
  24 + mutex_lock(&big_tty_mutex);
28 25 }
29   -
30   -void __lockfunc tty_lock(struct tty_struct *tty)
31   -{
32   - return tty_lock_nested(tty, TTY_MUTEX_NORMAL);
33   -}
34 26 EXPORT_SYMBOL(tty_lock);
35 27  
36   -void __lockfunc tty_unlock(struct tty_struct *tty)
  28 +void __lockfunc tty_unlock(void)
37 29 {
38   - if (tty->magic != TTY_MAGIC) {
39   - printk(KERN_ERR "U Bad %p\n", tty);
40   - WARN_ON(1);
41   - return;
42   - }
43   - mutex_unlock(&tty->legacy_mutex);
44   - tty_kref_put(tty);
  30 + mutex_unlock(&big_tty_mutex);
45 31 }
46 32 EXPORT_SYMBOL(tty_unlock);
47   -
48   -/*
49   - * Getting the big tty mutex for a pair of ttys with lock ordering
50   - * On a non pty/tty pair tty2 can be NULL which is just fine.
51   - */
52   -void __lockfunc tty_lock_pair(struct tty_struct *tty,
53   - struct tty_struct *tty2)
54   -{
55   - if (tty < tty2) {
56   - tty_lock(tty);
57   - tty_lock_nested(tty2, TTY_MUTEX_NESTED);
58   - } else {
59   - if (tty2 && tty2 != tty)
60   - tty_lock(tty2);
61   - tty_lock_nested(tty, TTY_MUTEX_NESTED);
62   - }
63   -}
64   -EXPORT_SYMBOL(tty_lock_pair);
65   -
66   -void __lockfunc tty_unlock_pair(struct tty_struct *tty,
67   - struct tty_struct *tty2)
68   -{
69   - tty_unlock(tty);
70   - if (tty2 && tty2 != tty)
71   - tty_unlock(tty2);
72   -}
73   -EXPORT_SYMBOL(tty_unlock_pair);
drivers/tty/tty_port.c
... ... @@ -230,7 +230,7 @@
230 230  
231 231 /* block if port is in the process of being closed */
232 232 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
233   - wait_event_interruptible_tty(tty, port->close_wait,
  233 + wait_event_interruptible_tty(port->close_wait,
234 234 !(port->flags & ASYNC_CLOSING));
235 235 if (port->flags & ASYNC_HUP_NOTIFY)
236 236 return -EAGAIN;
237 237  
... ... @@ -296,9 +296,9 @@
296 296 retval = -ERESTARTSYS;
297 297 break;
298 298 }
299   - tty_unlock(tty);
  299 + tty_unlock();
300 300 schedule();
301   - tty_lock(tty);
  301 + tty_lock();
302 302 }
303 303 finish_wait(&port->open_wait, &wait);
304 304  
... ... @@ -268,7 +268,6 @@
268 268 struct mutex ldisc_mutex;
269 269 struct tty_ldisc *ldisc;
270 270  
271   - struct mutex legacy_mutex;
272 271 struct mutex termios_mutex;
273 272 spinlock_t ctrl_lock;
274 273 /* Termios values are protected by the termios mutex */
... ... @@ -606,12 +605,8 @@
606 605  
607 606 /* tty_mutex.c */
608 607 /* functions for preparation of BKL removal */
609   -extern void __lockfunc tty_lock(struct tty_struct *tty);
610   -extern void __lockfunc tty_unlock(struct tty_struct *tty);
611   -extern void __lockfunc tty_lock_pair(struct tty_struct *tty,
612   - struct tty_struct *tty2);
613   -extern void __lockfunc tty_unlock_pair(struct tty_struct *tty,
614   - struct tty_struct *tty2);
  608 +extern void __lockfunc tty_lock(void) __acquires(tty_lock);
  609 +extern void __lockfunc tty_unlock(void) __releases(tty_lock);
615 610  
616 611 /*
617 612 * this shall be called only from where BTM is held (like close)
618 613  
... ... @@ -626,9 +621,9 @@
626 621 static inline void tty_wait_until_sent_from_close(struct tty_struct *tty,
627 622 long timeout)
628 623 {
629   - tty_unlock(tty); /* tty->ops->close holds the BTM, drop it while waiting */
  624 + tty_unlock(); /* tty->ops->close holds the BTM, drop it while waiting */
630 625 tty_wait_until_sent(tty, timeout);
631   - tty_lock(tty);
  626 + tty_lock();
632 627 }
633 628  
634 629 /*
635 630  
636 631  
... ... @@ -643,16 +638,16 @@
643 638 *
644 639 * Do not use in new code.
645 640 */
646   -#define wait_event_interruptible_tty(tty, wq, condition) \
  641 +#define wait_event_interruptible_tty(wq, condition) \
647 642 ({ \
648 643 int __ret = 0; \
649 644 if (!(condition)) { \
650   - __wait_event_interruptible_tty(tty, wq, condition, __ret); \
  645 + __wait_event_interruptible_tty(wq, condition, __ret); \
651 646 } \
652 647 __ret; \
653 648 })
654 649  
655   -#define __wait_event_interruptible_tty(tty, wq, condition, ret) \
  650 +#define __wait_event_interruptible_tty(wq, condition, ret) \
656 651 do { \
657 652 DEFINE_WAIT(__wait); \
658 653 \
659 654  
... ... @@ -661,9 +656,9 @@
661 656 if (condition) \
662 657 break; \
663 658 if (!signal_pending(current)) { \
664   - tty_unlock(tty); \
  659 + tty_unlock(); \
665 660 schedule(); \
666   - tty_lock(tty); \
  661 + tty_lock(); \
667 662 continue; \
668 663 } \
669 664 ret = -ERESTARTSYS; \
net/bluetooth/rfcomm/tty.c
... ... @@ -710,9 +710,9 @@
710 710 break;
711 711 }
712 712  
713   - tty_unlock(tty);
  713 + tty_unlock();
714 714 schedule();
715   - tty_lock(tty);
  715 + tty_lock();
716 716 }
717 717 set_current_state(TASK_RUNNING);
718 718 remove_wait_queue(&dev->wait, &wait);