* [PATCH] selftests/cgroup: Fix intermittent test_cgfreezer_ptrace test failures
@ 2026-07-14 18:31 Waiman Long
2026-07-14 22:09 ` Tejun Heo
0 siblings, 1 reply; 2+ messages in thread
From: Waiman Long @ 2026-07-14 18:31 UTC (permalink / raw)
To: Tejun Heo, Johannes Weiner, Michal Koutný, Shuah Khan
Cc: cgroups, linux-kernel, linux-kselftest, Waiman Long
It is found that the test_cgfreezer_ptrace test of test_freezer can
intermittently fail on some architectures like arm64 and ppc64.
After further tracing of the mechanics of the test_cgfreezer_ptrace test,
it is found that the ptrace(PTRACE_DETACH) call temporaily unfreezes the
cgroup and then freezes it again afterward in the detaching process. The
reading of the frozen flag from cgroup.events is done from a different
process running maybe on a different CPU. As a result, racing is possible
and the intermediate unfrozen state can be read leading to occasional test
failures especially on architectures with a weak memory model like arm64.
Fix that by adding a short 1 ms delay before reading the frozen state
to ensure that the final frozen value will be read.
By running test_freezer 100 times in a loop, there were 28
test_cgfreezer_ptrace failures out of 100 on an arm64 test system before
the patch. After applying the patch, there was no test failure at all
in 100 runs of test_freezer.
Signed-off-by: Waiman Long <longman@redhat.com>
---
tools/testing/selftests/cgroup/test_freezer.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/tools/testing/selftests/cgroup/test_freezer.c b/tools/testing/selftests/cgroup/test_freezer.c
index 0569e93fa6b0..8e2cca74d212 100644
--- a/tools/testing/selftests/cgroup/test_freezer.c
+++ b/tools/testing/selftests/cgroup/test_freezer.c
@@ -625,6 +625,18 @@ static int test_cgfreezer_ptrace(const char *root)
if (ptrace(PTRACE_DETACH, pid, NULL, NULL))
goto cleanup;
+ /*
+ * The ptrace(PTRACE_DETACH) call will temporaily unfreeze the cgroup
+ * and then freeze it again afterward in the detaching process. The
+ * reading of the frozen flag from cgroup.events is done from a
+ * different process running maybe on a different CPU. As a result,
+ * racing is possible and the intermediate unfrozen state can be read
+ * leading to occasional test failure especially on architectures with
+ * a weak memory model like arm64. This intermittent test failure can
+ * be avoided by adding a 1ms short delay before reading the frozen
+ * state.
+ */
+ usleep(1000);
if (cg_check_frozen(cgroup, true))
goto cleanup;
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] selftests/cgroup: Fix intermittent test_cgfreezer_ptrace test failures
2026-07-14 18:31 [PATCH] selftests/cgroup: Fix intermittent test_cgfreezer_ptrace test failures Waiman Long
@ 2026-07-14 22:09 ` Tejun Heo
0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2026-07-14 22:09 UTC (permalink / raw)
To: Waiman Long
Cc: Johannes Weiner, Michal Koutný, Shuah Khan, cgroups,
linux-kernel, linux-kselftest
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.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-14 22:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-14 18:31 [PATCH] selftests/cgroup: Fix intermittent test_cgfreezer_ptrace test failures Waiman Long
2026-07-14 22:09 ` Tejun Heo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox