Skip to content

Commit d8742e2

Browse files
committed
cgroup: css_set_lock should nest inside tasklist_lock
cgroup_enable_task_cg_lists() incorrectly nests non-irq-safe tasklist_lock inside irq-safe css_set_lock triggering the following lockdep warning. WARNING: possible irq lock inversion dependency detected 4.17.0-rc1-00027-gb37d049 #6 Not tainted -------------------------------------------------------- systemd/1 just changed the state of lock: 00000000fe57773b (css_set_lock){..-.}, at: cgroup_free+0xf2/0x12a but this lock took another, SOFTIRQ-unsafe lock in the past: (tasklist_lock){.+.+} and interrupts could create inverse lock ordering between them. other info that might help us debug this: Possible interrupt unsafe locking scenario: CPU0 CPU1 ---- ---- lock(tasklist_lock); local_irq_disable(); lock(css_set_lock); lock(tasklist_lock); <Interrupt> lock(css_set_lock); *** DEADLOCK *** The condition is highly unlikely to actually happen especially given that the path is executed only once per boot. Signed-off-by: Tejun Heo <[email protected]> Reported-by: Boqun Feng <[email protected]>
1 parent cc659e7 commit d8742e2

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

kernel/cgroup/cgroup.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,13 +1798,6 @@ static void cgroup_enable_task_cg_lists(void)
17981798
{
17991799
struct task_struct *p, *g;
18001800

1801-
spin_lock_irq(&css_set_lock);
1802-
1803-
if (use_task_css_set_links)
1804-
goto out_unlock;
1805-
1806-
use_task_css_set_links = true;
1807-
18081801
/*
18091802
* We need tasklist_lock because RCU is not safe against
18101803
* while_each_thread(). Besides, a forking task that has passed
@@ -1813,6 +1806,13 @@ static void cgroup_enable_task_cg_lists(void)
18131806
* tasklist if we walk through it with RCU.
18141807
*/
18151808
read_lock(&tasklist_lock);
1809+
spin_lock_irq(&css_set_lock);
1810+
1811+
if (use_task_css_set_links)
1812+
goto out_unlock;
1813+
1814+
use_task_css_set_links = true;
1815+
18161816
do_each_thread(g, p) {
18171817
WARN_ON_ONCE(!list_empty(&p->cg_list) ||
18181818
task_css_set(p) != &init_css_set);
@@ -1840,9 +1840,9 @@ static void cgroup_enable_task_cg_lists(void)
18401840
}
18411841
spin_unlock(&p->sighand->siglock);
18421842
} while_each_thread(g, p);
1843-
read_unlock(&tasklist_lock);
18441843
out_unlock:
18451844
spin_unlock_irq(&css_set_lock);
1845+
read_unlock(&tasklist_lock);
18461846
}
18471847

18481848
static void init_cgroup_housekeeping(struct cgroup *cgrp)

0 commit comments

Comments
 (0)