From: Zhang Qiao <zhangqiao22@huawei.com>
To: <linux-kernel@vger.kernel.org>, <cgroups@vger.kernel.org>
Cc: <tj@kernel.org>, <lizefan.x@bytedance.com>, <hannes@cmpxchg.org>,
<matthltc@us.ibm.com>, <bblum@google.com>, <menage@google.com>,
<akpm@linux-foundation.org>, <longman@redhat.com>,
<mkoutny@suse.com>, <zhaogongyi@huawei.com>
Subject: Re: [PATCH] cgroup/cpuset: Fix a race between cpuset_attach() and cpu hotplug
Date: Mon, 7 Feb 2022 14:17:30 +0800 [thread overview]
Message-ID: <0761d941-8fbb-d06b-3d0b-8330c8b54499@huawei.com> (raw)
In-Reply-To: <20220121101210.84926-1-zhangqiao22@huawei.com>
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 <zhaogongyi@huawei.com>
> Signed-off-by: Zhang Qiao <zhangqiao22@huawei.com>
> ---
> 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
>
> .
>
next prev parent reply other threads:[~2022-02-07 6:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-21 10:12 [PATCH] cgroup/cpuset: Fix a race between cpuset_attach() and cpu hotplug Zhang Qiao
2022-01-21 12:43 ` Waiman Long
2022-01-22 7:54 ` Zhang Qiao
2022-01-21 15:57 ` Michal Koutný
2022-01-22 7:37 ` Zhang Qiao
2022-02-07 6:17 ` Zhang Qiao [this message]
2022-02-14 19:50 ` Tejun Heo
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=0761d941-8fbb-d06b-3d0b-8330c8b54499@huawei.com \
--to=zhangqiao22@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=bblum@google.com \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan.x@bytedance.com \
--cc=longman@redhat.com \
--cc=matthltc@us.ibm.com \
--cc=menage@google.com \
--cc=mkoutny@suse.com \
--cc=tj@kernel.org \
--cc=zhaogongyi@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;
as well as URLs for NNTP newsgroup(s).