From patchwork Fri Sep 2 18:27:47 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 1122902 Received: from smtp1.linux-foundation.org (smtp1.linux-foundation.org [140.211.169.13]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p82IUfuG015317 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Fri, 2 Sep 2011 18:31:01 GMT Received: from daredevil.linux-foundation.org (localhost [127.0.0.1]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id p82ITAnZ010734; Fri, 2 Sep 2011 11:29:10 -0700 Received: from mail-pz0-f47.google.com (mail-pz0-f47.google.com [209.85.210.47]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id p82ISDgZ010073 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=FAIL); Fri, 2 Sep 2011 11:28:14 -0700 Received: by pzk2 with SMTP id 2so4380424pzk.20 for ; Fri, 02 Sep 2011 11:28:13 -0700 (PDT) Received: by 10.68.29.129 with SMTP id k1mr2581842pbh.45.1314988092746; Fri, 02 Sep 2011 11:28:12 -0700 (PDT) Received: from localhost.localdomain ([121.167.223.83]) by mx.google.com with ESMTPS id i1sm11753361pbe.1.2011.09.02.11.28.09 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 02 Sep 2011 11:28:12 -0700 (PDT) From: Tejun Heo To: oleg@redhat.com, matthltc@us.ibm.com, rjw@sisk.pl, paul@paulmenage.org Date: Sat, 3 Sep 2011 03:27:47 +0900 Message-Id: <1314988070-12244-4-git-send-email-tj@kernel.org> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1314988070-12244-1-git-send-email-tj@kernel.org> References: <1314988070-12244-1-git-send-email-tj@kernel.org> Received-SPF: pass (localhost is always allowed.) X-Spam-Status: No, hits=-4.156 required=5 tests=AWL, BAYES_00, OSDL_HEADER_SUBJECT_BRACKETED X-Spam-Checker-Version: SpamAssassin 3.2.4-osdl_revision__1.47__ X-MIMEDefang-Filter: lf-20110901g X-Scanned-By: MIMEDefang 2.63 on 140.211.169.21 X-Scanned-By: MIMEDefang 2.63 on 140.211.169.51 Cc: Tejun Heo , containers@lists.linux-foundation.org, linux-pm@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [linux-pm] [PATCH 3/6] freezer: restructure __refrigerator() X-BeenThere: linux-pm@lists.linux-foundation.org X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux power management List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-pm-bounces@lists.linux-foundation.org Errors-To: linux-pm-bounces@lists.linux-foundation.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Fri, 02 Sep 2011 18:31:01 +0000 (UTC) If another freeze happens before all tasks leave FROZEN state after being thawed, the freezer can see the existing FROZEN and consider the tasks to be frozen but they can clear FROZEN without checking the new freezing(). Oleg suggested restructuring __refrigerator() such that there's single condition check section inside freezer_lock and sigpending is cleared afterwards, which fixes the problem and simplifies the code. Restructure accordingly. -v2: Frozen loop exited without releasing freezer_lock. Fixed. Signed-off-by: Tejun Heo Reported-by: Oleg Nesterov Cc: "Rafael J. Wysocki" --- kernel/freezer.c | 29 +++++++++++------------------ 1 files changed, 11 insertions(+), 18 deletions(-) diff --git a/kernel/freezer.c b/kernel/freezer.c index 466ea6b..ebee1ab 100644 --- a/kernel/freezer.c +++ b/kernel/freezer.c @@ -52,36 +52,29 @@ bool __refrigerator(bool check_kthr_stop) /* Hmm, should we be allowed to suspend when there are realtime processes around? */ bool was_frozen = false; - long save; + long save = current->state; - /* - * No point in checking freezing() again - the caller already did. - * Proceed to enter FROZEN. - */ - spin_lock_irq(&freezer_lock); - current->flags |= PF_FROZEN; - spin_unlock_irq(&freezer_lock); - - save = current->state; pr_debug("%s entered refrigerator\n", current->comm); - spin_lock_irq(¤t->sighand->siglock); - recalc_sigpending(); /* We sent fake signal, clean it up */ - spin_unlock_irq(¤t->sighand->siglock); - for (;;) { set_current_state(TASK_UNINTERRUPTIBLE); + + spin_lock_irq(&freezer_lock); + current->flags |= PF_FROZEN; if (!freezing(current) || (check_kthr_stop && kthread_should_stop())) + current->flags &= ~PF_FROZEN; + spin_unlock_irq(&freezer_lock); + + if (!(current->flags & PF_FROZEN)) break; was_frozen = true; schedule(); } - /* leave FROZEN */ - spin_lock_irq(&freezer_lock); - current->flags &= ~PF_FROZEN; - spin_unlock_irq(&freezer_lock); + spin_lock_irq(¤t->sighand->siglock); + recalc_sigpending(); /* We sent fake signal, clean it up */ + spin_unlock_irq(¤t->sighand->siglock); pr_debug("%s left refrigerator\n", current->comm);