All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Roland McGrath <roland@redhat.com>
Cc: Christoph Hellwig <hch@infradead.org>,
	Ingo Molnar <mingo@elte.hu>,
	linux-kernel@vger.kernel.org
Subject: [RFC PATCH 2/X] ptrace: avoid using task->ptrace when possible in ptrace.{c,h}
Date: Mon, 25 May 2009 01:59:58 +0200	[thread overview]
Message-ID: <20090524235958.GA2211@redhat.com> (raw)

Do some s/->ptrace/task_ptrace()/ changes in ptrace.{c,h} as a preparation
for the future changes.

Change ptrace_setoptions() to access ->ptrace only once.

 include/linux/ptrace.h |   31 ++++++++++++++++---------------
 kernel/ptrace.c        |   28 +++++++++++++++-------------
 2 files changed, 31 insertions(+), 28 deletions(-)

--- PTRACE/include/linux/ptrace.h~2_PTRACE	2009-05-24 21:36:37.000000000 +0200
+++ PTRACE/include/linux/ptrace.h	2009-05-24 22:01:15.000000000 +0200
@@ -106,15 +106,27 @@ static inline int ptrace_reparented(stru
 {
 	return child->real_parent != child->parent;
 }
+
+/**
+ * task_ptrace - return %PT_* flags that apply to a task
+ * @task:	pointer to &task_struct in question
+ *
+ * Returns the %PT_* flags that apply to @task.
+ */
+static inline int task_ptrace(struct task_struct *task)
+{
+	return task->ptrace;
+}
+
 static inline void ptrace_link(struct task_struct *child,
 			       struct task_struct *new_parent)
 {
-	if (unlikely(child->ptrace))
+	if (unlikely(task_ptrace(child)))
 		__ptrace_link(child, new_parent);
 }
 static inline void ptrace_unlink(struct task_struct *child)
 {
-	if (unlikely(child->ptrace))
+	if (unlikely(task_ptrace(child)))
 		__ptrace_unlink(child);
 }
 
@@ -122,19 +134,8 @@ int generic_ptrace_peekdata(struct task_
 int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data);
 
 /**
- * task_ptrace - return %PT_* flags that apply to a task
- * @task:	pointer to &task_struct in question
- *
- * Returns the %PT_* flags that apply to @task.
- */
-static inline int task_ptrace(struct task_struct *task)
-{
-	return task->ptrace;
-}
-
-/**
  * ptrace_event - possibly stop for a ptrace event notification
- * @mask:	%PT_* bit to check in @current->ptrace
+ * @mask:	%PT_* bit to check in task_ptrace(@current)
  * @event:	%PTRACE_EVENT_* value to report if @mask is set
  * @message:	value for %PTRACE_GETEVENTMSG to return
  *
@@ -147,7 +148,7 @@ static inline int task_ptrace(struct tas
  */
 static inline int ptrace_event(int mask, int event, unsigned long message)
 {
-	if (mask && likely(!(current->ptrace & mask)))
+	if (mask && likely(!(task_ptrace(current) & mask)))
 		return 0;
 	current->ptrace_message = message;
 	ptrace_notify((event << 8) | SIGTRAP);
--- PTRACE/kernel/ptrace.c~2_PTRACE	2009-05-24 21:36:37.000000000 +0200
+++ PTRACE/kernel/ptrace.c	2009-05-24 22:01:15.000000000 +0200
@@ -79,7 +79,7 @@ static void ptrace_untrace(struct task_s
  */
 void __ptrace_unlink(struct task_struct *child)
 {
-	BUG_ON(!child->ptrace);
+	BUG_ON(!task_ptrace(child));
 
 	child->ptrace = 0;
 	child->parent = child->real_parent;
@@ -105,7 +105,7 @@ int ptrace_check_attach(struct task_stru
 	 * be changed by us so it's not changing right after this.
 	 */
 	read_lock(&tasklist_lock);
-	if ((child->ptrace & PT_PTRACED) && child->parent == current) {
+	if (task_ptrace(child) && child->parent == current) {
 		ret = 0;
 		/*
 		 * child->sighand can't be NULL, release_task()
@@ -203,7 +203,7 @@ int ptrace_attach(struct task_struct *ta
 	retval = -EPERM;
 	if (unlikely(task->exit_state))
 		goto unlock_tasklist;
-	if (task->ptrace)
+	if (task_ptrace(task))
 		goto unlock_tasklist;
 
 	task->ptrace = PT_PTRACED;
@@ -234,7 +234,7 @@ int ptrace_traceme(void)
 
 	write_lock_irq(&tasklist_lock);
 	/* Are we already being traced? */
-	if (!current->ptrace) {
+	if (!task_ptrace(current)) {
 		ret = security_ptrace_traceme(current->parent);
 		/*
 		 * Check PF_EXITING to ensure ->real_parent has not passed
@@ -315,7 +315,7 @@ int ptrace_detach(struct task_struct *ch
 	 * This child can be already killed. Make sure de_thread() or
 	 * our sub-thread doing do_wait() didn't do release_task() yet.
 	 */
-	if (child->ptrace) {
+	if (task_ptrace(child)) {
 		child->exit_code = data;
 		dead = __ptrace_detach(current, child);
 	}
@@ -402,29 +402,31 @@ int ptrace_writedata(struct task_struct 
 
 static int ptrace_setoptions(struct task_struct *child, long data)
 {
-	child->ptrace &= ~PT_TRACE_MASK;
+	unsigned int new_flags = 0;
 
 	if (data & PTRACE_O_TRACESYSGOOD)
-		child->ptrace |= PT_TRACESYSGOOD;
+		new_flags |= PT_TRACESYSGOOD;
 
 	if (data & PTRACE_O_TRACEFORK)
-		child->ptrace |= PT_TRACE_FORK;
+		new_flags |= PT_TRACE_FORK;
 
 	if (data & PTRACE_O_TRACEVFORK)
-		child->ptrace |= PT_TRACE_VFORK;
+		new_flags |= PT_TRACE_VFORK;
 
 	if (data & PTRACE_O_TRACECLONE)
-		child->ptrace |= PT_TRACE_CLONE;
+		new_flags |= PT_TRACE_CLONE;
 
 	if (data & PTRACE_O_TRACEEXEC)
-		child->ptrace |= PT_TRACE_EXEC;
+		new_flags |= PT_TRACE_EXEC;
 
 	if (data & PTRACE_O_TRACEVFORKDONE)
-		child->ptrace |= PT_TRACE_VFORK_DONE;
+		new_flags |= PT_TRACE_VFORK_DONE;
 
 	if (data & PTRACE_O_TRACEEXIT)
-		child->ptrace |= PT_TRACE_EXIT;
+		new_flags |= PT_TRACE_EXIT;
 
+	child->ptrace &= ~PT_TRACE_MASK;
+	child->ptrace |= new_flags;
 	return (data & ~PTRACE_O_MASK) ? -EINVAL : 0;
 }
 


                 reply	other threads:[~2009-05-25  0:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20090524235958.GA2211@redhat.com \
    --to=oleg@redhat.com \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.