From: Stanislav Fomichev <sdf@google.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
YiFei Zhu <zhuyifei1999@gmail.com>
Subject: Re: [PATCH bpf-next v4 4/5] bpftool: support dumping metadata
Date: Fri, 11 Sep 2020 08:56:19 -0700 [thread overview]
Message-ID: <CAKH8qBtiMh1evaQ-CQ83nESSS2UQLCM7avydoXvqY6aM+GHwDw@mail.gmail.com> (raw)
In-Reply-To: <CAEf4BzaWxnm_X=nZWn0tcq7bMnbL8ZFDuU=qzMNDh_aSAayXsA@mail.gmail.com>
On Thu, Sep 10, 2020 at 12:54 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Wed, Sep 9, 2020 at 11:25 AM Stanislav Fomichev <sdf@google.com> wrote:
> > diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
> > index f7923414a052..ca264dc22434 100644
> > --- a/tools/bpf/bpftool/prog.c
> > +++ b/tools/bpf/bpftool/prog.c
> > @@ -29,6 +29,9 @@
> > #include "main.h"
> > #include "xlated_dumper.h"
> >
> > +#define BPF_METADATA_PREFIX "bpf_metadata_"
> > +#define BPF_METADATA_PREFIX_LEN strlen(BPF_METADATA_PREFIX)
>
> this is a runtime check, why not (sizeof(BPF_METADATA_PREFIX) - 1) instead?
Make sense, will fix.
> > +static int bpf_prog_find_metadata(int prog_fd, int *map_id)
> > ...
> > +free_map_ids:
> > + saved_errno = errno;
> > + free(map_ids);
> > + errno = saved_errno;
>
> not clear why all this fussing with saving/restoring errno and then
> just returning 0 or -1? Just return -ENOMEM or -ENOENT as a result of
> this function?
Yeah, I just moved this function from it's original (libbpf) location as is.
I guess it makes sense to simplify the error handling now that
it's not in exported from libbpf.
> > + if (bpf_map_lookup_elem(map_fd, &key, value))
> > + goto out_free;
> > +
> > + err = btf__get_from_id(map_info.btf_id, &btf);
> > + if (err || !btf)
> > + goto out_free;
>
> if you make bpf_prog_find_metadata() to do this value lookup and pass
> &info, it would probably make bpf_prog_find_metadata a bit more
> usable? You'll just need to ensure that callers free allocated memory.
> Then show_prog_metadata() would take care of processing BTF info.
Sounds reasonable. I can maybe keep existing
bpf_prog_find_metadata (rename to bpf_prog_find_metadata_map_id?)
and add another wrapper that does that map lookup.
next prev parent reply other threads:[~2020-09-11 16:00 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-09 18:24 [PATCH bpf-next v4 0/5] Allow storage of flexible metadata information for eBPF programs Stanislav Fomichev
2020-09-09 18:24 ` [PATCH bpf-next v4 1/5] bpf: Mutex protect used_maps array and count Stanislav Fomichev
2020-09-10 19:23 ` Andrii Nakryiko
2020-09-09 18:24 ` [PATCH bpf-next v4 2/5] bpf: Add BPF_PROG_BIND_MAP syscall Stanislav Fomichev
2020-09-10 19:29 ` Andrii Nakryiko
2020-09-09 18:24 ` [PATCH bpf-next v4 3/5] libbpf: Add BPF_PROG_BIND_MAP syscall and use it on .metadata section Stanislav Fomichev
2020-09-10 19:40 ` Andrii Nakryiko
2020-09-11 15:49 ` Stanislav Fomichev
2020-09-09 18:24 ` [PATCH bpf-next v4 4/5] bpftool: support dumping metadata Stanislav Fomichev
2020-09-10 19:54 ` Andrii Nakryiko
2020-09-11 15:56 ` Stanislav Fomichev [this message]
2020-09-09 18:24 ` [PATCH bpf-next v4 5/5] selftests/bpf: Test load and dump metadata with btftool and skel Stanislav Fomichev
2020-09-10 19:59 ` Andrii Nakryiko
2020-09-11 15:57 ` Stanislav Fomichev
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=CAKH8qBtiMh1evaQ-CQ83nESSS2UQLCM7avydoXvqY6aM+GHwDw@mail.gmail.com \
--to=sdf@google.com \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=zhuyifei1999@gmail.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).