Skip to contentSkip to conversation

coredump: don't take tasklist_lock

PATCH In review Oleg Nesterov 2 participants 2 messages Apr 6, 2006 – Apr 10, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 4/4 coredump: don't take tasklist_lock

depends on
"[PATCH rc1-mm] de_thread: fix deadlockable process addition"

This patch removes tasklist_lock from zap_threads(). This is safe wrt:

	do_exit:
		The caller holds mm->mmap_sem. This means that task which
		shares the same ->mm can't pass exit_mm(), so it can't be
		unhashed from init_task.tasks or ->thread_group lists.

	fork:
		None of sub-threads can fork after zap_process(leader). All
		processes which were created before this point should be
		visible to zap_threads() because copy_process() adds the new
		process to the tail of init_task.tasks list, and ->siglock
		lock/unlock provides a memory barrier.

	de_thread:
		It does list_replace_rcu(&leader->tasks, &current->tasks).
		So zap_threads() will see either old or new leader, it does
		not matter. However, it can change p->sighand, so we should
		use lock_task_sighand() in zap_process().
fs/exec.c renamed from fs/exec.c~4_TLOCK +8 -4
@@ -1385,7 +1385,11 @@ static void zap_process(struct task_stru
 	struct task_struct *t;
 	unsigned long flags;
 
-	spin_lock_irqsave(&start->sighand->siglock, flags);
+	/*
+	 * start->sighand can't disappear, but may be
+	 * changed by de_thread()
+	 */
+	lock_task_sighand(start, &flags);
 	start->signal->flags = SIGNAL_GROUP_EXIT;
 	start->signal->group_stop_count = 0;
 
@@ -1398,7 +1402,7 @@ static void zap_process(struct task_stru
 		}
 	} while ((t = next_thread(t)) != start);
 
-	spin_unlock_irqrestore(&start->sighand->siglock, flags);
+	unlock_task_sighand(start, &flags);
 }
 
 static void zap_threads(struct mm_struct *mm)
@@ -1416,7 +1420,7 @@ static void zap_threads(struct mm_struct
 		complete(vfork_done);
 	}
 
-	read_lock(&tasklist_lock);
+	rcu_read_lock();
 	for_each_process(g) {
 		p = g;
 		do {
@@ -1427,7 +1431,7 @@ static void zap_threads(struct mm_struct
 			}
 		} while ((p = next_thread(p)) != g);
 	}
-	read_unlock(&tasklist_lock);
+	rcu_read_unlock();
 }
 
 static void coredump_wait(struct mm_struct *mm)
#1 lore raw
Quoted 1 line

This patch removes tasklist_lock from zap_threads().

That's a very worthwhile thing to do, and this change looks good to me. I have not 100% followed the recent related de_thread discussion, but certainly issues there should be resolved such that this change can be done.

Thanks,
Roland