From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1424C433FE for ; Mon, 7 Feb 2022 06:41:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232083AbiBGGiq (ORCPT ); Mon, 7 Feb 2022 01:38:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243603AbiBGGgK (ORCPT ); Mon, 7 Feb 2022 01:36:10 -0500 X-Greylist: delayed 1115 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sun, 06 Feb 2022 22:36:07 PST Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 884B6C043181; Sun, 6 Feb 2022 22:36:07 -0800 (PST) Received: from dggpeml500021.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4JsbWM4J66zcbcT; Mon, 7 Feb 2022 14:16:31 +0800 (CST) Received: from dggpeml500018.china.huawei.com (7.185.36.186) by dggpeml500021.china.huawei.com (7.185.36.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Mon, 7 Feb 2022 14:17:30 +0800 Received: from [10.67.111.186] (10.67.111.186) by dggpeml500018.china.huawei.com (7.185.36.186) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Mon, 7 Feb 2022 14:17:30 +0800 Message-ID: <0761d941-8fbb-d06b-3d0b-8330c8b54499@huawei.com> Date: Mon, 7 Feb 2022 14:17:30 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.1.1 Subject: Re: [PATCH] cgroup/cpuset: Fix a race between cpuset_attach() and cpu hotplug To: , CC: , , , , , , , , , References: <20220121101210.84926-1-zhangqiao22@huawei.com> From: Zhang Qiao In-Reply-To: <20220121101210.84926-1-zhangqiao22@huawei.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.111.186] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500018.china.huawei.com (7.185.36.186) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Gentle ping on this patch. 在 2022/1/21 18:12, Zhang Qiao 写道: > As previously discussed(https://lkml.org/lkml/2022/1/20/51), > cpuset_attach() is affected with similar cpu hotplug race, > as follow scenario: > > cpuset_attach() cpu hotplug > --------------------------- ---------------------- > down_write(cpuset_rwsem) > guarantee_online_cpus() // (load cpus_attach) > sched_cpu_deactivate > set_cpu_active() > // will change cpu_active_mask > set_cpus_allowed_ptr(cpus_attach) > __set_cpus_allowed_ptr_locked() > // (if the intersection of cpus_attach and > cpu_active_mask is empty, will return -EINVAL) > up_write(cpuset_rwsem) > > To avoid races such as described above, protect cpuset_attach() call > with cpu_hotplug_lock. > > Fixes: be367d099270 ("cgroups: let ss->can_attach and ss->attach do whole threadgroups at a time") > Reported-by: Zhao Gongyi > Signed-off-by: Zhang Qiao > --- > kernel/cgroup/cpuset.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c > index dc653ab26e50..0af5725cc1df 100644 > --- a/kernel/cgroup/cpuset.c > +++ b/kernel/cgroup/cpuset.c > @@ -2252,6 +2252,7 @@ static void cpuset_attach(struct cgroup_taskset *tset) > cgroup_taskset_first(tset, &css); > cs = css_cs(css); > > + cpus_read_lock(); > percpu_down_write(&cpuset_rwsem); > > guarantee_online_mems(cs, &cpuset_attach_nodemask_to); > @@ -2305,6 +2306,7 @@ static void cpuset_attach(struct cgroup_taskset *tset) > wake_up(&cpuset_attach_wq); > > percpu_up_write(&cpuset_rwsem); > + cpus_read_unlock(); > } > > /* The various types of files and directories in a cpuset file system */ > -- > 2.18.0 > > . >