cgroup: pids: fix race between cgroup_post_fork() and cgroup_migrate()
authorOleg Nesterov <oleg@redhat.com>
Fri, 27 Nov 2015 18:57:19 +0000 (19:57 +0100)
committerTejun Heo <tj@kernel.org>
Mon, 30 Nov 2015 14:48:18 +0000 (09:48 -0500)
commitc9e75f0492b248aeaa7af8991a6fc9a21506bc96
tree65b6a47aabaa91a19d1f0c01a613d73ab3cecee3
parent53254f900bd9ff1e3cc5628e76126bb403d9d160
cgroup: pids: fix race between cgroup_post_fork() and cgroup_migrate()

If the new child migrates to another cgroup before cgroup_post_fork() calls
subsys->fork(), then both pids_can_attach() and pids_fork() will do the same
pids_uncharge(old_pids) + pids_charge(pids) sequence twice.

Change copy_process() to call threadgroup_change_begin/threadgroup_change_end
unconditionally. percpu_down_read() is cheap and this allows other cleanups,
see the next changes.

Also, this way we can unify cgroup_threadgroup_rwsem and dup_mmap_sem.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Zefan Li <lizefan@huawei.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup_pids.c
kernel/fork.c