Skip to content

Commit b6053d4

Browse files
committed
cgroup: fix lockdep warning in debug controller
The debug controller grabs cgroup_mutex from interface file show functions which can deadlock and triggers lockdep warnings. Fix it by using cgroup_kn_lock_live()/cgroup_kn_unlock() instead. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Waiman Long <longman@redhat.com>
1 parent 2866c0b commit b6053d4

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

‎kernel/cgroup/debug.c‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@ static u64 debug_taskcount_read(struct cgroup_subsys_state *css,
3838

3939
static int current_css_set_read(struct seq_file *seq, void *v)
4040
{
41+
struct kernfs_open_file *of = seq->private;
4142
struct css_set *cset;
4243
struct cgroup_subsys *ss;
4344
struct cgroup_subsys_state *css;
4445
int i, refcnt;
4546

46-
mutex_lock(&cgroup_mutex);
47+
if (!cgroup_kn_lock_live(of->kn, false))
48+
return -ENODEV;
49+
4750
spin_lock_irq(&css_set_lock);
4851
rcu_read_lock();
4952
cset = rcu_dereference(current->cgroups);
@@ -65,7 +68,7 @@ static int current_css_set_read(struct seq_file *seq, void *v)
6568
}
6669
rcu_read_unlock();
6770
spin_unlock_irq(&css_set_lock);
68-
mutex_unlock(&cgroup_mutex);
71+
cgroup_kn_unlock(of->kn);
6972
return 0;
7073
}
7174

@@ -174,13 +177,17 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
174177

175178
static int cgroup_subsys_states_read(struct seq_file *seq, void *v)
176179
{
177-
struct cgroup *cgrp = seq_css(seq)->cgroup;
180+
struct kernfs_open_file *of = seq->private;
181+
struct cgroup *cgrp;
178182
struct cgroup_subsys *ss;
179183
struct cgroup_subsys_state *css;
180184
char pbuf[16];
181185
int i;
182186

183-
mutex_lock(&cgroup_mutex);
187+
cgrp = cgroup_kn_lock_live(of->kn, false);
188+
if (!cgrp)
189+
return -ENODEV;
190+
184191
for_each_subsys(ss, i) {
185192
css = rcu_dereference_check(cgrp->subsys[ss->id], true);
186193
if (!css)
@@ -196,7 +203,8 @@ static int cgroup_subsys_states_read(struct seq_file *seq, void *v)
196203
(unsigned long)css, css->id,
197204
atomic_read(&css->online_cnt), pbuf);
198205
}
199-
mutex_unlock(&cgroup_mutex);
206+
207+
cgroup_kn_unlock(of->kn);
200208
return 0;
201209
}
202210

@@ -221,12 +229,17 @@ static void cgroup_masks_read_one(struct seq_file *seq, const char *name,
221229

222230
static int cgroup_masks_read(struct seq_file *seq, void *v)
223231
{
224-
struct cgroup *cgrp = seq_css(seq)->cgroup;
232+
struct kernfs_open_file *of = seq->private;
233+
struct cgroup *cgrp;
234+
235+
cgrp = cgroup_kn_lock_live(of->kn, false);
236+
if (!cgrp)
237+
return -ENODEV;
225238

226-
mutex_lock(&cgroup_mutex);
227239
cgroup_masks_read_one(seq, "subtree_control", cgrp->subtree_control);
228240
cgroup_masks_read_one(seq, "subtree_ss_mask", cgrp->subtree_ss_mask);
229-
mutex_unlock(&cgroup_mutex);
241+
242+
cgroup_kn_unlock(of->kn);
230243
return 0;
231244
}
232245

0 commit comments

Comments
 (0)