aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>2010-12-29 17:07:11 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2010-12-30 13:07:06 -0500
commitebb76ce16daf6908dc030dec1c00827d37129fe5 (patch)
tree28abdc67466bb5d8d4566e36c914518b0533b4bf /mm
parentb83be6f20a0e468f715b14225c9f897538dfe5ad (diff)
memcg: fix wrong VM_BUG_ON() in try_charge()'s mm->owner check
At __mem_cgroup_try_charge(), VM_BUG_ON(!mm->owner) is checked. But as commented in mem_cgroup_from_task(), mm->owner can be NULL in some racy case. This check of VM_BUG_ON() is bad. A possible story to hit this is at swapoff()->try_to_unuse(). It passes mm_struct to mem_cgroup_try_charge_swapin() while mm->owner is NULL. If we can't get proper mem_cgroup from swap_cgroup information, mm->owner is used as charge target and we see NULL. Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Reported-by: Hugh Dickins <hughd@google.com> Reported-by: Thomas Meyer <thomas@m3y3r.de> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Reviewed-by: Balbir Singh <balbir@linux.vnet.ibm.com> Signed-off-by: Hugh Dickins <hughd@google.com> Cc: stable@kernel.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/memcontrol.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 7a22b4129211..00bb8a64d028 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1925,19 +1925,18 @@ again:
1925 1925
1926 rcu_read_lock(); 1926 rcu_read_lock();
1927 p = rcu_dereference(mm->owner); 1927 p = rcu_dereference(mm->owner);
1928 VM_BUG_ON(!p);
1929 /* 1928 /*
1930 * because we don't have task_lock(), "p" can exit while 1929 * Because we don't have task_lock(), "p" can exit.
1931 * we're here. In that case, "mem" can point to root 1930 * In that case, "mem" can point to root or p can be NULL with
1932 * cgroup but never be NULL. (and task_struct itself is freed 1931 * race with swapoff. Then, we have small risk of mis-accouning.
1933 * by RCU, cgroup itself is RCU safe.) Then, we have small 1932 * But such kind of mis-account by race always happens because
1934 * risk here to get wrong cgroup. But such kind of mis-account 1933 * we don't have cgroup_mutex(). It's overkill and we allo that
1935 * by race always happens because we don't have cgroup_mutex(). 1934 * small race, here.
1936 * It's overkill and we allow that small race, here. 1935 * (*) swapoff at el will charge against mm-struct not against
1936 * task-struct. So, mm->owner can be NULL.
1937 */ 1937 */
1938 mem = mem_cgroup_from_task(p); 1938 mem = mem_cgroup_from_task(p);
1939 VM_BUG_ON(!mem); 1939 if (!mem || mem_cgroup_is_root(mem)) {
1940 if (mem_cgroup_is_root(mem)) {
1941 rcu_read_unlock(); 1940 rcu_read_unlock();
1942 goto done; 1941 goto done;
1943 } 1942 }