All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: oleg@redhat.com, matthltc@us.ibm.com, rjw@sisk.pl, paul@paulmenage.org
Cc: containers@lists.linux-foundation.org,
	linux-pm@lists.linux-foundation.org,
	linux-kernel@vger.kernel.org, Tejun Heo <tj@kernel.org>
Subject: [PATCH 3/6] freezer: restructure __refrigerator()
Date: Sat,  3 Sep 2011 03:27:47 +0900	[thread overview]
Message-ID: <1314988070-12244-4-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1314988070-12244-1-git-send-email-tj@kernel.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.

-v2: Frozen loop exited without releasing freezer_lock.  Fixed.

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 |   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(&current->sighand->siglock);
-	recalc_sigpending(); /* We sent fake signal, clean it up */
-	spin_unlock_irq(&current->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(&current->sighand->siglock);
+	recalc_sigpending(); /* We sent fake signal, clean it up */
+	spin_unlock_irq(&current->sighand->siglock);
 
 	pr_debug("%s left refrigerator\n", current->comm);
 
-- 
1.7.6


  parent reply	other threads:[~2011-09-02 18:28 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-02 18:27 [PATCHSET pm-freezer] freezer: fixes & simplifications Tejun Heo
2011-09-02 18:27 ` [PATCH 1/6] cgroup_freezer: fix freezer->state setting bug in freezer_change_state() Tejun Heo
2011-09-04 18:02   ` Oleg Nesterov
     [not found]   ` <1314988070-12244-2-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2011-09-04 18:02     ` Oleg Nesterov
2011-09-04 18:02       ` Oleg Nesterov
2011-09-04 18:11       ` Tejun Heo
     [not found]       ` <20110904180206.GA28520-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2011-09-04 18:11         ` Tejun Heo
2011-09-04 18:11           ` Tejun Heo
     [not found]           ` <20110904181139.GA9807-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2011-09-04 18:20             ` Oleg Nesterov
2011-09-04 18:20               ` Oleg Nesterov
2011-09-04 18:20           ` Oleg Nesterov
2011-09-02 18:27 ` Tejun Heo
2011-09-02 18:27 ` [PATCH 2/6] freezer: set PF_NOFREEZE on a dying task right before TASK_DEAD " Tejun Heo
2011-09-02 18:27 ` Tejun Heo
2011-09-02 18:27 ` [PATCH 3/6] freezer: restructure __refrigerator() Tejun Heo
2011-09-02 18:27 ` Tejun Heo [this message]
2011-09-02 18:27 ` [PATCH 4/6] freezer: use lock_task_sighand() in fake_signal_wake_up() Tejun Heo
2011-09-02 18:27 ` Tejun Heo
2011-09-02 18:27 ` [PATCH 5/6] freezer: remove unused @sig_only from freeze_task() Tejun Heo
2011-09-02 18:27 ` Tejun Heo
     [not found] ` <1314988070-12244-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2011-09-02 18:27   ` [PATCH 1/6] cgroup_freezer: fix freezer->state setting bug in freezer_change_state() Tejun Heo
2011-09-02 18:27   ` [PATCH 2/6] freezer: set PF_NOFREEZE on a dying task right before TASK_DEAD " Tejun Heo
2011-09-02 18:27   ` [PATCH 3/6] freezer: restructure __refrigerator() Tejun Heo
2011-09-02 18:27   ` [PATCH 4/6] freezer: use lock_task_sighand() in fake_signal_wake_up() Tejun Heo
2011-09-02 18:27   ` [PATCH 5/6] freezer: remove unused @sig_only from freeze_task() Tejun Heo
2011-09-02 18:27   ` [PATCH 6/6] freezer: kill unused set_freezable_with_signal() Tejun Heo
2011-09-04 18:48   ` [PATCHSET pm-freezer] freezer: fixes & simplifications Oleg Nesterov
2011-09-04 18:48     ` Oleg Nesterov
2011-09-02 18:27 ` [PATCH 6/6] freezer: kill unused set_freezable_with_signal() Tejun Heo
     [not found]   ` <1314988070-12244-7-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2011-09-04 18:46     ` Oleg Nesterov
2011-09-04 18:46   ` Oleg Nesterov
2011-09-05  2:33     ` Tejun Heo
2011-09-05  2:33     ` Tejun Heo
2011-09-05  2:35       ` Tejun Heo
2011-09-05  2:35       ` Tejun Heo
2011-09-05 16:21         ` Oleg Nesterov
2011-09-05 16:21         ` Oleg Nesterov
     [not found]         ` <20110905023505.GC9807-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2011-09-05 16:21           ` Oleg Nesterov
2011-09-05 16:20       ` Oleg Nesterov
2011-09-05 16:20       ` Oleg Nesterov
2011-09-06  3:28         ` Tejun Heo
2011-09-06  3:28         ` Tejun Heo
2011-09-06 15:18           ` Oleg Nesterov
2011-09-06 15:18           ` Oleg Nesterov
2011-09-06 15:25             ` Oleg Nesterov
     [not found]             ` <20110906151836.GA15568-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2011-09-06 15:25               ` Oleg Nesterov
2011-09-06 15:25             ` Oleg Nesterov
2011-09-06 15:53               ` Tejun Heo
2011-09-06 15:53               ` Tejun Heo
2011-09-07 18:21                 ` [PATCH 0/1] freezer: fix wait_event_freezable/__thaw_task races Oleg Nesterov
2011-09-07 18:21                 ` Oleg Nesterov
2011-09-07 18:22                   ` [PATCH 1/1] " Oleg Nesterov
2011-09-07 18:22                   ` Oleg Nesterov
     [not found]                     ` <20110907182217.GB13909-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2011-09-08  1:05                       ` Tejun Heo
2011-09-08  1:05                         ` Tejun Heo
2011-09-08 17:59                         ` Oleg Nesterov
     [not found]                         ` <20110908010530.GD3987-9pTldWuhBndy/B6EtB590w@public.gmane.org>
2011-09-08 17:59                           ` Oleg Nesterov
2011-09-08 17:59                             ` Oleg Nesterov
2011-09-11  1:54                             ` Tejun Heo
     [not found]                             ` <20110908175926.GA26986-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2011-09-11  1:54                               ` Tejun Heo
2011-09-11  1:54                             ` Tejun Heo
2011-09-11 18:29                               ` Oleg Nesterov
2011-09-11 18:41                                 ` Oleg Nesterov
2011-09-08  1:05                     ` Tejun Heo
     [not found]                   ` <20110907182156.GA13909-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2011-09-07 18:22                     ` Oleg Nesterov
     [not found]                 ` <20110906155332.GF18425-9pTldWuhBndy/B6EtB590w@public.gmane.org>
2011-09-07 18:21                   ` [PATCH 0/1] " Oleg Nesterov
     [not found]               ` <20110906152539.GA16899-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2011-09-06 15:53                 ` [PATCH 6/6] freezer: kill unused set_freezable_with_signal() Tejun Heo
2011-09-08 18:01           ` Matt Helsley
     [not found]           ` <20110906032846.GA18425-9pTldWuhBndy/B6EtB590w@public.gmane.org>
2011-09-06 15:18             ` Oleg Nesterov
2011-09-08 18:01             ` Matt Helsley
2011-09-08 18:01               ` Matt Helsley
     [not found]               ` <20110908180159.GA4197-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2011-09-11  1:37                 ` Tejun Heo
2011-09-11  1:37               ` Tejun Heo
2011-09-11  1:37               ` Tejun Heo
     [not found]         ` <20110905162012.GA4445-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2011-09-06  3:28           ` Tejun Heo
     [not found]       ` <20110905023315.GB9807-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2011-09-05  2:35         ` Tejun Heo
2011-09-05 16:20         ` Oleg Nesterov
     [not found]     ` <20110904184626.GA30101-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2011-09-05  2:33       ` Tejun Heo
2011-09-04 18:46   ` Oleg Nesterov
2011-09-02 18:27 ` Tejun Heo
2011-09-04 18:48 ` [PATCHSET pm-freezer] freezer: fixes & simplifications Oleg Nesterov

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=1314988070-12244-4-git-send-email-tj@kernel.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=matthltc@us.ibm.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.