All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kirill Tkhai <ktkhai@odin.com>
To: <linux-kernel@vger.kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Ingo Molnar <mingo@redhat.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	Michal Hocko <mhocko@suse.cz>, "Rik van Riel" <riel@redhat.com>,
	Ionut Alexa <ionut.m.alexa@gmail.com>,
	Peter Hurley <peter@hurleysoftware.com>,
	Kirill Tkhai <tkhai@yandex.ru>
Subject: [PATCH RFC 12/13] exit: Delete write dependence on tasklist_lock in exit_notify()
Date: Mon, 25 May 2015 20:46:10 +0300	[thread overview]
Message-ID: <1432575970.6866.45.camel@odin.com> (raw)
In-Reply-To: <20150525162722.5171.15901.stgit@pro>

Relatives and parent notifications have already protected by appropriate
kin_lock, so we may do not to take tasklist_lock for writing.

Hovewer, we still need it read locked to protect PGRP and PSID.

Signed-off-by: Kirill Tkhai <ktkhai@odin.com>
---
 kernel/exit.c   |   19 +++++++------------
 kernel/ptrace.c |    6 +++---
 2 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/kernel/exit.c b/kernel/exit.c
index aeded00..99d7aa3 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -460,8 +460,6 @@ static struct task_struct *find_alive_thread(struct task_struct *p)
 }
 
 static void check_pid_ns_reaper_exit(struct task_struct *father)
-	__releases(&tasklist_lock)
-	__acquires(&tasklist_lock)
 {
 	struct pid_namespace *pid_ns = task_active_pid_ns(father);
 	struct task_struct *reaper;
@@ -473,7 +471,7 @@ static void check_pid_ns_reaper_exit(struct task_struct *father)
 	if (likely(reaper != father))
 		return;
 
-	write_lock(&pid_ns->cr_lock);
+	write_lock_irq(&pid_ns->cr_lock);
 	read_real_parent_lock(father);
 
 	reaper = find_alive_thread(father);
@@ -481,18 +479,16 @@ static void check_pid_ns_reaper_exit(struct task_struct *father)
 		pid_ns->child_reaper = reaper;
 
 	read_real_parent_unlock(father);
-	write_unlock(&pid_ns->cr_lock);
+	write_unlock_irq(&pid_ns->cr_lock);
 
 	if (reaper)
 		return;
 
-	write_unlock_irq(&tasklist_lock);
 	if (unlikely(pid_ns == &init_pid_ns)) {
 		panic("Attempted to kill init! exitcode=0x%08x\n",
 			father->signal->group_exit_code ?: father->exit_code);
 	}
 	zap_pid_ns_processes(pid_ns);
-	write_lock_irq(&tasklist_lock);
 }
 
 /*
@@ -598,7 +594,6 @@ static void forget_original_parent(struct task_struct *father,
 	if (unlikely(!list_empty(&father->ptraced)))
 		exit_ptrace(father, dead);
 
-	/* Can drop and reacquire tasklist_lock */
 	check_pid_ns_reaper_exit(father);
 
 	/* read_lock() guarantees concurrent thread sees our PF_EXITING */
@@ -609,7 +604,7 @@ static void forget_original_parent(struct task_struct *father,
 	}
 	read_unlock(&father->kin_lock);
 
-	read_lock(&task_active_pid_ns(father)->cr_lock);
+	read_lock_irq(&task_active_pid_ns(father)->cr_lock);
 	reaper = find_double_lock_new_reaper(father);
 
 	list_for_each_entry(p, &father->children, sibling) {
@@ -632,7 +627,7 @@ static void forget_original_parent(struct task_struct *father,
 	list_splice_tail_init(&father->children, &reaper->children);
 
 	double_write_unlock(&reaper->kin_lock, &father->kin_lock);
-	read_unlock(&task_active_pid_ns(father)->cr_lock);
+	read_unlock_irq(&task_active_pid_ns(father)->cr_lock);
 }
 
 /*
@@ -645,12 +640,13 @@ static void exit_notify(struct task_struct *tsk, int group_dead)
 	struct task_struct *p, *n;
 	LIST_HEAD(dead);
 
-	write_lock_irq(&tasklist_lock);
 	forget_original_parent(tsk, &dead);
 
+	read_lock_irq(&tasklist_lock);
 	write_parent_and_real_parent_lock(tsk);
 	if (group_dead)
 		kill_orphaned_pgrp(tsk->group_leader, NULL);
+	read_unlock(&tasklist_lock);
 
 	if (unlikely(tsk->ptrace)) {
 		int sig = thread_group_leader(tsk) &&
@@ -672,8 +668,7 @@ static void exit_notify(struct task_struct *tsk, int group_dead)
 	/* mt-exec, de_thread() is waiting for group leader */
 	if (unlikely(tsk->signal->notify_count < 0))
 		wake_up_process(tsk->signal->group_exit_task);
-	write_parent_and_real_parent_unlock(tsk);
-	write_unlock_irq(&tasklist_lock);
+	write_parent_and_real_parent_unlock_irq(tsk);
 
 	list_for_each_entry_safe(p, n, &dead, ptrace_entry) {
 		list_del_init(&p->ptrace_entry);
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index 6785f66..d6e2d0b 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -505,9 +505,9 @@ void exit_ptrace(struct task_struct *tracer, struct list_head *dead)
 		if (!p)
 			break;
 
-		write_parent_and_real_parent_lock(p);
+		write_parent_and_real_parent_lock_irq(p);
 		if (p->parent != tracer) {
-			write_parent_and_real_parent_unlock(p);
+			write_parent_and_real_parent_unlock_irq(p);
 			continue;
 		}
 
@@ -517,7 +517,7 @@ void exit_ptrace(struct task_struct *tracer, struct list_head *dead)
 		if (__ptrace_detach(tracer, p))
 			list_add(&p->ptrace_entry, dead);
 
-		write_parent_and_real_parent_unlock(p);
+		write_parent_and_real_parent_unlock_irq(p);
 	}
 	rcu_read_unlock();
 }




  parent reply	other threads:[~2015-05-25 17:46 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20150525162722.5171.15901.stgit@pro>
2015-05-25 17:44 ` [PATCH RFC 01/13] exit: Clarify choice of new parent in forget_original_parent() Kirill Tkhai
2015-05-25 17:44 ` [PATCH RFC 02/13] rwlock_t: Implement double_write_{,un}lock() Kirill Tkhai
2015-05-25 17:44 ` [PATCH RFC 03/13] pid_ns: Implement rwlock_t pid_ns::cr_lock for locking child_reaper Kirill Tkhai
2015-05-25 17:44 ` [PATCH RFC 04/13] exit: Small refactoring mm_update_next_owner() Kirill Tkhai
2015-05-25 17:45 ` [PATCH RFC 05/13] fs: Refactoring in get_children_pid() Kirill Tkhai
2015-05-25 17:45 ` [PATCH RFC 06/13] core: Add rwlock_t task_list::kin_lock Kirill Tkhai
2015-05-25 17:45 ` [PATCH RFC 07/13] kin_lock: Implement helpers for kin_lock locking Kirill Tkhai
2015-05-25 17:45 ` [PATCH RFC 08/13] core: Use kin_lock synchronizations between parent and child and for thread group Kirill Tkhai
2015-05-25 17:45 ` [PATCH RFC 09/13] exit: Use for_each_thread() in do_wait() Kirill Tkhai
2015-05-26 19:46   ` Oleg Nesterov
2015-05-27  9:33     ` Kirill Tkhai
2015-05-27  9:42       ` Kirill Tkhai
2015-05-25 17:45 ` [PATCH RFC 10/13] exit: Add struct wait_opts's member held_lock and use it for tasklist_lock Kirill Tkhai
2015-05-25 17:46 ` [PATCH RFC 11/13] exit: Syncronize on kin_lock while do_notify_parent() Kirill Tkhai
2015-05-25 17:46 ` Kirill Tkhai [this message]
2015-05-25 17:46 ` [PATCH RFC 13/13] core: Nest tasklist_lock into task_struct::kin_lock Kirill Tkhai

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=1432575970.6866.45.camel@odin.com \
    --to=ktkhai@odin.com \
    --cc=akpm@linux-foundation.org \
    --cc=ionut.m.alexa@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhocko@suse.cz \
    --cc=mingo@redhat.com \
    --cc=oleg@redhat.com \
    --cc=peter@hurleysoftware.com \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    --cc=tkhai@yandex.ru \
    /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.