BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/2] BPF selftests misc fixes
@ 2024-07-10 13:10 Geliang Tang
  2024-07-10 13:10 ` [PATCH bpf-next v2 1/2] selftests/bpf: Null checks for links in bpf_tcp_ca Geliang Tang
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Geliang Tang @ 2024-07-10 13:10 UTC (permalink / raw)
  To: Andrii Nakryiko, Eduard Zingerman, Mykola Lysenko,
	Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo, Jiri Olsa, Shuah Khan
  Cc: Geliang Tang, bpf, linux-kselftest

From: Geliang Tang <tanggeliang@kylinos.cn>

v2:
 - only check the first "link" (link_nl) in test_mixed_links().
 - Drop patch 2 in v1.

Resend patch 1 out of "skip ENOTSUPP BPF selftests" set as Eduard
suggested. Together with another fix for xdp_adjust_tail.

Geliang Tang (2):
  selftests/bpf: Null checks for links in bpf_tcp_ca
  selftests/bpf: Close obj in error path in xdp_adjust_tail

 .../selftests/bpf/prog_tests/bpf_tcp_ca.c        | 16 ++++++++++++----
 .../selftests/bpf/prog_tests/xdp_adjust_tail.c   |  2 +-
 2 files changed, 13 insertions(+), 5 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH bpf-next v2 1/2] selftests/bpf: Null checks for links in bpf_tcp_ca
  2024-07-10 13:10 [PATCH bpf-next v2 0/2] BPF selftests misc fixes Geliang Tang
@ 2024-07-10 13:10 ` Geliang Tang
  2024-07-10 13:10 ` [PATCH bpf-next v2 2/2] selftests/bpf: Close obj in error path in xdp_adjust_tail Geliang Tang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Geliang Tang @ 2024-07-10 13:10 UTC (permalink / raw)
  To: Andrii Nakryiko, Eduard Zingerman, Mykola Lysenko,
	Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo, Jiri Olsa, Shuah Khan
  Cc: Geliang Tang, bpf, linux-kselftest, Alan Maguire

From: Geliang Tang <tanggeliang@kylinos.cn>

Run bpf_tcp_ca selftests (./test_progs -t bpf_tcp_ca) on a Loongarch
platform, some "Segmentation fault" errors occur:

'''
 test_dctcp:PASS:bpf_dctcp__open_and_load 0 nsec
 test_dctcp:FAIL:bpf_map__attach_struct_ops unexpected error: -524
 #29/1    bpf_tcp_ca/dctcp:FAIL
 test_cubic:PASS:bpf_cubic__open_and_load 0 nsec
 test_cubic:FAIL:bpf_map__attach_struct_ops unexpected error: -524
 #29/2    bpf_tcp_ca/cubic:FAIL
 test_dctcp_fallback:PASS:dctcp_skel 0 nsec
 test_dctcp_fallback:PASS:bpf_dctcp__load 0 nsec
 test_dctcp_fallback:FAIL:dctcp link unexpected error: -524
 #29/4    bpf_tcp_ca/dctcp_fallback:FAIL
 test_write_sk_pacing:PASS:open_and_load 0 nsec
 test_write_sk_pacing:FAIL:attach_struct_ops unexpected error: -524
 #29/6    bpf_tcp_ca/write_sk_pacing:FAIL
 test_update_ca:PASS:open 0 nsec
 test_update_ca:FAIL:attach_struct_ops unexpected error: -524
 settcpca:FAIL:setsockopt unexpected setsockopt: \
					actual -1 == expected -1
 (network_helpers.c:99: errno: No such file or directory) \
					Failed to call post_socket_cb
 start_test:FAIL:start_server_str unexpected start_server_str: \
					actual -1 == expected -1
 test_update_ca:FAIL:ca1_ca1_cnt unexpected ca1_ca1_cnt: \
					actual 0 <= expected 0
 #29/9    bpf_tcp_ca/update_ca:FAIL
 #29      bpf_tcp_ca:FAIL
 Caught signal #11!
 Stack trace:
 ./test_progs(crash_handler+0x28)[0x5555567ed91c]
 linux-vdso.so.1(__vdso_rt_sigreturn+0x0)[0x7ffffee408b0]
 ./test_progs(bpf_link__update_map+0x80)[0x555556824a78]
 ./test_progs(+0x94d68)[0x5555564c4d68]
 ./test_progs(test_bpf_tcp_ca+0xe8)[0x5555564c6a88]
 ./test_progs(+0x3bde54)[0x5555567ede54]
 ./test_progs(main+0x61c)[0x5555567efd54]
 /usr/lib64/libc.so.6(+0x22208)[0x7ffff2aaa208]
 /usr/lib64/libc.so.6(__libc_start_main+0xac)[0x7ffff2aaa30c]
 ./test_progs(_start+0x48)[0x55555646bca8]
 Segmentation fault
'''

This is because BPF trampoline is not implemented on Loongarch yet,
"link" returned by bpf_map__attach_struct_ops() is NULL. test_progs
crashs when this NULL link passes to bpf_link__update_map(). This
patch adds NULL checks for all links in bpf_tcp_ca to fix these errors.
If "link" is NULL, goto the newly added label "out" to destroy the skel.

v2:
 - use "goto out" instead of "return" as Eduard suggested.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
---
 .../selftests/bpf/prog_tests/bpf_tcp_ca.c        | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
index bceff5900016..63422f4f3896 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
@@ -411,7 +411,8 @@ static void test_update_ca(void)
 		return;
 
 	link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
-	ASSERT_OK_PTR(link, "attach_struct_ops");
+	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
+		goto out;
 
 	do_test(&opts);
 	saved_ca1_cnt = skel->bss->ca1_cnt;
@@ -425,6 +426,7 @@ static void test_update_ca(void)
 	ASSERT_GT(skel->bss->ca2_cnt, 0, "ca2_ca2_cnt");
 
 	bpf_link__destroy(link);
+out:
 	tcp_ca_update__destroy(skel);
 }
 
@@ -447,7 +449,8 @@ static void test_update_wrong(void)
 		return;
 
 	link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
-	ASSERT_OK_PTR(link, "attach_struct_ops");
+	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
+		goto out;
 
 	do_test(&opts);
 	saved_ca1_cnt = skel->bss->ca1_cnt;
@@ -460,6 +463,7 @@ static void test_update_wrong(void)
 	ASSERT_GT(skel->bss->ca1_cnt, saved_ca1_cnt, "ca2_ca1_cnt");
 
 	bpf_link__destroy(link);
+out:
 	tcp_ca_update__destroy(skel);
 }
 
@@ -481,7 +485,8 @@ static void test_mixed_links(void)
 		return;
 
 	link_nl = bpf_map__attach_struct_ops(skel->maps.ca_no_link);
-	ASSERT_OK_PTR(link_nl, "attach_struct_ops_nl");
+	if (!ASSERT_OK_PTR(link_nl, "attach_struct_ops_nl"))
+		goto out;
 
 	link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
 	ASSERT_OK_PTR(link, "attach_struct_ops");
@@ -494,6 +499,7 @@ static void test_mixed_links(void)
 
 	bpf_link__destroy(link);
 	bpf_link__destroy(link_nl);
+out:
 	tcp_ca_update__destroy(skel);
 }
 
@@ -536,7 +542,8 @@ static void test_link_replace(void)
 	bpf_link__destroy(link);
 
 	link = bpf_map__attach_struct_ops(skel->maps.ca_update_2);
-	ASSERT_OK_PTR(link, "attach_struct_ops_2nd");
+	if (!ASSERT_OK_PTR(link, "attach_struct_ops_2nd"))
+		goto out;
 
 	/* BPF_F_REPLACE with a wrong old map Fd. It should fail!
 	 *
@@ -559,6 +566,7 @@ static void test_link_replace(void)
 
 	bpf_link__destroy(link);
 
+out:
 	tcp_ca_update__destroy(skel);
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH bpf-next v2 2/2] selftests/bpf: Close obj in error path in xdp_adjust_tail
  2024-07-10 13:10 [PATCH bpf-next v2 0/2] BPF selftests misc fixes Geliang Tang
  2024-07-10 13:10 ` [PATCH bpf-next v2 1/2] selftests/bpf: Null checks for links in bpf_tcp_ca Geliang Tang
@ 2024-07-10 13:10 ` Geliang Tang
  2024-07-10 19:50 ` [PATCH bpf-next v2 0/2] BPF selftests misc fixes patchwork-bot+netdevbpf
  2024-07-10 19:50 ` Martin KaFai Lau
  3 siblings, 0 replies; 5+ messages in thread
From: Geliang Tang @ 2024-07-10 13:10 UTC (permalink / raw)
  To: Andrii Nakryiko, Eduard Zingerman, Mykola Lysenko,
	Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo, Jiri Olsa, Shuah Khan
  Cc: Geliang Tang, bpf, linux-kselftest

From: Geliang Tang <tanggeliang@kylinos.cn>

If bpf_object__load() fails in test_xdp_adjust_frags_tail_grow(), "obj"
opened before this should be closed. So use "goto out" to close it instead
of using "return" here.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
index f09505f8b038..53d6ad8c2257 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
@@ -222,7 +222,7 @@ static void test_xdp_adjust_frags_tail_grow(void)
 
 	prog = bpf_object__next_program(obj, NULL);
 	if (bpf_object__load(obj))
-		return;
+		goto out;
 
 	prog_fd = bpf_program__fd(prog);
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next v2 0/2] BPF selftests misc fixes
  2024-07-10 13:10 [PATCH bpf-next v2 0/2] BPF selftests misc fixes Geliang Tang
  2024-07-10 13:10 ` [PATCH bpf-next v2 1/2] selftests/bpf: Null checks for links in bpf_tcp_ca Geliang Tang
  2024-07-10 13:10 ` [PATCH bpf-next v2 2/2] selftests/bpf: Close obj in error path in xdp_adjust_tail Geliang Tang
@ 2024-07-10 19:50 ` patchwork-bot+netdevbpf
  2024-07-10 19:50 ` Martin KaFai Lau
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-07-10 19:50 UTC (permalink / raw)
  To: Geliang Tang
  Cc: andrii, eddyz87, mykolal, ast, daniel, martin.lau, song,
	yonghong.song, john.fastabend, kpsingh, sdf, haoluo, jolsa, shuah,
	tanggeliang, bpf, linux-kselftest

Hello:

This series was applied to bpf/bpf-next.git (master)
by Martin KaFai Lau <martin.lau@kernel.org>:

On Wed, 10 Jul 2024 21:10:15 +0800 you wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> v2:
>  - only check the first "link" (link_nl) in test_mixed_links().
>  - Drop patch 2 in v1.
> 
> Resend patch 1 out of "skip ENOTSUPP BPF selftests" set as Eduard
> suggested. Together with another fix for xdp_adjust_tail.
> 
> [...]

Here is the summary with links:
  - [bpf-next,v2,1/2] selftests/bpf: Null checks for links in bpf_tcp_ca
    https://git.kernel.org/bpf/bpf-next/c/eef0532e900c
  - [bpf-next,v2,2/2] selftests/bpf: Close obj in error path in xdp_adjust_tail
    https://git.kernel.org/bpf/bpf-next/c/52b49ec1b2c7

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next v2 0/2] BPF selftests misc fixes
  2024-07-10 13:10 [PATCH bpf-next v2 0/2] BPF selftests misc fixes Geliang Tang
                   ` (2 preceding siblings ...)
  2024-07-10 19:50 ` [PATCH bpf-next v2 0/2] BPF selftests misc fixes patchwork-bot+netdevbpf
@ 2024-07-10 19:50 ` Martin KaFai Lau
  3 siblings, 0 replies; 5+ messages in thread
From: Martin KaFai Lau @ 2024-07-10 19:50 UTC (permalink / raw)
  To: Geliang Tang
  Cc: Andrii Nakryiko, Eduard Zingerman, Mykola Lysenko,
	Alexei Starovoitov, Daniel Borkmann, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Hao Luo, Jiri Olsa, Shuah Khan,
	Geliang Tang, bpf, linux-kselftest

On 7/10/24 6:10 AM, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> v2:
>   - only check the first "link" (link_nl) in test_mixed_links().
>   - Drop patch 2 in v1.
> 
> Resend patch 1 out of "skip ENOTSUPP BPF selftests" set as Eduard
> suggested. Together with another fix for xdp_adjust_tail.

This is not very useful as a cover letter to summarize what has been fixed. I 
need to go back to the "skip ENOTSUPP BPF selftests". I beefed it up a little.

I also added the Fixes tag before applying. Please remember to add Fixes tag 
next time for bug fixing.

Thanks for the fixes.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-07-10 19:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-10 13:10 [PATCH bpf-next v2 0/2] BPF selftests misc fixes Geliang Tang
2024-07-10 13:10 ` [PATCH bpf-next v2 1/2] selftests/bpf: Null checks for links in bpf_tcp_ca Geliang Tang
2024-07-10 13:10 ` [PATCH bpf-next v2 2/2] selftests/bpf: Close obj in error path in xdp_adjust_tail Geliang Tang
2024-07-10 19:50 ` [PATCH bpf-next v2 0/2] BPF selftests misc fixes patchwork-bot+netdevbpf
2024-07-10 19:50 ` Martin KaFai Lau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox