mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Roland McGrath <roland@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: utrace-devel@redhat.com, linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] signals: tracehook_notify_jctl change
Date: Fri, 20 Mar 2009 18:41:00 -0700 (PDT)	[thread overview]
Message-ID: <20090321014100.5C4A9FC3AB@magilla.sf.frob.com> (raw)
In-Reply-To: Roland McGrath's message of  Friday, 20 March 2009 18:39:46 -0700 <20090321013946.890F4FC3AB@magilla.sf.frob.com>

This changes tracehook_notify_jctl() so it's called with the siglock held,
and changes its argument and return value definition.  These clean-ups make
it a better fit for what new tracing hooks need to check.

Tracing needs the siglock here, held from the time TASK_STOPPED was set,
to avoid potential SIGCONT races if it wants to allow any blocking in its
tracing hooks.

This also folds the finish_stop() function into its caller do_signal_stop().
The function is short, called only once and only unconditionally.  It aids
readability to fold it in.

Signed-off-by: Roland McGrath <roland@redhat.com>
---
 include/linux/tracehook.h |   25 ++++++++++------
 kernel/signal.c           |   69 +++++++++++++++++++++++----------------------
 2 files changed, 51 insertions(+), 43 deletions(-)

diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
index 6186a78..b622498 100644  
--- a/include/linux/tracehook.h
+++ b/include/linux/tracehook.h
@@ -1,7 +1,7 @@
 /*
  * Tracing hooks
  *
- * Copyright (C) 2008 Red Hat, Inc.  All rights reserved.
+ * Copyright (C) 2008-2009 Red Hat, Inc.  All rights reserved.
  *
  * This copyrighted material is made available to anyone wishing to use,
  * modify, copy, or redistribute it subject to the terms and conditions
@@ -469,22 +469,29 @@ static inline int tracehook_get_signal(s
 
 /**
  * tracehook_notify_jctl - report about job control stop/continue
- * @notify:		nonzero if this is the last thread in the group to stop
+ * @notify:		zero, %CLD_STOPPED or %CLD_CONTINUED
  * @why:		%CLD_STOPPED or %CLD_CONTINUED
  *
  * This is called when we might call do_notify_parent_cldstop().
- * It's called when about to stop for job control; we are already in
- * %TASK_STOPPED state, about to call schedule().  It's also called when
- * a delayed %CLD_STOPPED or %CLD_CONTINUED report is ready to be made.
  *
- * Return nonzero to generate a %SIGCHLD with @why, which is
- * normal if @notify is nonzero.
+ * @notify is zero if we would not ordinarily send a %SIGCHLD,
+ * or is the %CLD_STOPPED or %CLD_CONTINUED .si_code for %SIGCHLD.
  *
- * Called with no locks held.
+ * @why is %CLD_STOPPED when about to stop for job control;
+ * we are already in %TASK_STOPPED state, about to call schedule().
+ * It might also be that we have just exited (check %PF_EXITING),
+ * but need to report that a group-wide stop is complete.
+ *
+ * @why is %CLD_CONTINUED when waking up after job control stop and
+ * ready to make a delayed @notify report.
+ *
+ * Return the %CLD_* value for %SIGCHLD, or zero to generate no signal.
+ *
+ * Called with the siglock held.
  */
 static inline int tracehook_notify_jctl(int notify, int why)
 {
-	return notify || (current->ptrace & PT_PTRACED);
+	return notify ?: (current->ptrace & PT_PTRACED) ? why : 0;
 }
 
 #define DEATH_REAP			-1
diff --git a/kernel/signal.c b/kernel/signal.c
index 2a74fe8..9a0d98f 100644  
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -691,7 +691,7 @@ static int prepare_signal(int sig, struc
 
 		if (why) {
 			/*
-			 * The first thread which returns from finish_stop()
+			 * The first thread which returns from do_signal_stop()
 			 * will take ->siglock, notice SIGNAL_CLD_MASK, and
 			 * notify its parent. See get_signal_to_deliver().
 			 */
@@ -1629,29 +1629,6 @@ void ptrace_notify(int exit_code)
 	spin_unlock_irq(&current->sighand->siglock);
 }
 
-static void
-finish_stop(int stop_count)
-{
-	/*
-	 * If there are no other threads in the group, or if there is
-	 * a group stop in progress and we are the last to stop,
-	 * report to the parent.  When ptraced, every thread reports itself.
-	 */
-	if (tracehook_notify_jctl(stop_count == 0, CLD_STOPPED)) {
-		read_lock(&tasklist_lock);
-		do_notify_parent_cldstop(current, CLD_STOPPED);
-		read_unlock(&tasklist_lock);
-	}
-
-	do {
-		schedule();
-	} while (try_to_freeze());
-	/*
-	 * Now we don't run again until continued.
-	 */
-	current->exit_code = 0;
-}
-
 /*
  * This performs the stopping for SIGSTOP and other stop signals.
  * We have to stop all threads in the thread group.
@@ -1662,6 +1639,7 @@ static int do_signal_stop(int signr)
 {
 	struct signal_struct *sig = current->signal;
 	int stop_count;
+	int notify;
 
 	if (sig->group_stop_count > 0) {
 		/*
@@ -1701,8 +1679,30 @@ static int do_signal_stop(int signr)
 	current->exit_code = sig->group_exit_code;
 	__set_current_state(TASK_STOPPED);
 
+	/*
+	 * If there are no other threads in the group, or if there is
+	 * a group stop in progress and we are the last to stop,
+	 * report to the parent.  When ptraced, every thread reports itself.
+	 */
+	notify = tracehook_notify_jctl(stop_count == 0 ? CLD_STOPPED : 0,
+				       CLD_STOPPED);
+
 	spin_unlock_irq(&current->sighand->siglock);
-	finish_stop(stop_count);
+
+	if (notify) {
+		read_lock(&tasklist_lock);
+		do_notify_parent_cldstop(current, notify);
+		read_unlock(&tasklist_lock);
+	}
+
+	do {
+		schedule();
+	} while (try_to_freeze());
+	/*
+	 * Now we don't run again until continued.
+	 */
+	current->exit_code = 0;
+
 	return 1;
 }
 
@@ -1771,14 +1771,15 @@ relock:
 		int why = (signal->flags & SIGNAL_STOP_CONTINUED)
 				? CLD_CONTINUED : CLD_STOPPED;
 		signal->flags &= ~SIGNAL_CLD_MASK;
-		spin_unlock_irq(&sighand->siglock);
 
-		if (unlikely(!tracehook_notify_jctl(1, why)))
-			goto relock;
+		why = tracehook_notify_jctl(why, CLD_CONTINUED);
+		spin_unlock_irq(&sighand->siglock);
 
-		read_lock(&tasklist_lock);
-		do_notify_parent_cldstop(current->group_leader, why);
-		read_unlock(&tasklist_lock);
+		if (why) {
+			read_lock(&tasklist_lock);
+			do_notify_parent_cldstop(current->group_leader, why);
+			read_unlock(&tasklist_lock);
+		}
 		goto relock;
 	}
 
@@ -1936,14 +1937,14 @@ void exit_signals(struct task_struct *ts
 	if (unlikely(tsk->signal->group_stop_count) &&
 			!--tsk->signal->group_stop_count) {
 		tsk->signal->flags = SIGNAL_STOP_STOPPED;
-		group_stop = 1;
+		group_stop = tracehook_notify_jctl(CLD_STOPPED, CLD_STOPPED);
 	}
 out:
 	spin_unlock_irq(&tsk->sighand->siglock);
 
-	if (unlikely(group_stop) && tracehook_notify_jctl(1, CLD_STOPPED)) {
+	if (unlikely(group_stop)) {
 		read_lock(&tasklist_lock);
-		do_notify_parent_cldstop(tsk, CLD_STOPPED);
+		do_notify_parent_cldstop(tsk, group_stop);
 		read_unlock(&tasklist_lock);
 	}
 }

  reply	other threads:[~2009-03-21  1:42 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-21  1:39 [PATCH 0/3] utrace Roland McGrath
2009-03-21  1:41 ` Roland McGrath [this message]
2009-03-21  1:41 ` [PATCH 2/3] utrace core Roland McGrath
2009-03-21  8:49   ` Andrew Morton
2009-03-21 14:08     ` Renzo Davoli
2009-03-21 14:34       ` Ingo Molnar
2009-03-21 16:37         ` Renzo Davoli
2009-03-21 16:44           ` Ingo Molnar
2009-03-23  4:34             ` Roland McGrath
2009-03-23  4:35     ` Roland McGrath
2009-03-23 10:57     ` Will Newton
2009-03-21  1:42 ` [PATCH 3/3] utrace-based ftrace "process" engine, v2 Roland McGrath
2009-03-21  7:43   ` Ingo Molnar
2009-03-21  8:39     ` Andrew Morton
2009-03-21  9:12       ` Ingo Molnar
2009-03-21 11:19         ` Andrew Morton
2009-03-21 11:51           ` Frank Ch. Eigler
2009-03-21 12:04             ` Andrew Morton
2009-03-21 12:57               ` Frank Ch. Eigler
2009-03-21 15:45               ` Ingo Molnar
2009-03-21 20:35                 ` Diego Calleja
2009-03-22 12:17                   ` Ingo Molnar
2009-03-21 21:34                 ` Andrew Morton
2009-03-21 21:51                   ` Frank Ch. Eigler
2009-03-21 22:02                     ` Linus Torvalds
2009-03-21 22:20                       ` Frank Ch. Eigler
2009-03-21 22:37                         ` Alexey Dobriyan
2009-03-21 23:38                           ` Frank Ch. Eigler
2009-03-22 10:25                             ` Ingo Molnar
2009-03-23  5:33                               ` Roland McGrath
2009-03-23  5:20                             ` Roland McGrath
2009-03-22 12:37                       ` Ingo Molnar
2009-03-23 13:48                         ` Alexey Dobriyan
2009-03-23 15:14                           ` Oleg Nesterov
2009-03-23 21:44                             ` Theodore Tso
2009-03-30 22:18                               ` Andrew Morton
2009-03-30 22:52                                 ` Frank Ch. Eigler
2009-03-31  9:17                                 ` Peter Zijlstra
2009-03-31 11:27                                   ` Peter Zijlstra
2009-03-31 11:38                                   ` Frank Ch. Eigler
2009-03-31 16:25                                   ` Christoph Hellwig
2009-03-31 20:54                                     ` Roland McGrath
2009-03-21 21:48                 ` Frank Ch. Eigler
2009-03-22 12:08                   ` Ingo Molnar
2009-03-22 12:53                     ` Ingo Molnar
2009-03-23 20:25                     ` Frank Ch. Eigler
2009-03-23 20:39                       ` Linus Torvalds
2009-03-23  5:09               ` Roland McGrath
2009-03-24  5:29               ` Ananth N Mavinakayanahalli
2009-03-24  5:54                 ` Andrew Morton
2009-03-24  6:10                   ` Ananth N Mavinakayanahalli
2009-03-23  4:49         ` Roland McGrath
2009-03-23  6:34           ` Ingo Molnar

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=20090321014100.5C4A9FC3AB@magilla.sf.frob.com \
    --to=roland@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=oleg@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

all inboxes | Powered by JetHome®