Commit b52723c5 authored by KOSAKI Motohiro's avatar KOSAKI Motohiro Committed by Linus Torvalds

oom: fix tasklist_lock leak

Commit 0aad4b31 ("oom: fold __out_of_memory into out_of_memory")
introduced a tasklist_lock leak.  Then it caused following obvious
danger warnings and panic.

    ================================================
    [ BUG: lock held when returning to user space! ]
    ------------------------------------------------
    rsyslogd/1422 is leaving the kernel with locks still held!
    1 lock held by rsyslogd/1422:
     #0:  (tasklist_lock){.+.+.+}, at: [<ffffffff810faf64>] out_of_memory+0x164/0x3f0
    BUG: scheduling while atomic: rsyslogd/1422/0x00000002
    INFO: lockdep is turned off.

This patch fixes it.
Signed-off-by: default avatarKOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Reviewed-by: default avatarMinchan Kim <minchan.kim@gmail.com>
Acked-by: default avatarDavid Rientjes <rientjes@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent be71cf22
...@@ -646,6 +646,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, ...@@ -646,6 +646,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
unsigned long freed = 0; unsigned long freed = 0;
unsigned int points; unsigned int points;
enum oom_constraint constraint = CONSTRAINT_NONE; enum oom_constraint constraint = CONSTRAINT_NONE;
int killed = 0;
blocking_notifier_call_chain(&oom_notify_list, 0, &freed); blocking_notifier_call_chain(&oom_notify_list, 0, &freed);
if (freed > 0) if (freed > 0)
...@@ -683,7 +684,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, ...@@ -683,7 +684,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
if (!oom_kill_process(current, gfp_mask, order, 0, totalpages, if (!oom_kill_process(current, gfp_mask, order, 0, totalpages,
NULL, nodemask, NULL, nodemask,
"Out of memory (oom_kill_allocating_task)")) "Out of memory (oom_kill_allocating_task)"))
return; goto out;
} }
retry: retry:
...@@ -691,7 +692,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, ...@@ -691,7 +692,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
constraint == CONSTRAINT_MEMORY_POLICY ? nodemask : constraint == CONSTRAINT_MEMORY_POLICY ? nodemask :
NULL); NULL);
if (PTR_ERR(p) == -1UL) if (PTR_ERR(p) == -1UL)
return; goto out;
/* Found nothing?!?! Either we hang forever, or we panic. */ /* Found nothing?!?! Either we hang forever, or we panic. */
if (!p) { if (!p) {
...@@ -703,13 +704,15 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, ...@@ -703,13 +704,15 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL, if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
nodemask, "Out of memory")) nodemask, "Out of memory"))
goto retry; goto retry;
killed = 1;
out:
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
/* /*
* Give "p" a good chance of killing itself before we * Give "p" a good chance of killing itself before we
* retry to allocate memory unless "p" is current * retry to allocate memory unless "p" is current
*/ */
if (!test_thread_flag(TIF_MEMDIE)) if (killed && !test_thread_flag(TIF_MEMDIE))
schedule_timeout_uninterruptible(1); schedule_timeout_uninterruptible(1);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment