From: Tejun Heo <tj@kernel.org>
To: "Rafael J. Wysocki" <rjw@sisk.pl>,
Oleg Nesterov <oleg@redhat.com>,
Paul Menage <paul@paulmenage.org>
Cc: containers@lists.linux-foundation.org,
linux-pm@lists.linux-foundation.org,
linux-kernel@vger.kernel.org
Subject: [PATCH pm-freezer 3/4] freezer: restructure __refrigerator()
Date: Wed, 31 Aug 2011 12:22:10 +0200 [thread overview]
Message-ID: <20110831102210.GC2828@mtj.dyndns.org> (raw)
In-Reply-To: <20110831102143.GB2828@mtj.dyndns.org>
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.
Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Oleg Nesterov <oleg@redhat.com>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
---
kernel/freezer.c | 33 ++++++++++++++-------------------
1 file changed, 14 insertions(+), 19 deletions(-)
Index: work/kernel/freezer.c
===================================================================
--- work.orig/kernel/freezer.c
+++ work/kernel/freezer.c
@@ -52,36 +52,31 @@ 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()))
+ (check_kthr_stop && kthread_should_stop())) {
+ current->flags &= ~PF_FROZEN;
+ break;
+ }
+ 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);
next prev parent reply other threads:[~2011-08-31 10:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-31 10:21 [PATCH pm-freezer 1/4] cgroup_freezer: fix freezer->state setting bug in freezer_change_state() Tejun Heo
2011-08-31 10:21 ` [PATCH pm-freezer 2/4] freezer: set PF_NOFREEZE on a dying task right before TASK_DEAD " Tejun Heo
2011-08-31 10:22 ` Tejun Heo [this message]
2011-08-31 10:22 ` [PATCH pm-freezer 4/4] freezer: use lock_task_sighand() in fake_signal_wake_up() Tejun Heo
2011-09-02 17:08 ` [PATCH pm-freezer 3/4] freezer: restructure __refrigerator() Oleg Nesterov
2011-08-31 18:08 ` [PATCH pm-freezer 1/4] cgroup_freezer: fix freezer->state setting bug in freezer_change_state() Oleg Nesterov
2011-09-02 0:42 ` Matt Helsley
2011-09-02 2:50 ` Tejun Heo
2011-09-02 16:58 ` Oleg Nesterov
2011-09-02 17:08 ` Tejun Heo
2011-09-02 17:15 ` Oleg Nesterov
2011-09-02 17:31 ` Tejun Heo
2011-09-02 17:30 ` Oleg Nesterov
2011-09-02 18:31 ` Matt Helsley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110831102210.GC2828@mtj.dyndns.org \
--to=tj@kernel.org \
--cc=containers@lists.linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@lists.linux-foundation.org \
--cc=oleg@redhat.com \
--cc=paul@paulmenage.org \
--cc=rjw@sisk.pl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome