[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAP0ea-s2QwQhKpu81b+n5Fcq7dscbwTxoFf2tpV926RXw3ca1g@mail.gmail.com>
Date: Thu, 16 Nov 2023 09:29:51 -0700
From: Mark Hasemeyer <markhas@...gle.com>
To: Tim Van Patten <timvp@...omium.org>
Cc: LKML <linux-kernel@...r.kernel.org>,
Tim Van Patten <timvp@...gle.com>,
Johannes Weiner <hannes@...xchg.org>,
Tejun Heo <tj@...nel.org>, Zefan Li <lizefan.x@...edance.com>,
cgroups@...r.kernel.org
Subject: Re: [PATCH] cgroup_freezer: cgroup_freezing: Check if not frozen
>
> From: Tim Van Patten <timvp@...gle.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@...gle.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@...omium.org>
Powered by blists - more mailing lists