[Devel] [PATCH rh7 1/2] memcg: mm_update_next_owner() should skip kthreads

Andrey Ryabinin aryabinin at virtuozzo.com
Tue Jun 11 14:53:29 MSK 2019


From: Oleg Nesterov <oleg at redhat.com>

"Search through everything else" in mm_update_next_owner() can hit a
kthread which adopted this "mm" via use_mm(), it should not be used as
mm->owner.  Add the PF_KTHREAD check.

While at it, change this code to use for_each_process_thread() instead
of deprecated do_each_thread/while_each_thread.

Signed-off-by: Oleg Nesterov <oleg at redhat.com>
Reviewed-by: Michal Hocko <mhocko at suse.cz>
Cc: Balbir Singh <bsingharora at gmail.com>
Cc: Johannes Weiner <hannes at cmpxchg.org>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu at jp.fujitsu.com>
Cc: Michal Hocko <mhocko at suse.cz>
Cc: Peter Chiang <pchiang at nvidia.com>
Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>

https://pmc.acronis.com/browse/VSTOR-23975
(cherry picked from commit f87fb599ae4d2a152a93f9821b94f3158146d097)
Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
 kernel/exit.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/kernel/exit.c b/kernel/exit.c
index 44ddc41cb6ee..659f0286096c 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -491,13 +491,12 @@ void mm_update_next_owner(struct mm_struct *mm)
 	}
 
 	/*
-	 * Search through everything else. We should not get
-	 * here often
+	 * Search through everything else, we should not get here often.
 	 */
-	do_each_thread(g, c) {
-		if (c->mm == mm)
+	for_each_process_thread(g, c) {
+		if (!(c->flags & PF_KTHREAD) && c->mm == mm)
 			goto assign_new_owner;
-	} while_each_thread(g, c);
+	}
 
 	qread_unlock(&tasklist_lock);
 	/*
-- 
2.21.0



More information about the Devel mailing list