mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: <chaixianping@huawei.com>
To: <lizefan@huawei.com>, <cgroups@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Cc: chaixianping <chaixianping@huawei.com>,
	Zhenghua Jia <jiazhenghua@huawei.com>,
	Leeyou <leeyou.li@huawei.com>, Lei Liu <lay.liu@huawei.com>
Subject: [PATCH] Cgroup:Fix race between fork and update cpuset mask
Date: Wed, 3 Aug 2016 19:50:57 +0800	[thread overview]
Message-ID: <1470225057-18557-1-git-send-email-chaixianping@huawei.com> (raw)

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

             reply	other threads:[~2016-08-03 12:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-03 11:50 chaixianping [this message]
2016-08-04 11:23 chaixianping
2016-08-05 10:49 ` Greg KH

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=1470225057-18557-1-git-send-email-chaixianping@huawei.com \
    --to=chaixianping@huawei.com \
    --cc=cgroups@vger.kernel.org \
    --cc=jiazhenghua@huawei.com \
    --cc=lay.liu@huawei.com \
    --cc=leeyou.li@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    /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

all inboxes | Powered by JetHome®