linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [BUGFIX][PATCH] fix wrong VM_BUG_ON() in try_charge()'s mm->owner check
@ 2010-11-02 15:10 Hiroyuki Kamezawa
  2010-11-03  5:16 ` Balbir Singh
  2010-11-04 17:31 ` Hugh Dickins
  0 siblings, 2 replies; 4+ messages in thread
From: Hiroyuki Kamezawa @ 2010-11-02 15:10 UTC (permalink / raw)
  To: linux-mm
  Cc: KAMEZAWA Hiroyuki, balbir, nishimura, Andrew Morton, linux-kernel,
	kosaki.motohiro, hughd

[-- Attachment #1: Type: text/plain, Size: 139 bytes --]

I'm sorry for attached file, I have to use unusual mailer this time.
This is a fix for wrong VM_BUG_ON() for mm/memcontol.c

Thanks,
-Kame

[-- Attachment #2: fix-mm-owner-check.patch --]
[-- Type: application/octet-stream, Size: 2151 bytes --]

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 stroy 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: Balbir Singh <balbir@in.ibm.com>
Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Reported-by: Hugh Dickins <hughd@google.com>
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
---
 mm/memcontrol.c |   19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

Index: linux-2.6.36/mm/memcontrol.c
===================================================================
--- linux-2.6.36.orig/mm/memcontrol.c
+++ linux-2.6.36/mm/memcontrol.c
@@ -1729,19 +1729,18 @@ again:
 
 		rcu_read_lock();
 		p = rcu_dereference(mm->owner);
-		VM_BUG_ON(!p);
 		/*
-		 * because we don't have task_lock(), "p" can exit while
-		 * we're here. In that case, "mem" can point to root
-		 * cgroup but never be NULL. (and task_struct itself is freed
-		 * by RCU, cgroup itself is RCU safe.) Then, we have small
-		 * risk here to get wrong cgroup. But such kind of mis-account
-		 * by race always happens because we don't have cgroup_mutex().
-		 * It's overkill and we allow that small race, here.
+		 * Because we don't have task_lock(), "p" can exit.
+		 * In that case, "mem" can point to root or p can be NULL with
+		 * race with swapoff. Then, we have small risk of mis-accouning.
+		 * But such kind of mis-account by race always happens because
+		 * we don't have cgroup_mutex(). It's overkill and we allo that
+		 * small race, here.
+		 * (*) swapoff at el will charge against mm-struct not against
+		 * task-struct. So, mm->owner can be NULL.
 		 */
 		mem = mem_cgroup_from_task(p);
-		VM_BUG_ON(!mem);
-		if (mem_cgroup_is_root(mem)) {
+		if (!mem || mem_cgroup_is_root(mem)) {
 			rcu_read_unlock();
 			goto done;
 		}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [BUGFIX][PATCH] fix wrong VM_BUG_ON() in try_charge()'s mm->owner check
  2010-11-02 15:10 [BUGFIX][PATCH] fix wrong VM_BUG_ON() in try_charge()'s mm->owner check Hiroyuki Kamezawa
@ 2010-11-03  5:16 ` Balbir Singh
  2010-11-04 17:31 ` Hugh Dickins
  1 sibling, 0 replies; 4+ messages in thread
From: Balbir Singh @ 2010-11-03  5:16 UTC (permalink / raw)
  To: Hiroyuki Kamezawa
  Cc: linux-mm, KAMEZAWA Hiroyuki, nishimura, Andrew Morton,
	linux-kernel, kosaki.motohiro, hughd

* Hiroyuki Kamezawa <kamezawa.hiroyuki@gmail.com> [2010-11-03 00:10:50]:

> I'm sorry for attached file, I have to use unusual mailer this time.
> This is a fix for wrong VM_BUG_ON() for mm/memcontol.c
>

Yes, that seems reasonable. If we race with try_to_unuse() and
the mm has no new owner we set mm->owner to NULL, in those cases it
makes no sense to charge.


Reviewed-by: Balbir Singh <balbir@linux.vnet.ibm.com>
 

-- 
	Three Cheers,
	Balbir

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [BUGFIX][PATCH] fix wrong VM_BUG_ON() in try_charge()'s mm->owner check
  2010-11-02 15:10 [BUGFIX][PATCH] fix wrong VM_BUG_ON() in try_charge()'s mm->owner check Hiroyuki Kamezawa
  2010-11-03  5:16 ` Balbir Singh
@ 2010-11-04 17:31 ` Hugh Dickins
  2010-11-08  9:50   ` Johannes Weiner
  1 sibling, 1 reply; 4+ messages in thread
From: Hugh Dickins @ 2010-11-04 17:31 UTC (permalink / raw)
  To: Hiroyuki Kamezawa
  Cc: linux-mm, KAMEZAWA Hiroyuki, balbir, nishimura, Andrew Morton,
	linux-kernel, kosaki.motohiro

On Wed, 3 Nov 2010, Hiroyuki Kamezawa wrote:
> I'm sorry for attached file, I have to use unusual mailer this time.
> This is a fix for wrong VM_BUG_ON() for mm/memcontol.c

Thanks, Kame, that's good: I've inlined it below with Balbir's Review,
my Ack, and a Cc: stable@kernel.org.

Hugh


[PATCH] 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>
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Reviewed-by: Balbir Singh <balbir@linux.vnet.ibm.com>
Acked-by: Hugh Dickins <hughd@google.com>
Cc: stable@kernel.org
---
 mm/memcontrol.c |   19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

Index: linux-2.6.36/mm/memcontrol.c
===================================================================
--- linux-2.6.36.orig/mm/memcontrol.c
+++ linux-2.6.36/mm/memcontrol.c
@@ -1729,19 +1729,18 @@ again:
 
 		rcu_read_lock();
 		p = rcu_dereference(mm->owner);
-		VM_BUG_ON(!p);
 		/*
-		 * because we don't have task_lock(), "p" can exit while
-		 * we're here. In that case, "mem" can point to root
-		 * cgroup but never be NULL. (and task_struct itself is freed
-		 * by RCU, cgroup itself is RCU safe.) Then, we have small
-		 * risk here to get wrong cgroup. But such kind of mis-account
-		 * by race always happens because we don't have cgroup_mutex().
-		 * It's overkill and we allow that small race, here.
+		 * Because we don't have task_lock(), "p" can exit.
+		 * In that case, "mem" can point to root or p can be NULL with
+		 * race with swapoff. Then, we have small risk of mis-accouning.
+		 * But such kind of mis-account by race always happens because
+		 * we don't have cgroup_mutex(). It's overkill and we allo that
+		 * small race, here.
+		 * (*) swapoff at el will charge against mm-struct not against
+		 * task-struct. So, mm->owner can be NULL.
 		 */
 		mem = mem_cgroup_from_task(p);
-		VM_BUG_ON(!mem);
-		if (mem_cgroup_is_root(mem)) {
+		if (!mem || mem_cgroup_is_root(mem)) {
 			rcu_read_unlock();
 			goto done;
 		}

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [BUGFIX][PATCH] fix wrong VM_BUG_ON() in try_charge()'s mm->owner check
  2010-11-04 17:31 ` Hugh Dickins
@ 2010-11-08  9:50   ` Johannes Weiner
  0 siblings, 0 replies; 4+ messages in thread
From: Johannes Weiner @ 2010-11-08  9:50 UTC (permalink / raw)
  To: Hugh Dickins
  Cc: Hiroyuki Kamezawa, linux-mm, KAMEZAWA Hiroyuki, balbir, nishimura,
	Andrew Morton, linux-kernel, kosaki.motohiro

On Thu, Nov 04, 2010 at 10:31:58AM -0700, Hugh Dickins wrote:
> On Wed, 3 Nov 2010, Hiroyuki Kamezawa wrote:
> > I'm sorry for attached file, I have to use unusual mailer this time.
> > This is a fix for wrong VM_BUG_ON() for mm/memcontol.c
> 
> Thanks, Kame, that's good: I've inlined it below with Balbir's Review,
> my Ack, and a Cc: stable@kernel.org.
> 
> Hugh
> 
> 
> [PATCH] 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>
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> Reviewed-by: Balbir Singh <balbir@linux.vnet.ibm.com>
> Acked-by: Hugh Dickins <hughd@google.com>
> Cc: stable@kernel.org

Reviewed-by: Johannes Weiner <hannes@cmpxchg.org>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-11-08  9:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-02 15:10 [BUGFIX][PATCH] fix wrong VM_BUG_ON() in try_charge()'s mm->owner check Hiroyuki Kamezawa
2010-11-03  5:16 ` Balbir Singh
2010-11-04 17:31 ` Hugh Dickins
2010-11-08  9:50   ` Johannes Weiner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).