[PATCH] Cgroup:Fix race between fork and update cpuset mask

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: chaixianping <chaixianping@xxxxxxxxxx>

Fix the race between fork and update_cpumask or update_nodemask.
Scenario as follows:
1)A process fork a child process, the child process have
inherited the parent process cpus_allowed,mems_allowed
Before being added cset->tasks list.
2)Update_cpumask or update_nodemask change the parent's allowed
to a new value, *but the child still is the old value.
after being added cset->tasks list.

Signed-off-by: Xianping Chai <chaixianping@xxxxxxxxxx>
Signed-off-by: Zhenghua Jia <jiazhenghua@xxxxxxxxxx>
Signed-off-by: Leeyou <leeyou.li@xxxxxxxxxx>
Signed-off-by: Lei Liu <lay.liu@xxxxxxxxxx>
---
 kernel/cpuset.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index c7fd277..090b700 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -1015,6 +1015,33 @@ static void cpuset_migrate_mm(struct mm_struct *mm, const nodemask_t *from,
 	}
 }
 
+
+/*
+ *Fix the race between fork and update_cpumask or update_nodemask.
+ *Scenario as follows:
+ *1)A process fork a child process, the child process have
+ *inherited the parent process cpus_allowed,mems_allowed
+ *Before being added cset->tasks list.
+ *2)Update_cpumask or update_nodemask change the parent's allowed
+ *to a new value, *but the child still is the old value
+ *after being added cset->tasks list.
+ */
+static void cpuset_fork(struct task_struct *task)
+{
+	nodemask_t cpuset_mems_allowed;
+
+	mutex_lock(&cpuset_mutex);
+	rcu_read_lock();
+
+	do_set_cpus_allowed(task, task_cs(task)->effective_cpus);
+
+	guarantee_online_mems(task_cs(task), &cpuset_mems_allowed);
+	task->mems_allowed = cpuset_mems_allowed;
+
+	rcu_read_unlock();
+	mutex_unlock(&cpuset_mutex);
+}
+
 static void cpuset_post_attach(void)
 {
 	flush_workqueue(cpuset_migrate_mm_wq);
@@ -2078,6 +2105,7 @@ struct cgroup_subsys cpuset_cgrp_subsys = {
 	.cancel_attach	= cpuset_cancel_attach,
 	.attach		= cpuset_attach,
 	.post_attach	= cpuset_post_attach,
+	.fork   = cpuset_fork,
 	.bind		= cpuset_bind,
 	.legacy_cftypes	= files,
 	.early_init	= true,
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe cgroups" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [Monitors]

  Powered by Linux