Skip to content

Commit

Permalink
selftests/bpf: Add test for using css_task iter in sleepable progs
Browse files Browse the repository at this point in the history
This Patch add a test to prove css_task iter can be used in normal
sleepable progs.

Signed-off-by: Chuyi Zhou <[email protected]>
Acked-by: Yonghong Song <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alexei Starovoitov <[email protected]>
  • Loading branch information
Chuyi Zhou authored and Alexei Starovoitov committed Nov 2, 2023
1 parent f49843a commit d8234d4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/testing/selftests/bpf/prog_tests/iters.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ void test_iters(void)
RUN_TESTS(iters_state_safety);
RUN_TESTS(iters_looping);
RUN_TESTS(iters);
RUN_TESTS(iters_css_task);

if (env.has_testmod)
RUN_TESTS(iters_testmod_seq);
Expand Down
19 changes: 19 additions & 0 deletions tools/testing/selftests/bpf/progs/iters_css_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,22 @@ int cgroup_id_printer(struct bpf_iter__cgroup *ctx)
bpf_cgroup_release(acquired);
return 0;
}

SEC("?fentry.s/" SYS_PREFIX "sys_getpgid")
int BPF_PROG(iter_css_task_for_each_sleep)
{
u64 cgrp_id = bpf_get_current_cgroup_id();
struct cgroup *cgrp = bpf_cgroup_from_id(cgrp_id);
struct cgroup_subsys_state *css;
struct task_struct *task;

if (cgrp == NULL)
return 0;
css = &cgrp->self;

bpf_for_each(css_task, task, css, CSS_TASK_ITER_PROCS) {

}
bpf_cgroup_release(cgrp);
return 0;
}

0 comments on commit d8234d4

Please sign in to comment.