mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [next] cgroup,freezer: fix incomplete freezing when attaching tasks
@ 2025-06-18  7:32 Chen Ridong
  2025-06-18  8:42 ` Michal Koutný
  2025-06-18 19:45 ` Tejun Heo
  0 siblings, 2 replies; 4+ messages in thread
From: Chen Ridong @ 2025-06-18  7:32 UTC (permalink / raw)
  To: tj, hannes, mkoutny, rafael.j.wysocki, mingo, peterz
  Cc: cgroups, linux-kernel, lujialin4, chenridong

From: Chen Ridong <chenridong@huawei.com>

An issue was found:

	# cd /sys/fs/cgroup/freezer/
	# mkdir test
	# echo FROZEN > test/freezer.state
	# cat test/freezer.state
	FROZEN
	# sleep 1000 &
	[1] 863
	# echo 863 > test/cgroup.procs
	# cat test/freezer.state
	FREEZING

When tasks are migrated to a frozen cgroup, the freezer fails to
immediately freeze the tasks, causing the cgroup to remain in the
"FREEZING".

The freeze_task() function is called before clearing the CGROUP_FROZEN
flag. This causes the freezing() check to incorrectly return false,
preventing __freeze_task() from being invoked for the migrated task.

To fix this issue, clear the CGROUP_FROZEN state before calling
freeze_task().

Fixes: f5d39b020809 ("freezer,sched: Rewrite core freezer logic")
Reported-by: Zhong Jiawei <zhongjiawei1@huawei.com>
Signed-off-by: Chen Ridong <chenridong@huawei.com>
---
 kernel/cgroup/legacy_freezer.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/cgroup/legacy_freezer.c b/kernel/cgroup/legacy_freezer.c
index 039d1eb2f215..507b8f19a262 100644
--- a/kernel/cgroup/legacy_freezer.c
+++ b/kernel/cgroup/legacy_freezer.c
@@ -188,13 +188,12 @@ static void freezer_attach(struct cgroup_taskset *tset)
 		if (!(freezer->state & CGROUP_FREEZING)) {
 			__thaw_task(task);
 		} else {
-			freeze_task(task);
-
 			/* clear FROZEN and propagate upwards */
 			while (freezer && (freezer->state & CGROUP_FROZEN)) {
 				freezer->state &= ~CGROUP_FROZEN;
 				freezer = parent_freezer(freezer);
 			}
+			freeze_task(task);
 		}
 	}
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [next] cgroup,freezer: fix incomplete freezing when attaching tasks
  2025-06-18  7:32 [next] cgroup,freezer: fix incomplete freezing when attaching tasks Chen Ridong
@ 2025-06-18  8:42 ` Michal Koutný
  2025-06-18  9:03   ` Chen Ridong
  2025-06-18 19:45 ` Tejun Heo
  1 sibling, 1 reply; 4+ messages in thread
From: Michal Koutný @ 2025-06-18  8:42 UTC (permalink / raw)
  To: Chen Ridong
  Cc: tj, hannes, rafael.j.wysocki, mingo, peterz, cgroups,
	linux-kernel, lujialin4, chenridong

[-- Attachment #1: Type: text/plain, Size: 1312 bytes --]

On Wed, Jun 18, 2025 at 07:32:17AM +0000, Chen Ridong <chenridong@huaweicloud.com> wrote:
> From: Chen Ridong <chenridong@huawei.com>
> 
> An issue was found:

An obligatory reminder to move to freezer in the unifier hierarchy if
possible. Thanks for the fix though.

> 
> 	# cd /sys/fs/cgroup/freezer/
> 	# mkdir test
> 	# echo FROZEN > test/freezer.state
> 	# cat test/freezer.state
> 	FROZEN
> 	# sleep 1000 &
> 	[1] 863
> 	# echo 863 > test/cgroup.procs
> 	# cat test/freezer.state
> 	FREEZING
> 
> When tasks are migrated to a frozen cgroup, the freezer fails to
> immediately freeze the tasks, causing the cgroup to remain in the
> "FREEZING".
> 
> The freeze_task() function is called before clearing the CGROUP_FROZEN
> flag. This causes the freezing() check to incorrectly return false,
> preventing __freeze_task() from being invoked for the migrated task.
> 
> To fix this issue, clear the CGROUP_FROZEN state before calling
> freeze_task().
> 
> Fixes: f5d39b020809 ("freezer,sched: Rewrite core freezer logic")
> Reported-by: Zhong Jiawei <zhongjiawei1@huawei.com>
> Signed-off-by: Chen Ridong <chenridong@huawei.com>
> ---
>  kernel/cgroup/legacy_freezer.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)

Acked-by: Michal Koutný <mkoutny@suse.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [next] cgroup,freezer: fix incomplete freezing when attaching tasks
  2025-06-18  8:42 ` Michal Koutný
@ 2025-06-18  9:03   ` Chen Ridong
  0 siblings, 0 replies; 4+ messages in thread
From: Chen Ridong @ 2025-06-18  9:03 UTC (permalink / raw)
  To: Michal Koutný
  Cc: tj, hannes, rafael.j.wysocki, mingo, peterz, cgroups,
	linux-kernel, lujialin4, chenridong



On 2025/6/18 16:42, Michal Koutný wrote:
> On Wed, Jun 18, 2025 at 07:32:17AM +0000, Chen Ridong <chenridong@huaweicloud.com> wrote:
>> From: Chen Ridong <chenridong@huawei.com>
>>
>> An issue was found:
> 
> An obligatory reminder to move to freezer in the unifier hierarchy if
> possible. Thanks for the fix though.
> 
Thanks, we are trying to switch to cgroup v2. However some products are
still using cgroup v1.

Thank you for your review.

BR,
Ridong

>>
>> 	# cd /sys/fs/cgroup/freezer/
>> 	# mkdir test
>> 	# echo FROZEN > test/freezer.state
>> 	# cat test/freezer.state
>> 	FROZEN
>> 	# sleep 1000 &
>> 	[1] 863
>> 	# echo 863 > test/cgroup.procs
>> 	# cat test/freezer.state
>> 	FREEZING
>>
>> When tasks are migrated to a frozen cgroup, the freezer fails to
>> immediately freeze the tasks, causing the cgroup to remain in the
>> "FREEZING".
>>
>> The freeze_task() function is called before clearing the CGROUP_FROZEN
>> flag. This causes the freezing() check to incorrectly return false,
>> preventing __freeze_task() from being invoked for the migrated task.
>>
>> To fix this issue, clear the CGROUP_FROZEN state before calling
>> freeze_task().
>>
>> Fixes: f5d39b020809 ("freezer,sched: Rewrite core freezer logic")
>> Reported-by: Zhong Jiawei <zhongjiawei1@huawei.com>
>> Signed-off-by: Chen Ridong <chenridong@huawei.com>
>> ---
>>  kernel/cgroup/legacy_freezer.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> Acked-by: Michal Koutný <mkoutny@suse.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [next] cgroup,freezer: fix incomplete freezing when attaching tasks
  2025-06-18  7:32 [next] cgroup,freezer: fix incomplete freezing when attaching tasks Chen Ridong
  2025-06-18  8:42 ` Michal Koutný
@ 2025-06-18 19:45 ` Tejun Heo
  1 sibling, 0 replies; 4+ messages in thread
From: Tejun Heo @ 2025-06-18 19:45 UTC (permalink / raw)
  To: Chen Ridong
  Cc: hannes, mkoutny, rafael.j.wysocki, mingo, peterz, cgroups,
	linux-kernel, lujialin4, chenridong

On Wed, Jun 18, 2025 at 07:32:17AM +0000, Chen Ridong wrote:
> From: Chen Ridong <chenridong@huawei.com>
> 
> An issue was found:
> 
> 	# cd /sys/fs/cgroup/freezer/
> 	# mkdir test
> 	# echo FROZEN > test/freezer.state
> 	# cat test/freezer.state
> 	FROZEN
> 	# sleep 1000 &
> 	[1] 863
> 	# echo 863 > test/cgroup.procs
> 	# cat test/freezer.state
> 	FREEZING
> 
> When tasks are migrated to a frozen cgroup, the freezer fails to
> immediately freeze the tasks, causing the cgroup to remain in the
> "FREEZING".
> 
> The freeze_task() function is called before clearing the CGROUP_FROZEN
> flag. This causes the freezing() check to incorrectly return false,
> preventing __freeze_task() from being invoked for the migrated task.
> 
> To fix this issue, clear the CGROUP_FROZEN state before calling
> freeze_task().
> 
> Fixes: f5d39b020809 ("freezer,sched: Rewrite core freezer logic")
> Reported-by: Zhong Jiawei <zhongjiawei1@huawei.com>
> Signed-off-by: Chen Ridong <chenridong@huawei.com>

Applied to cgroup/for-6.16-fixes w/ stable cc'd.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-06-18 19:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-18  7:32 [next] cgroup,freezer: fix incomplete freezing when attaching tasks Chen Ridong
2025-06-18  8:42 ` Michal Koutný
2025-06-18  9:03   ` Chen Ridong
2025-06-18 19:45 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®