diff options
author | Alexei Starovoitov <ast@kernel.org> | 2020-07-02 03:10:18 +0200 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2020-07-26 05:16:32 +0200 |
commit | a228a64fc1e4428e2b96dc68e9ad3c447095c9e7 (patch) | |
tree | 60f1dbabaaabc43cd02535c1ff0bbe6aeba481a5 /kernel/bpf/syscall.c | |
parent | bpf: Fix pos computation for bpf_iter seq_ops->start() (diff) | |
download | linux-a228a64fc1e4428e2b96dc68e9ad3c447095c9e7.tar.xz linux-a228a64fc1e4428e2b96dc68e9ad3c447095c9e7.zip |
bpf: Add bpf_prog iterator
It's mostly a copy paste of commit 6086d29def80 ("bpf: Add bpf_map iterator")
that is use to implement bpf_seq_file opreations to traverse all bpf programs.
v1->v2: Tweak to use build time btf_id
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'kernel/bpf/syscall.c')
-rw-r--r-- | kernel/bpf/syscall.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index d07417d17712..ee290b1f2d9e 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -3044,6 +3044,25 @@ again: return map; } +struct bpf_prog *bpf_prog_get_curr_or_next(u32 *id) +{ + struct bpf_prog *prog; + + spin_lock_bh(&prog_idr_lock); +again: + prog = idr_get_next(&prog_idr, id); + if (prog) { + prog = bpf_prog_inc_not_zero(prog); + if (IS_ERR(prog)) { + (*id)++; + goto again; + } + } + spin_unlock_bh(&prog_idr_lock); + + return prog; +} + #define BPF_PROG_GET_FD_BY_ID_LAST_FIELD prog_id struct bpf_prog *bpf_prog_by_id(u32 id) |