Skip to contentSkip to conversation

+ oom_kill-add-rcu_read_lock-into-find_lock_task_mm.patch added to -mm tree

PATCH [email protected] 1 participant 1 message Dec 9, 2013

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

Subject: + oom_kill-add-rcu_read_lock-into-find_lock_task_mm.patch added to -mm tree
To: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]
From: [email protected]
Date: Mon, 09 Dec 2013 15:07:37 -0800

The patch titled
Subject: oom_kill: add rcu_read_lock() into find_lock_task_mm()
has been added to the -mm tree. Its filename is
oom_kill-add-rcu_read_lock-into-find_lock_task_mm.patch

This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/oom_kill-add-rcu_read_lock-into-find_lock_task_mm.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/oom_kill-add-rcu_read_lock-into-find_lock_task_mm.patch

Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/SubmitChecklist when testing your code ***

The -mm tree is included into linux-next and is updated there every 3-4 working days

------------------------------------------------------
From: Oleg Nesterov <[email protected]>
Subject: oom_kill: add rcu_read_lock() into find_lock_task_mm()

find_lock_task_mm() expects it is called under rcu or tasklist lock, but it seems that at least oom_unkillable_task()->task_in_mem_cgroup() and mem_cgroup_out_of_memory()->oom_badness() can call it lockless.

Perhaps we could fix the callers, but this patch simply adds rcu lock into find_lock_task_mm(). This also allows to simplify a bit one of its callers, oom_kill_process().

Cc Sergey Dyasly <[email protected]>
Cc Sameer Nanda <[email protected]>
Cc "Eric W. Biederman" <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Mandeep Singh Baines <[email protected]>
Cc "Ma, Xindong" <[email protected]>
Cc "Tu, Xiaobing" <[email protected]>

---

 mm/oom_kill.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
mm/oom_kill.c renamed from mm/oom_kill.c~oom_kill-add-rcu_read_lock-into-find_lock_task_mm +8 -4
diff -puN mm/oom_kill.c~oom_kill-add-rcu_read_lock-into-find_lock_task_mm mm/oom_kill.c
@@ -102,14 +102,19 @@ struct task_struct *find_lock_task_mm(st
 {
 	struct task_struct *t;
 
+	rcu_read_lock();
+
 	for_each_thread(p, t) {
 		task_lock(t);
 		if (likely(t->mm))
-			return t;
+			goto found;
 		task_unlock(t);
 	}
+	t = NULL;
+found:
+	rcu_read_unlock();
 
-	return NULL;
+	return t;
 }
 
 /* return true if the task is not adequate as candidate victim task. */
@@ -461,10 +466,8 @@ void oom_kill_process(struct task_struct
 	}
 	read_unlock(&tasklist_lock);
 
-	rcu_read_lock();
 	p = find_lock_task_mm(victim);
 	if (!p) {
-		rcu_read_unlock();
 		put_task_struct(victim);
 		return;
 	} else if (victim != p) {
@@ -490,6 +493,7 @@ void oom_kill_process(struct task_struct
 	 * That thread will now get access to memory reserves since it has a
 	 * pending fatal signal.
 	 */
+	rcu_read_lock();
 	for_each_process(p)
 		if (p->mm == mm && !same_thread_group(p, victim) &&
 		    !(p->flags & PF_KTHREAD)) {

_

Patches currently in -mm which might be from [email protected] are

introduce-for_each_thread-to-replace-the-buggy-while_each_thread.patch oom_kill-change-oom_killc-to-use-for_each_thread.patch oom_kill-has_intersects_mems_allowed-needs-rcu_read_lock.patch oom_kill-add-rcu_read_lock-into-find_lock_task_mm.patch autofs4-allow-autofs-to-work-outside-the-initial-pid-namespace.patch autofs4-translate-pids-to-the-right-namespace-for-the-daemon.patch coredump-set_dumpable-fix-the-theoretical-race-with-itself.patch coredump-kill-mmf_dumpable-and-mmf_dump_securely.patch coredump-make-__get_dumpable-get_dumpable-inline-kill-fs-coredumph.patch proc-cleanup-simplify-get_task_state-task_state_array.patch proc-fix-the-potential-use-after-free-in-first_tid.patch proc-change-first_tid-to-use-while_each_thread-rather-than-next_thread.patch proc-dont-abuse-group_leader-in-proc_task_readdir-paths.patch proc-fix-f_pos-overflows-in-first_tid.patch kernel-forkc-remove-redundant-null-check-in-dup_mm.patch exec-check_unsafe_exec-use-while_each_thread-rather-than-next_thread.patch exec-check_unsafe_exec-kill-the-dead-eagain-and-clear_in_exec-logic.patch exec-move-the-final-allow_write_access-fput-into-free_bprm.patch exec-kill-task_struct-did_exec.patch fs-proc-arrayc-change-do_task_stat-to-use-while_each_thread.patch kernel-sysc-k_getrusage-can-use-while_each_thread.patch kernel-signalc-change-do_signal_stop-do_sigaction-to-use-while_each_thread.patch linux-next.patch