bpf: Introduce task open coded iterator kfuncs
authorChuyi Zhou <zhouchuyi@bytedance.com>
Wed, 18 Oct 2023 06:17:41 +0000 (14:17 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 20 Oct 2023 00:02:46 +0000 (17:02 -0700)
commitc68a78ffe2cb4207f64fd0f4262818c728c67be0
tree6a95dc7b2480bb918ba7c3e0eaa96da6ad67c18f
parent9c66dc94b62aef23300f05f63404afb8990920b4
bpf: Introduce task open coded iterator kfuncs

This patch adds kfuncs bpf_iter_task_{new,next,destroy} which allow
creation and manipulation of struct bpf_iter_task in open-coded iterator
style. BPF programs can use these kfuncs or through bpf_for_each macro to
iterate all processes in the system.

The API design keep consistent with SEC("iter/task"). bpf_iter_task_new()
accepts a specific task and iterating type which allows:

1. iterating all process in the system (BPF_TASK_ITER_ALL_PROCS)

2. iterating all threads in the system (BPF_TASK_ITER_ALL_THREADS)

3. iterating all threads of a specific task (BPF_TASK_ITER_PROC_THREADS)

Signed-off-by: Chuyi Zhou <zhouchuyi@bytedance.com>
Link: https://lore.kernel.org/r/20231018061746.111364-4-zhouchuyi@bytedance.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/helpers.c
kernel/bpf/task_iter.c
tools/testing/selftests/bpf/bpf_experimental.h