All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hangbin Liu <liuhangbin@gmail.com>
To: Quentin Monnet <quentin@isovalent.com>
Cc: bpf <bpf@vger.kernel.org>, "Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Jesper Dangaard Brouer" <jbrouer@redhat.com>,
	"Yauheni Kaliuta" <ykaliuta@redhat.com>,
	"Toke Høiland-Jørgensen" <toke@redhat.com>
Subject: Re: How about adding a name for bpftool self created maps?
Date: Thu, 4 Aug 2022 14:30:24 +0800	[thread overview]
Message-ID: <YutngHf+k4BGjkxf@Laptop-X1> (raw)
In-Reply-To: <CACdoK4JrrVoMjvwQusdpYOO5gDqZDKky2QZqyb08p+2R1186Gw@mail.gmail.com>

On Tue, Jun 21, 2022 at 10:28:27PM +0100, Quentin Monnet wrote:
> Hi Hangbin,
> 
> No plan currently. Adding names has been suggested before, but it's
> not compatible with some older kernels that don't support map names
> [0]. Maybe one solution would be to probe the kernel for map name
> support, and to add a name if supported.

Hi Quentin,

I looked into this issue this week. And I have some questions.
Can we just use the probe_kern_prog_name() function directly? e.g.

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index e89cc9c885b3..f7d1580cd54e 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -4476,7 +4476,10 @@ 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);
+       if (probe_kern_prog_name() > 0)
+               map = bpf_map_create(BPF_MAP_TYPE_ARRAY, "global_data", sizeof(int), 32, 1, NULL);
+       else
+               map = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, sizeof(int), 32, 1, NULL);
        if (map < 0) {
                ret = -errno;
                cp = libbpf_strerror_r(ret, errmsg, sizeof(errmsg));

I know the map name and prog name supports are not in the same patch. But they are
added to kernel in one patch series. I doubt any one will backport them separately.

And I also have a question about function probe_kern_prog_name(). I only
saw it created a prog with name "test". But I didn't find the function check
if the prog are really has name "test". If a old kernel doesn't support prog
name, I think it will just ignore the name field. No?

Another way I think we can use to probe if kernel supports map name is try
to attach a kprobe/bpf_obj_name_cpy. If attach success, the kernel should support
the prog/map name. WDYT?

Thanks
Hangbin

  parent reply	other threads:[~2022-08-04  6:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-21  2:09 How about adding a name for bpftool self created maps? Hangbin Liu
2022-06-21 21:28 ` Quentin Monnet
2022-06-22 10:15   ` Hangbin Liu
2022-08-04  6:30   ` Hangbin Liu [this message]
2022-08-04 10:01     ` Quentin Monnet
2022-08-05  9:10       ` Hangbin Liu

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=YutngHf+k4BGjkxf@Laptop-X1 \
    --to=liuhangbin@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jbrouer@redhat.com \
    --cc=quentin@isovalent.com \
    --cc=toke@redhat.com \
    --cc=ykaliuta@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.