Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp307418imu; Thu, 8 Nov 2018 02:12:46 -0800 (PST) X-Google-Smtp-Source: AJdET5cSUStg/8IbMSFiCG8l9MGnP603OgNIDpeBoeEOjiZH/PUl5o+jZsdzkLnVDC/NA5Sa9zz/ X-Received: by 2002:a62:507:: with SMTP id 7-v6mr3980031pff.80.1541671966424; Thu, 08 Nov 2018 02:12:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541671966; cv=none; d=google.com; s=arc-20160816; b=bOolYwvOP8xWejD0jdLzcQTaGWcQco6+sBgFH7wm2Eub4A0y2CAuYWhMCzPPFLqbBq IaBTvaX0GYJHWMoOLVgefXmzUDsAkf94UHT5FA2oaOEdr0ROBmfShVpb4kQa/abiH79k KtW2OFpV+SAtkFXwAagpizwYCvvlA6WVscHgOQd7y7XEP5Ly7kfLv9QMmbg78gaz3eB1 hXbhYX+7eUVtf0vhFLi7us4r3Wn/bT+OJb+VN9l0b1fGV30vT8bUNo2fEdaEY4rXv427 Px7NruUbVhMvFPWjSU6h6phoKfMOa9itQ9NgwkZjJvEceDmH+cAuUamslLszFodrpmlA Sh7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=jDZzYOd5EUQPwZcpWN4Qejve0TMiut+reRz3lw9t8xw=; b=ZKzvzA3f2XTf7U8gxq6+61d7uvZ0MfRZF7NkytnQN7zpmmtB+uBB5RP5NqUgp17f7N QWbOMmd3NjNvx1Lh1n2Ce2uE1SV/Y9ehyeKwLs5CHXPpO3S68ri4ur2CKwYMruml3tJ8 lK3odu03vfGZ3477I1HFrBmgOcxFCUxYNpsrs3EeuLlkOOOmWAoot/us1p7++guiKMJk Tf5s3Xf91yDKrwVN1y0F+rVHmUS1fFHLwhCZcwB7zIKM0akM9YCgp+dHx8lzeHTIC0gD JoTlCmOAEuT6x/4hFxUV3cm1KqRyuOzW6IAaZ5dhTU5E6oBhy/dncckt6nb2Cgh7QgBz LlSA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t7-v6si3635738plo.191.2018.11.08.02.12.19; Thu, 08 Nov 2018 02:12:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726847AbeKHTou (ORCPT + 99 others); Thu, 8 Nov 2018 14:44:50 -0500 Received: from lgeamrelo12.lge.com ([156.147.23.52]:59412 "EHLO lgeamrelo11.lge.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726758AbeKHTot (ORCPT ); Thu, 8 Nov 2018 14:44:49 -0500 Received: from unknown (HELO lgemrelse6q.lge.com) (156.147.1.121) by 156.147.23.52 with ESMTP; 8 Nov 2018 19:10:03 +0900 X-Original-SENDERIP: 156.147.1.121 X-Original-MAILFROM: chanho.min@lge.com Received: from unknown (HELO kernel.lge.com) (165.186.175.97) by 156.147.1.121 with ESMTP; 8 Nov 2018 19:10:03 +0900 X-Original-SENDERIP: 165.186.175.97 X-Original-MAILFROM: chanho.min@lge.com From: Chanho Min To: "Rafael J. Wysocki" , Pavel Machek , Len Brown , Andrew Morton , "Eric W. Biederman" , Christian Brauner , Oleg Nesterov , Anna-Maria Gleixner Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Seungho Park , Chanho Min Subject: [PATCH] freezer: fix freeze timeout on exec Date: Thu, 8 Nov 2018 19:09:55 +0900 Message-Id: <1541671796-8725-1-git-send-email-chanho.min@lge.com> X-Mailer: git-send-email 2.1.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Suspend fails due to the exec family of fuctnions blocking the freezer. This issue has been found that it is mentioned in the ancient mail thread. The casue is that de_thread() sleeps in TASK_UNINTERRUPTIBLE waiting for all sub-threads to die, and we have the "deadlock" if one of them is frozen. It causes freeze timeout as bellows. Freezing of tasks failed after 20.010 seconds (1 tasks refusing to freeze, wq_busy=0): setcpushares-ls D ffffffc00008ed70 0 5817 1483 0x0040000d Call trace: [] __switch_to+0x88/0xa0 [] __schedule+0x1bc/0x720 [] schedule+0x40/0xa8 [] flush_old_exec+0xdc/0x640 [] load_elf_binary+0x2a8/0x1090 [] search_binary_handler+0x9c/0x240 [] load_script+0x20c/0x228 [] search_binary_handler+0x9c/0x240 [] do_execveat_common.isra.14+0x4f8/0x6e8 [] compat_SyS_execve+0x38/0x48 [] el0_svc_naked+0x24/0x28 To fix this, I suggest a patch by emboding the mentioned solution. First, revive and rework cancel_freezing_and_thaw() function whitch stops the task from sleeping in refrigirator reliably. And, The task to be killed does not allow to freeze. Reference: http://lkml.iu.edu/hypermail//linux/kernel/0702.2/1300.html Signed-off-by: Chanho Min --- include/linux/freezer.h | 7 +++++++ kernel/freezer.c | 14 ++++++++++++++ kernel/signal.c | 7 +++++++ 3 files changed, 28 insertions(+) diff --git a/include/linux/freezer.h b/include/linux/freezer.h index 21f5aa0..1c1e3cb 100644 --- a/include/linux/freezer.h +++ b/include/linux/freezer.h @@ -57,6 +57,12 @@ static inline bool try_to_freeze_unsafe(void) might_sleep(); if (likely(!freezing(current))) return false; + /* + * we are going to call do_exit() really soon, + * we have a pending SIGKILL + */ + if (unlikely(current->signal->flags & SIGNAL_GROUP_EXIT)) + return false; return __refrigerator(false); } @@ -68,6 +74,7 @@ static inline bool try_to_freeze(void) } extern bool freeze_task(struct task_struct *p); +extern void cancel_freezing_thaw_task(struct task_struct *p); extern bool set_freezable(void); #ifdef CONFIG_CGROUP_FREEZER diff --git a/kernel/freezer.c b/kernel/freezer.c index b162b74..584c5c8 100644 --- a/kernel/freezer.c +++ b/kernel/freezer.c @@ -148,6 +148,20 @@ bool freeze_task(struct task_struct *p) return true; } +void cancel_freezing_thaw_task(struct task_struct *p) +{ + unsigned long flags; + + spin_lock_irqsave(&freezer_lock, flags); + if (freezing(p)) { + spin_lock(&p->sighand->siglock); + recalc_sigpending_and_wake(p); + spin_unlock(&p->sighand->siglock); + } else if (frozen(p)) + wake_up_process(p); + spin_unlock_irqrestore(&freezer_lock, flags); +} + void __thaw_task(struct task_struct *p) { unsigned long flags; diff --git a/kernel/signal.c b/kernel/signal.c index 5843c54..ca9b25b 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -41,6 +41,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include @@ -1273,6 +1274,12 @@ int zap_other_threads(struct task_struct *p) /* Don't bother with already dead threads */ if (t->exit_state) continue; + + /* + * we can check sig->group_exit_task to detect de_thread, + * but perhaps it doesn't hurt if the caller is do_group_exit + */ + cancel_freezing_thaw_task(t); sigaddset(&t->pending.signal, SIGKILL); signal_wake_up(t, 1); } -- 2.7.4