Skip to content

Commit 5ece3ea

Browse files
committed
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>
1 parent 96ee6d8 commit 5ece3ea

1 file changed

Lines changed: 11 additions & 21 deletions

File tree

‎kernel/freezer.c‎

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,39 +52,29 @@ bool __refrigerator(bool check_kthr_stop)
5252
/* Hmm, should we be allowed to suspend when there are realtime
5353
processes around? */
5454
bool was_frozen = false;
55-
long save;
55+
long save = current->state;
5656

57-
/*
58-
* No point in checking freezing() again - the caller already did.
59-
* Proceed to enter FROZEN.
60-
*/
61-
spin_lock_irq(&freezer_lock);
62-
repeat:
63-
current->flags |= PF_FROZEN;
64-
spin_unlock_irq(&freezer_lock);
65-
66-
save = current->state;
6757
pr_debug("%s entered refrigerator\n", current->comm);
6858

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-
7359
for (;;) {
7460
set_current_state(TASK_UNINTERRUPTIBLE);
61+
62+
spin_lock_irq(&freezer_lock);
63+
current->flags |= PF_FROZEN;
7564
if (!freezing(current) ||
7665
(check_kthr_stop && kthread_should_stop()))
66+
current->flags &= ~PF_FROZEN;
67+
spin_unlock_irq(&freezer_lock);
68+
69+
if (!(current->flags & PF_FROZEN))
7770
break;
7871
was_frozen = true;
7972
schedule();
8073
}
8174

82-
/* leave FROZEN */
83-
spin_lock_irq(&freezer_lock);
84-
if (freezing(current))
85-
goto repeat;
86-
current->flags &= ~PF_FROZEN;
87-
spin_unlock_irq(&freezer_lock);
75+
spin_lock_irq(&current->sighand->siglock);
76+
recalc_sigpending(); /* We sent fake signal, clean it up */
77+
spin_unlock_irq(&current->sighand->siglock);
8878

8979
pr_debug("%s left refrigerator\n", current->comm);
9080

0 commit comments

Comments
 (0)