linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
	Roland McGrath <roland@redhat.com>
Cc: "Luis Claudio R. Goncalves" <lclaudio@uudg.org>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-mm <linux-mm@kvack.org>,
	David Rientjes <rientjes@google.com>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	Nick Piggin <npiggin@suse.de>,
	Minchan Kim <minchan.kim@gmail.com>
Subject: [PATCH 1/1] signals: introduce send_sigkill() helper
Date: Thu, 10 Jun 2010 03:00:23 +0200	[thread overview]
Message-ID: <20100610010023.GB4727@redhat.com> (raw)
In-Reply-To: <20100610005937.GA4727@redhat.com>

Cleanup, no functional changes.

There are a lot of buggy SIGKILL users in kernel. For example, almost
every force_sig(SIGKILL) is wrong. force_sig() is not safe, it assumes
that the task has the valid ->sighand, and in general it should be used
only for synchronous signals. send_sig(SIGKILL, p, 1) or
send_xxx(SEND_SIG_FORCED/SEND_SIG_PRIV) is not right too but this is not
immediately obvious.

The only way to correctly send SIGKILL is send_sig_info(SEND_SIG_NOINFO)
but we do not want to use this directly, because we can optimize this
case later. For example, zap_pid_ns_processes() allocates sigqueue for
each process in namespace, this is unneeded.

Introduce the trivial send_sigkill() helper on top of send_sig_info()
and change zap_pid_ns_processes() as an example.

Note: we need more cleanups here, this is only the first change.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---

 include/linux/sched.h  |    9 +++++++++
 kernel/pid_namespace.c |    8 +-------
 2 files changed, 10 insertions(+), 7 deletions(-)

--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2053,6 +2053,15 @@ static inline int kill_cad_pid(int sig, 
 #define SEND_SIG_PRIV	((struct siginfo *) 1)
 #define SEND_SIG_FORCED	((struct siginfo *) 2)
 
+static inline int send_sigkill(struct task_struct * p)
+{
+	/*
+	 * Kills any user-space task, even SIGNAL_UNKILLABLE.
+	 * We use SEND_SIG_NOINFO to make si_fromuser() true.
+	 */
+	return send_sig_info(SIGKILL, SEND_SIG_NOINFO, p);
+}
+
 /*
  * True if we are on the alternate signal stack.
  */
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -160,15 +160,9 @@ void zap_pid_ns_processes(struct pid_nam
 	nr = next_pidmap(pid_ns, 1);
 	while (nr > 0) {
 		rcu_read_lock();
-
-		/*
-		 * Any nested-container's init processes won't ignore the
-		 * SEND_SIG_NOINFO signal, see send_signal()->si_fromuser().
-		 */
 		task = pid_task(find_vpid(nr), PIDTYPE_PID);
 		if (task)
-			send_sig_info(SIGKILL, SEND_SIG_NOINFO, task);
-
+			send_sigkill(task);
 		rcu_read_unlock();
 
 		nr = next_pidmap(pid_ns, nr);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2010-06-10  1:02 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-08 11:53 [0/10] 3rd pile of OOM patch series KOSAKI Motohiro
2010-06-08 11:54 ` [PATCH 01/10] oom: don't try to kill oom_unkillable child KOSAKI Motohiro
2010-06-08 19:10   ` David Rientjes
2010-06-08 11:55 ` [PATCH 02/10] oom: remove verbose argument from __oom_kill_process() KOSAKI Motohiro
2010-06-08 19:09   ` David Rientjes
2010-06-08 11:56 ` [PATCH 03/10] oom: rename badness() to oom_badness() KOSAKI Motohiro
2010-06-08 19:09   ` David Rientjes
2010-06-08 11:57 ` [PATCH 04/10] oom: move sysctl declarations to oom.h KOSAKI Motohiro
2010-06-08 11:58 ` [PATCH 05/10] oom: enable oom tasklist dump by default KOSAKI Motohiro
2010-06-08 11:59 ` [PATCH 06/10] oom: cleanup has_intersects_mems_allowed() KOSAKI Motohiro
2010-06-08 19:07   ` David Rientjes
2010-06-08 11:59 ` [PATCH 07/10] oom: kill useless debug print KOSAKI Motohiro
2010-06-08 19:01   ` David Rientjes
2010-06-08 12:01 ` [PATCH 08/10] oom: use send_sig() instead force_sig() KOSAKI Motohiro
2010-06-08 18:41   ` Oleg Nesterov
2010-06-10  0:59     ` [PATCH 0/1] signals: introduce send_sigkill() helper Oleg Nesterov
2010-06-10  1:00       ` Oleg Nesterov [this message]
2010-06-11  0:40         ` [PATCH 1/1] " KAMEZAWA Hiroyuki
2010-06-13 11:24         ` KOSAKI Motohiro
2010-06-13 15:29         ` Oleg Nesterov
2010-06-16 10:00           ` KOSAKI Motohiro
2010-06-13 11:24     ` [PATCH 08/10] oom: use send_sig() instead force_sig() KOSAKI Motohiro
2010-06-08 12:02 ` [PATCH 09/10] oom: filter tasks not sharing the same cpuset KOSAKI Motohiro
2010-06-08 19:05   ` David Rientjes
2010-06-08 12:04 ` [PATCH 10/10] oom: select task from tasklist for mempolicy ooms KOSAKI Motohiro

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=20100610010023.GB4727@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=lclaudio@uudg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan.kim@gmail.com \
    --cc=npiggin@suse.de \
    --cc=rientjes@google.com \
    --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;
as well as URLs for NNTP newsgroup(s).