From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Yonghong Song <yhs@fb.com>
Cc: bpf <bpf@vger.kernel.org>, Networking <netdev@vger.kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH bpf-next v2 2/3] bpf: implement link_query callbacks in map element iterators
Date: Thu, 20 Aug 2020 23:33:30 -0700 [thread overview]
Message-ID: <CAEf4BzaqMO5YgDhSf2gmhbDsp8md5kfvyrUqOc_AyD_3jJBmeA@mail.gmail.com> (raw)
In-Reply-To: <20200820224918.483254-1-yhs@fb.com>
On Thu, Aug 20, 2020 at 3:50 PM Yonghong Song <yhs@fb.com> wrote:
>
> For bpf_map_elem and bpf_sk_local_storage bpf iterators,
> additional map_id should be shown for fdinfo and
> userspace query. For example, the following is for
> a bpf_map_elem iterator.
> $ cat /proc/1753/fdinfo/9
> pos: 0
> flags: 02000000
> mnt_id: 14
> link_type: iter
> link_id: 34
> prog_tag: 104be6d3fe45e6aa
> prog_id: 173
> target_name: bpf_map_elem
> map_id: 127
>
> Signed-off-by: Yonghong Song <yhs@fb.com>
> ---
> include/linux/bpf.h | 4 ++++
> kernel/bpf/map_iter.c | 15 +++++++++++++++
> net/core/bpf_sk_storage.c | 2 ++
> 3 files changed, 21 insertions(+)
>
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index 529e9b183eeb..30c144af894a 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -1256,6 +1256,10 @@ int bpf_iter_new_fd(struct bpf_link *link);
> bool bpf_link_is_iter(struct bpf_link *link);
> struct bpf_prog *bpf_iter_get_info(struct bpf_iter_meta *meta, bool in_stop);
> int bpf_iter_run_prog(struct bpf_prog *prog, void *ctx);
> +void bpf_iter_map_show_fdinfo(const struct bpf_iter_aux_info *aux,
> + struct seq_file *seq);
> +int bpf_iter_map_fill_link_info(const struct bpf_iter_aux_info *aux,
> + struct bpf_link_info *info);
>
> int bpf_percpu_hash_copy(struct bpf_map *map, void *key, void *value);
> int bpf_percpu_array_copy(struct bpf_map *map, void *key, void *value);
> diff --git a/kernel/bpf/map_iter.c b/kernel/bpf/map_iter.c
> index af86048e5afd..714e74556aa2 100644
> --- a/kernel/bpf/map_iter.c
> +++ b/kernel/bpf/map_iter.c
> @@ -149,6 +149,19 @@ static void bpf_iter_detach_map(struct bpf_iter_aux_info *aux)
> bpf_map_put_with_uref(aux->map);
> }
>
> +void bpf_iter_map_show_fdinfo(const struct bpf_iter_aux_info *aux,
> + struct seq_file *seq)
> +{
> + seq_printf(seq, "map_id:\t\t%u\n", aux->map->id);
nit: I think it's a bad idea to have two tabs here to align everything
visually, might make parsing unnecessarily harder
> +}
> +
> +int bpf_iter_map_fill_link_info(const struct bpf_iter_aux_info *aux,
> + struct bpf_link_info *info)
> +{
> + info->iter.map.map_id = aux->map->id;
> + return 0;
> +}
> +
> DEFINE_BPF_ITER_FUNC(bpf_map_elem, struct bpf_iter_meta *meta,
> struct bpf_map *map, void *key, void *value)
>
> @@ -156,6 +169,8 @@ static const struct bpf_iter_reg bpf_map_elem_reg_info = {
> .target = "bpf_map_elem",
> .attach_target = bpf_iter_attach_map,
> .detach_target = bpf_iter_detach_map,
> + .show_fdinfo = bpf_iter_map_show_fdinfo,
> + .fill_link_info = bpf_iter_map_fill_link_info,
> .ctx_arg_info_size = 2,
> .ctx_arg_info = {
> { offsetof(struct bpf_iter__bpf_map_elem, key),
> diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c
> index b988f48153a4..281200dc0a01 100644
> --- a/net/core/bpf_sk_storage.c
> +++ b/net/core/bpf_sk_storage.c
> @@ -1437,6 +1437,8 @@ static struct bpf_iter_reg bpf_sk_storage_map_reg_info = {
> .target = "bpf_sk_storage_map",
> .attach_target = bpf_iter_attach_map,
> .detach_target = bpf_iter_detach_map,
> + .show_fdinfo = bpf_iter_map_show_fdinfo,
> + .fill_link_info = bpf_iter_map_fill_link_info,
> .ctx_arg_info_size = 2,
> .ctx_arg_info = {
> { offsetof(struct bpf_iter__bpf_sk_storage_map, sk),
> --
> 2.24.1
>
next prev parent reply other threads:[~2020-08-21 6:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-20 22:49 [PATCH bpf-next v2 0/3] bpf: implement link_query for bpf iterators Yonghong Song
2020-08-20 22:49 ` [PATCH bpf-next v2 1/3] " Yonghong Song
2020-08-21 6:31 ` Andrii Nakryiko
2020-08-21 6:42 ` Yonghong Song
2020-08-21 16:44 ` Andrii Nakryiko
2020-08-21 17:46 ` Yonghong Song
2020-08-20 22:49 ` [PATCH bpf-next v2 2/3] bpf: implement link_query callbacks in map element iterators Yonghong Song
2020-08-21 6:33 ` Andrii Nakryiko [this message]
2020-08-21 6:44 ` Yonghong Song
2020-08-20 22:49 ` [PATCH bpf-next v2 3/3] bpftool: implement link_query for bpf iterators Yonghong Song
2020-08-21 6:35 ` Andrii Nakryiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAEf4BzaqMO5YgDhSf2gmhbDsp8md5kfvyrUqOc_AyD_3jJBmeA@mail.gmail.com \
--to=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).