From: <chaixianping@huawei.com>
To: <lizefan@huawei.com>, <cgroups@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Cc: <stable@vger.kernel.org>, chaixianping <chaixianping@huawei.com>,
"Zhenghua Jia" <jiazhenghua@huawei.com>,
Leeyou <leeyou.li@huawei.com>, Lei Liu <liulei@huawei.com>
Subject: [PATCH] Cgroup:Fix race between fork and update cpuset mask
Date: Thu, 4 Aug 2016 19:23:03 +0800 [thread overview]
Message-ID: <1470309783-11328-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 <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
next reply other threads:[~2016-08-04 11:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-04 11:23 chaixianping [this message]
2016-08-05 10:49 ` Greg KH
-- strict thread matches above, loose matches on Subject: below --
2016-08-03 11:50 chaixianping
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=1470309783-11328-1-git-send-email-chaixianping@huawei.com \
--to=chaixianping@huawei.com \
--cc=cgroups@vger.kernel.org \
--cc=jiazhenghua@huawei.com \
--cc=leeyou.li@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=liulei@huawei.com \
--cc=lizefan@huawei.com \
--cc=stable@vger.kernel.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
all inboxes | Powered by JetHome®