OSDN Git Service

cgroup: Fix deadlock in cpu hotplug path
authorPrateek Sood <prsood@codeaurora.org>
Tue, 19 Dec 2017 10:41:54 +0000 (16:11 +0530)
committerGerrit - the friendly Code Review server <code-review@localhost>
Tue, 14 Aug 2018 06:21:04 +0000 (23:21 -0700)
commit47d4272073b20d8a359b4279a9eb468ea2541289
treee944e3981f2d2b32d6a628206064e4634edd3029
parent5298eb8be59364c03234493b14803fabb8a09b2d
cgroup: Fix deadlock in cpu hotplug path

Deadlock during cgroup migration from cpu hotplug path when a task T is
being moved from source to destination cgroup.

kworker/0:0
cpuset_hotplug_workfn()
   cpuset_hotplug_update_tasks()
      hotplug_update_tasks_legacy()
        remove_tasks_in_empty_cpuset()
          cgroup_transfer_tasks() // stuck in iterator loop
            cgroup_migrate()
              cgroup_migrate_add_task()

In cgroup_migrate_add_task() it checks for PF_EXITING flag of task T.
Task T will not migrate to destination cgroup. css_task_iter_start()
will keep pointing to task T in loop waiting for task T cg_list node
to be removed.

Task T
do_exit()
  exit_signals() // sets PF_EXITING
  exit_task_namespaces()
    switch_task_namespaces()
      free_nsproxy()
        put_mnt_ns()
          drop_collected_mounts()
            namespace_unlock()
              synchronize_rcu()
                _synchronize_rcu_expedited()
                  schedule_work() // on cpu0 low priority worker pool
                  wait_event() // waiting for work item to execute

Task T inserted a work item in the worklist of cpu0 low priority
worker pool. It is waiting for expedited grace period work item
to execute. This work item will only be executed once kworker/0:0
complete execution of cpuset_hotplug_workfn().

kworker/0:0 ==> Task T ==>kworker/0:0

In case of PF_EXITING task being migrated from source to destination
cgroup, migrate next available task in source cgroup.

Change-Id: I706aeff24c336c660b5a9b3e5a409c5769968960
Signed-off-by: Prateek Sood <prsood@codeaurora.org>
kernel/cgroup.c