Skip to content

Commit 05c7b7a

Browse files
Zhang Qiaohtejun
Zhang Qiao
authored andcommitted
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: be367d0 ("cgroups: let ss->can_attach and ss->attach do whole threadgroups at a time") Cc: [email protected] # v2.6.32+ Reported-by: Zhao Gongyi <[email protected]> Signed-off-by: Zhang Qiao <[email protected]> Acked-by: Waiman Long <[email protected]> Reviewed-by: Michal Koutný <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 2bdfd28 commit 05c7b7a

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

kernel/cgroup/cpuset.c

+2
Original file line numberDiff line numberDiff line change
@@ -2289,6 +2289,7 @@ static void cpuset_attach(struct cgroup_taskset *tset)
22892289
cgroup_taskset_first(tset, &css);
22902290
cs = css_cs(css);
22912291

2292+
cpus_read_lock();
22922293
percpu_down_write(&cpuset_rwsem);
22932294

22942295
guarantee_online_mems(cs, &cpuset_attach_nodemask_to);
@@ -2342,6 +2343,7 @@ static void cpuset_attach(struct cgroup_taskset *tset)
23422343
wake_up(&cpuset_attach_wq);
23432344

23442345
percpu_up_write(&cpuset_rwsem);
2346+
cpus_read_unlock();
23452347
}
23462348

23472349
/* The various types of files and directories in a cpuset file system */

0 commit comments

Comments
 (0)