diff mbox series

[bpf-next] selftests/bpf: Add missing bpf_iter_vma_offset__destroy call

Message ID 20221002151141.1074196-1-jolsa@kernel.org (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next] selftests/bpf: Add missing bpf_iter_vma_offset__destroy call | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers fail 1 blamed authors not CCed: martin.lau@linux.dev; 7 maintainers not CCed: 9erthalion6@gmail.com linux-kselftest@vger.kernel.org kpsingh@kernel.org song@kernel.org shuah@kernel.org mykolal@fb.com martin.lau@linux.dev
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 24 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-6 success Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-4 success Logs for llvm-toolchain
bpf/vmtest-bpf-next-VM_Test-5 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-1 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-10 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-12 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-PR fail PR summary

Commit Message

Jiri Olsa Oct. 2, 2022, 3:11 p.m. UTC
Adding missing bpf_iter_vma_offset__destroy call to
test_task_vma_offset_common function and related goto jumps.

Fixes: b3e1331eb925 ("selftests/bpf: Test parameterized task BPF iterators.")
Cc: Kui-Feng Lee <kuifeng@fb.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Martin KaFai Lau Oct. 4, 2022, 12:12 a.m. UTC | #1
On 10/2/22 8:11 AM, Jiri Olsa wrote:
> Adding missing bpf_iter_vma_offset__destroy call to
> test_task_vma_offset_common function and related goto jumps.
> 
> Fixes: b3e1331eb925 ("selftests/bpf: Test parameterized task BPF iterators.")
> Cc: Kui-Feng Lee <kuifeng@fb.com>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>   tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> index 3369c5ec3a17..462fe92e0736 100644
> --- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> +++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> @@ -1515,11 +1515,11 @@ static void test_task_vma_offset_common(struct bpf_iter_attach_opts *opts, bool
>   
>   	link = bpf_program__attach_iter(skel->progs.get_vma_offset, opts);

Thanks for the fix.

A nit.  Instead of adding a new goto label.  How about doing

	skel->links.get_vma_offset = bpf_program_attach_iter(...)

and bpf_iter_vma_offset__destroy(skel) will take care of the link destroy.  The 
earlier test_task_vma_common() is doing that also.

Kui-Feng, please also take a look.

>   	if (!ASSERT_OK_PTR(link, "attach_iter"))
> -		return;
> +		goto exit_skel;
>   
>   	iter_fd = bpf_iter_create(bpf_link__fd(link));
>   	if (!ASSERT_GT(iter_fd, 0, "create_iter"))
> -		goto exit;
> +		goto exit_link;
>   
>   	while ((len = read(iter_fd, buf, sizeof(buf))) > 0)
>   		;
> @@ -1534,8 +1534,10 @@ static void test_task_vma_offset_common(struct bpf_iter_attach_opts *opts, bool
>   
>   	close(iter_fd);
>   
> -exit:
> +exit_link:
>   	bpf_link__destroy(link);
> +exit_skel:
> +	bpf_iter_vma_offset__destroy(skel);
>   }
>   
>   static void test_task_vma_offset(void)
Jiri Olsa Oct. 4, 2022, 6:38 a.m. UTC | #2
On Mon, Oct 03, 2022 at 05:12:44PM -0700, Martin KaFai Lau wrote:
> On 10/2/22 8:11 AM, Jiri Olsa wrote:
> > Adding missing bpf_iter_vma_offset__destroy call to
> > test_task_vma_offset_common function and related goto jumps.
> > 
> > Fixes: b3e1331eb925 ("selftests/bpf: Test parameterized task BPF iterators.")
> > Cc: Kui-Feng Lee <kuifeng@fb.com>
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >   tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 8 +++++---
> >   1 file changed, 5 insertions(+), 3 deletions(-)
> > 
> > diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> > index 3369c5ec3a17..462fe92e0736 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> > @@ -1515,11 +1515,11 @@ static void test_task_vma_offset_common(struct bpf_iter_attach_opts *opts, bool
> >   	link = bpf_program__attach_iter(skel->progs.get_vma_offset, opts);
> 
> Thanks for the fix.
> 
> A nit.  Instead of adding a new goto label.  How about doing
> 
> 	skel->links.get_vma_offset = bpf_program_attach_iter(...)
> 
> and bpf_iter_vma_offset__destroy(skel) will take care of the link destroy.
> The earlier test_task_vma_common() is doing that also.

right, I forgot destroy would do that.. it'll be simpler change

thanks,
jirka

> 
> Kui-Feng, please also take a look.
> 
> >   	if (!ASSERT_OK_PTR(link, "attach_iter"))
> > -		return;
> > +		goto exit_skel;
> >   	iter_fd = bpf_iter_create(bpf_link__fd(link));
> >   	if (!ASSERT_GT(iter_fd, 0, "create_iter"))
> > -		goto exit;
> > +		goto exit_link;
> >   	while ((len = read(iter_fd, buf, sizeof(buf))) > 0)
> >   		;
> > @@ -1534,8 +1534,10 @@ static void test_task_vma_offset_common(struct bpf_iter_attach_opts *opts, bool
> >   	close(iter_fd);
> > -exit:
> > +exit_link:
> >   	bpf_link__destroy(link);
> > +exit_skel:
> > +	bpf_iter_vma_offset__destroy(skel);
> >   }
> >   static void test_task_vma_offset(void)
>
Jiri Olsa Oct. 4, 2022, 12:16 p.m. UTC | #3
On Tue, Oct 04, 2022 at 08:38:23AM +0200, Jiri Olsa wrote:
> On Mon, Oct 03, 2022 at 05:12:44PM -0700, Martin KaFai Lau wrote:
> > On 10/2/22 8:11 AM, Jiri Olsa wrote:
> > > Adding missing bpf_iter_vma_offset__destroy call to
> > > test_task_vma_offset_common function and related goto jumps.
> > > 
> > > Fixes: b3e1331eb925 ("selftests/bpf: Test parameterized task BPF iterators.")
> > > Cc: Kui-Feng Lee <kuifeng@fb.com>
> > > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > > ---
> > >   tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 8 +++++---
> > >   1 file changed, 5 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> > > index 3369c5ec3a17..462fe92e0736 100644
> > > --- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> > > +++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> > > @@ -1515,11 +1515,11 @@ static void test_task_vma_offset_common(struct bpf_iter_attach_opts *opts, bool
> > >   	link = bpf_program__attach_iter(skel->progs.get_vma_offset, opts);
> > 
> > Thanks for the fix.
> > 
> > A nit.  Instead of adding a new goto label.  How about doing
> > 
> > 	skel->links.get_vma_offset = bpf_program_attach_iter(...)
> > 
> > and bpf_iter_vma_offset__destroy(skel) will take care of the link destroy.
> > The earlier test_task_vma_common() is doing that also.
> 
> right, I forgot destroy would do that.. it'll be simpler change

ugh actually no ;-) it's outside (of skeleton) link,
so it won't get closed in bpf_iter_vma_offset__destroy

the earlier test_task_vma_common does not create such link

jirka

> 
> thanks,
> jirka
> 
> > 
> > Kui-Feng, please also take a look.
> > 
> > >   	if (!ASSERT_OK_PTR(link, "attach_iter"))
> > > -		return;
> > > +		goto exit_skel;
> > >   	iter_fd = bpf_iter_create(bpf_link__fd(link));
> > >   	if (!ASSERT_GT(iter_fd, 0, "create_iter"))
> > > -		goto exit;
> > > +		goto exit_link;
> > >   	while ((len = read(iter_fd, buf, sizeof(buf))) > 0)
> > >   		;
> > > @@ -1534,8 +1534,10 @@ static void test_task_vma_offset_common(struct bpf_iter_attach_opts *opts, bool
> > >   	close(iter_fd);
> > > -exit:
> > > +exit_link:
> > >   	bpf_link__destroy(link);
> > > +exit_skel:
> > > +	bpf_iter_vma_offset__destroy(skel);
> > >   }
> > >   static void test_task_vma_offset(void)
> >
Andrii Nakryiko Oct. 5, 2022, 10:58 p.m. UTC | #4
On Tue, Oct 4, 2022 at 5:16 AM Jiri Olsa <olsajiri@gmail.com> wrote:
>
> On Tue, Oct 04, 2022 at 08:38:23AM +0200, Jiri Olsa wrote:
> > On Mon, Oct 03, 2022 at 05:12:44PM -0700, Martin KaFai Lau wrote:
> > > On 10/2/22 8:11 AM, Jiri Olsa wrote:
> > > > Adding missing bpf_iter_vma_offset__destroy call to
> > > > test_task_vma_offset_common function and related goto jumps.
> > > >
> > > > Fixes: b3e1331eb925 ("selftests/bpf: Test parameterized task BPF iterators.")
> > > > Cc: Kui-Feng Lee <kuifeng@fb.com>
> > > > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > > > ---
> > > >   tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 8 +++++---
> > > >   1 file changed, 5 insertions(+), 3 deletions(-)
> > > >
> > > > diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> > > > index 3369c5ec3a17..462fe92e0736 100644
> > > > --- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> > > > +++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> > > > @@ -1515,11 +1515,11 @@ static void test_task_vma_offset_common(struct bpf_iter_attach_opts *opts, bool
> > > >           link = bpf_program__attach_iter(skel->progs.get_vma_offset, opts);
> > >
> > > Thanks for the fix.
> > >
> > > A nit.  Instead of adding a new goto label.  How about doing
> > >
> > >     skel->links.get_vma_offset = bpf_program_attach_iter(...)
> > >
> > > and bpf_iter_vma_offset__destroy(skel) will take care of the link destroy.
> > > The earlier test_task_vma_common() is doing that also.
> >
> > right, I forgot destroy would do that.. it'll be simpler change
>
> ugh actually no ;-) it's outside (of skeleton) link,
> so it won't get closed in bpf_iter_vma_offset__destroy

Martin's point was that if you assign it to skel->links.get_vma_offset
it will be closed by skeleton's destroy method. So let's do that?

>
> the earlier test_task_vma_common does not create such link
>
> jirka
>
> >
> > thanks,
> > jirka
> >
> > >
> > > Kui-Feng, please also take a look.
> > >
> > > >           if (!ASSERT_OK_PTR(link, "attach_iter"))
> > > > -         return;
> > > > +         goto exit_skel;
> > > >           iter_fd = bpf_iter_create(bpf_link__fd(link));
> > > >           if (!ASSERT_GT(iter_fd, 0, "create_iter"))
> > > > -         goto exit;
> > > > +         goto exit_link;
> > > >           while ((len = read(iter_fd, buf, sizeof(buf))) > 0)
> > > >                   ;
> > > > @@ -1534,8 +1534,10 @@ static void test_task_vma_offset_common(struct bpf_iter_attach_opts *opts, bool
> > > >           close(iter_fd);
> > > > -exit:
> > > > +exit_link:
> > > >           bpf_link__destroy(link);
> > > > +exit_skel:
> > > > + bpf_iter_vma_offset__destroy(skel);
> > > >   }
> > > >   static void test_task_vma_offset(void)
> > >
Jiri Olsa Oct. 6, 2022, 7:03 a.m. UTC | #5
On Wed, Oct 05, 2022 at 03:58:45PM -0700, Andrii Nakryiko wrote:
> On Tue, Oct 4, 2022 at 5:16 AM Jiri Olsa <olsajiri@gmail.com> wrote:
> >
> > On Tue, Oct 04, 2022 at 08:38:23AM +0200, Jiri Olsa wrote:
> > > On Mon, Oct 03, 2022 at 05:12:44PM -0700, Martin KaFai Lau wrote:
> > > > On 10/2/22 8:11 AM, Jiri Olsa wrote:
> > > > > Adding missing bpf_iter_vma_offset__destroy call to
> > > > > test_task_vma_offset_common function and related goto jumps.
> > > > >
> > > > > Fixes: b3e1331eb925 ("selftests/bpf: Test parameterized task BPF iterators.")
> > > > > Cc: Kui-Feng Lee <kuifeng@fb.com>
> > > > > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > > > > ---
> > > > >   tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 8 +++++---
> > > > >   1 file changed, 5 insertions(+), 3 deletions(-)
> > > > >
> > > > > diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> > > > > index 3369c5ec3a17..462fe92e0736 100644
> > > > > --- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> > > > > +++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> > > > > @@ -1515,11 +1515,11 @@ static void test_task_vma_offset_common(struct bpf_iter_attach_opts *opts, bool
> > > > >           link = bpf_program__attach_iter(skel->progs.get_vma_offset, opts);
> > > >
> > > > Thanks for the fix.
> > > >
> > > > A nit.  Instead of adding a new goto label.  How about doing
> > > >
> > > >     skel->links.get_vma_offset = bpf_program_attach_iter(...)
> > > >
> > > > and bpf_iter_vma_offset__destroy(skel) will take care of the link destroy.
> > > > The earlier test_task_vma_common() is doing that also.
> > >
> > > right, I forgot destroy would do that.. it'll be simpler change
> >
> > ugh actually no ;-) it's outside (of skeleton) link,
> > so it won't get closed in bpf_iter_vma_offset__destroy
> 
> Martin's point was that if you assign it to skel->links.get_vma_offset
> it will be closed by skeleton's destroy method. So let's do that?

ah ok, will send new version

thanks,
jirka
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
index 3369c5ec3a17..462fe92e0736 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
@@ -1515,11 +1515,11 @@  static void test_task_vma_offset_common(struct bpf_iter_attach_opts *opts, bool
 
 	link = bpf_program__attach_iter(skel->progs.get_vma_offset, opts);
 	if (!ASSERT_OK_PTR(link, "attach_iter"))
-		return;
+		goto exit_skel;
 
 	iter_fd = bpf_iter_create(bpf_link__fd(link));
 	if (!ASSERT_GT(iter_fd, 0, "create_iter"))
-		goto exit;
+		goto exit_link;
 
 	while ((len = read(iter_fd, buf, sizeof(buf))) > 0)
 		;
@@ -1534,8 +1534,10 @@  static void test_task_vma_offset_common(struct bpf_iter_attach_opts *opts, bool
 
 	close(iter_fd);
 
-exit:
+exit_link:
 	bpf_link__destroy(link);
+exit_skel:
+	bpf_iter_vma_offset__destroy(skel);
 }
 
 static void test_task_vma_offset(void)