From c0b687f9ce05c09008fe5912f9aca81a0a1f4200 Mon Sep 17 00:00:00 2001 From: Tetsuo Handa Date: Sun, 16 Mar 2014 09:50:52 +0900 Subject: [PATCH] kthread: defer leaving kthread_create() upon SIGKILL. Commit 786235ee "kthread: make kthread_create() killable" changed to leave kthread_create() as soon as receiving SIGKILL. But this change caused boot failures if systemd-udevd received SIGKILL (probably due to timeout) while loading SCSI disk controller drivers using finit_module() [1]. Therefore, this patch changes kthread_create() to defer leaving for 10 seconds, unless chosen by the OOM killer, in order to give the kthreadd a chance to complete the request. [1] https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1276705 Signed-off-by: Tetsuo Handa Cc: [3.13+] --- kernel/kthread.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kernel/kthread.c b/kernel/kthread.c index b5ae3ee..6de10d0 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -293,6 +293,17 @@ struct task_struct *kthread_create_on_node(int (*threadfn)(void *data), */ if (unlikely(wait_for_completion_killable(&done))) { /* + * If I got SIGKILL but I was not chosen by the OOM killer, + * wait for 10 seconds for completion in unkillable state. + * We must avoid waiting forever in unkillable state, for + * the OOM killer might choose me while waiting. Also, we + * should avoid waiting for too long, for I might call + * this function several times before I become ready to die. + */ + if (!test_tsk_thread_flag(current, TIF_MEMDIE)) + wait_for_completion_timeout(&done, + msecs_to_jiffies(10000)); + /* * If I was SIGKILLed before kthreadd (or new kernel thread) * calls complete(), leave the cleanup of this structure to * that thread. -- 1.7.9.5