[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzZA3_eXuUQtUCUF6hMk5winEYgsUeT1HoJCFnz9REkjZQ@mail.gmail.com>
Date: Wed, 8 Jul 2020 14:55:50 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Alexei Starovoitov <alexei.starovoitov@...il.com>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>,
"David S. Miller" <davem@...emloft.net>,
Daniel Borkmann <daniel@...earbox.net>,
"Eric W. Biederman" <ebiederm@...ssion.com>,
Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
Kernel Team <kernel-team@...com>
Subject: Re: [PATCH bpf-next 2/3] bpf: Add BPF program and map iterators as
built-in BPF programs.
On Thu, Jul 2, 2020 at 1:04 PM Alexei Starovoitov
<alexei.starovoitov@...il.com> wrote:
>
> From: Alexei Starovoitov <ast@...nel.org>
>
> The program and map iterators work similar to seq_file-s.
> Once the program is pinned in bpffs it can be read with "cat" tool
> to print human readable output. In this case about BPF programs and maps.
> For example:
> $ cat /sys/fs/bpf/progs
> id name pages attached
> 5 dump_bpf_map 1 bpf_iter_bpf_map
> 6 dump_bpf_prog 1 bpf_iter_bpf_prog
> $ cat /sys/fs/bpf/maps
> id name pages
> 3 iterator.rodata 2
>
> To avoid kernel build dependency on clang 10 separate bpf skeleton generation
> into manual "make" step and instead check-in generated .skel.h into git.
>
> Signed-off-by: Alexei Starovoitov <ast@...nel.org>
> ---
> kernel/bpf/preload/iterators/.gitignore | 2 +
> kernel/bpf/preload/iterators/Makefile | 57 +++
> kernel/bpf/preload/iterators/README | 4 +
> kernel/bpf/preload/iterators/iterators.bpf.c | 81 ++++
> kernel/bpf/preload/iterators/iterators.skel.h | 359 ++++++++++++++++++
> 5 files changed, 503 insertions(+)
> create mode 100644 kernel/bpf/preload/iterators/.gitignore
> create mode 100644 kernel/bpf/preload/iterators/Makefile
> create mode 100644 kernel/bpf/preload/iterators/README
> create mode 100644 kernel/bpf/preload/iterators/iterators.bpf.c
> create mode 100644 kernel/bpf/preload/iterators/iterators.skel.h
>
[...]
> +struct seq_file;
> +struct bpf_iter_meta {
> + struct seq_file *seq;
> + __u64 session_id;
> + __u64 seq_num;
> +} __attribute__((preserve_access_index));
> +
> +struct bpf_map_memory {
> + __u32 pages;
> +};
forgot __attribute__((preserve_access_index)) here?
> +struct bpf_map {
> + __u32 id;
> + struct bpf_map_memory memory;
> + char name[16];
> +} __attribute__((preserve_access_index));
> +
[...]
> +SEC("iter/bpf_map")
> +int dump_bpf_map(struct bpf_iter__bpf_map *ctx)
> +{
> + struct seq_file *seq = ctx->meta->seq;
> + __u64 seq_num = ctx->meta->seq_num;
> + struct bpf_map *map = ctx->map;
> +
> + if (!map)
> + return 0;
> +
> + if (seq_num == 0)
> + BPF_SEQ_PRINTF(seq, " id name pages\n");
> +
> + BPF_SEQ_PRINTF(seq, "%4u%16s%6d\n", map->id, map->name, map->memory.pages);
Here and below, please use %-16s for left-aligned strings for map name
and prog name.
> + return 0;
> +}
> +
> +SEC("iter/bpf_prog")
> +int dump_bpf_prog(struct bpf_iter__bpf_prog *ctx)
> +{
> + struct seq_file *seq = ctx->meta->seq;
> + __u64 seq_num = ctx->meta->seq_num;
> + struct bpf_prog *prog = ctx->prog;
> + struct bpf_prog_aux *aux;
> +
> + if (!prog)
> + return 0;
> +
> + aux = prog->aux;
> + if (seq_num == 0)
> + BPF_SEQ_PRINTF(seq, " id name pages attached\n");
> +
> + BPF_SEQ_PRINTF(seq, "%4u%16s%6d %s %s\n", aux->id, aux->name, prog->pages,
> + aux->attach_func_name, aux->linked_prog->aux->name);
> + return 0;
> +}
> +char LICENSE[] SEC("license") = "GPL";
[...]
Powered by blists - more mailing lists