From: Quentin Monnet <quentin@isovalent.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Dave Marchevsky <davemarchevsky@fb.com>,
bpf <bpf@vger.kernel.org>,
"linux-perf-use." <linux-perf-users@vger.kernel.org>,
Song Liu <songliubraving@fb.com>,
Andrii Nakryiko <andrii@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>
Subject: Re: [PATCH v2 bpf-next 2/4] bpftool: use bpf_obj_get_info_by_fd directly
Date: Wed, 20 Oct 2021 23:15:49 +0100 [thread overview]
Message-ID: <CACdoK4LnHvpB2idD33R_gC3cn4C6Fw8W5zuikQu8OQqwXQJQGA@mail.gmail.com> (raw)
In-Reply-To: <CAEf4BzZk=fO8YNR9VQYUodSATp76XpRD6xd+pXMF90KummFwqQ@mail.gmail.com>
On Wed, 20 Oct 2021 at 18:37, Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
>
> On Mon, Oct 11, 2021 at 1:20 AM Dave Marchevsky <davemarchevsky@fb.com> wrote:
> >
> > To prepare for impending deprecation of libbpf's
> > bpf_program__get_prog_info_linear, migrate uses of this function to use
> > bpf_obj_get_info_by_fd.
> >
> > Since the profile_target_name and dump_prog_id_as_func_ptr helpers were
> > only looking at the first func_info, avoid grabbing the rest to save a
> > malloc. For do_dump, add a more full-featured helper, but avoid
> > free/realloc of buffer when possible for multi-prog dumps.
> >
> > Signed-off-by: Dave Marchevsky <davemarchevsky@fb.com>
> > ---
> > tools/bpf/bpftool/btf_dumper.c | 40 +++++----
> > tools/bpf/bpftool/prog.c | 154 +++++++++++++++++++++++++--------
> > 2 files changed, 144 insertions(+), 50 deletions(-)
> >
> > diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c
> > index 9c25286a5c73..0f85704628bf 100644
> > --- a/tools/bpf/bpftool/btf_dumper.c
> > +++ b/tools/bpf/bpftool/btf_dumper.c
> > @@ -32,14 +32,16 @@ static int dump_prog_id_as_func_ptr(const struct btf_dumper *d,
> > const struct btf_type *func_proto,
> > __u32 prog_id)
> > {
> > - struct bpf_prog_info_linear *prog_info = NULL;
> > const struct btf_type *func_type;
> > + int prog_fd = -1, func_sig_len;
> > + struct bpf_prog_info info = {};
> > + __u32 info_len = sizeof(info);
> > const char *prog_name = NULL;
> > - struct bpf_func_info *finfo;
> > struct btf *prog_btf = NULL;
> > - struct bpf_prog_info *info;
> > - int prog_fd, func_sig_len;
> > + struct bpf_func_info finfo;
> > + __u32 finfo_rec_size;
> > char prog_str[1024];
> > + int err;
> >
> > /* Get the ptr's func_proto */
> > func_sig_len = btf_dump_func(d->btf, prog_str, func_proto, NULL, 0,
> > @@ -55,22 +57,27 @@ static int dump_prog_id_as_func_ptr(const struct btf_dumper *d,
> > if (prog_fd == -1)
>
> please change this to (prog_fd < 0), see [0] for why
>
> we should check all the other places in bpftool to see if there are
> any patterns like this that would break on libbpf 1.0 (cc Quentin as
> well)
>
> [0] https://github.com/libbpf/libbpf/wiki/Libbpf-1.0-migration-guide#direct-error-code-returning-libbpf_strict_direct_errs
Hi! Looking at bpftool's code (looking for "-1"), I could find only
two occurrences of that pattern, one in btf_dumper.c as noted above,
and another one in struct_ops.c:
fd = bpf_map_get_fd_by_id(id);
if (fd == -1) {
[...]
}
Dave, are you willing to address it as well? I can send a patch later
this week otherwise.
Thanks,
Quentin
next prev parent reply other threads:[~2021-10-20 22:16 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-11 8:20 [PATCH v2 bpf-next 0/4] libbpf: deprecate bpf_program__get_prog_info_linear Dave Marchevsky
2021-10-11 8:20 ` [PATCH v2 bpf-next 1/4] libbpf: migrate internal use of bpf_program__get_prog_info_linear Dave Marchevsky
2021-10-20 17:36 ` Andrii Nakryiko
2021-10-11 8:20 ` [PATCH v2 bpf-next 2/4] bpftool: use bpf_obj_get_info_by_fd directly Dave Marchevsky
2021-10-20 17:37 ` Andrii Nakryiko
2021-10-20 22:15 ` Quentin Monnet [this message]
2021-10-11 8:20 ` [PATCH v2 bpf-next 3/4] perf: pull in bpf_program__get_prog_info_linear Dave Marchevsky
2021-10-20 17:37 ` Andrii Nakryiko
[not found] ` <5080FF1F-8E7A-4AF7-AD7E-7349E58CFEDB@fb.com>
2021-10-31 17:13 ` Arnaldo Carvalho de Melo
2021-10-11 8:20 ` [PATCH v2 bpf-next 4/4] libbpf: deprecate bpf_program__get_prog_info_linear Dave Marchevsky
2021-10-20 17:37 ` Andrii Nakryiko
2021-10-20 21:01 ` Toke Høiland-Jørgensen
[not found] ` <d3de589a-21f3-7a0d-59de-126d3c70fba1@fb.com>
2021-10-22 19:26 ` 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=CACdoK4LnHvpB2idD33R_gC3cn4C6Fw8W5zuikQu8OQqwXQJQGA@mail.gmail.com \
--to=quentin@isovalent.com \
--cc=acme@kernel.org \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davemarchevsky@fb.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=songliubraving@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).