• Tejun Heo's avatar
    cgroup: always lock threadgroup during migration · cd3d0952
    Tejun Heo authored
    Update cgroup to take advantage of the fack that threadgroup_lock()
    guarantees stable threadgroup.
    
    * Lock threadgroup even if the target is a single task.  This
      guarantees that when the target tasks stay stable during migration
      regardless of the target type.
    
    * Remove PF_EXITING early exit optimization from attach_task_by_pid()
      and check it in cgroup_task_migrate() instead.  The optimization was
      for rather cold path to begin with and PF_EXITING state can be
      trusted throughout migration by checking it after locking
      threadgroup.
    
    * Don't add PF_EXITING tasks to target task array in
      cgroup_attach_proc().  This ensures that task migration is performed
      only for live tasks.
    
    * Remove -ESRCH failure path from cgroup_task_migrate().  With the
      above changes, it's guaranteed to be called only for live tasks.
    
    After the changes, only live tasks are migrated and they're guaranteed
    to stay alive until migration is complete.  This removes problems
    caused by exec and exit racing against cgroup migration including
    symmetry among cgroup attach methods and different cgroup methods
    racing each other.
    
    v2: Oleg pointed out that one more PF_EXITING check can be removed
        from cgroup_attach_proc().  Removed.
    Signed-off-by: default avatarTejun Heo <tj@kernel.org>
    Reviewed-by: default avatarKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
    Reviewed-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
    Acked-by: default avatarLi Zefan <lizf@cn.fujitsu.com>
    Cc: Oleg Nesterov <oleg@redhat.com>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Paul Menage <paul@paulmenage.org>
    cd3d0952
cgroup.c 138 KB