aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/freezer.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2011-11-21 15:32:26 -0500
committerTejun Heo <tj@kernel.org>2011-11-21 15:32:26 -0500
commit5ece3eae4cdb968c269e0bc7e2c0e2b223552025 (patch)
tree8e38ac6fc88864eff7fbbe3fa3671a4b76cfd8e9 /kernel/freezer.c
parent96ee6d8539c9fc6742908d85eb9723abb5c91854 (diff)
freezer: restructure __refrigerator()
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> Acked-by: Oleg Nesterov <oleg@redhat.com> Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Diffstat (limited to 'kernel/freezer.c')
-rw-r--r--kernel/freezer.c32
1 files changed, 11 insertions, 21 deletions
diff --git a/kernel/freezer.c b/kernel/freezer.c
index b1e7a7b3d2cd..c3496c6a91b2 100644
--- a/kernel/freezer.c
+++ b/kernel/freezer.c
@@ -52,39 +52,29 @@ bool __refrigerator(bool check_kthr_stop)
52 /* Hmm, should we be allowed to suspend when there are realtime 52 /* Hmm, should we be allowed to suspend when there are realtime
53 processes around? */ 53 processes around? */
54 bool was_frozen = false; 54 bool was_frozen = false;
55 long save; 55 long save = current->state;
56 56
57 /*
58 * No point in checking freezing() again - the caller already did.
59 * Proceed to enter FROZEN.
60 */
61 spin_lock_irq(&freezer_lock);
62repeat:
63 current->flags |= PF_FROZEN;
64 spin_unlock_irq(&freezer_lock);
65
66 save = current->state;
67 pr_debug("%s entered refrigerator\n", current->comm); 57 pr_debug("%s entered refrigerator\n", current->comm);
68 58
69 spin_lock_irq(&current->sighand->siglock);
70 recalc_sigpending(); /* We sent fake signal, clean it up */
71 spin_unlock_irq(&current->sighand->siglock);
72
73 for (;;) { 59 for (;;) {
74 set_current_state(TASK_UNINTERRUPTIBLE); 60 set_current_state(TASK_UNINTERRUPTIBLE);
61
62 spin_lock_irq(&freezer_lock);
63 current->flags |= PF_FROZEN;
75 if (!freezing(current) || 64 if (!freezing(current) ||
76 (check_kthr_stop && kthread_should_stop())) 65 (check_kthr_stop && kthread_should_stop()))
66 current->flags &= ~PF_FROZEN;
67 spin_unlock_irq(&freezer_lock);
68
69 if (!(current->flags & PF_FROZEN))
77 break; 70 break;
78 was_frozen = true; 71 was_frozen = true;
79 schedule(); 72 schedule();
80 } 73 }
81 74
82 /* leave FROZEN */ 75 spin_lock_irq(&current->sighand->siglock);
83 spin_lock_irq(&freezer_lock); 76 recalc_sigpending(); /* We sent fake signal, clean it up */
84 if (freezing(current)) 77 spin_unlock_irq(&current->sighand->siglock);
85 goto repeat;
86 current->flags &= ~PF_FROZEN;
87 spin_unlock_irq(&freezer_lock);
88 78
89 pr_debug("%s left refrigerator\n", current->comm); 79 pr_debug("%s left refrigerator\n", current->comm);
90 80