Skip to content

Commit d3f9752

Browse files
htejungregkh
authored andcommitted
memcg: add RCU locking around css_for_each_descendant_pre() in memcg_offline_kmem()
commit 3a06bb7 upstream. memcg_offline_kmem() may be called from memcg_free_kmem() after a css init failure. memcg_free_kmem() is a ->css_free callback which is called without cgroup_mutex and memcg_offline_kmem() ends up using css_for_each_descendant_pre() without any locking. Fix it by adding rcu read locking around it. mkdir: cannot create directory `65530': No space left on device =============================== [ INFO: suspicious RCU usage. ] 4.6.0-work+ raspberrypi#321 Not tainted ------------------------------- kernel/cgroup.c:4008 cgroup_mutex or RCU read lock required! [ 527.243970] other info that might help us debug this: [ 527.244715] rcu_scheduler_active = 1, debug_locks = 0 2 locks held by kworker/0:5/1664: #0: ("cgroup_destroy"){.+.+..}, at: [<ffffffff81060ab5>] process_one_work+0x165/0x4a0 #1: ((&css->destroy_work)raspberrypi#3){+.+...}, at: [<ffffffff81060ab5>] process_one_work+0x165/0x4a0 [ 527.248098] stack backtrace: CPU: 0 PID: 1664 Comm: kworker/0:5 Not tainted 4.6.0-work+ raspberrypi#321 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.9.1-1.fc24 04/01/2014 Workqueue: cgroup_destroy css_free_work_fn Call Trace: dump_stack+0x68/0xa1 lockdep_rcu_suspicious+0xd7/0x110 css_next_descendant_pre+0x7d/0xb0 memcg_offline_kmem.part.44+0x4a/0xc0 mem_cgroup_css_free+0x1ec/0x200 css_free_work_fn+0x49/0x5e0 process_one_work+0x1c5/0x4a0 worker_thread+0x49/0x490 kthread+0xea/0x100 ret_from_fork+0x1f/0x40 Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Tejun Heo <[email protected]> Acked-by: Vladimir Davydov <[email protected]> Acked-by: Johannes Weiner <[email protected]> Cc: Michal Hocko <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1125f3b commit d3f9752

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

mm/memcontrol.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3661,13 +3661,16 @@ static void memcg_deactivate_kmem(struct mem_cgroup *memcg)
36613661
* ordering is imposed by list_lru_node->lock taken by
36623662
* memcg_drain_all_list_lrus().
36633663
*/
3664+
rcu_read_lock(); /* can be called from css_free w/o cgroup_mutex */
36643665
css_for_each_descendant_pre(css, &memcg->css) {
36653666
child = mem_cgroup_from_css(css);
36663667
BUG_ON(child->kmemcg_id != kmemcg_id);
36673668
child->kmemcg_id = parent->kmemcg_id;
36683669
if (!memcg->use_hierarchy)
36693670
break;
36703671
}
3672+
rcu_read_unlock();
3673+
36713674
memcg_drain_all_list_lrus(kmemcg_id, parent->kmemcg_id);
36723675

36733676
memcg_free_cache_id(kmemcg_id);

0 commit comments

Comments
 (0)