From: Peter Zijlstra <peterz@infradead.org>
To: Chen Ridong <chenridong@huaweicloud.com>
Cc: timvp@google.com, Michal Koutn?? <mkoutny@suse.com>,
rafael@kernel.org, pavel@kernel.org, tj@kernel.org,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
lujialin4@huawei.com, chenridong@huawei.com
Subject: Re: [PATCH next] sched,freezer: prevent tasks from escaping being frozen
Date: Mon, 7 Jul 2025 12:10:19 +0200 [thread overview]
Message-ID: <20250707101019.GE1613200@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <bdc5a4d3-6942-4ba2-a13d-35f2e13c0b37@huaweicloud.com>
On Mon, Jul 07, 2025 at 12:02:47PM +0800, Chen Ridong wrote:
> >> And I'm not quite sure I understand this hunk either. If we bail out,
> >> current->__state is reset to TASK_RUNNING, so what's the problem?
> >
> > The issue occurs in this race scenario:
> >
> > echo FROZEN > freezer.state
> > freeze_cgroup()
> > freeze_task()
> > fake_signal_wake_up() // wakes task to freeze it
> >
> > In task context:
> > get_signal
> > try_to_freeze
> > __refrigerator
> > WRITE_ONCE(current->__state, TASK_FROZEN); // set TASK_FROZEN
> > // race: cgroup state updates to frozen
I suppose this is me not quite knowing how this cgroup freezer works;
how does it race? what code marks the task frozen?
> > freezing(current) now return false
> > // We bail out, the task is not frozen but it should be frozen.
> >
> > I hope this explanation clarifies the issue I encountered.
> >
>
> Hi, Peter, Tim
>
> I was looking at the WARN_ON_ONCE(freezing(p)) check in __thaw_task
> and started wondering: since we already have !frozen(p) check, is this
> warning still needed? If we can remove it, maybe reverting commit
> cff5f49d433f ("cgroup_freezer: cgroup_freezing: Check if not frozen")
> would be a better approach.
I suppose that is possible; modern sensibilities require we write that
function something like so:
void __thaw_task(struct task_struct *p)
{
guard(spinlock_irqsave)(&freezer_lock);
if (frozen(p) && !task_call_func(p, __restore_freezer_state, NULL))
wake_up_state(p, TASK_FROZEN);
}
next prev parent reply other threads:[~2025-07-07 10:10 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-03 13:34 [PATCH next] sched,freezer: prevent tasks from escaping being frozen Chen Ridong
2025-07-03 17:01 ` Michal Koutný
2025-07-04 3:02 ` Chen Ridong
2025-07-04 3:11 ` Chen Ridong
2025-07-04 7:57 ` Peter Zijlstra
2025-07-04 10:25 ` Chen Ridong
2025-07-07 4:02 ` Chen Ridong
2025-07-07 10:10 ` Peter Zijlstra [this message]
2025-07-07 11:32 ` Chen Ridong
2025-07-08 7:28 ` Peter Zijlstra
2025-07-08 15:35 ` Tim Van Patten
2025-07-10 15:44 ` Michal Koutný
2025-07-11 0:51 ` Chen Ridong
2025-07-07 16:38 ` Michal Koutný
2025-07-08 1:38 ` Chen Ridong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250707101019.GE1613200@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=chenridong@huawei.com \
--cc=chenridong@huaweicloud.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lujialin4@huawei.com \
--cc=mkoutny@suse.com \
--cc=pavel@kernel.org \
--cc=rafael@kernel.org \
--cc=timvp@google.com \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox