Skip to content

Commit 23ab79e

Browse files
eberman-quicPeter Zijlstra
authored and
Peter Zijlstra
committed
freezer,sched: Do not restore saved_state of a thawed task
It is possible for a task to be thawed multiple times when mixing the *legacy* cgroup freezer and system-wide freezer. To do this, freeze the cgroup, do system-wide freeze/thaw, then thaw the cgroup. When this happens, then a stale saved_state can be written to the task's state and cause task to hang indefinitely. Fix this by only trying to thaw tasks that are actually frozen. This change also has the marginal benefit avoiding unnecessary wake_up_state(p, TASK_FROZEN) if we know the task is already thawed. There is not possibility of time-of-compare/time-of-use race when we skip the wake_up_state because entering/exiting TASK_FROZEN is guarded by freezer_lock. Fixes: 8f0eed4 ("freezer,sched: Use saved_state to reduce some spurious wakeups") Signed-off-by: Elliot Berman <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Abhijeet Dharmapurikar <[email protected]> Link: https://lore.kernel.org/r/20231120-freezer-state-multiple-thaws-v1-1-f2e1dd7ce5a2@quicinc.com
1 parent 2cc14f5 commit 23ab79e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/freezer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ void __thaw_task(struct task_struct *p)
201201
if (WARN_ON_ONCE(freezing(p)))
202202
goto unlock;
203203

204-
if (task_call_func(p, __restore_freezer_state, NULL))
204+
if (!frozen(p) || task_call_func(p, __restore_freezer_state, NULL))
205205
goto unlock;
206206

207207
wake_up_state(p, TASK_FROZEN);

0 commit comments

Comments
 (0)