• Tejun Heo's avatar
    cgroup: Fix threadgroup_rwsem <-> cpus_read_lock() deadlock · 4f7e7236
    Tejun Heo authored
    Bringing up a CPU may involve creating and destroying tasks which requires
    read-locking threadgroup_rwsem, so threadgroup_rwsem nests inside
    cpus_read_lock(). However, cpuset's ->attach(), which may be called with
    thredagroup_rwsem write-locked, also wants to disable CPU hotplug and
    acquires cpus_read_lock(), leading to a deadlock.
    
    Fix it by guaranteeing that ->attach() is always called with CPU hotplug
    disabled and removing cpus_read_lock() call from cpuset_attach().
    Signed-off-by: default avatarTejun Heo <tj@kernel.org>
    Reviewed-and-tested-by: default avatarImran Khan <imran.f.khan@oracle.com>
    Reported-and-tested-by: default avatarXuewen Yan <xuewen.yan@unisoc.com>
    Fixes: 05c7b7a9 ("cgroup/cpuset: Fix a race between cpuset_attach() and cpu hotplug")
    Cc: stable@vger.kernel.org # v5.17+
    4f7e7236
cpuset.c 104 KB