Blob Blame History Raw
From: Konstantin Khlebnikov <khlebnikov@openvz.org>
Date: Sat, 09 Jun 2012 13:43:32 +0400
Subject: [PATCH] mm: correctly synchronize rss-counters at exit/exec
Patch-mainline: v3.5-rc3
Git-commit: 4fe7efdbdfb1c7e7a7f31decfd831c0f31d37091
References: bnc#767152

do_exit() and exec_mmap() call sync_mm_rss() before mm_release()
does put_user(clear_child_tid) which can update task->rss_stat
and thus make mm->rss_stat inconsistent. This triggers the "BUG:"
printk in check_mm().

Let's fix this bug in the safest way, and optimize/cleanup this later.

Reported-by: Markus Trippelsdorf <markus@trippelsdorf.de>
Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
Acked-by: Michal Hocko <mhocko@suse.cz>

---
 fs/exec.c     |    2 +-
 kernel/exit.c |    1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

Index: linux-3.4-openSUSE-12.2/fs/exec.c
===================================================================
--- linux-3.4-openSUSE-12.2.orig/fs/exec.c
+++ linux-3.4-openSUSE-12.2/fs/exec.c
@@ -823,10 +823,10 @@ static int exec_mmap(struct mm_struct *m
 	/* Notify parent that we're no longer interested in the old VM */
 	tsk = current;
 	old_mm = current->mm;
-	sync_mm_rss(old_mm);
 	mm_release(tsk, old_mm);
 
 	if (old_mm) {
+		sync_mm_rss(old_mm);
 		/*
 		 * Make sure that if there is a core dump in progress
 		 * for the old mm, we get out and die instead of going
Index: linux-3.4-openSUSE-12.2/kernel/exit.c
===================================================================
--- linux-3.4-openSUSE-12.2.orig/kernel/exit.c
+++ linux-3.4-openSUSE-12.2/kernel/exit.c
@@ -643,6 +643,7 @@ static void exit_mm(struct task_struct *
 	mm_release(tsk, mm);
 	if (!mm)
 		return;
+	sync_mm_rss(mm);
 	/*
 	 * Serialize with any possible pending coredump.
 	 * We must hold mmap_sem around checking core_state