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  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzZ3Yf4fvM2bo0ES9_NzBgVdhXBkV-u4wbPGrSej+uB4Xw@mail.gmail.com>
Date:   Thu, 31 Oct 2019 10:52:13 -0700
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Toke Høiland-Jørgensen <toke@...hat.com>
Cc:     Daniel Borkmann <daniel@...earbox.net>,
        Alexei Starovoitov <ast@...nel.org>,
        Martin KaFai Lau <kafai@...com>,
        Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
        Jesper Dangaard Brouer <brouer@...hat.com>,
        David Miller <davem@...emloft.net>,
        Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>
Subject: Re: [PATCH bpf-next v4 4/5] libbpf: Add auto-pinning of maps when
 loading BPF objects

On Thu, Oct 31, 2019 at 10:37 AM Andrii Nakryiko
<andrii.nakryiko@...il.com> wrote:
>
> On Tue, Oct 29, 2019 at 12:39 PM Toke Høiland-Jørgensen <toke@...hat.com> wrote:
> >
> > From: Toke Høiland-Jørgensen <toke@...hat.com>
> >
> > This adds support to libbpf for setting map pinning information as part of
> > the BTF map declaration, to get automatic map pinning (and reuse) on load.
> > The pinning type currently only supports a single PIN_BY_NAME mode, where
> > each map will be pinned by its name in a path that can be overridden, but
> > defaults to /sys/fs/bpf.
> >
> > Since auto-pinning only does something if any maps actually have a
> > 'pinning' BTF attribute set, we default the new option to enabled, on the
> > assumption that seamless pinning is what most callers want.
> >
> > When a map has a pin_path set at load time, libbpf will compare the map
> > pinned at that location (if any), and if the attributes match, will re-use
> > that map instead of creating a new one. If no existing map is found, the
> > newly created map will instead be pinned at the location.
> >
> > Programs wanting to customise the pinning can override the pinning paths
> > using bpf_map__set_pin_path() before calling bpf_object__load() (including
> > setting it to NULL to disable pinning of a particular map).
> >
> > Signed-off-by: Toke Høiland-Jørgensen <toke@...hat.com>
> > ---
>
> Please fix unconditional pin_path setting, with that:
>
> Acked-by: Andrii Nakryiko <andriin@...com>
>
> >  tools/lib/bpf/bpf_helpers.h |    6 ++
> >  tools/lib/bpf/libbpf.c      |  144 +++++++++++++++++++++++++++++++++++++++++--
> >  tools/lib/bpf/libbpf.h      |   13 ++++
> >  3 files changed, 154 insertions(+), 9 deletions(-)
> >
> > diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h
> > index 2203595f38c3..0c7d28292898 100644
> > --- a/tools/lib/bpf/bpf_helpers.h
> > +++ b/tools/lib/bpf/bpf_helpers.h
> > @@ -38,4 +38,10 @@ struct bpf_map_def {
> >         unsigned int map_flags;
> >  };
> >
>
> [...]
>
> > @@ -1270,6 +1292,28 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
> >                         }
> >                         map->def.value_size = sz;
> >                         map->btf_value_type_id = t->type;
> > +               } else if (strcmp(name, "pinning") == 0) {
> > +                       __u32 val;
> > +                       int err;
> > +
> > +                       if (!get_map_field_int(map_name, obj->btf, def, m,
> > +                                              &val))
> > +                               return -EINVAL;
> > +                       pr_debug("map '%s': found pinning = %u.\n",
> > +                                map_name, val);
> > +
> > +                       if (val != LIBBPF_PIN_NONE &&
> > +                           val != LIBBPF_PIN_BY_NAME) {
> > +                               pr_warn("map '%s': invalid pinning value %u.\n",
> > +                                       map_name, val);
> > +                               return -EINVAL;
> > +                       }
> > +                       err = build_map_pin_path(map, pin_root_path);
>
> uhm... only if (val == LIBBPF_PIN_BY_NAME)?.. maybe extend tests with
> a mix if auto-pinned and never pinned map to catch issue like this?

I was wondering why your selftest didn't catch this, got puzzled for a
bit. It's because this code path will be executed only when map
defintion has __uint(pinning, LIBBPF_PIN_NONE), can you please add
that to selftest as well?

>
> > +                       if (err) {
> > +                               pr_warn("map '%s': couldn't build pin path.\n",
> > +                                       map_name);
> > +                               return err;
> > +                       }
> >                 } else {
> >                         if (strict) {
> >                                 pr_warn("map '%s': unknown field '%s'.\n",
> > @@ -1289,7 +1333,8 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
> >         return 0;
> >  }
> >
>
> [...]

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ