Commit ad4ba375 authored by Paul E. McKenney's avatar Paul E. McKenney

memcg: css_id() must be called under rcu_read_lock()

This patch fixes task_in_mem_cgroup(), mem_cgroup_uncharge_swapcache(),
mem_cgroup_move_swap_account(), and is_target_pte_for_mc() to protect
calls to css_id().  An additional RCU lockdep splat was reported for
memcg_oom_wake_function(), however, this function is not yet in
mainline as of 2.6.34-rc5.
Reported-by: default avatarLi Zefan <lizf@cn.fujitsu.com>
Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Cc: Balbir Singh <balbir@linux.vnet.ibm.com>
Signed-off-by: default avatarKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Tested-by: default avatarLi Zefan <lizf@cn.fujitsu.com>
Signed-off-by: default avatarPaul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
parent 1ce7e4ff
...@@ -811,10 +811,12 @@ int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem) ...@@ -811,10 +811,12 @@ int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem)
* enabled in "curr" and "curr" is a child of "mem" in *cgroup* * enabled in "curr" and "curr" is a child of "mem" in *cgroup*
* hierarchy(even if use_hierarchy is disabled in "mem"). * hierarchy(even if use_hierarchy is disabled in "mem").
*/ */
rcu_read_lock();
if (mem->use_hierarchy) if (mem->use_hierarchy)
ret = css_is_ancestor(&curr->css, &mem->css); ret = css_is_ancestor(&curr->css, &mem->css);
else else
ret = (curr == mem); ret = (curr == mem);
rcu_read_unlock();
css_put(&curr->css); css_put(&curr->css);
return ret; return ret;
} }
...@@ -2312,7 +2314,9 @@ mem_cgroup_uncharge_swapcache(struct page *page, swp_entry_t ent, bool swapout) ...@@ -2312,7 +2314,9 @@ mem_cgroup_uncharge_swapcache(struct page *page, swp_entry_t ent, bool swapout)
/* record memcg information */ /* record memcg information */
if (do_swap_account && swapout && memcg) { if (do_swap_account && swapout && memcg) {
rcu_read_lock();
swap_cgroup_record(ent, css_id(&memcg->css)); swap_cgroup_record(ent, css_id(&memcg->css));
rcu_read_unlock();
mem_cgroup_get(memcg); mem_cgroup_get(memcg);
} }
if (swapout && memcg) if (swapout && memcg)
...@@ -2369,8 +2373,10 @@ static int mem_cgroup_move_swap_account(swp_entry_t entry, ...@@ -2369,8 +2373,10 @@ static int mem_cgroup_move_swap_account(swp_entry_t entry,
{ {
unsigned short old_id, new_id; unsigned short old_id, new_id;
rcu_read_lock();
old_id = css_id(&from->css); old_id = css_id(&from->css);
new_id = css_id(&to->css); new_id = css_id(&to->css);
rcu_read_unlock();
if (swap_cgroup_cmpxchg(entry, old_id, new_id) == old_id) { if (swap_cgroup_cmpxchg(entry, old_id, new_id) == old_id) {
mem_cgroup_swap_statistics(from, false); mem_cgroup_swap_statistics(from, false);
...@@ -4038,11 +4044,16 @@ static int is_target_pte_for_mc(struct vm_area_struct *vma, ...@@ -4038,11 +4044,16 @@ static int is_target_pte_for_mc(struct vm_area_struct *vma,
put_page(page); put_page(page);
} }
/* throught */ /* throught */
if (ent.val && do_swap_account && !ret && if (ent.val && do_swap_account && !ret) {
css_id(&mc.from->css) == lookup_swap_cgroup(ent)) { unsigned short id;
ret = MC_TARGET_SWAP; rcu_read_lock();
if (target) id = css_id(&mc.from->css);
target->ent = ent; rcu_read_unlock();
if (id == lookup_swap_cgroup(ent)) {
ret = MC_TARGET_SWAP;
if (target)
target->ent = ent;
}
} }
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment