From: Waiman Long <longman@redhat.com>
To: Tao Cui <cui.tao@linux.dev>, Tejun Heo <tj@kernel.org>
Cc: "Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Shuah Khan" <shuah@kernel.org>,
cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH] selftests/cgroup: Fix intermittent test_cgfreezer_ptrace test failures
Date: Wed, 15 Jul 2026 00:17:51 -0400 [thread overview]
Message-ID: <5e074ad6-c844-4e03-a4f2-02fd709f90e6@redhat.com> (raw)
In-Reply-To: <2e5102e4-0732-41c2-a5be-bbff2f386e58@linux.dev>
On 7/14/26 9:24 PM, Tao Cui wrote:
>
> 在 2026/7/15 06:09, Tejun Heo 写道:
>> Hello, Waiman.
>>
>>> + usleep(1000);
>>> if (cg_check_frozen(cgroup, true))
>>> goto cleanup;
>> A fixed 1ms sleep only hides the race. On a loaded machine or a slow arch
>> (you mention ppc64) the refreeze can take longer than 1ms, and the test
>> reads the unfrozen state and fails anyway.
>>
>> The freezer test already has a way to wait for this properly.
>> cg_prepare_for_wait() sets up an inotify watch on cgroup.events and
>> cg_wait_for() blocks until it changes. cg_enter_and_wait_for_frozen() shows
>> the pattern: loop cg_wait_for() then cg_check_frozen(). The cgroup always
>> ends up frozen, so looping until cg_check_frozen() reports frozen is
>> reliable and doesn't depend on timing.
>>
>> Can you respin using that instead of usleep()?
>>
>> Also, temporaily -> temporarily, in both the changelog and the comment.
>>
> Hi Tejun, Waiman,
>
> I ran into a similar issue a while back and can add a data point on
> the reproducibility: when running the full cgroup selftest suite, a
> few cases -- test_cgfreezer_ptrace and test_cgfreezer_stopped -- fail
> intermittently (around 40-70% on VMs), yet each failing case passes
> reliably when run on its own. That points at state carried across
> tests rather than a per-test bug, which is also why a fixed sleep/retry
> is fragile.
>
> On the "unfrozen state" above, I traced where CGRP_FROZEN actually gets
> cleared. When the frozen tracee is woken by PTRACE_INTERRUPT,
> JOBCTL_TRAP_STOP takes priority over JOBCTL_TRAP_FREEZE in get_signal(),
> so the task enters ptrace_stop() instead of going back to
> do_freezer_trap(). With debug printk in cgroup_update_frozen_flag() and
> cgroup_leave_frozen(), the cg_test_ptrace trace shows:
>
> 0 -> 1 nr_frozen=1 task_count=1 /* initial freeze */
> 1 -> 0 nr_frozen=0 task_count=1 /* dec, task still in cgroup */
> 0 -> 1 nr_frozen=0 task_count=0 /* task left cgroup */
>
> The 1 -> 0 step (nr_frozen 1->0 while task_count is still 1) is
> cgroup_dec_frozen_cnt(), called from cgroup_leave_frozen(true) at the
> end of ptrace_stop() (signal.c:2479) when the tracee is woken by
> PTRACE_DETACH. That clears CGRP_FROZEN until the task loops back into
> do_freezer_trap() and re-enters the frozen state -- the transient
> unfrozen window the test hits.
>
> As a kernel-side attempt I changed cgroup_enter_frozen() so it no longer
> returns early when current->frozen is already true: css_set_lock is
> taken before the check and, if CGRP_FREEZE is still set,
> cgroup_update_frozen() is called to re-verify the cgroup frozen state
> when a frozen task is handed off to ptrace.
get_signal() => ptrace_do_notify() => ptrace_stop() is where I saw the
cgroup became unfrozen. Later cgroup_enter_frozen() is called to be
frozen again. I do my testing mostly on bare metal and I don't see
failure in x86, but I do see intermittent failures in arm64 and ppc64le.
Also the clearing and setting of the frozen flag and the reading of
frozen flag is from different processes running on different CPUs. I
suppose the PTRACE_DETACH operation is synchronous. That is why I
suspect it can be a racing issue where the frozen flag is seen to be set
in one CPU while the other CPU may still see it cleared. This kind of
racing issues are much more visible in archs with weak memory model.
Cheers,
Longman
next prev parent reply other threads:[~2026-07-15 4:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 18:31 Waiman Long
2026-07-14 22:09 ` Tejun Heo
2026-07-15 1:24 ` Tao Cui
2026-07-15 4:17 ` Waiman Long [this message]
2026-07-15 1:25 ` Waiman Long
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=5e074ad6-c844-4e03-a4f2-02fd709f90e6@redhat.com \
--to=longman@redhat.com \
--cc=cgroups@vger.kernel.org \
--cc=cui.tao@linux.dev \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mkoutny@suse.com \
--cc=shuah@kernel.org \
--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
Powered by JetHome