Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Chuyi Zhou and committed by
Martin KaFai Lau
3c5864ba 0de4f50d

+4 -12
+4 -12
tools/testing/selftests/bpf/progs/iters_css_task.c
··· 56 56 int cgroup_id_printer(struct bpf_iter__cgroup *ctx) 57 57 { 58 58 struct seq_file *seq = ctx->meta->seq; 59 - struct cgroup *cgrp, *acquired; 59 + struct cgroup *cgrp = ctx->cgroup; 60 60 struct cgroup_subsys_state *css; 61 61 struct task_struct *task; 62 - u64 cgrp_id; 63 - 64 - cgrp = ctx->cgroup; 65 62 66 63 /* epilogue */ 67 64 if (cgrp == NULL) { ··· 70 73 if (ctx->meta->seq_num == 0) 71 74 BPF_SEQ_PRINTF(seq, "prologue\n"); 72 75 73 - cgrp_id = cgroup_id(cgrp); 76 + BPF_SEQ_PRINTF(seq, "%8llu\n", cgroup_id(cgrp)); 74 77 75 - BPF_SEQ_PRINTF(seq, "%8llu\n", cgrp_id); 76 - 77 - acquired = bpf_cgroup_from_id(cgrp_id); 78 - if (!acquired) 79 - return 0; 80 - css = &acquired->self; 78 + css = &cgrp->self; 81 79 css_task_cnt = 0; 82 80 bpf_for_each(css_task, task, css, CSS_TASK_ITER_PROCS) { 83 81 if (task->pid == target_pid) 84 82 css_task_cnt++; 85 83 } 86 - bpf_cgroup_release(acquired); 84 + 87 85 return 0; 88 86 } 89 87