Skip to content

Commit 03afed8

Browse files
committed
freezer: clean up freeze_processes() failure path
freeze_processes() failure path is rather messy. Freezing is canceled for workqueues and tasks which aren't frozen yet but frozen tasks are left alone and should be thawed by the caller and of course some callers (xen and kexec) didn't do it. This patch updates __thaw_task() to handle cancelation correctly and makes freeze_processes() and freeze_kernel_threads() call thaw_processes() on failure instead so that the system is fully thawed on failure. Unnecessary [suspend_]thaw_processes() calls are removed from kernel/power/hibernate.c, suspend.c and user.c. While at it, restructure error checking if clause in suspend_prepare() to be less weird. -v2: Srivatsa spotted missing removal of suspend_thaw_processes() in suspend_prepare() and error in commit message. Updated. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
1 parent 376fede commit 03afed8

6 files changed

Lines changed: 23 additions & 46 deletions

File tree

‎include/linux/freezer.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ static inline bool try_to_freeze(void)
6161
}
6262

6363
extern bool freeze_task(struct task_struct *p, bool sig_only);
64-
extern void cancel_freezing(struct task_struct *p);
6564

6665
#ifdef CONFIG_CGROUP_FREEZER
6766
extern int cgroup_freezing_or_frozen(struct task_struct *task);

‎kernel/freezer.c‎

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,6 @@ bool freeze_task(struct task_struct *p, bool sig_only)
129129
return ret;
130130
}
131131

132-
void cancel_freezing(struct task_struct *p)
133-
{
134-
unsigned long flags;
135-
136-
spin_lock_irqsave(&freezer_lock, flags);
137-
if (freezing(p)) {
138-
pr_debug(" clean up: %s\n", p->comm);
139-
clear_freeze_flag(p);
140-
spin_lock(&p->sighand->siglock);
141-
recalc_sigpending_and_wake(p);
142-
spin_unlock(&p->sighand->siglock);
143-
}
144-
spin_unlock_irqrestore(&freezer_lock, flags);
145-
}
146-
147132
void __thaw_task(struct task_struct *p)
148133
{
149134
unsigned long flags;
@@ -153,10 +138,18 @@ void __thaw_task(struct task_struct *p)
153138
* be visible to @p as waking up implies wmb. Waking up inside
154139
* freezer_lock also prevents wakeups from leaking outside
155140
* refrigerator.
141+
*
142+
* If !FROZEN, @p hasn't reached refrigerator, recalc sigpending to
143+
* avoid leaving dangling TIF_SIGPENDING behind.
156144
*/
157145
spin_lock_irqsave(&freezer_lock, flags);
158146
clear_freeze_flag(p);
159-
if (frozen(p))
147+
if (frozen(p)) {
160148
wake_up_process(p);
149+
} else {
150+
spin_lock(&p->sighand->siglock);
151+
recalc_sigpending_and_wake(p);
152+
spin_unlock(&p->sighand->siglock);
153+
}
161154
spin_unlock_irqrestore(&freezer_lock, flags);
162155
}

‎kernel/power/hibernate.c‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -607,17 +607,6 @@ static void power_down(void)
607607
while(1);
608608
}
609609

610-
static int prepare_processes(void)
611-
{
612-
int error = 0;
613-
614-
if (freeze_processes()) {
615-
error = -EBUSY;
616-
thaw_processes();
617-
}
618-
return error;
619-
}
620-
621610
/**
622611
* hibernate - Carry out system hibernation, including saving the image.
623612
*/
@@ -650,7 +639,7 @@ int hibernate(void)
650639
sys_sync();
651640
printk("done.\n");
652641

653-
error = prepare_processes();
642+
error = freeze_processes();
654643
if (error)
655644
goto Finish;
656645

@@ -811,7 +800,7 @@ static int software_resume(void)
811800
goto close_finish;
812801

813802
pr_debug("PM: Preparing processes for restore.\n");
814-
error = prepare_processes();
803+
error = freeze_processes();
815804
if (error) {
816805
swsusp_close(FMODE_READ);
817806
goto Done;

‎kernel/power/process.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,26 +91,18 @@ static int try_to_freeze_tasks(bool sig_only)
9191
elapsed_csecs = elapsed_csecs64;
9292

9393
if (todo) {
94-
/* This does not unfreeze processes that are already frozen
95-
* (we have slightly ugly calling convention in that respect,
96-
* and caller must call thaw_processes() if something fails),
97-
* but it cleans up leftover PF_FREEZE requests.
98-
*/
9994
printk("\n");
10095
printk(KERN_ERR "Freezing of tasks %s after %d.%02d seconds "
10196
"(%d tasks refusing to freeze, wq_busy=%d):\n",
10297
wakeup ? "aborted" : "failed",
10398
elapsed_csecs / 100, elapsed_csecs % 100,
10499
todo - wq_busy, wq_busy);
105100

106-
thaw_workqueues();
107-
108101
read_lock(&tasklist_lock);
109102
do_each_thread(g, p) {
110103
if (!wakeup && !freezer_should_skip(p) &&
111104
freezing(p) && !frozen(p))
112105
sched_show_task(p);
113-
cancel_freezing(p);
114106
} while_each_thread(g, p);
115107
read_unlock(&tasklist_lock);
116108
} else {
@@ -123,6 +115,8 @@ static int try_to_freeze_tasks(bool sig_only)
123115

124116
/**
125117
* freeze_processes - Signal user space processes to enter the refrigerator.
118+
*
119+
* On success, returns 0. On failure, -errno and system is fully thawed.
126120
*/
127121
int freeze_processes(void)
128122
{
@@ -137,11 +131,15 @@ int freeze_processes(void)
137131
printk("\n");
138132
BUG_ON(in_atomic());
139133

134+
if (error)
135+
thaw_processes();
140136
return error;
141137
}
142138

143139
/**
144140
* freeze_kernel_threads - Make freezable kernel threads go to the refrigerator.
141+
*
142+
* On success, returns 0. On failure, -errno and system is fully thawed.
145143
*/
146144
int freeze_kernel_threads(void)
147145
{
@@ -155,6 +153,8 @@ int freeze_kernel_threads(void)
155153
printk("\n");
156154
BUG_ON(in_atomic());
157155

156+
if (error)
157+
thaw_processes();
158158
return error;
159159
}
160160

‎kernel/power/suspend.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,11 @@ static int suspend_prepare(void)
106106
goto Finish;
107107

108108
error = suspend_freeze_processes();
109-
if (error) {
110-
suspend_stats.failed_freeze++;
111-
dpm_save_failed_step(SUSPEND_FREEZE);
112-
} else
109+
if (!error)
113110
return 0;
114111

115-
suspend_thaw_processes();
112+
suspend_stats.failed_freeze++;
113+
dpm_save_failed_step(SUSPEND_FREEZE);
116114
usermodehelper_enable();
117115
Finish:
118116
pm_notifier_call_chain(PM_POST_SUSPEND);

‎kernel/power/user.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,8 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
257257
break;
258258

259259
error = freeze_processes();
260-
if (error) {
261-
thaw_processes();
260+
if (error)
262261
usermodehelper_enable();
263-
}
264262
if (!error)
265263
data->frozen = 1;
266264
break;

0 commit comments

Comments
 (0)