Commit 3c5864ba authored by Chuyi Zhou's avatar Chuyi Zhou Committed by Martin KaFai Lau

selftests/bpf: get trusted cgrp from bpf_iter__cgroup directly

Commit f49843af (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: default avatarChuyi Zhou <zhouchuyi@bytedance.com>
Acked-by: default avatarYonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20231107132204.912120-3-zhouchuyi@bytedance.comSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
parent 0de4f50d
...@@ -56,12 +56,9 @@ SEC("?iter/cgroup") ...@@ -56,12 +56,9 @@ SEC("?iter/cgroup")
int cgroup_id_printer(struct bpf_iter__cgroup *ctx) int cgroup_id_printer(struct bpf_iter__cgroup *ctx)
{ {
struct seq_file *seq = ctx->meta->seq; struct seq_file *seq = ctx->meta->seq;
struct cgroup *cgrp, *acquired; struct cgroup *cgrp = ctx->cgroup;
struct cgroup_subsys_state *css; struct cgroup_subsys_state *css;
struct task_struct *task; struct task_struct *task;
u64 cgrp_id;
cgrp = ctx->cgroup;
/* epilogue */ /* epilogue */
if (cgrp == NULL) { if (cgrp == NULL) {
...@@ -73,20 +70,15 @@ int cgroup_id_printer(struct bpf_iter__cgroup *ctx) ...@@ -73,20 +70,15 @@ int cgroup_id_printer(struct bpf_iter__cgroup *ctx)
if (ctx->meta->seq_num == 0) if (ctx->meta->seq_num == 0)
BPF_SEQ_PRINTF(seq, "prologue\n"); BPF_SEQ_PRINTF(seq, "prologue\n");
cgrp_id = cgroup_id(cgrp); BPF_SEQ_PRINTF(seq, "%8llu\n", cgroup_id(cgrp));
BPF_SEQ_PRINTF(seq, "%8llu\n", cgrp_id);
acquired = bpf_cgroup_from_id(cgrp_id); css = &cgrp->self;
if (!acquired)
return 0;
css = &acquired->self;
css_task_cnt = 0; css_task_cnt = 0;
bpf_for_each(css_task, task, css, CSS_TASK_ITER_PROCS) { bpf_for_each(css_task, task, css, CSS_TASK_ITER_PROCS) {
if (task->pid == target_pid) if (task->pid == target_pid)
css_task_cnt++; css_task_cnt++;
} }
bpf_cgroup_release(acquired);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment