[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220228172208.566431934@linuxfoundation.org>
Date: Mon, 28 Feb 2022 18:24:07 +0100
From: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To: linux-kernel@...r.kernel.org
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
stable@...r.kernel.org, Zhao Gongyi <zhaogongyi@...wei.com>,
Zhang Qiao <zhangqiao22@...wei.com>,
Waiman Long <longman@...hat.com>,
Michal Koutný <mkoutny@...e.com>,
Tejun Heo <tj@...nel.org>
Subject: [PATCH 4.19 01/34] cgroup/cpuset: Fix a race between cpuset_attach() and cpu hotplug
From: Zhang Qiao <zhangqiao22@...wei.com>
commit 05c7b7a92cc87ff8d7fde189d0fade250697573c upstream.
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")
Cc: stable@...r.kernel.org # v2.6.32+
Reported-by: Zhao Gongyi <zhaogongyi@...wei.com>
Signed-off-by: Zhang Qiao <zhangqiao22@...wei.com>
Acked-by: Waiman Long <longman@...hat.com>
Reviewed-by: Michal Koutný <mkoutny@...e.com>
Signed-off-by: Tejun Heo <tj@...nel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
---
kernel/cgroup/cpuset.c | 2 ++
1 file changed, 2 insertions(+)
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -1528,6 +1528,7 @@ static void cpuset_attach(struct cgroup_
cgroup_taskset_first(tset, &css);
cs = css_cs(css);
+ cpus_read_lock();
mutex_lock(&cpuset_mutex);
/* prepare for attach */
@@ -1583,6 +1584,7 @@ static void cpuset_attach(struct cgroup_
wake_up(&cpuset_attach_wq);
mutex_unlock(&cpuset_mutex);
+ cpus_read_unlock();
}
/* The various types of files and directories in a cpuset file system */
Powered by blists - more mailing lists