Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

oom: fix tasklist_lock leak

Commit 0aad4b3124 ("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: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Reviewed-by: Minchan Kim <minchan.kim@gmail.com>
Acked-by: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

KOSAKI Motohiro and committed by
Linus Torvalds
b52723c5 be71cf22

+6 -3
+6 -3
mm/oom_kill.c
··· 646 646 unsigned long freed = 0; 647 647 unsigned int points; 648 648 enum oom_constraint constraint = CONSTRAINT_NONE; 649 + int killed = 0; 649 650 650 651 blocking_notifier_call_chain(&oom_notify_list, 0, &freed); 651 652 if (freed > 0) ··· 684 683 if (!oom_kill_process(current, gfp_mask, order, 0, totalpages, 685 684 NULL, nodemask, 686 685 "Out of memory (oom_kill_allocating_task)")) 687 - return; 686 + goto out; 688 687 } 689 688 690 689 retry: ··· 692 691 constraint == CONSTRAINT_MEMORY_POLICY ? nodemask : 693 692 NULL); 694 693 if (PTR_ERR(p) == -1UL) 695 - return; 694 + goto out; 696 695 697 696 /* Found nothing?!?! Either we hang forever, or we panic. */ 698 697 if (!p) { ··· 704 703 if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL, 705 704 nodemask, "Out of memory")) 706 705 goto retry; 706 + killed = 1; 707 + out: 707 708 read_unlock(&tasklist_lock); 708 709 709 710 /* 710 711 * Give "p" a good chance of killing itself before we 711 712 * retry to allocate memory unless "p" is current 712 713 */ 713 - if (!test_thread_flag(TIF_MEMDIE)) 714 + if (killed && !test_thread_flag(TIF_MEMDIE)) 714 715 schedule_timeout_uninterruptible(1); 715 716 } 716 717