Skip to content

Commit 6680c16

Browse files
committed
selftests/cgroup: Don't require synchronous populated update on task exit
test_cgcore_populated (test_core) and test_cgkill_{simple,tree,forkbomb} (test_kill) check cgroup.events "populated 0" immediately after reaping child tasks with waitpid(). This used to work because cgroup_task_exit() in do_exit() unlinked tasks from css_sets before exit_notify() woke up waitpid(). d245698 ("cgroup: Defer task cgroup unlink until after the task is done switching out") moved the unlink to cgroup_task_dead() in finish_task_switch(), which runs after exit_notify(). The populated counter is now decremented after the parent's waitpid() can return, so there is no longer a synchronous ordering guarantee. On PREEMPT_RT, where cgroup_task_dead() is further deferred through lazy irq_work, the race window is even larger. The synchronous populated transition was never part of the cgroup interface contract - it was an implementation artifact. Use cg_read_strcmp_wait() which retries for up to 1 second, matching what these tests actually need to verify: that the cgroup eventually becomes unpopulated after all tasks exit. Fixes: d245698 ("cgroup: Defer task cgroup unlink until after the task is done switching out") Reported-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Tejun Heo <[email protected]> Tested-by: Sebastian Andrzej Siewior <[email protected]> Cc: Christian Brauner <[email protected]> Cc: [email protected]
1 parent 1b164b8 commit 6680c16

4 files changed

Lines changed: 23 additions & 4 deletions

File tree

tools/testing/selftests/cgroup/lib/cgroup_util.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,21 @@ int cg_read_strcmp(const char *cgroup, const char *control,
123123
return ret;
124124
}
125125

126+
int cg_read_strcmp_wait(const char *cgroup, const char *control,
127+
const char *expected)
128+
{
129+
int i, ret;
130+
131+
for (i = 0; i < 100; i++) {
132+
ret = cg_read_strcmp(cgroup, control, expected);
133+
if (!ret)
134+
return ret;
135+
usleep(10000);
136+
}
137+
138+
return ret;
139+
}
140+
126141
int cg_read_strstr(const char *cgroup, const char *control, const char *needle)
127142
{
128143
char buf[PAGE_SIZE];

tools/testing/selftests/cgroup/lib/include/cgroup_util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ extern int cg_read(const char *cgroup, const char *control,
6161
char *buf, size_t len);
6262
extern int cg_read_strcmp(const char *cgroup, const char *control,
6363
const char *expected);
64+
extern int cg_read_strcmp_wait(const char *cgroup, const char *control,
65+
const char *expected);
6466
extern int cg_read_strstr(const char *cgroup, const char *control,
6567
const char *needle);
6668
extern long cg_read_long(const char *cgroup, const char *control);

tools/testing/selftests/cgroup/test_core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ static int test_cgcore_populated(const char *root)
233233
if (err)
234234
goto cleanup;
235235

236-
if (cg_read_strcmp(cg_test_d, "cgroup.events", "populated 0\n"))
236+
if (cg_read_strcmp_wait(cg_test_d, "cgroup.events",
237+
"populated 0\n"))
237238
goto cleanup;
238239

239240
/* Remove cgroup. */

tools/testing/selftests/cgroup/test_kill.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static int test_cgkill_simple(const char *root)
8686
wait_for_pid(pids[i]);
8787

8888
if (ret == KSFT_PASS &&
89-
cg_read_strcmp(cgroup, "cgroup.events", "populated 0\n"))
89+
cg_read_strcmp_wait(cgroup, "cgroup.events", "populated 0\n"))
9090
ret = KSFT_FAIL;
9191

9292
if (cgroup)
@@ -190,7 +190,8 @@ static int test_cgkill_tree(const char *root)
190190
wait_for_pid(pids[i]);
191191

192192
if (ret == KSFT_PASS &&
193-
cg_read_strcmp(cgroup[0], "cgroup.events", "populated 0\n"))
193+
cg_read_strcmp_wait(cgroup[0], "cgroup.events",
194+
"populated 0\n"))
194195
ret = KSFT_FAIL;
195196

196197
for (i = 9; i >= 0 && cgroup[i]; i--) {
@@ -251,7 +252,7 @@ static int test_cgkill_forkbomb(const char *root)
251252
wait_for_pid(pid);
252253

253254
if (ret == KSFT_PASS &&
254-
cg_read_strcmp(cgroup, "cgroup.events", "populated 0\n"))
255+
cg_read_strcmp_wait(cgroup, "cgroup.events", "populated 0\n"))
255256
ret = KSFT_FAIL;
256257

257258
if (cgroup)

0 commit comments

Comments
 (0)