public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@tv-sign.ru>
To: Atsushi Tsuji <a-tsuji@bk.jp.nec.com>
Cc: linux-kernel@vger.kernel.org,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	Roland McGrath <roland@redhat.com>
Subject: Re: [PATCH] kill_something_info: don't take tasklist_lock for pid==-1 case
Date: Tue, 25 Mar 2008 16:56:45 +0300	[thread overview]
Message-ID: <20080325135645.GA96@tv-sign.ru> (raw)
In-Reply-To: <47E87F2A.2040303@bk.jp.nec.com>

On 03/25, Atsushi Tsuji wrote:
> 
> This patch avoid taking tasklist_lock in kill_something_info() when
> the pid is -1. It can convert to rcu_read_lock() for this case because
> group_send_sig_info() doesn't need tasklist_lock.
> 
> This patch is for 2.6.25-rc5-mm1.
> 
> Signed-off-by: Atsushi Tsuji <a-tsuji@bk.jp.nec.com>
> ---
> diff --git a/kernel/signal.c b/kernel/signal.c
> index 3edbfd4..a888c58 100644
> --- a/kernel/signal.c
> +++ b/kernel/signal.c
> @@ -1089,14 +1089,16 @@ static int kill_something_info(int sig, struct 
> siginfo *info, int pid)
>  		return ret;
>  	}
> 
> -	read_lock(&tasklist_lock);
>  	if (pid != -1) {
> +		read_lock(&tasklist_lock);
>  		ret = __kill_pgrp_info(sig, info,
>  				pid ? find_vpid(-pid) : task_pgrp(current));
> +		read_unlock(&tasklist_lock);
>  	} else {
>  		int retval = 0, count = 0;
>  		struct task_struct * p;
> 
> +		rcu_read_lock();
>  		for_each_process(p) {
>  			if (p->pid > 1 && !same_thread_group(p, current)) {
>  				int err = group_send_sig_info(sig, info, p);
> @@ -1106,8 +1108,8 @@ static int kill_something_info(int sig, struct 
> siginfo *info, int pid)
>  			}
>  		}
>  		ret = count ? retval : -ESRCH;
> +		rcu_read_unlock();
>  	}
> -	read_unlock(&tasklist_lock);
> 
>  	return ret;
>  }

Hmm. Yes, group_send_sig_info() doesn't need tasklist_lock. But we
take tasklist_lock to "freeze" the tasks list, so that we can't miss
a new forked process.

Same for __kill_pgrp_info(), we take tasklist to kill the whole group
"atomically".


However. Is it really needed? copy_process() returns -ERESTARTNOINTR
if signal_pending(), and the new task is always placed at the tail
of the list. Looks like nobody can escape the signal, at least fatal
or SIGSTOP.

If the signal is blocked/ignored or has a handler, we can miss a forked
child, but this looks OK, we can pretend it was forked after we dropped
tasklist_lock.

Note also that copy_process() does list_add_tail_rcu(p->tasks) under
->siglock, this means kill_something_info() must see the new childs
after group_send_sig_info() drops ->siglock.


Except: We don't send the signal to /sbin/init. This means that (say)
kill(-1, SIGKILL) can miss the task forked by init. Note that this
task could be forked even before we start kill_something_info(), but
without tasklist there is no guarantee we will see it on the ->tasks
list.

I think this is the only problem with this change.

Eric, Roland?

(Unfortunately, attach_pid() adds the task to the head of hlist, this
 means we can't avoid tasklist for __kill_pgrp_info).

Oleg.


  reply	other threads:[~2008-03-25 13:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-25  4:27 [PATCH] kill_something_info: don't take tasklist_lock for pid==-1 case Atsushi Tsuji
2008-03-25 13:56 ` Oleg Nesterov [this message]
2008-05-21  1:48   ` Atsushi Tsuji
2008-05-21  2:53     ` Eric W. Biederman
2008-05-21  3:47   ` Eric W. Biederman
2008-05-26  7:03     ` Atsushi TSUJI
2008-05-28 15:03       ` Eric W. Biederman
2008-05-31 16:55     ` Oleg Nesterov
2008-05-31 23:55       ` Eric W. Biederman
2008-06-01 16:29         ` Oleg Nesterov

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=20080325135645.GA96@tv-sign.ru \
    --to=oleg@tv-sign.ru \
    --cc=a-tsuji@bk.jp.nec.com \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roland@redhat.com \
    /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