]> git.baikalelectronics.ru Git - kernel.git/commit
cgroup/cpuset: Fix a race between cpuset_attach() and cpu hotplug
authorZhang Qiao <zhangqiao22@huawei.com>
Fri, 21 Jan 2022 10:12:10 +0000 (18:12 +0800)
committerTejun Heo <tj@kernel.org>
Mon, 14 Feb 2022 19:48:04 +0000 (09:48 -1000)
commitb73af54f52ab81610f1f4c1eefd3a80a319e47da
treeca03eee0d94326ebdd3915f3e0127bbbdc3d4289
parent511c7c9bb2afedd5566ecc0f8ee4e04fd2b331df
cgroup/cpuset: Fix a race between cpuset_attach() and cpu hotplug

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: 2b491c144cfb ("cgroups: let ss->can_attach and ss->attach do whole threadgroups at a time")
Cc: stable@vger.kernel.org # v2.6.32+
Reported-by: Zhao Gongyi <zhaogongyi@huawei.com>
Signed-off-by: Zhang Qiao <zhangqiao22@huawei.com>
Acked-by: Waiman Long <longman@redhat.com>
Reviewed-by: Michal Koutný <mkoutny@suse.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup/cpuset.c