All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cgroup_freezer: cgroup_freezing: Check if not frozen
@ 2023-11-15 16:20 Tim Van Patten
  2023-11-16 16:29 ` Mark Hasemeyer
  2023-11-19 15:05 ` Tejun Heo
  0 siblings, 2 replies; 6+ messages in thread
From: Tim Van Patten @ 2023-11-15 16:20 UTC (permalink / raw)
  To: LKML
  Cc: markhas, Tim Van Patten, Johannes Weiner, Tejun Heo, Zefan Li, cgroups

From: Tim Van Patten <timvp@google.com>

__thaw_task() was recently updated to warn if the task being thawed was
part of a freezer cgroup that is still currently freezing:

	void __thaw_task(struct task_struct *p)
	{
	...
		if (WARN_ON_ONCE(freezing(p)))
			goto unlock;

This has exposed a bug in cgroup1 freezing where when CGROUP_FROZEN is
asserted, the CGROUP_FREEZING bits are not also cleared at the same
time. Meaning, when a cgroup is marked FROZEN it continues to be marked
FREEZING as well. This causes the WARNING to trigger, because
cgroup_freezing() thinks the cgroup is still freezing.

There are two ways to fix this:

1. Whenever FROZEN is set, clear FREEZING for the cgroup and all
children cgroups.
2. Update cgroup_freezing() to also verify that FROZEN is not set.

This patch implements option (2), since it's smaller and more
straightforward.

Signed-off-by: Tim Van Patten <timvp@google.com>
---

 kernel/cgroup/legacy_freezer.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/kernel/cgroup/legacy_freezer.c b/kernel/cgroup/legacy_freezer.c
index 122dacb3a443..66d1708042a7 100644
--- a/kernel/cgroup/legacy_freezer.c
+++ b/kernel/cgroup/legacy_freezer.c
@@ -66,9 +66,15 @@ static struct freezer *parent_freezer(struct freezer *freezer)
 bool cgroup_freezing(struct task_struct *task)
 {
 	bool ret;
+	unsigned int state;
 
 	rcu_read_lock();
-	ret = task_freezer(task)->state & CGROUP_FREEZING;
+	/* Check if the cgroup is still FREEZING, but not FROZEN. The extra
+	 * !FROZEN check is required, because the FREEZING bit is not cleared
+	 * when the state FROZEN is reached.
+	 */
+	state = task_freezer(task)->state;
+	ret = (state & CGROUP_FREEZING) && !(state & CGROUP_FROZEN);
 	rcu_read_unlock();
 
 	return ret;
-- 
2.43.0.rc0.421.g78406f8d94-goog


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

* Re: [PATCH] cgroup_freezer: cgroup_freezing: Check if not frozen
  2023-11-15 16:20 [PATCH] cgroup_freezer: cgroup_freezing: Check if not frozen Tim Van Patten
@ 2023-11-16 16:29 ` Mark Hasemeyer
  2023-11-19 15:05 ` Tejun Heo
  1 sibling, 0 replies; 6+ messages in thread
From: Mark Hasemeyer @ 2023-11-16 16:29 UTC (permalink / raw)
  To: Tim Van Patten
  Cc: LKML, Tim Van Patten, Johannes Weiner, Tejun Heo, Zefan Li, cgroups

>
> From: Tim Van Patten <timvp@google.com>
>
> __thaw_task() was recently updated to warn if the task being thawed was
> part of a freezer cgroup that is still currently freezing:
>
>         void __thaw_task(struct task_struct *p)
>         {
>         ...
>                 if (WARN_ON_ONCE(freezing(p)))
>                         goto unlock;
>
> This has exposed a bug in cgroup1 freezing where when CGROUP_FROZEN is
> asserted, the CGROUP_FREEZING bits are not also cleared at the same
> time. Meaning, when a cgroup is marked FROZEN it continues to be marked
> FREEZING as well. This causes the WARNING to trigger, because
> cgroup_freezing() thinks the cgroup is still freezing.
>
> There are two ways to fix this:
>
> 1. Whenever FROZEN is set, clear FREEZING for the cgroup and all
> children cgroups.
> 2. Update cgroup_freezing() to also verify that FROZEN is not set.
>
> This patch implements option (2), since it's smaller and more
> straightforward.
>
> Signed-off-by: Tim Van Patten <timvp@google.com>
> ---
>
>  kernel/cgroup/legacy_freezer.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/cgroup/legacy_freezer.c b/kernel/cgroup/legacy_freezer.c
> index 122dacb3a443..66d1708042a7 100644
> --- a/kernel/cgroup/legacy_freezer.c
> +++ b/kernel/cgroup/legacy_freezer.c
> @@ -66,9 +66,15 @@ static struct freezer *parent_freezer(struct freezer *freezer)
>  bool cgroup_freezing(struct task_struct *task)
>  {
>         bool ret;
> +       unsigned int state;
>
>         rcu_read_lock();
> -       ret = task_freezer(task)->state & CGROUP_FREEZING;
> +       /* Check if the cgroup is still FREEZING, but not FROZEN. The extra
> +        * !FROZEN check is required, because the FREEZING bit is not cleared
> +        * when the state FROZEN is reached.
> +        */
> +       state = task_freezer(task)->state;
> +       ret = (state & CGROUP_FREEZING) && !(state & CGROUP_FROZEN);
>         rcu_read_unlock();
>
>         return ret;
> --
Tested-by: Mark Hasemeyer <markhas@chromium.org>

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

* Re: [PATCH] cgroup_freezer: cgroup_freezing: Check if not frozen
  2023-11-15 16:20 [PATCH] cgroup_freezer: cgroup_freezing: Check if not frozen Tim Van Patten
  2023-11-16 16:29 ` Mark Hasemeyer
@ 2023-11-19 15:05 ` Tejun Heo
  2023-11-27 18:19   ` Mark Hasemeyer
  1 sibling, 1 reply; 6+ messages in thread
From: Tejun Heo @ 2023-11-19 15:05 UTC (permalink / raw)
  To: Tim Van Patten
  Cc: LKML, markhas, Tim Van Patten, Johannes Weiner, Zefan Li, cgroups

On Wed, Nov 15, 2023 at 09:20:43AM -0700, Tim Van Patten wrote:
> From: Tim Van Patten <timvp@google.com>
> 
> __thaw_task() was recently updated to warn if the task being thawed was
> part of a freezer cgroup that is still currently freezing:
> 
> 	void __thaw_task(struct task_struct *p)
> 	{
> 	...
> 		if (WARN_ON_ONCE(freezing(p)))
> 			goto unlock;
> 
> This has exposed a bug in cgroup1 freezing where when CGROUP_FROZEN is
> asserted, the CGROUP_FREEZING bits are not also cleared at the same
> time. Meaning, when a cgroup is marked FROZEN it continues to be marked
> FREEZING as well. This causes the WARNING to trigger, because
> cgroup_freezing() thinks the cgroup is still freezing.
> 
> There are two ways to fix this:
> 
> 1. Whenever FROZEN is set, clear FREEZING for the cgroup and all
> children cgroups.
> 2. Update cgroup_freezing() to also verify that FROZEN is not set.
> 
> This patch implements option (2), since it's smaller and more
> straightforward.
> 
> Signed-off-by: Tim Van Patten <timvp@google.com>

Applied to cgroup/for-6.7-fixes.

Thanks.

-- 
tejun

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

* Re: [PATCH] cgroup_freezer: cgroup_freezing: Check if not frozen
  2023-11-19 15:05 ` Tejun Heo
@ 2023-11-27 18:19   ` Mark Hasemeyer
  2023-11-28 16:52     ` Tejun Heo
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Hasemeyer @ 2023-11-27 18:19 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Tim Van Patten, LKML, Tim Van Patten, Johannes Weiner, Zefan Li, cgroups

> Applied to cgroup/for-6.7-fixes.
>
> Thanks.
>
> --
> tejun

Thanks Tejun!
As this hasn't been merged to Linus's tree yet, do you think you could
Cc: stable@vger.kernel.org?

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

* Re: [PATCH] cgroup_freezer: cgroup_freezing: Check if not frozen
  2023-11-27 18:19   ` Mark Hasemeyer
@ 2023-11-28 16:52     ` Tejun Heo
  2023-11-28 17:32       ` Mark Hasemeyer
  0 siblings, 1 reply; 6+ messages in thread
From: Tejun Heo @ 2023-11-28 16:52 UTC (permalink / raw)
  To: Mark Hasemeyer
  Cc: Tim Van Patten, LKML, Tim Van Patten, Johannes Weiner, Zefan Li, cgroups

On Mon, Nov 27, 2023 at 11:19:52AM -0700, Mark Hasemeyer wrote:
> > Applied to cgroup/for-6.7-fixes.
> >
> > Thanks.
> >
> > --
> > tejun
> 
> Thanks Tejun!
> As this hasn't been merged to Linus's tree yet, do you think you could
> Cc: stable@vger.kernel.org?

Yeah, I can do that. That'd be for v6.1+ and fix f5d39b020809
("freezer,sched: Rewrite core freezer logic"), right?

Thanks.

-- 
tejun

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

* Re: [PATCH] cgroup_freezer: cgroup_freezing: Check if not frozen
  2023-11-28 16:52     ` Tejun Heo
@ 2023-11-28 17:32       ` Mark Hasemeyer
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Hasemeyer @ 2023-11-28 17:32 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Tim Van Patten, LKML, Tim Van Patten, Johannes Weiner, Zefan Li, cgroups

> Yeah, I can do that. That'd be for v6.1+ and fix f5d39b020809
> ("freezer,sched: Rewrite core freezer logic"), right?
>
> Thanks.
>
> --
> tejun

Correct. Thank you!

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

end of thread, other threads:[~2023-11-28 17:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-15 16:20 [PATCH] cgroup_freezer: cgroup_freezing: Check if not frozen Tim Van Patten
2023-11-16 16:29 ` Mark Hasemeyer
2023-11-19 15:05 ` Tejun Heo
2023-11-27 18:19   ` Mark Hasemeyer
2023-11-28 16:52     ` Tejun Heo
2023-11-28 17:32       ` Mark Hasemeyer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.