Skip to content

Commit 3c5864b

Browse files
kchuyizhouMartin KaFai Lau
authored andcommitted
selftests/bpf: get trusted cgrp from bpf_iter__cgroup directly
Commit f49843a (selftests/bpf: Add tests for css_task iter combining with cgroup iter) added a test which demonstrates how css_task iter can be combined with cgroup iter. That test used bpf_cgroup_from_id() to convert bpf_iter__cgroup->cgroup to a trusted ptr which is pointless now, since with the previous fix, we can get a trusted cgroup directly from bpf_iter__cgroup. Signed-off-by: Chuyi Zhou <zhouchuyi@bytedance.com> Acked-by: Yonghong Song <yonghong.song@linux.dev> Link: https://lore.kernel.org/r/20231107132204.912120-3-zhouchuyi@bytedance.com Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
1 parent 0de4f50 commit 3c5864b

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,9 @@ SEC("?iter/cgroup")
5656
int cgroup_id_printer(struct bpf_iter__cgroup *ctx)
5757
{
5858
struct seq_file *seq = ctx->meta->seq;
59-
struct cgroup *cgrp, *acquired;
59+
struct cgroup *cgrp = ctx->cgroup;
6060
struct cgroup_subsys_state *css;
6161
struct task_struct *task;
62-
u64 cgrp_id;
63-
64-
cgrp = ctx->cgroup;
6562

6663
/* epilogue */
6764
if (cgrp == NULL) {
@@ -73,20 +70,15 @@ int cgroup_id_printer(struct bpf_iter__cgroup *ctx)
7370
if (ctx->meta->seq_num == 0)
7471
BPF_SEQ_PRINTF(seq, "prologue\n");
7572

76-
cgrp_id = cgroup_id(cgrp);
77-
78-
BPF_SEQ_PRINTF(seq, "%8llu\n", cgrp_id);
73+
BPF_SEQ_PRINTF(seq, "%8llu\n", cgroup_id(cgrp));
7974

80-
acquired = bpf_cgroup_from_id(cgrp_id);
81-
if (!acquired)
82-
return 0;
83-
css = &acquired->self;
75+
css = &cgrp->self;
8476
css_task_cnt = 0;
8577
bpf_for_each(css_task, task, css, CSS_TASK_ITER_PROCS) {
8678
if (task->pid == target_pid)
8779
css_task_cnt++;
8880
}
89-
bpf_cgroup_release(acquired);
81+
9082
return 0;
9183
}
9284

0 commit comments

Comments
 (0)