[PATCH] tty_check_change-avoid-taking-tasklist_lock-while-holding-tty-ctrl_lock-simplify

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Oleg Nesterov
Date: Thursday, May 15, 2008 - 9:27 am

On 05/14, Oleg Nesterov wrote:

IOW, I think the patch below makes sense.

With the previous patch tty->ctrl_lock buys nothing, it only protects the
"task_pgrp(current) == tty->pgrp" check, but tty->pgrp can be changed right
after spin_unlock_irqrestore(tty->ctrl_lock) anyway.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

--- HL/drivers/char/tty_io.c~TTY	2008-05-15 19:09:35.000000000 +0400
+++ HL/drivers/char/tty_io.c	2008-05-15 19:11:57.000000000 +0400
@@ -1199,27 +1199,21 @@ EXPORT_SYMBOL_GPL(tty_find_polling_drive
  *	If we try to write to, or set the state of, a terminal and we're
  *	not in the foreground, send a SIGTTOU.  If the signal is blocked or
  *	ignored, go ahead and perform the operation.  (POSIX 7.2)
- *
- *	Locking: ctrl_lock
  */
 
 int tty_check_change(struct tty_struct *tty)
 {
-	unsigned long flags;
 	int ret = 0;
 
 	if (current->signal->tty != tty)
 		return 0;
 
-	spin_lock_irqsave(&tty->ctrl_lock, flags);
-
 	if (!tty->pgrp) {
 		printk(KERN_WARNING "tty_check_change: tty->pgrp == NULL!\n");
-		goto out_unlock;
+		goto out;
 	}
 	if (task_pgrp(current) == tty->pgrp)
-		goto out_unlock;
-	spin_unlock_irqrestore(&tty->ctrl_lock, flags);
+		goto out;
 	if (is_ignored(SIGTTOU))
 		goto out;
 	if (is_current_pgrp_orphaned()) {
@@ -1231,9 +1225,6 @@ int tty_check_change(struct tty_struct *
 	ret = -ERESTARTSYS;
 out:
 	return ret;
-out_unlock:
-	spin_unlock_irqrestore(&tty->ctrl_lock, flags);
-	return ret;
 }
 
 EXPORT_SYMBOL(tty_check_change);

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[vfs/tty] possible circular locking dependency detected, Marcin Slusarz, (Mon May 12, 11:32 am)
[PATCH] tty_check_change-avoid-taking-tasklist_lock-while- ..., Oleg Nesterov, (Thu May 15, 9:27 am)