Patchwork [3.5.yuz,extended,stable] Patch "Revert "cgroup: Remove task_lock() from cgroup_post_fork()"" has been added to staging queue

mail settings
Submitter Herton Ronaldo Krzesinski
Date Nov. 22, 2012, 4:46 a.m.
Message ID <>
Download mbox | patch
Permalink /patch/200953/
State New
Headers show


Herton Ronaldo Krzesinski - Nov. 22, 2012, 4:46 a.m.
This is a note to let you know that I have just added a patch titled

    Revert "cgroup: Remove task_lock() from cgroup_post_fork()"

to the linux-3.5.y-queue branch of the 3.5.yuz extended stable tree 
which can be found at:;a=shortlog;h=refs/heads/linux-3.5.y-queue

If you, or anyone else, feels it should not be added to this tree, please 
reply to this email.

For more information about the 3.5.yuz tree, see



From ef501122155212d6193bc95b82ef86828e56aad2 Mon Sep 17 00:00:00 2001
From: Tejun Heo <>
Date: Thu, 18 Oct 2012 17:40:30 -0700
Subject: [PATCH] Revert "cgroup: Remove task_lock() from cgroup_post_fork()"

commit d87838321124061f6c935069d97f37010fa417e6 upstream.

This reverts commit 7e3aa30ac8c904a706518b725c451bb486daaae9.

The commit incorrectly assumed that fork path always performed
threadgroup_change_begin/end() and depended on that for
synchronization against task exit and cgroup migration paths instead
of explicitly grabbing task_lock().

threadgroup_change is not locked when forking a new process (as
opposed to a new thread in the same process) and even if it were it
wouldn't be effective as different processes use different threadgroup

Revert the incorrect optimization.

Signed-off-by: Tejun Heo <>
LKML-Reference: <20121008020000.GB2575@localhost>
Acked-by: Li Zefan <>
Cc: Frederic Weisbecker <>
Signed-off-by: Herton Ronaldo Krzesinski <>
 kernel/cgroup.c |   15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)



diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 75d4318..a91aa0b 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -4805,19 +4805,10 @@  void cgroup_post_fork(struct task_struct *child)
 	if (use_task_css_set_links) {
-		if (list_empty(&child->cg_list)) {
-			/*
-			 * It's safe to use child->cgroups without task_lock()
-			 * here because we are protected through
-			 * threadgroup_change_begin() against concurrent
-			 * css_set change in cgroup_task_migrate(). Also
-			 * the task can't exit at that point until
-			 * wake_up_new_task() is called, so we are protected
-			 * against cgroup_exit() setting child->cgroup to
-			 * init_css_set.
-			 */
+		task_lock(child);
+		if (list_empty(&child->cg_list))
 			list_add(&child->cg_list, &child->cgroups->tasks);
-		}
+		task_unlock(child);