Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+119 -191
+7 -7
drivers/tty/amiserial.c
··· 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 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; ··· 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 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 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 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
+1 -1
drivers/tty/cyclades.c
··· 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 }
+5 -6
drivers/tty/n_r3964.c
··· 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) { ··· 1077 1078 goto unlock; 1078 1079 } 1079 1080 /* block until there is a message: */ 1080 - wait_event_interruptible_tty(tty, pInfo->read_wait, 1081 + wait_event_interruptible_tty(pInfo->read_wait, 1081 1082 (pMsg = remove_msg(pInfo, pClient))); 1082 1083 } 1083 1084 ··· 1107 1108 } 1108 1109 ret = -EPERM; 1109 1110 unlock: 1110 - tty_unlock(tty); 1111 + tty_unlock(); 1111 1112 return ret; 1112 1113 } 1113 1114 ··· 1156 1157 pHeader->locks = 0; 1157 1158 pHeader->owner = NULL; 1158 1159 1159 - tty_lock(tty); 1160 + tty_lock(); 1160 1161 1161 1162 pClient = findClient(pInfo, task_pid(current)); 1162 1163 if (pClient) { ··· 1175 1176 add_tx_queue(pInfo, pHeader); 1176 1177 trigger_transmit(pInfo); 1177 1178 1178 - tty_unlock(tty); 1179 + tty_unlock(); 1179 1180 1180 1181 return 0; 1181 1182 }
+11 -14
drivers/tty/pty.c
··· 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; ··· 62 63 mutex_unlock(&devpts_mutex); 63 64 } 64 65 #endif 65 - tty_unlock(tty); 66 + tty_unlock(); 66 67 tty_vhangup(tty->link); 67 - tty_lock(tty); 68 + tty_lock(); 68 69 } 69 70 } 70 71 ··· 622 623 return retval; 623 624 624 625 /* find a device that is not in use. */ 625 - mutex_lock(&devpts_mutex); 626 + tty_lock(); 626 627 index = devpts_new_index(inode); 628 + tty_unlock(); 627 629 if (index < 0) { 628 630 retval = index; 629 631 goto err_file; 630 632 } 631 633 632 - mutex_unlock(&devpts_mutex); 633 - 634 634 mutex_lock(&tty_mutex); 635 + mutex_lock(&devpts_mutex); 635 636 tty = tty_init_dev(ptm_driver, index); 637 + mutex_unlock(&devpts_mutex); 638 + tty_lock(); 639 + mutex_unlock(&tty_mutex); 636 640 637 641 if (IS_ERR(tty)) { 638 642 retval = PTR_ERR(tty); 639 643 goto out; 640 644 } 641 - 642 - /* The tty returned here is locked so we can safely 643 - drop the mutex */ 644 - mutex_unlock(&tty_mutex); 645 645 646 646 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ 647 647 ··· 654 656 if (retval) 655 657 goto err_release; 656 658 657 - tty_unlock(tty); 659 + tty_unlock(); 658 660 return 0; 659 661 err_release: 660 - tty_unlock(tty); 662 + tty_unlock(); 661 663 tty_release(inode, filp); 662 664 return retval; 663 665 out: 664 - mutex_unlock(&tty_mutex); 665 666 devpts_kill_index(inode, index); 667 + tty_unlock(); 666 668 err_file: 667 - mutex_unlock(&devpts_mutex); 668 669 tty_free_file(filp); 669 670 return retval; 670 671 }
+4 -4
drivers/tty/serial/crisv10.c
··· 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) ··· 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 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) ?
+2 -2
drivers/tty/synclink.c
··· 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);
+2 -2
drivers/tty/synclinkmp.c
··· 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);
+27 -40
drivers/tty/tty_io.c
··· 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 ··· 573 574 } 574 575 spin_unlock(&redirect_lock); 575 576 576 - tty_lock(tty); 577 + tty_lock(); 577 578 578 579 /* some functions below drop BTM, so we need this bit */ 579 580 set_bit(TTY_HUPPING, &tty->flags); ··· 666 667 clear_bit(TTY_HUPPING, &tty->flags); 667 668 tty_ldisc_enable(tty); 668 669 669 - tty_unlock(tty); 670 + tty_unlock(); 670 671 671 672 if (f) 672 673 fput(f); ··· 1103 1104 { 1104 1105 if (tty) { 1105 1106 mutex_lock(&tty->atomic_write_lock); 1106 - tty_lock(tty); 1107 + tty_lock(); 1107 1108 if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) { 1108 - tty_unlock(tty); 1109 + tty_unlock(); 1109 1110 tty->ops->write(tty, msg, strlen(msg)); 1110 1111 } else 1111 - tty_unlock(tty); 1112 + tty_unlock(); 1112 1113 tty_write_unlock(tty); 1113 1114 } 1114 1115 return; ··· 1403 1404 } 1404 1405 initialize_tty_struct(tty, driver, idx); 1405 1406 1406 - tty_lock(tty); 1407 1407 retval = tty_driver_install_tty(driver, tty); 1408 1408 if (retval < 0) 1409 1409 goto err_deinit_tty; ··· 1415 1417 retval = tty_ldisc_setup(tty, tty->link); 1416 1418 if (retval) 1417 1419 goto err_release_tty; 1418 - /* Return the tty locked so that it cannot vanish under the caller */ 1419 1420 return tty; 1420 1421 1421 1422 err_deinit_tty: 1422 - tty_unlock(tty); 1423 1423 deinitialize_tty_struct(tty); 1424 1424 free_tty_struct(tty); 1425 1425 err_module_put: ··· 1426 1430 1427 1431 /* call the tty release_tty routine to clean out this slot */ 1428 1432 err_release_tty: 1429 - tty_unlock(tty); 1430 1433 printk_ratelimited(KERN_INFO "tty_init_dev: ldisc open failed, " 1431 1434 "clearing slot %d\n", idx); 1432 1435 release_tty(tty, idx); ··· 1628 1633 if (tty_paranoia_check(tty, inode, __func__)) 1629 1634 return 0; 1630 1635 1631 - tty_lock(tty); 1636 + tty_lock(); 1632 1637 check_tty_count(tty, __func__); 1633 1638 1634 1639 __tty_fasync(-1, filp, 0); ··· 1637 1642 pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY && 1638 1643 tty->driver->subtype == PTY_TYPE_MASTER); 1639 1644 devpts = (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) != 0; 1640 - /* Review: parallel close */ 1641 1645 o_tty = tty->link; 1642 1646 1643 1647 if (tty_release_checks(tty, o_tty, idx)) { 1644 - tty_unlock(tty); 1648 + tty_unlock(); 1645 1649 return 0; 1646 1650 } 1647 1651 ··· 1652 1658 if (tty->ops->close) 1653 1659 tty->ops->close(tty, filp); 1654 1660 1655 - tty_unlock(tty); 1661 + tty_unlock(); 1656 1662 /* 1657 1663 * Sanity check: if tty->count is going to zero, there shouldn't be 1658 1664 * any waiters on tty->read_wait or tty->write_wait. We test the ··· 1675 1681 opens on /dev/tty */ 1676 1682 1677 1683 mutex_lock(&tty_mutex); 1678 - tty_lock_pair(tty, o_tty); 1684 + tty_lock(); 1679 1685 tty_closing = tty->count <= 1; 1680 1686 o_tty_closing = o_tty && 1681 1687 (o_tty->count <= (pty_master ? 1 : 0)); ··· 1706 1712 1707 1713 printk(KERN_WARNING "%s: %s: read/write wait queue active!\n", 1708 1714 __func__, tty_name(tty, buf)); 1709 - tty_unlock_pair(tty, o_tty); 1715 + tty_unlock(); 1710 1716 mutex_unlock(&tty_mutex); 1711 1717 schedule(); 1712 1718 } ··· 1769 1775 1770 1776 /* check whether both sides are closing ... */ 1771 1777 if (!tty_closing || (o_tty && !o_tty_closing)) { 1772 - tty_unlock_pair(tty, o_tty); 1778 + tty_unlock(); 1773 1779 return 0; 1774 1780 } 1775 1781 ··· 1782 1788 tty_ldisc_release(tty, o_tty); 1783 1789 /* 1784 1790 * The release_tty function takes care of the details of clearing 1785 - * the slots and preserving the termios structure. The tty_unlock_pair 1786 - * should be safe as we keep a kref while the tty is locked (so the 1787 - * unlock never unlocks a freed tty). 1791 + * the slots and preserving the termios structure. 1788 1792 */ 1789 1793 release_tty(tty, idx); 1790 - tty_unlock_pair(tty, o_tty); 1791 1794 1792 1795 /* Make this pty number available for reallocation */ 1793 1796 if (devpts) 1794 1797 devpts_kill_index(inode, idx); 1798 + tty_unlock(); 1795 1799 return 0; 1796 1800 } 1797 1801 ··· 1893 1901 * Locking: tty_mutex protects tty, tty_lookup_driver and tty_init_dev. 1894 1902 * tty->count should protect the rest. 1895 1903 * ->siglock protects ->signal/->sighand 1896 - * 1897 - * Note: the tty_unlock/lock cases without a ref are only safe due to 1898 - * tty_mutex 1899 1904 */ 1900 1905 1901 1906 static int tty_open(struct inode *inode, struct file *filp) ··· 1916 1927 retval = 0; 1917 1928 1918 1929 mutex_lock(&tty_mutex); 1919 - /* This is protected by the tty_mutex */ 1930 + tty_lock(); 1931 + 1920 1932 tty = tty_open_current_tty(device, filp); 1921 1933 if (IS_ERR(tty)) { 1922 1934 retval = PTR_ERR(tty); ··· 1938 1948 } 1939 1949 1940 1950 if (tty) { 1941 - tty_lock(tty); 1942 1951 retval = tty_reopen(tty); 1943 - if (retval < 0) { 1944 - tty_unlock(tty); 1952 + if (retval) 1945 1953 tty = ERR_PTR(retval); 1946 - } 1947 - } else /* Returns with the tty_lock held for now */ 1954 + } else 1948 1955 tty = tty_init_dev(driver, index); 1949 1956 1950 1957 mutex_unlock(&tty_mutex); 1951 1958 if (driver) 1952 1959 tty_driver_kref_put(driver); 1953 1960 if (IS_ERR(tty)) { 1961 + tty_unlock(); 1954 1962 retval = PTR_ERR(tty); 1955 1963 goto err_file; 1956 1964 } ··· 1977 1989 printk(KERN_DEBUG "%s: error %d in opening %s...\n", __func__, 1978 1990 retval, tty->name); 1979 1991 #endif 1980 - tty_unlock(tty); /* need to call tty_release without BTM */ 1992 + tty_unlock(); /* need to call tty_release without BTM */ 1981 1993 tty_release(inode, filp); 1982 1994 if (retval != -ERESTARTSYS) 1983 1995 return retval; ··· 1989 2001 /* 1990 2002 * Need to reset f_op in case a hangup happened. 1991 2003 */ 2004 + tty_lock(); 1992 2005 if (filp->f_op == &hung_up_tty_fops) 1993 2006 filp->f_op = &tty_fops; 2007 + tty_unlock(); 1994 2008 goto retry_open; 1995 2009 } 1996 - tty_unlock(tty); 2010 + tty_unlock(); 1997 2011 1998 2012 1999 2013 mutex_lock(&tty_mutex); 2000 - tty_lock(tty); 2014 + tty_lock(); 2001 2015 spin_lock_irq(&current->sighand->siglock); 2002 2016 if (!noctty && 2003 2017 current->signal->leader && ··· 2007 2017 tty->session == NULL) 2008 2018 __proc_set_tty(current, tty); 2009 2019 spin_unlock_irq(&current->sighand->siglock); 2010 - tty_unlock(tty); 2020 + tty_unlock(); 2011 2021 mutex_unlock(&tty_mutex); 2012 2022 return 0; 2013 2023 err_unlock: 2024 + tty_unlock(); 2014 2025 mutex_unlock(&tty_mutex); 2015 2026 /* after locks to avoid deadlock */ 2016 2027 if (!IS_ERR_OR_NULL(driver)) ··· 2094 2103 2095 2104 static int tty_fasync(int fd, struct file *filp, int on) 2096 2105 { 2097 - struct tty_struct *tty = file_tty(filp); 2098 2106 int retval; 2099 - 2100 - tty_lock(tty); 2107 + tty_lock(); 2101 2108 retval = __tty_fasync(fd, filp, on); 2102 - tty_unlock(tty); 2103 - 2109 + tty_unlock(); 2104 2110 return retval; 2105 2111 } 2106 2112 ··· 2934 2946 tty->pgrp = NULL; 2935 2947 tty->overrun_time = jiffies; 2936 2948 tty_buffer_init(tty); 2937 - mutex_init(&tty->legacy_mutex); 2938 2949 mutex_init(&tty->termios_mutex); 2939 2950 mutex_init(&tty->ldisc_mutex); 2940 2951 init_waitqueue_head(&tty->write_wait);
+29 -38
drivers/tty/tty_ldisc.c
··· 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. ··· 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 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 /* ··· 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 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 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 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 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 ··· 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 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 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 ··· 912 929 * race with the set_ldisc code path. 913 930 */ 914 931 915 - tty_unlock_pair(tty, o_tty); 932 + tty_unlock(); 916 933 tty_ldisc_halt(tty); 917 934 tty_ldisc_flush_works(tty); 918 - if (o_tty) { 919 - tty_ldisc_halt(o_tty); 920 - tty_ldisc_flush_works(o_tty); 921 - } 922 - tty_lock_pair(tty, o_tty); 935 + tty_lock(); 923 936 937 + mutex_lock(&tty->ldisc_mutex); 938 + /* 939 + * Now kill off the ldisc 940 + */ 941 + tty_ldisc_close(tty, tty->ldisc); 942 + tty_ldisc_put(tty->ldisc); 943 + /* Force an oops if we mess this up */ 944 + tty->ldisc = NULL; 924 945 925 - tty_ldisc_kill(tty); 946 + /* Ensure the next open requests the N_TTY ldisc */ 947 + tty_set_termios_ldisc(tty, N_TTY); 948 + mutex_unlock(&tty->ldisc_mutex); 949 + 950 + /* This will need doing differently if we need to lock */ 926 951 if (o_tty) 927 - tty_ldisc_kill(o_tty); 952 + tty_ldisc_release(o_tty, NULL); 928 953 929 954 /* And the memory resources remaining (buffers, termios) will be 930 955 disposed of when the kref hits zero */
+15 -56
drivers/tty/tty_mutex.c
··· 4 4 #include <linux/semaphore.h> 5 5 #include <linux/sched.h> 6 6 7 - /* Legacy tty mutex glue */ 8 - 9 - enum { 10 - TTY_MUTEX_NORMAL, 11 - TTY_MUTEX_NESTED, 12 - }; 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); 13 18 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); 28 - } 29 - 30 - void __lockfunc tty_lock(struct tty_struct *tty) 31 - { 32 - return tty_lock_nested(tty, TTY_MUTEX_NORMAL); 24 + mutex_lock(&big_tty_mutex); 33 25 } 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);
+3 -3
drivers/tty/tty_port.c
··· 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; ··· 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
+9 -14
include/linux/tty.h
··· 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 */ ··· 605 606 606 607 /* tty_mutex.c */ 607 608 /* functions for preparation of BKL removal */ 608 - extern void __lockfunc tty_lock(struct tty_struct *tty); 609 - extern void __lockfunc tty_unlock(struct tty_struct *tty); 610 - extern void __lockfunc tty_lock_pair(struct tty_struct *tty, 611 - struct tty_struct *tty2); 612 - extern void __lockfunc tty_unlock_pair(struct tty_struct *tty, 613 - struct tty_struct *tty2); 609 + extern void __lockfunc tty_lock(void) __acquires(tty_lock); 610 + extern void __lockfunc tty_unlock(void) __releases(tty_lock); 614 611 615 612 /* 616 613 * this shall be called only from where BTM is held (like close) ··· 621 626 static inline void tty_wait_until_sent_from_close(struct tty_struct *tty, 622 627 long timeout) 623 628 { 624 - tty_unlock(tty); /* tty->ops->close holds the BTM, drop it while waiting */ 629 + tty_unlock(); /* tty->ops->close holds the BTM, drop it while waiting */ 625 630 tty_wait_until_sent(tty, timeout); 626 - tty_lock(tty); 631 + tty_lock(); 627 632 } 628 633 629 634 /* ··· 638 643 * 639 644 * Do not use in new code. 640 645 */ 641 - #define wait_event_interruptible_tty(tty, wq, condition) \ 646 + #define wait_event_interruptible_tty(wq, condition) \ 642 647 ({ \ 643 648 int __ret = 0; \ 644 649 if (!(condition)) { \ 645 - __wait_event_interruptible_tty(tty, wq, condition, __ret); \ 650 + __wait_event_interruptible_tty(wq, condition, __ret); \ 646 651 } \ 647 652 __ret; \ 648 653 }) 649 654 650 - #define __wait_event_interruptible_tty(tty, wq, condition, ret) \ 655 + #define __wait_event_interruptible_tty(wq, condition, ret) \ 651 656 do { \ 652 657 DEFINE_WAIT(__wait); \ 653 658 \ ··· 656 661 if (condition) \ 657 662 break; \ 658 663 if (!signal_pending(current)) { \ 659 - tty_unlock(tty); \ 664 + tty_unlock(); \ 660 665 schedule(); \ 661 - tty_lock(tty); \ 666 + tty_lock(); \ 662 667 continue; \ 663 668 } \ 664 669 ret = -ERESTARTSYS; \
+2 -2
net/bluetooth/rfcomm/tty.c
··· 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);