* [PATCH] do_task_stat: don't take tty_mutex
@ 2006-10-22 15:57 Oleg Nesterov
2006-10-23 11:16 ` Peter Zijlstra
0 siblings, 1 reply; 3+ messages in thread
From: Oleg Nesterov @ 2006-10-22 15:57 UTC (permalink / raw)
To: Andrew Morton; +Cc: Peter Zijlstra, Alan Cox, linux-kernel
Depends on
tty-signal-tty-locking.patch
->signal->tty is protected by ->siglock, no need to take the global tty_mutex.
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
--- rc2-mm2/fs/proc/array.c~ 2006-10-22 19:28:17.000000000 +0400
+++ rc2-mm2/fs/proc/array.c 2006-10-22 19:45:52.000000000 +0400
@@ -346,20 +346,13 @@ static int do_task_stat(struct task_stru
sigemptyset(&sigcatch);
cutime = cstime = utime = stime = cputime_zero;
- mutex_lock(&tty_mutex);
rcu_read_lock();
if (lock_task_sighand(task, &flags)) {
struct signal_struct *sig = task->signal;
- struct tty_struct *tty = sig->tty;
- if (tty) {
- /*
- * sig->tty is not stable, but tty_mutex
- * protects us from release_dev(tty)
- */
- barrier();
- tty_pgrp = tty->pgrp;
- tty_nr = new_encode_dev(tty_devnum(tty));
+ if (sig->tty) {
+ tty_pgrp = sig->tty->pgrp;
+ tty_nr = new_encode_dev(tty_devnum(sig->tty));
}
num_threads = atomic_read(&sig->count);
@@ -395,7 +388,6 @@ static int do_task_stat(struct task_stru
unlock_task_sighand(task, &flags);
}
rcu_read_unlock();
- mutex_unlock(&tty_mutex);
if (!whole || num_threads<2)
wchan = get_wchan(task);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] do_task_stat: don't take tty_mutex
2006-10-22 15:57 [PATCH] do_task_stat: don't take tty_mutex Oleg Nesterov
@ 2006-10-23 11:16 ` Peter Zijlstra
2006-10-23 14:05 ` Oleg Nesterov
0 siblings, 1 reply; 3+ messages in thread
From: Peter Zijlstra @ 2006-10-23 11:16 UTC (permalink / raw)
To: Oleg Nesterov; +Cc: Andrew Morton, Alan Cox, linux-kernel
On Sun, 2006-10-22 at 19:57 +0400, Oleg Nesterov wrote:
> Depends on
> tty-signal-tty-locking.patch
>
> ->signal->tty is protected by ->siglock, no need to take the global tty_mutex.
>
> Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
->siglock protects the value of ->signal->tty, not memory it points to;
however since destroying the tty also means clearing all ->signal->tty
references, which means taking all ->siglocks, just holding the
->siglock around this piece of code looks sufficient indeed.
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
> --- rc2-mm2/fs/proc/array.c~ 2006-10-22 19:28:17.000000000 +0400
> +++ rc2-mm2/fs/proc/array.c 2006-10-22 19:45:52.000000000 +0400
> @@ -346,20 +346,13 @@ static int do_task_stat(struct task_stru
> sigemptyset(&sigcatch);
> cutime = cstime = utime = stime = cputime_zero;
>
> - mutex_lock(&tty_mutex);
> rcu_read_lock();
> if (lock_task_sighand(task, &flags)) {
> struct signal_struct *sig = task->signal;
> - struct tty_struct *tty = sig->tty;
>
> - if (tty) {
> - /*
> - * sig->tty is not stable, but tty_mutex
> - * protects us from release_dev(tty)
> - */
> - barrier();
> - tty_pgrp = tty->pgrp;
> - tty_nr = new_encode_dev(tty_devnum(tty));
> + if (sig->tty) {
> + tty_pgrp = sig->tty->pgrp;
> + tty_nr = new_encode_dev(tty_devnum(sig->tty));
> }
>
> num_threads = atomic_read(&sig->count);
> @@ -395,7 +388,6 @@ static int do_task_stat(struct task_stru
> unlock_task_sighand(task, &flags);
> }
> rcu_read_unlock();
> - mutex_unlock(&tty_mutex);
>
> if (!whole || num_threads<2)
> wchan = get_wchan(task);
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] do_task_stat: don't take tty_mutex
2006-10-23 11:16 ` Peter Zijlstra
@ 2006-10-23 14:05 ` Oleg Nesterov
0 siblings, 0 replies; 3+ messages in thread
From: Oleg Nesterov @ 2006-10-23 14:05 UTC (permalink / raw)
To: Peter Zijlstra; +Cc: Andrew Morton, Alan Cox, linux-kernel
On 10/23, Peter Zijlstra wrote:
>
> On Sun, 2006-10-22 at 19:57 +0400, Oleg Nesterov wrote:
> > Depends on
> > tty-signal-tty-locking.patch
> >
> > ->signal->tty is protected by ->siglock, no need to take the global tty_mutex.
> >
> > Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
>
> ->siglock protects the value of ->signal->tty, not memory it points to;
Yes. That is why we can't avoid tty_mutex in audit_log_exit() (unless we copy
tty->name to the safe location). But is is bad we take tasklist_lock to access
tsk->signal. This 'tsk' should be 'current', we can use get_current_tty().
Or we can use lock_task_sighand() to be safe.
What do you think?
Oleg.
> however since destroying the tty also means clearing all ->signal->tty
> references, which means taking all ->siglocks, just holding the
> ->siglock around this piece of code looks sufficient indeed.
>
> Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
>
> > --- rc2-mm2/fs/proc/array.c~ 2006-10-22 19:28:17.000000000 +0400
> > +++ rc2-mm2/fs/proc/array.c 2006-10-22 19:45:52.000000000 +0400
> > @@ -346,20 +346,13 @@ static int do_task_stat(struct task_stru
> > sigemptyset(&sigcatch);
> > cutime = cstime = utime = stime = cputime_zero;
> >
> > - mutex_lock(&tty_mutex);
> > rcu_read_lock();
> > if (lock_task_sighand(task, &flags)) {
> > struct signal_struct *sig = task->signal;
> > - struct tty_struct *tty = sig->tty;
> >
> > - if (tty) {
> > - /*
> > - * sig->tty is not stable, but tty_mutex
> > - * protects us from release_dev(tty)
> > - */
> > - barrier();
> > - tty_pgrp = tty->pgrp;
> > - tty_nr = new_encode_dev(tty_devnum(tty));
> > + if (sig->tty) {
> > + tty_pgrp = sig->tty->pgrp;
> > + tty_nr = new_encode_dev(tty_devnum(sig->tty));
> > }
> >
> > num_threads = atomic_read(&sig->count);
> > @@ -395,7 +388,6 @@ static int do_task_stat(struct task_stru
> > unlock_task_sighand(task, &flags);
> > }
> > rcu_read_unlock();
> > - mutex_unlock(&tty_mutex);
> >
> > if (!whole || num_threads<2)
> > wchan = get_wchan(task);
> >
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-10-23 14:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-22 15:57 [PATCH] do_task_stat: don't take tty_mutex Oleg Nesterov
2006-10-23 11:16 ` Peter Zijlstra
2006-10-23 14:05 ` Oleg Nesterov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox