All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cgroup_freezer: Freezing and task move race fix
@ 2010-08-10 19:53 Tomasz Buchert
  2010-08-10 21:57 ` Matt Helsley
                   ` (3 more replies)
  0 siblings, 4 replies; 38+ messages in thread
From: Tomasz Buchert @ 2010-08-10 19:53 UTC (permalink / raw)
  To: Paul Menage, Li Zefan, containers, linux-kernel; +Cc: Tomasz Buchert

Writing 'FROZEN' to freezer.state file does not
forbid the task to be moved away from its cgroup
(for a very short time). Nevertheless the moved task
can become frozen OUTSIDE its cgroup which puts
discussed task in a permanent 'D' state.

This patch forbids migration of either FROZEN
or FREEZING tasks.

This behavior was observed and easily reproduced on
a single core laptop. Program and instructions how
to reproduce the bug can be fetched from:
http://pentium.hopto.org/~thinred/repos/linux-misc/freezer_bug.c

Signed-off-by: Tomasz Buchert <tomasz.buchert@inria.fr>
---
 kernel/cgroup_freezer.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c
index ce71ed5..e49aa8c 100644
--- a/kernel/cgroup_freezer.c
+++ b/kernel/cgroup_freezer.c
@@ -161,6 +161,12 @@ static bool is_task_frozen_enough(struct task_struct *task)
 		(task_is_stopped_or_traced(task) && freezing(task));
 }
 
+/* Task is in a state that forbids any cgroup migration. */
+static bool is_task_pinned_down(struct task_struct *task)
+{
+	return freezing(task) || frozen(task);
+}
+
 /*
  * The call to cgroup_lock() in the freezer.state write method prevents
  * a write to that file racing against an attach, and hence the
@@ -179,7 +185,7 @@ static int freezer_can_attach(struct cgroup_subsys *ss,
 	 * frozen, so it's sufficient to check the latter condition.
 	 */
 
-	if (is_task_frozen_enough(task))
+	if (is_task_pinned_down(task))
 		return -EBUSY;
 
 	freezer = cgroup_freezer(new_cgroup);
@@ -191,7 +197,7 @@ static int freezer_can_attach(struct cgroup_subsys *ss,
 
 		rcu_read_lock();
 		list_for_each_entry_rcu(c, &task->thread_group, thread_group) {
-			if (is_task_frozen_enough(c)) {
+			if (is_task_pinned_down(c)) {
 				rcu_read_unlock();
 				return -EBUSY;
 			}
-- 
1.6.3.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread
* [PATCH] cgroup_freezer: Freezing and task move race fix
@ 2010-08-10 19:53 Tomasz Buchert
  0 siblings, 0 replies; 38+ messages in thread
From: Tomasz Buchert @ 2010-08-10 19:53 UTC (permalink / raw)
  To: Paul Menage, Li Zefan,
	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: Tomasz Buchert

Writing 'FROZEN' to freezer.state file does not
forbid the task to be moved away from its cgroup
(for a very short time). Nevertheless the moved task
can become frozen OUTSIDE its cgroup which puts
discussed task in a permanent 'D' state.

This patch forbids migration of either FROZEN
or FREEZING tasks.

This behavior was observed and easily reproduced on
a single core laptop. Program and instructions how
to reproduce the bug can be fetched from:
http://pentium.hopto.org/~thinred/repos/linux-misc/freezer_bug.c

Signed-off-by: Tomasz Buchert <tomasz.buchert-MZpvjPyXg2s@public.gmane.org>
---
 kernel/cgroup_freezer.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c
index ce71ed5..e49aa8c 100644
--- a/kernel/cgroup_freezer.c
+++ b/kernel/cgroup_freezer.c
@@ -161,6 +161,12 @@ static bool is_task_frozen_enough(struct task_struct *task)
 		(task_is_stopped_or_traced(task) && freezing(task));
 }
 
+/* Task is in a state that forbids any cgroup migration. */
+static bool is_task_pinned_down(struct task_struct *task)
+{
+	return freezing(task) || frozen(task);
+}
+
 /*
  * The call to cgroup_lock() in the freezer.state write method prevents
  * a write to that file racing against an attach, and hence the
@@ -179,7 +185,7 @@ static int freezer_can_attach(struct cgroup_subsys *ss,
 	 * frozen, so it's sufficient to check the latter condition.
 	 */
 
-	if (is_task_frozen_enough(task))
+	if (is_task_pinned_down(task))
 		return -EBUSY;
 
 	freezer = cgroup_freezer(new_cgroup);
@@ -191,7 +197,7 @@ static int freezer_can_attach(struct cgroup_subsys *ss,
 
 		rcu_read_lock();
 		list_for_each_entry_rcu(c, &task->thread_group, thread_group) {
-			if (is_task_frozen_enough(c)) {
+			if (is_task_pinned_down(c)) {
 				rcu_read_unlock();
 				return -EBUSY;
 			}
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2010-08-19  8:37 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-10 19:53 [PATCH] cgroup_freezer: Freezing and task move race fix Tomasz Buchert
2010-08-10 21:57 ` Matt Helsley
2010-08-10 22:18   ` Tomasz Buchert
2010-08-11  4:27     ` Matt Helsley
2010-08-11  7:35       ` Tomasz Buchert
     [not found]         ` <4C6252CF.1090100-MZpvjPyXg2s@public.gmane.org>
2010-08-12  0:21           ` Matt Helsley
2010-08-12  0:21         ` Matt Helsley
     [not found]           ` <20100812002154.GJ2927-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2010-08-12  0:53             ` Tomasz Buchert
2010-08-13  1:35             ` Rafael J. Wysocki
2010-08-12  0:53           ` Tomasz Buchert
2010-08-12 20:13             ` Matt Helsley
2010-08-18  1:13               ` Tomasz Buchert
     [not found]                 ` <4C6B339E.6010907-MZpvjPyXg2s@public.gmane.org>
2010-08-18  2:22                   ` Matt Helsley
2010-08-18  2:22                 ` Matt Helsley
2010-08-19  8:37                   ` Tomasz Buchert
     [not found]                   ` <20100818022210.GH3648-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2010-08-19  8:37                     ` Tomasz Buchert
     [not found]               ` <20100812201334.GA29096-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2010-08-18  1:13                 ` Tomasz Buchert
     [not found]             ` <4C634605.50301-MZpvjPyXg2s@public.gmane.org>
2010-08-12 20:13               ` Matt Helsley
2010-08-13  1:35           ` Rafael J. Wysocki
     [not found]       ` <20100811042738.GH2927-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2010-08-11  7:35         ` Tomasz Buchert
     [not found]     ` <4C61D044.2060703-MZpvjPyXg2s@public.gmane.org>
2010-08-11  4:27       ` Matt Helsley
     [not found]   ` <20100810215741.GC2927-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2010-08-10 22:18     ` Tomasz Buchert
2010-08-11  1:10 ` Matt Helsley
     [not found]   ` <20100811011033.GF2927-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2010-08-11  7:30     ` Tomasz Buchert
2010-08-11  7:30   ` Tomasz Buchert
2010-08-11  8:01     ` Tomasz Buchert
     [not found]     ` <4C625181.4060606-MZpvjPyXg2s@public.gmane.org>
2010-08-11  8:01       ` Tomasz Buchert
2010-08-12  9:45 ` [PATCH 0/3] Two bugfixes for cgroup freezer Tomasz Buchert
2010-08-12  9:45   ` [PATCH 1/3] cgroup_freezer: Unnecessary test in cgroup_freezing_or_frozen Tomasz Buchert
2010-08-12  9:45     ` [PATCH 2/3] cgroup_freezer: Fix can_attach to prohibit moving from/to freezing/frozen cgroups Tomasz Buchert
     [not found]       ` <1281606323-16245-3-git-send-email-tomasz.buchert-MZpvjPyXg2s@public.gmane.org>
2010-08-12  9:45         ` [PATCH 3/3] cgroup_freezer: update_freezer_state does incorrect state transactions Tomasz Buchert
2010-08-12  9:45       ` Tomasz Buchert
     [not found]     ` <1281606323-16245-2-git-send-email-tomasz.buchert-MZpvjPyXg2s@public.gmane.org>
2010-08-12  9:45       ` [PATCH 2/3] cgroup_freezer: Fix can_attach to prohibit moving from/to freezing/frozen cgroups Tomasz Buchert
     [not found]   ` <1281606323-16245-1-git-send-email-tomasz.buchert-MZpvjPyXg2s@public.gmane.org>
2010-08-12  9:45     ` [PATCH 1/3] cgroup_freezer: Unnecessary test in cgroup_freezing_or_frozen Tomasz Buchert
     [not found] ` <1281470001-14320-1-git-send-email-tomasz.buchert-MZpvjPyXg2s@public.gmane.org>
2010-08-10 21:57   ` [PATCH] cgroup_freezer: Freezing and task move race fix Matt Helsley
2010-08-11  1:10   ` Matt Helsley
2010-08-12  9:45   ` [PATCH 0/3] Two bugfixes for cgroup freezer Tomasz Buchert
  -- strict thread matches above, loose matches on Subject: below --
2010-08-10 19:53 [PATCH] cgroup_freezer: Freezing and task move race fix Tomasz Buchert

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.