[RHEL7,COMMIT] memcg: mm_update_next_owner() should skip kthreads

Submitted by Konstantin Khorenko on June 14, 2019, 4:29 p.m.


Message ID 201906141629.x5EGTGHR009766@finist-ce7.sw.ru
State New
Series "Series without cover letter"
Headers show

Commit Message

Konstantin Khorenko June 14, 2019, 4:29 p.m.
The commit is pushed to "branch-rh7-3.10.0-957.12.2.vz7.96.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-957.12.2.vz7.96.15
commit 79426efde5c9efb5c63939500057a43f3c997c2b
Author: Oleg Nesterov <oleg@redhat.com>
Date:   Fri Jun 14 19:29:16 2019 +0300

    memcg: mm_update_next_owner() should skip kthreads
    "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@redhat.com>
    Reviewed-by: Michal Hocko <mhocko@suse.cz>
    Cc: Balbir Singh <bsingharora@gmail.com>
    Cc: Johannes Weiner <hannes@cmpxchg.org>
    Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
    Cc: Michal Hocko <mhocko@suse.cz>
    Cc: Peter Chiang <pchiang@nvidia.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    (cherry picked from commit f87fb599ae4d2a152a93f9821b94f3158146d097)
    Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
 kernel/exit.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

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);
+	}