From bc15f69419485b9d912970391db51e7dc9fa5ee6 Mon Sep 17 00:00:00 2001 From: Konstantin Khlebnikov Date: Thu, 3 May 2012 15:44:44 +1000 Subject: [PATCH] fork: call complete_vfork_done() after clearing child_tid and flushing rss-counters Child should wake up the parent from vfork() only after finishing all operations with shared mm. There is no sense in using CLONE_CHILD_CLEARTID together with CLONE_VFORK, but it looks more accurate now. Signed-off-by: Konstantin Khlebnikov Cc: Oleg Nesterov Cc: Hugh Dickins Cc: KAMEZAWA Hiroyuki Cc: Konstantin Khlebnikov Cc: Markus Trippelsdorf Signed-off-by: Andrew Morton --- kernel/fork.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/kernel/fork.c b/kernel/fork.c index ccce08455906..0c12225aecad 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -760,9 +760,6 @@ void mm_release(struct task_struct *tsk, struct mm_struct *mm) /* Get rid of any cached register state */ deactivate_mm(tsk, mm); - if (tsk->vfork_done) - complete_vfork_done(tsk); - /* * If we're exiting normally, clear a user-space tid field if * requested. We leave this alone when dying by signal, to leave @@ -791,6 +788,13 @@ void mm_release(struct task_struct *tsk, struct mm_struct *mm) */ if (mm) sync_mm_rss(mm); + + /* + * All done, finally we can wake up parent and return this mm to him. + * Also kthread_stop() uses this completion for synchronization. + */ + if (tsk->vfork_done) + complete_vfork_done(tsk); } /* -- 2.39.5