From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Song Liu <song@kernel.org>
Cc: Andrii Nakryiko <andriin@fb.com>, bpf <bpf@vger.kernel.org>,
Networking <netdev@vger.kernel.org>,
Alexei Starovoitov <ast@fb.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH bpf 2/2] selftests/bpf: extend map-in-map selftest to detect memory leaks
Date: Mon, 27 Jul 2020 15:02:18 -0700 [thread overview]
Message-ID: <CAEf4BzZUN-kH8LzPp76BHW-8iBX=QUKCHmpxid0hxapbZ6t9rw@mail.gmail.com> (raw)
In-Reply-To: <CAPhsuW68tUDQf7kgB-r5aJFH3Bk_5_b_0eokqjYe9-8YpHX3zg@mail.gmail.com>
On Mon, Jul 27, 2020 at 1:53 PM Song Liu <song@kernel.org> wrote:
>
> On Thu, Jul 23, 2020 at 6:17 PM Andrii Nakryiko <andriin@fb.com> wrote:
> >
> > Add test validating that all inner maps are released properly after skeleton
> > is destroyed. To ensure determinism, trigger kernel-size synchronize_rcu()
> > before checking map existence by their IDs.
> >
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> > ---
> > .../selftests/bpf/prog_tests/btf_map_in_map.c | 104 +++++++++++++++---
> > 1 file changed, 91 insertions(+), 13 deletions(-)
> >
> > diff --git a/tools/testing/selftests/bpf/prog_tests/btf_map_in_map.c b/tools/testing/selftests/bpf/prog_tests/btf_map_in_map.c
> > index f7ee8fa377ad..043e8ffe03d1 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/btf_map_in_map.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/btf_map_in_map.c
> > @@ -5,10 +5,50 @@
> >
> > #include "test_btf_map_in_map.skel.h"
> >
> > +static int duration;
> > +
> > +int bpf_map_id(struct bpf_map *map)
> Should this return __u32?
yeah, probably, will change
>
> > +{
> > + struct bpf_map_info info;
> > + __u32 info_len = sizeof(info);
> > + int err;
> > +
> > + memset(&info, 0, info_len);
> > + err = bpf_obj_get_info_by_fd(bpf_map__fd(map), &info, &info_len);
> > + if (err)
> > + return 0;
> > + return info.id;
> > +}
> > +
> > +int kern_sync_rcu() {
>
> int kern_sync_rcu(void)
> {
> ...
>
> A comment for this function would be nice too.
Sure.
>
> > + int inner_map_fd, outer_map_fd, err, zero = 0;
> > +
> > + inner_map_fd = bpf_create_map(BPF_MAP_TYPE_ARRAY, 4, 4, 1, 0);
> > + if (CHECK(inner_map_fd < 0, "inner_map_create", "failed %d\n", -errno))
> > + return -1;
> > +
> > + outer_map_fd = bpf_create_map_in_map(BPF_MAP_TYPE_ARRAY_OF_MAPS, NULL,
> > + sizeof(int), inner_map_fd, 1, 0);
> > + if (CHECK(outer_map_fd < 0, "outer_map_create", "failed %d\n", -errno)) {
> > + close(inner_map_fd);
> > + return -1;
> > + }
> > +
> > + err = bpf_map_update_elem(outer_map_fd, &zero, &inner_map_fd, 0);
> > + if (err)
> > + err = -errno;
> > + CHECK(err, "outer_map_update", "failed %d\n", err);
> > + close(inner_map_fd);
> > + close(outer_map_fd);
> > + return err;
> > +}
> > +
> > void test_btf_map_in_map(void)
> > {
> > - int duration = 0, err, key = 0, val;
> > + int err, key = 0, val, i;
> > struct test_btf_map_in_map* skel;
> > + int outer_arr_fd, outer_hash_fd;
> > + int fd, map1_fd, map2_fd, map1_id, map2_id;
> nit: reverse Christmas tree.
We don't enforce that and it hasn't been a requirement for a long
time. It's better to minimize a code churn rather than preserving
pretty line ordering.
>
> >
> > skel = test_btf_map_in_map__open_and_load();
> > if (CHECK(!skel, "skel_open", "failed to open&load skeleton\n"))
> > @@ -18,32 +58,70 @@ void test_btf_map_in_map(void)
> > if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err))
> > goto cleanup;
> >
[...]
next prev parent reply other threads:[~2020-07-27 22:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-24 1:16 [PATCH bpf 1/2] bpf: fix map leak in HASH_OF_MAPS map Andrii Nakryiko
2020-07-24 1:17 ` [PATCH bpf 2/2] selftests/bpf: extend map-in-map selftest to detect memory leaks Andrii Nakryiko
2020-07-27 20:53 ` Song Liu
2020-07-27 22:02 ` Andrii Nakryiko [this message]
2020-07-27 21:02 ` [PATCH bpf 1/2] bpf: fix map leak in HASH_OF_MAPS map Song Liu
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='CAEf4BzZUN-kH8LzPp76BHW-8iBX=QUKCHmpxid0hxapbZ6t9rw@mail.gmail.com' \
--to=andrii.nakryiko@gmail.com \
--cc=andriin@fb.com \
--cc=ast@fb.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
--cc=song@kernel.org \
/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).