All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Cgroup:Fix race between fork and update cpuset mask
@ 2016-08-04 11:23 ` chaixianping
  0 siblings, 0 replies; 5+ messages in thread
From: chaixianping @ 2016-08-04 11:23 UTC (permalink / raw)
  To: lizefan, cgroups, linux-kernel
  Cc: stable, chaixianping, Zhenghua Jia, Leeyou, Lei Liu

From: chaixianping <chaixianping@huawei.com>

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@huawei.com>
Signed-off-by: Zhenghua Jia <jiazhenghua@huawei.com>
Signed-off-by: Leeyou <leeyou.li@huawei.com>
Signed-off-by: Lei Liu <liulei@huawei.com>
---
 kernel/cpuset.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index c7fd277..ae3d092 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -1015,6 +1015,34 @@ 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();
+
+	cpumask_copy(&task->cpus_allowed, task_cs(task)->effective_cpus);
+	task->nr_cpus_allowed = cpumask_weight(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 +2106,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

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

* [PATCH] Cgroup:Fix race between fork and update cpuset mask
@ 2016-08-04 11:23 ` chaixianping
  0 siblings, 0 replies; 5+ messages in thread
From: chaixianping @ 2016-08-04 11:23 UTC (permalink / raw)
  To: lizefan, cgroups, linux-kernel
  Cc: stable, chaixianping, Zhenghua Jia, Leeyou, Lei Liu

From: chaixianping <chaixianping@huawei.com>

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@huawei.com>
Signed-off-by: Zhenghua Jia <jiazhenghua@huawei.com>
Signed-off-by: Leeyou <leeyou.li@huawei.com>
Signed-off-by: Lei Liu <liulei@huawei.com>
---
 kernel/cpuset.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index c7fd277..ae3d092 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -1015,6 +1015,34 @@ 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();
+
+	cpumask_copy(&task->cpus_allowed, task_cs(task)->effective_cpus);
+	task->nr_cpus_allowed = cpumask_weight(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 +2106,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


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

* Re: [PATCH] Cgroup:Fix race between fork and update cpuset mask
  2016-08-04 11:23 ` chaixianping
  (?)
@ 2016-08-05 10:49 ` Greg KH
  -1 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2016-08-05 10:49 UTC (permalink / raw)
  To: chaixianping
  Cc: lizefan, cgroups, linux-kernel, stable, Zhenghua Jia, Leeyou, Lei Liu

On Thu, Aug 04, 2016 at 07:23:03PM +0800, chaixianping@huawei.com wrote:
> From: chaixianping <chaixianping@huawei.com>
> 
> 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@huawei.com>

This name doesn't match your From: line :(

> Signed-off-by: Zhenghua Jia <jiazhenghua@huawei.com>
> Signed-off-by: Leeyou <leeyou.li@huawei.com>
> Signed-off-by: Lei Liu <liulei@huawei.com>
> ---
>  kernel/cpuset.c | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)

<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read Documentation/stable_kernel_rules.txt
for how to do this properly.

</formletter>

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

* [PATCH] Cgroup:Fix race between fork and update cpuset mask
@ 2016-08-03 11:50 ` chaixianping
  0 siblings, 0 replies; 5+ messages in thread
From: chaixianping @ 2016-08-03 11:50 UTC (permalink / raw)
  To: lizefan, cgroups, linux-kernel
  Cc: chaixianping, Zhenghua Jia, Leeyou, Lei Liu

From: chaixianping <chaixianping@huawei.com>

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@huawei.com>
Signed-off-by: Zhenghua Jia <jiazhenghua@huawei.com>
Signed-off-by: Leeyou <leeyou.li@huawei.com>
Signed-off-by: Lei Liu <lay.liu@huawei.com>
---
 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

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

* [PATCH] Cgroup:Fix race between fork and update cpuset mask
@ 2016-08-03 11:50 ` chaixianping
  0 siblings, 0 replies; 5+ messages in thread
From: chaixianping @ 2016-08-03 11:50 UTC (permalink / raw)
  To: lizefan, cgroups, linux-kernel
  Cc: chaixianping, Zhenghua Jia, Leeyou, Lei Liu

From: chaixianping <chaixianping@huawei.com>

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@huawei.com>
Signed-off-by: Zhenghua Jia <jiazhenghua@huawei.com>
Signed-off-by: Leeyou <leeyou.li@huawei.com>
Signed-off-by: Lei Liu <lay.liu@huawei.com>
---
 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


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

end of thread, other threads:[~2016-08-05 10:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-04 11:23 [PATCH] Cgroup:Fix race between fork and update cpuset mask chaixianping
2016-08-04 11:23 ` chaixianping
2016-08-05 10:49 ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2016-08-03 11:50 chaixianping
2016-08-03 11:50 ` chaixianping

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.