From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933291AbcHDLm1 (ORCPT ); Thu, 4 Aug 2016 07:42:27 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:40436 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758198AbcHDLmW (ORCPT ); Thu, 4 Aug 2016 07:42:22 -0400 From: To: , , CC: , chaixianping , "Zhenghua Jia" , Leeyou , Lei Liu Subject: [PATCH] Cgroup:Fix race between fork and update cpuset mask Date: Thu, 4 Aug 2016 19:23:03 +0800 Message-ID: <1470309783-11328-1-git-send-email-chaixianping@huawei.com> X-Mailer: git-send-email 2.6.2 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.137.116] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020204.57A32A01.0173,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 1b2391db47461c70dbb59b1a046d725b Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: chaixianping 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 Signed-off-by: Zhenghua Jia Signed-off-by: Leeyou Signed-off-by: Lei Liu --- 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