]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
freezer,sched: Do not restore saved_state of a thawed task
authorElliot Berman <quic_eberman@quicinc.com>
Mon, 20 Nov 2023 17:36:31 +0000 (09:36 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 15 Aug 2025 10:09:07 +0000 (12:09 +0200)
commit2e62985121b74e3f334d8aa1eedc1472176e64f4
treefbecbaf6d8712dc8dfd1bc920d72578f82df6281
parente241ca2f0ec364ed3e202ce84e8ae4d3b6e8dac2
freezer,sched: Do not restore saved_state of a thawed task

commit 23ab79e8e469e2605beec2e3ccb40d19c68dd2e0 upstream.

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: 8f0eed4a78a8 ("freezer,sched: Use saved_state to reduce some spurious wakeups")
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Abhijeet Dharmapurikar <quic_adharmap@quicinc.com>
Link: https://lore.kernel.org/r/20231120-freezer-state-multiple-thaws-v1-1-f2e1dd7ce5a2@quicinc.com
Signed-off-by: Chen Ridong <chenridong@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/freezer.c