kmod: make __request_module() killable
authorOleg Nesterov <oleg@redhat.com>
Fri, 23 Mar 2012 22:02:50 +0000 (15:02 -0700)
committerLeann Ogasawara <leann.ogasawara@canonical.com>
Mon, 2 Apr 2012 20:24:14 +0000 (13:24 -0700)
commit3a2d258c6a32271493e916a53926fdc120c30326
tree73e04d79d6d240f85eca1b5c46c8e80f1e21da83
parent0257027bf008b993a00d1c0c5b1aec484ff5db36
kmod: make __request_module() killable

BugLink: http://bugs.launchpad.net/bugs/963685

As Tetsuo Handa pointed out, request_module() can stress the system
while the oom-killed caller sleeps in TASK_UNINTERRUPTIBLE.

The task T uses "almost all" memory, then it does something which
triggers request_module().  Say, it can simply call sys_socket().  This
in turn needs more memory and leads to OOM.  oom-killer correctly
chooses T and kills it, but this can't help because it sleeps in
TASK_UNINTERRUPTIBLE and after that oom-killer becomes "disabled" by the
TIF_MEMDIE task T.

Make __request_module() killable.  The only necessary change is that
call_modprobe() should kmalloc argv and module_name, they can't live in
the stack if we use UMH_KILLABLE.  This memory is freed via
call_usermodehelper_freeinfo()->cleanup.

Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Tejun Heo <tj@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 1cc684ab75123efe7ff446eb821d44375ba8fa30)

Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
kernel/kmod.c