selftests/bpf: get trusted cgrp from bpf_iter__cgroup directly
Commit f49843afde (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>
This commit is contained in:
parent
0de4f50de2
commit
3c5864ba9c
@ -56,12 +56,9 @@ SEC("?iter/cgroup")
|
||||
int cgroup_id_printer(struct bpf_iter__cgroup *ctx)
|
||||
{
|
||||
struct seq_file *seq = ctx->meta->seq;
|
||||
struct cgroup *cgrp, *acquired;
|
||||
struct cgroup *cgrp = ctx->cgroup;
|
||||
struct cgroup_subsys_state *css;
|
||||
struct task_struct *task;
|
||||
u64 cgrp_id;
|
||||
|
||||
cgrp = ctx->cgroup;
|
||||
|
||||
/* epilogue */
|
||||
if (cgrp == NULL) {
|
||||
@ -73,20 +70,15 @@ int cgroup_id_printer(struct bpf_iter__cgroup *ctx)
|
||||
if (ctx->meta->seq_num == 0)
|
||||
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);
|
||||
if (!acquired)
|
||||
return 0;
|
||||
css = &acquired->self;
|
||||
css = &cgrp->self;
|
||||
css_task_cnt = 0;
|
||||
bpf_for_each(css_task, task, css, CSS_TASK_ITER_PROCS) {
|
||||
if (task->pid == target_pid)
|
||||
css_task_cnt++;
|
||||
}
|
||||
bpf_cgroup_release(acquired);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user