From: Quentin Monnet <quentin@isovalent.com>
To: Hangbin Liu <liuhangbin@gmail.com>, netdev@vger.kernel.org
Cc: Andrii Nakryiko <andrii@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>,
bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next] libbpf: try to add a name for bpftool self-created maps
Date: Mon, 8 Aug 2022 14:45:03 +0100 [thread overview]
Message-ID: <9656fc7c-a5f6-8fa8-31c1-aeac07b765d8@isovalent.com> (raw)
In-Reply-To: <20220808093304.46291-1-liuhangbin@gmail.com>
On 08/08/2022 10:33, Hangbin Liu wrote:
> As discussed before[1], the bpftool self-created maps can appear in final
> map show output due to deferred removal in kernel. These maps don't have
> a name, which would make users confused about where it comes from.
>
> Adding names for these maps could make users know what these maps used for.
> It also could make some tests (like test_offload.py, which skip base maps
> without names as a workaround) filter them out.
>
> As Quentin suggested, add a small wrapper to fall back with no name
> if kernel is not supported.
>
> [1] https://lore.kernel.org/bpf/CAEf4BzY66WPKQbDe74AKZ6nFtZjq5e+G3Ji2egcVytB9R6_sGQ@mail.gmail.com/
>
> Suggested-by: Quentin Monnet <quentin@isovalent.com>
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> ---
> tools/lib/bpf/libbpf.c | 22 +++++++++++++++++++---
> 1 file changed, 19 insertions(+), 3 deletions(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 77e3797cf75a..db4f1a02b9e0 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -4423,6 +4423,22 @@ static int probe_kern_prog_name(void)
> return probe_fd(ret);
> }
>
> +static int probe_kern_map_name(enum bpf_map_type map_type,
> + const char *map_name, __u32 key_size,
> + __u32 value_size, __u32 max_entries,
> + const struct bpf_map_create_opts *opts)
> +{
> + int map;
> +
> + map = bpf_map_create(map_type, map_name, key_size, value_size, max_entries, opts);
> + if (map < 0 && errno == EINVAL) {
> + /* Retry without name */
> + map = bpf_map_create(map_type, NULL, key_size, value_size, max_entries, opts);
> + }
> +
> + return map;
> +}
> +
> static int probe_kern_global_data(void)
> {
> char *cp, errmsg[STRERR_BUFSIZE];
> @@ -4434,7 +4450,7 @@ static int probe_kern_global_data(void)
> };
> int ret, map, insn_cnt = ARRAY_SIZE(insns);
>
> - map = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, sizeof(int), 32, 1, NULL);
> + map = probe_kern_map_name(BPF_MAP_TYPE_ARRAY, "global_data", sizeof(int), 32, 1, NULL);
Thanks! Some comments on the naming: It reads strange here to "probe"
for the maps, given that we still need to compare the return value
below. Maybe use something else instead of "probe_kern_map_name()"?
Maybe "map_create_adjust_name()" or "map_create_compat()" (or something
else)?
Regarding "global_data": If the intent is to filter out these maps from
the output of bpftool for example, should we use a common prefix for the
three of them? "libbpf_" or "probe_"? Or even something shorter? I know
we're limited to 15 characters.
Quentin
next prev parent reply other threads:[~2022-08-08 13:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-08 9:33 [PATCH bpf-next] libbpf: try to add a name for bpftool self-created maps Hangbin Liu
2022-08-08 13:45 ` Quentin Monnet [this message]
2022-08-08 22:34 ` Andrii Nakryiko
2022-08-08 22:33 ` 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=9656fc7c-a5f6-8fa8-31c1-aeac07b765d8@isovalent.com \
--to=quentin@isovalent.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=liuhangbin@gmail.com \
--cc=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=sdf@google.com \
--cc=song@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