[PATCH] tty_check_change-avoid-taking-tasklist_lock-while-holding-tty-ctrl_lock-simplify
From: Oleg Nesterov
Date: Thu May 15 2008 - 12:26:23 EST
On 05/14, Oleg Nesterov wrote:
>
> The patch looks correct anyway, but perhaps tty_check_change() doesn't need
> ->ctrl_lock at all? We don't dereference tty->pgrp.
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@xxxxxxxxxx>
--- 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);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/