cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Frederic Weisbecker
	<fweisbec-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>,
	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH cgroup/for-3.7-fixes 2/2] Revert "cgroup: Drop task_lock(parent) on cgroup_fork()"
Date: Thu, 18 Oct 2012 17:59:51 -0700	[thread overview]
Message-ID: <20121019005951.GH13370@google.com> (raw)
In-Reply-To: <20121008020000.GB2575@localhost>

From c8b27924a8b6fd74066088f1cf07c256bbc6ed74 Mon Sep 17 00:00:00 2001
From: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Date: Thu, 18 Oct 2012 17:52:07 -0700

This reverts commit 7e381b0eb1e1a9805c37335562e8dc02e7d7848c.

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
locks.

Revert the incorrect optimization.

Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
LKML-Reference: <20121008020000.GB2575@localhost>
Cc: Frederic Weisbecker <fweisbec-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
Cc: stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
---
 kernel/cgroup.c |   23 ++++++-----------------
 1 files changed, 6 insertions(+), 17 deletions(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 2990dc7..f24f724 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -4814,31 +4814,20 @@ static const struct file_operations proc_cgroupstats_operations = {
  *
  * A pointer to the shared css_set was automatically copied in
  * fork.c by dup_task_struct().  However, we ignore that copy, since
- * it was not made under the protection of RCU, cgroup_mutex or
- * threadgroup_change_begin(), so it might no longer be a valid
- * cgroup pointer.  cgroup_attach_task() might have already changed
- * current->cgroups, allowing the previously referenced cgroup
- * group to be removed and freed.
- *
- * Outside the pointer validity we also need to process the css_set
- * inheritance between threadgoup_change_begin() and
- * threadgoup_change_end(), this way there is no leak in any process
- * wide migration performed by cgroup_attach_proc() that could otherwise
- * miss a thread because it is too early or too late in the fork stage.
+ * it was not made under the protection of RCU or cgroup_mutex, so
+ * might no longer be a valid cgroup pointer.  cgroup_attach_task() might
+ * have already changed current->cgroups, allowing the previously
+ * referenced cgroup group to be removed and freed.
  *
  * At the point that cgroup_fork() is called, 'current' is the parent
  * task, and the passed argument 'child' points to the child task.
  */
 void cgroup_fork(struct task_struct *child)
 {
-	/*
-	 * We don't need to task_lock() current because current->cgroups
-	 * can't be changed concurrently here. The parent obviously hasn't
-	 * exited and called cgroup_exit(), and we are synchronized against
-	 * cgroup migration through threadgroup_change_begin().
-	 */
+	task_lock(current);
 	child->cgroups = current->cgroups;
 	get_css_set(child->cgroups);
+	task_unlock(current);
 	INIT_LIST_HEAD(&child->cg_list);
 }
 
-- 
1.7.7.3

  parent reply	other threads:[~2012-10-19  0:59 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-08  2:00 Is not locking task_lock in cgroup_fork() safe? Tejun Heo
2012-10-08  2:01 ` Tejun Heo
2012-10-08  5:46   ` Li Zefan
     [not found]     ` <507268AA.8050509-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2012-10-08  6:57       ` Tejun Heo
2012-10-16 19:34         ` Tejun Heo
     [not found]           ` <20121016193428.GE16166-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-17  7:26             ` Li Zefan
2012-10-08 12:58   ` Frederic Weisbecker
2012-10-08 12:48 ` Frederic Weisbecker
     [not found]   ` <CAFTL4hzXWtzp7megsCAEuak5=_2SWmp9age-+wrpyQAU4BRZ0w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-16 19:33     ` Tejun Heo
     [not found]       ` <20121016193341.GD16166-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-18 14:50         ` Frederic Weisbecker
     [not found]           ` <CAFTL4hzo_w7HTgC9ApTk113X8WdZSpV+D+VSEe=604YEJFmKsg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-18 20:07             ` Tejun Heo
     [not found]               ` <20121018200705.GG13370-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-18 20:53                 ` Frederic Weisbecker
     [not found]                   ` <CAFTL4hy7g4e11OUOyoihrEU8hiVgZoV1=141UtUpj9a72SNs_Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-19  0:38                     ` Tejun Heo
     [not found]                       ` <20121019003835.GE13370-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-19  0:58                         ` Tejun Heo
     [not found]                           ` <20121019005801.GF13370-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-19  8:50                             ` Li Zefan
2012-10-19  0:59 ` [PATCH cgroup/for-3.7-fixes 1/2] Revert "cgroup: Remove task_lock() from cgroup_post_fork()" Tejun Heo
     [not found]   ` <20121019005922.GG13370-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-19  8:51     ` Li Zefan
2012-10-19 13:35     ` Frederic Weisbecker
     [not found]       ` <CAFTL4hz82==b3ioSMhbKzh0CN1ivR7RQMKKMFFWu5PHPjg=Bfg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-19 19:38         ` Tejun Heo
     [not found]           ` <20121019193808.GL13370-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-19 19:44             ` Frederic Weisbecker
     [not found]               ` <CAFTL4hwQ6Ntn5GJwj=jiO2p3GdwhEMp0MyR8dgUj_Lx0U4kNqg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-19 21:07                 ` Tejun Heo
     [not found]                   ` <20121019210738.GA1180-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-20 18:21                     ` Frederic Weisbecker
     [not found]                       ` <CAFTL4hy+vrvJKrc1Y2FW44k=LBi72H=34337xALpbtG_3u5O7w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-20 18:23                         ` Frederic Weisbecker
2012-10-20 22:37                         ` Tejun Heo
     [not found]                           ` <20121020223709.GA5626-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2012-10-22  9:30                             ` Frederic Weisbecker
2012-10-19  0:59 ` Tejun Heo [this message]
     [not found]   ` <20121019005951.GH13370-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-19  8:51     ` [PATCH cgroup/for-3.7-fixes 2/2] Revert "cgroup: Drop task_lock(parent) on cgroup_fork()" Li Zefan
2012-10-19 13:45     ` Frederic Weisbecker

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=20121019005951.GH13370@google.com \
    --to=tj-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
    --cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=fweisbec-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).