lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 15 Jan 2020 05:54:11 +0000
From:   Martin Lau <kafai@...com>
To:     Andrii Nakryiko <andrii.nakryiko@...il.com>
CC:     bpf <bpf@...r.kernel.org>, Alexei Starovoitov <ast@...nel.org>,
        "Daniel Borkmann" <daniel@...earbox.net>,
        David Miller <davem@...emloft.net>,
        "Kernel Team" <Kernel-team@...com>,
        Networking <netdev@...r.kernel.org>,
        Paul Chaignon <paul.chaignon@...nge.com>
Subject: Re: [PATCH bpf-next 2/5] bpftool: Fix missing BTF output for json
 during map dump

On Tue, Jan 14, 2020 at 05:34:33PM -0800, Andrii Nakryiko wrote:
> On Tue, Jan 14, 2020 at 2:45 PM Martin KaFai Lau <kafai@...com> wrote:
> >
> > The btf availability check is only done for plain text output.
> > It causes the whole BTF output went missing when json_output
> > is used.
> >
> > This patch simplifies the logic a little by avoiding passing "int btf" to
> > map_dump().
> >
> > For plain text output, the btf_wtr is only created when the map has
> > BTF (i.e. info->btf_id != 0).  The nullness of "json_writer_t *wtr"
> > in map_dump() alone can decide if dumping BTF output is needed.
> > As long as wtr is not NULL, map_dump() will print out the BTF-described
> > data whenever a map has BTF available (i.e. info->btf_id != 0)
> > regardless of json or plain-text output.
> >
> > In do_dump(), the "int btf" is also renamed to "int do_plain_btf".
> >
> > Fixes: 99f9863a0c45 ("bpftool: Match maps by name")
> > Cc: Paul Chaignon <paul.chaignon@...nge.com>
> > Signed-off-by: Martin KaFai Lau <kafai@...com>
> > ---
> 
> just one nit below
> 
> Acked-by: Andrii Nakryiko <andriin@...com>
> 
> >  tools/bpf/bpftool/map.c | 42 ++++++++++++++++++++---------------------
> >  1 file changed, 20 insertions(+), 22 deletions(-)
> >
> > diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
> > index e00e9e19d6b7..45c1eda6512c 100644
> > --- a/tools/bpf/bpftool/map.c
> > +++ b/tools/bpf/bpftool/map.c
> > @@ -933,7 +933,7 @@ static int maps_have_btf(int *fds, int nb_fds)
> >
> >  static int
> >  map_dump(int fd, struct bpf_map_info *info, json_writer_t *wtr,
> > -        bool enable_btf, bool show_header)
> > +        bool show_header)
> >  {
> >         void *key, *value, *prev_key;
> >         unsigned int num_elems = 0;
> > @@ -950,18 +950,16 @@ map_dump(int fd, struct bpf_map_info *info, json_writer_t *wtr,
> >
> >         prev_key = NULL;
> >
> > -       if (enable_btf) {
> > -               err = btf__get_from_id(info->btf_id, &btf);
> > -               if (err || !btf) {
> > -                       /* enable_btf is true only if we've already checked
> > -                        * that all maps have BTF information.
> > -                        */
> > -                       p_err("failed to get btf");
> > -                       goto exit_free;
> > +       if (wtr) {
> > +               if (info->btf_id) {
> 
> combine into if (wtr && info->btf_id) and reduce nestedness?
There is other logic under the same "if (wtr)".
Thus, it is better to leave it as is.
and this indentation will be gone in patch 5.

> 
> 
> > +                       err = btf__get_from_id(info->btf_id, &btf);
> > +                       if (err || !btf) {
> > +                               err = err ? : -ESRCH;
> > +                               p_err("failed to get btf");
> > +                               goto exit_free;
> > +                       }
> 
> [...]

Powered by blists - more mailing lists