Skip to contentSkip to conversation

selftests/bpf: Add missing bpf_iter_vma_offset__destroy call

PATCH Superseded Jiri Olsa 4 participants 6 messages Oct 2, 2022 – Oct 6, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

PATCH 1/1 selftests/bpf: Add missing bpf_iter_vma_offset__destroy call

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 <[email protected]>
---
 tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +5 -3
index 3369c5ec3a17..462fe92e0736 100644
@@ -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)
Signature · 1 line
2.37.3
#1 lore raw
Quoted 15 lines · Jiri Olsa

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 <[email protected]>
---
  tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +0 -0
index 3369c5ec3a17..462fe92e0736 100644

tools/testing/selftests/bpf/prog_tests/bpf_iter.c static void test_task_vma_offset_common(struct bpf_iter_attach_opts *opts, bool · line 1516

Quoted 2 lines
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +0 -0
@@ -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.

Quoted 23 lines
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +5 -3
  	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)
#2 lore raw
Quoted 20 lines · Martin KaFai Lau
Quoted 15 lines · Jiri Olsa

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 <[email protected]>
---
  tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +0 -0
index 3369c5ec3a17..462fe92e0736 100644

tools/testing/selftests/bpf/prog_tests/bpf_iter.c static void test_task_vma_offset_common(struct bpf_iter_attach_opts *opts, bool · line 1515

Quoted 1 line
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +0 -0
@@ -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.

Quoted 6 lines

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

Quoted 22 lines

Kui-Feng, please also take a look.

Quoted 18 lines
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +5 -3
  	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)
#3 lore raw
Quoted 21 lines · Jiri Olsa
Quoted 20 lines · Martin KaFai Lau
Quoted 15 lines · Jiri Olsa

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 <[email protected]>
---
  tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +0 -0
index 3369c5ec3a17..462fe92e0736 100644

tools/testing/selftests/bpf/prog_tests/bpf_iter.c static void test_task_vma_offset_common(struct bpf_iter_attach_opts *opts, bool · line 1515

Quoted 1 line
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +0 -0
@@ -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.

Quoted 8 lines
Quoted 6 lines

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

Quoted 26 lines

thanks,
jirka

Quoted 22 lines

Kui-Feng, please also take a look.

Quoted 18 lines
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +5 -3
  	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)
#4 lore raw
Quoted 27 lines · Jiri Olsa
Quoted 25 lines · Jiri Olsa
Quoted 24 lines · Martin KaFai Lau
Quoted 15 lines · Jiri Olsa

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 <[email protected]>
---
  tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +0 -0
index 3369c5ec3a17..462fe92e0736 100644

tools/testing/selftests/bpf/prog_tests/bpf_iter.c static void test_task_vma_offset_common(struct bpf_iter_attach_opts *opts, bool · line 1515

Quoted 1 line
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +0 -0
@@ -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(...)
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

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?

Quoted 31 lines

the earlier test_task_vma_common does not create such link

jirka

Quoted 26 lines

thanks,
jirka

Quoted 22 lines

Kui-Feng, please also take a look.

Quoted 18 lines
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +5 -3
          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)
#5 lore raw
Quoted 31 lines · Andrii Nakryiko
Quoted 30 lines · Jiri Olsa
Quoted 28 lines · Jiri Olsa
Quoted 26 lines · Martin KaFai Lau
Quoted 15 lines · Jiri Olsa

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 <[email protected]>
---
  tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +0 -0
index 3369c5ec3a17..462fe92e0736 100644

tools/testing/selftests/bpf/prog_tests/bpf_iter.c static void test_task_vma_offset_common(struct bpf_iter_attach_opts *opts, bool · line 1515

Quoted 1 line
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +0 -0
@@ -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.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

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