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] [day] [month] [year] [list]
Message-ID: <CAEf4BzYQZHNfUgYP+9iu-N7M=E-ywwV5pzo8=opbVkb60Ppqag@mail.gmail.com>
Date:   Fri, 8 Feb 2019 10:11:44 -0800
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Song Liu <songliubraving@...com>
Cc:     Andrii Nakryiko <andriin@...com>,
        Alexei Starovoitov <alexei.starovoitov@...il.com>,
        Yonghong Song <yhs@...com>, Alexei Starovoitov <ast@...com>,
        Martin Lau <kafai@...com>,
        "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
        Kernel Team <Kernel-team@...com>,
        "daniel@...earbox.net" <daniel@...earbox.net>
Subject: Re: [PATCH v3 bpf-next 4/4] tools/bpf: remove btf__get_strings
 superseded() by raw data API

On Fri, Feb 8, 2019 at 9:31 AM Song Liu <songliubraving@...com> wrote:
>
>
>
> > On Feb 7, 2019, at 6:55 PM, Andrii Nakryiko <andriin@...com> wrote:
> >
> > Now that we have btf__get_raw_data() it's trivial for tests to iterate
> > over all strings for testing purposes, which eliminates the need for
> > btf__get_strings() API.
> >
> > Signed-off-by: Andrii Nakryiko <andriin@...com>
> > ---
> > tools/lib/bpf/btf.c                    |  7 -----
> > tools/lib/bpf/btf.h                    |  2 --
> > tools/testing/selftests/bpf/test_btf.c | 39 +++++++++++++++++---------
> > 3 files changed, 26 insertions(+), 22 deletions(-)
> >
> > diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> > index c87cc3d71b9f..a986dc28f17d 100644
> > --- a/tools/lib/bpf/btf.c
> > +++ b/tools/lib/bpf/btf.c
> > @@ -447,13 +447,6 @@ const void *btf__get_raw_data(const struct btf *btf, __u32 *size)
> >       return btf->data;
> > }
> >
> > -void btf__get_strings(const struct btf *btf, const char **strings,
> > -                   __u32 *str_len)
> > -{
> > -     *strings = btf->strings;
> > -     *str_len = btf->hdr->str_len;
> > -}
> > -
> > const char *btf__name_by_offset(const struct btf *btf, __u32 offset)
> > {
> >       if (offset < btf->hdr->str_len)
> > diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
> > index ad9f648260c2..6179291f2cec 100644
> > --- a/tools/lib/bpf/btf.h
> > +++ b/tools/lib/bpf/btf.h
> > @@ -67,8 +67,6 @@ LIBBPF_API __s64 btf__resolve_size(const struct btf *btf, __u32 type_id);
> > LIBBPF_API int btf__resolve_type(const struct btf *btf, __u32 type_id);
> > LIBBPF_API int btf__fd(const struct btf *btf);
> > LIBBPF_API const void *btf__get_raw_data(const struct btf *btf, __u32 *size);
> > -LIBBPF_API void btf__get_strings(const struct btf *btf, const char **strings,
> > -                              __u32 *str_len);
>
> I guess we need to update libbpf.map with this?

Definitely! I must have lost it during rebase, fixing.

>
> > LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset);
> > LIBBPF_API int btf__get_from_id(__u32 id, struct btf **btf);
> > LIBBPF_API int btf__get_map_kv_tids(const struct btf *btf, const char *map_name,
> > diff --git a/tools/testing/selftests/bpf/test_btf.c b/tools/testing/selftests/bpf/test_btf.c
> > index 447acc34db94..bbcacba39590 100644
> > --- a/tools/testing/selftests/bpf/test_btf.c
> > +++ b/tools/testing/selftests/bpf/test_btf.c
> > @@ -5882,15 +5882,17 @@ static void dump_btf_strings(const char *strs, __u32 len)
> > static int do_test_dedup(unsigned int test_num)
> > {
> >       const struct btf_dedup_test *test = &dedup_tests[test_num - 1];
> > -     int err = 0, i;
> > -     __u32 test_nr_types, expect_nr_types, test_str_len, expect_str_len;
> > -     void *raw_btf;
> > -     unsigned int raw_btf_size;
> > +     __u32 test_nr_types, expect_nr_types, test_btf_size, expect_btf_size;
> > +     const struct btf_header *test_hdr, *expect_hdr;
> >       struct btf *test_btf = NULL, *expect_btf = NULL;
> > +     const void *test_btf_data, *expect_btf_data;
> >       const char *ret_test_next_str, *ret_expect_next_str;
> >       const char *test_strs, *expect_strs;
> >       const char *test_str_cur, *test_str_end;
> >       const char *expect_str_cur, *expect_str_end;
> > +     unsigned int raw_btf_size;
> > +     void *raw_btf;
> > +     int err = 0, i;
> >
> >       fprintf(stderr, "BTF dedup test[%u] (%s):", test_num, test->descr);
> >
> > @@ -5927,23 +5929,34 @@ static int do_test_dedup(unsigned int test_num)
> >               goto done;
> >       }
> >
> > -     btf__get_strings(test_btf, &test_strs, &test_str_len);
> > -     btf__get_strings(expect_btf, &expect_strs, &expect_str_len);
> > -     if (CHECK(test_str_len != expect_str_len,
> > -               "test_str_len:%u != expect_str_len:%u",
> > -               test_str_len, expect_str_len)) {
> > +     test_btf_data = btf__get_raw_data(test_btf, &test_btf_size);
> > +     expect_btf_data = btf__get_raw_data(expect_btf, &expect_btf_size);
> > +     if (CHECK(test_btf_size != expect_btf_size,
> > +               "test_btf_size:%u != expect_btf_size:%u",
> > +               test_btf_size, expect_btf_size)) {
> > +             err = -1;
> > +             goto done;
> > +     }
> > +
> > +     test_hdr = test_btf_data;
> > +     test_strs = test_btf_data + test_hdr->str_off;
> > +     expect_hdr = expect_btf_data;
> > +     expect_strs = expect_btf_data + expect_hdr->str_off;
> > +     if (CHECK(test_hdr->str_len != expect_hdr->str_len,
> > +               "test_hdr->str_len:%u != expect_hdr->str_len:%u",
> > +               test_hdr->str_len, expect_hdr->str_len)) {
> >               fprintf(stderr, "\ntest strings:\n");
> > -             dump_btf_strings(test_strs, test_str_len);
> > +             dump_btf_strings(test_strs, test_hdr->str_len);
> >               fprintf(stderr, "\nexpected strings:\n");
> > -             dump_btf_strings(expect_strs, expect_str_len);
> > +             dump_btf_strings(expect_strs, expect_hdr->str_len);
> >               err = -1;
> >               goto done;
> >       }
> >
> >       test_str_cur = test_strs;
> > -     test_str_end = test_strs + test_str_len;
> > +     test_str_end = test_strs + test_hdr->str_len;
> >       expect_str_cur = expect_strs;
> > -     expect_str_end = expect_strs + expect_str_len;
> > +     expect_str_end = expect_strs + expect_hdr->str_len;
> >       while (test_str_cur < test_str_end && expect_str_cur < expect_str_end) {
> >               size_t test_len, expect_len;
> >
> > --
> > 2.17.1
> >
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ