Skip to content

Commit d8234d4

Browse files
kchuyizhouAlexei Starovoitov
authored andcommitted
selftests/bpf: Add test for using css_task iter in sleepable progs
This Patch add a test to prove css_task iter can be used in normal sleepable progs. Signed-off-by: Chuyi Zhou <zhouchuyi@bytedance.com> Acked-by: Yonghong Song <yonghong.song@linux.dev> Link: https://lore.kernel.org/r/20231031050438.93297-4-zhouchuyi@bytedance.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent f49843a commit d8234d4

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

tools/testing/selftests/bpf/prog_tests/iters.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ void test_iters(void)
294294
RUN_TESTS(iters_state_safety);
295295
RUN_TESTS(iters_looping);
296296
RUN_TESTS(iters);
297+
RUN_TESTS(iters_css_task);
297298

298299
if (env.has_testmod)
299300
RUN_TESTS(iters_testmod_seq);

tools/testing/selftests/bpf/progs/iters_css_task.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,22 @@ int cgroup_id_printer(struct bpf_iter__cgroup *ctx)
8989
bpf_cgroup_release(acquired);
9090
return 0;
9191
}
92+
93+
SEC("?fentry.s/" SYS_PREFIX "sys_getpgid")
94+
int BPF_PROG(iter_css_task_for_each_sleep)
95+
{
96+
u64 cgrp_id = bpf_get_current_cgroup_id();
97+
struct cgroup *cgrp = bpf_cgroup_from_id(cgrp_id);
98+
struct cgroup_subsys_state *css;
99+
struct task_struct *task;
100+
101+
if (cgrp == NULL)
102+
return 0;
103+
css = &cgrp->self;
104+
105+
bpf_for_each(css_task, task, css, CSS_TASK_ITER_PROCS) {
106+
107+
}
108+
bpf_cgroup_release(cgrp);
109+
return 0;
110+
}

0 commit comments

Comments
 (0)