public inbox for linux-next@vger.kernel.org 
 help / color / mirror / Atom feed
From: Siddhesh Poyarekar <siddhesh.poyarekar@gmail•com>
To: Mark Salter <msalter@redhat•com>
Cc: linux-next <linux-next@vger•kernel.org>,
	linux-kernel <linux-kernel@vger•kernel.org>,
	Andrew Morton <akpm@linux-foundation•org>,
	Paul Gortmaker <paul.gortmaker@windriver•com>,
	Oleg Nesterov <oleg@redhat•com>,
	Siddhesh Poyarekar <siddhesh.poyarekar@gmail•com>
Subject: [PATCH 2/2] mm/linux-next: Fix rcu locking in vm_is_stack
Date: Wed,  7 Mar 2012 01:46:34 +0530	[thread overview]
Message-ID: <1331064994-6693-2-git-send-email-siddhesh.poyarekar@gmail.com> (raw)
In-Reply-To: <1331064994-6693-1-git-send-email-siddhesh.poyarekar@gmail.com>

Take rcu read lock before we do anything at all with the threadgroup
list. Also use list_first_entry_rcu to safely get the reference to the
first task in the list.

Signed-off-by: Siddhesh Poyarekar <siddhesh.poyarekar@gmail•com>
---
 mm/memory.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index 0ca7fe6..1d5830c 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3932,18 +3932,20 @@ pid_t vm_is_stack(struct task_struct *task,
 		return task->pid;
 
 	if (in_group) {
-		struct task_struct *t = task;
+		struct task_struct *t;
 		rcu_read_lock();
-		while_each_thread(task, t) {
+		t = list_first_entry_rcu(&task->thread_group,
+					 struct task_struct, thread_group);
+		do {
 			if (vm_is_stack_for_task(t, vma)) {
 				ret = t->pid;
 				goto done;
 			}
-		}
+		} while_each_thread(task, t);
+done:
+		rcu_read_unlock();
 	}
 
-done:
-	rcu_read_unlock();
 	return ret;
 }
 
-- 
1.7.7.4

  reply	other threads:[~2012-03-06 20:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-06 14:49 nommu build failure in linux-next Mark Salter
2012-03-06 15:19 ` Siddhesh Poyarekar
2012-03-06 20:16 ` [PATCH 1/2] mm: Fix task_nommu build regression " Siddhesh Poyarekar
2012-03-06 20:16   ` Siddhesh Poyarekar [this message]
2012-03-07 15:38     ` [PATCH 2/2] mm/linux-next: Fix rcu locking in vm_is_stack Oleg Nesterov
2012-03-07 16:05       ` Siddhesh Poyarekar
2012-03-07 22:11       ` Siddhesh Poyarekar
2012-03-08 17:40         ` Oleg Nesterov
2012-03-08 18:35           ` Siddhesh Poyarekar
2012-03-06 20:39   ` [PATCH 1/2] mm: Fix task_nommu build regression in linux-next Andrew Morton
2012-03-07  3:31     ` Siddhesh Poyarekar
2012-03-07 16:43   ` Siddhesh Poyarekar

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=1331064994-6693-2-git-send-email-siddhesh.poyarekar@gmail.com \
    --to=siddhesh.poyarekar@gmail$(echo .)com \
    --cc=akpm@linux-foundation$(echo .)org \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=linux-next@vger$(echo .)kernel.org \
    --cc=msalter@redhat$(echo .)com \
    --cc=oleg@redhat$(echo .)com \
    --cc=paul.gortmaker@windriver$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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