• Tejun Heo's avatar
    cgroup: update how a newly forked task gets associated with css_set · eaf797ab
    Tejun Heo authored
    When a new process is forked, cgroup_fork() associates it with the
    css_set of its parent but doesn't link it into it.  After the new
    process is linked to tasklist, cgroup_post_fork() does the linking.
    
    This is problematic for cgroup_transfer_tasks() as there's no way to
    tell whether there are tasks which are pointing to a css_set but not
    linked yet.  It is impossible to implement an operation which transfer
    all tasks of a cgroup to another and the current
    cgroup_transfer_tasks() can easily be tricked into leaving a newly
    forked process behind if it gets called between cgroup_fork() and
    cgroup_post_fork().
    
    Let's make association with a css_set and linking atomic by moving it
    to cgroup_post_fork().  cgroup_fork() sets child->cgroups to
    init_css_set as a placeholder and cgroup_post_fork() is updated to
    perform both the association with the parent's cgroup and linking
    there.  This means that a newly created task will point to
    init_css_set without holding a ref to it much like what it does on the
    exit path.  Empty cg_list is used to indicate that the task isn't
    holding a ref to the associated css_set.
    
    This fixes an actual bug with cgroup_transfer_tasks(); however, I'm
    not marking it for -stable.  The whole thing is broken in multiple
    other ways which require invasive updates to fix and I don't think
    it's worthwhile to bother with backporting this particular one.
    Fortunately, the only user is cpuset and these bugs don't crash the
    machine.
    Signed-off-by: default avatarTejun Heo <tj@kernel.org>
    Acked-by: default avatarLi Zefan <lizefan@huawei.com>
    eaf797ab
cgroup.c 129 KB