public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@tv-sign.ru>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Marcin Slusarz <marcin.slusarz@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: [PATCH] tty_check_change-avoid-taking-tasklist_lock-while-holding-tty-ctrl_lock-simplify
Date: Thu, 15 May 2008 20:27:03 +0400	[thread overview]
Message-ID: <20080515162703.GA430@tv-sign.ru> (raw)
In-Reply-To: <20080514153933.GA122@tv-sign.ru>

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@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);


      reply	other threads:[~2008-05-15 16:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-12 18:32 [vfs/tty] possible circular locking dependency detected Marcin Slusarz
2008-05-14  1:47 ` Andrew Morton
2008-05-14 15:39   ` Oleg Nesterov
2008-05-15 16:27     ` Oleg Nesterov [this message]

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=20080515162703.GA430@tv-sign.ru \
    --to=oleg@tv-sign.ru \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcin.slusarz@gmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /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