aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorPaul E. McKenney <paulmck@linux.vnet.ibm.com>2010-04-23 15:26:38 -0400
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>2010-05-04 12:25:03 -0400
commitad4ba375373937817404fd92239ef4cadbded23b (patch)
tree1c59ebd7a1e3ace3539396dd35ecff0f06132fe8 /mm
parent1ce7e4ff24fe338438bc7837e02780f202bf202b (diff)
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: Li 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: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Tested-by: Li Zefan <lizf@cn.fujitsu.com> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/memcontrol.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index f4ede99c8b9b..e06490d4ae5e 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -811,10 +811,12 @@ int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem)
811 * enabled in "curr" and "curr" is a child of "mem" in *cgroup* 811 * enabled in "curr" and "curr" is a child of "mem" in *cgroup*
812 * hierarchy(even if use_hierarchy is disabled in "mem"). 812 * hierarchy(even if use_hierarchy is disabled in "mem").
813 */ 813 */
814 rcu_read_lock();
814 if (mem->use_hierarchy) 815 if (mem->use_hierarchy)
815 ret = css_is_ancestor(&curr->css, &mem->css); 816 ret = css_is_ancestor(&curr->css, &mem->css);
816 else 817 else
817 ret = (curr == mem); 818 ret = (curr == mem);
819 rcu_read_unlock();
818 css_put(&curr->css); 820 css_put(&curr->css);
819 return ret; 821 return ret;
820} 822}
@@ -2312,7 +2314,9 @@ mem_cgroup_uncharge_swapcache(struct page *page, swp_entry_t ent, bool swapout)
2312 2314
2313 /* record memcg information */ 2315 /* record memcg information */
2314 if (do_swap_account && swapout && memcg) { 2316 if (do_swap_account && swapout && memcg) {
2317 rcu_read_lock();
2315 swap_cgroup_record(ent, css_id(&memcg->css)); 2318 swap_cgroup_record(ent, css_id(&memcg->css));
2319 rcu_read_unlock();
2316 mem_cgroup_get(memcg); 2320 mem_cgroup_get(memcg);
2317 } 2321 }
2318 if (swapout && memcg) 2322 if (swapout && memcg)
@@ -2369,8 +2373,10 @@ static int mem_cgroup_move_swap_account(swp_entry_t entry,
2369{ 2373{
2370 unsigned short old_id, new_id; 2374 unsigned short old_id, new_id;
2371 2375
2376 rcu_read_lock();
2372 old_id = css_id(&from->css); 2377 old_id = css_id(&from->css);
2373 new_id = css_id(&to->css); 2378 new_id = css_id(&to->css);
2379 rcu_read_unlock();
2374 2380
2375 if (swap_cgroup_cmpxchg(entry, old_id, new_id) == old_id) { 2381 if (swap_cgroup_cmpxchg(entry, old_id, new_id) == old_id) {
2376 mem_cgroup_swap_statistics(from, false); 2382 mem_cgroup_swap_statistics(from, false);
@@ -4038,11 +4044,16 @@ static int is_target_pte_for_mc(struct vm_area_struct *vma,
4038 put_page(page); 4044 put_page(page);
4039 } 4045 }
4040 /* throught */ 4046 /* throught */
4041 if (ent.val && do_swap_account && !ret && 4047 if (ent.val && do_swap_account && !ret) {
4042 css_id(&mc.from->css) == lookup_swap_cgroup(ent)) { 4048 unsigned short id;
4043 ret = MC_TARGET_SWAP; 4049 rcu_read_lock();
4044 if (target) 4050 id = css_id(&mc.from->css);
4045 target->ent = ent; 4051 rcu_read_unlock();
4052 if (id == lookup_swap_cgroup(ent)) {
4053 ret = MC_TARGET_SWAP;
4054 if (target)
4055 target->ent = ent;
4056 }
4046 } 4057 }
4047 return ret; 4058 return ret;
4048} 4059}