diff mbox series

[bpf,v3,3/4] selftests/bpf: fix a CI failure caused by vsock sockmap test

Message ID 20230804073740.194770-4-xukuohai@huaweicloud.com (mailing list archive)
State Accepted
Commit 90f0074cd9f9a24b7b6c4d5afffa676aee48c0e9
Delegated to: BPF
Headers show
Series bug fixes for sockmap | expand

Checks

Context Check Description
bpf/vmtest-bpf-PR fail PR summary
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for bpf
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
netdev/cc_maintainers fail 1 blamed authors not CCed: sgarzare@redhat.com; 12 maintainers not CCed: yhs@fb.com kpsingh@kernel.org martin.lau@linux.dev shuah@kernel.org sdf@google.com song@kernel.org andrii@kernel.org mykolal@fb.com sgarzare@redhat.com linux-kselftest@vger.kernel.org jolsa@kernel.org haoluo@google.com
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
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: 9 this patch: 9
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-VM_Test-16 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-VM_Test-12 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-VM_Test-8 success Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-VM_Test-4 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-VM_Test-5 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-6 success Logs for set-matrix
bpf/vmtest-bpf-VM_Test-3 success Logs for build for s390x with gcc
bpf/vmtest-bpf-VM_Test-7 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-9 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-10 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-13 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-15 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-17 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-19 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-20 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-22 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-23 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-25 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-27 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-28 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-11 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-14 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-18 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-21 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-24 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-26 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-VM_Test-29 success Logs for veristat

Commit Message

Xu Kuohai Aug. 4, 2023, 7:37 a.m. UTC
From: Xu Kuohai <xukuohai@huawei.com>

BPF CI has reported the following failure:

Error: #200/79 sockmap_listen/sockmap VSOCK test_vsock_redir
  Error: #200/79 sockmap_listen/sockmap VSOCK test_vsock_redir
  ./test_progs:vsock_unix_redir_connectible:1506: egress: write: Transport endpoint is not connected
  vsock_unix_redir_connectible:FAIL:1506
  ./test_progs:vsock_unix_redir_connectible:1506: ingress: write: Transport endpoint is not connected
  vsock_unix_redir_connectible:FAIL:1506
  ./test_progs:vsock_unix_redir_connectible:1506: egress: write: Transport endpoint is not connected
  vsock_unix_redir_connectible:FAIL:1506
  ./test_progs:vsock_unix_redir_connectible:1514: ingress: recv() err, errno=11
  vsock_unix_redir_connectible:FAIL:1514
  ./test_progs:vsock_unix_redir_connectible:1518: ingress: vsock socket map failed, a != b
  vsock_unix_redir_connectible:FAIL:1518
  ./test_progs:vsock_unix_redir_connectible:1525: ingress: want pass count 1, have 0

It’s because the recv(... MSG_DONTWAIT) syscall in the test case is
called before the queued work sk_psock_backlog() in the kernel finishes
executing. So the data to be read is still queued in psock->ingress_skb
and cannot be read by the user program. Therefore, the non-blocking
recv() reads nothing and reports an EAGAIN error.

So replace recv(... MSG_DONTWAIT) with xrecv_nonblock(), which calls
select() to wait for data to be readable or timeout before calls recv().

Fixes: d61bd8c1fd02 ("selftests/bpf: add a test case for vsock sockmap")
Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
---
 tools/testing/selftests/bpf/prog_tests/sockmap_listen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Daniel Borkmann Aug. 30, 2023, 8:10 a.m. UTC | #1
Hi Xu,

On 8/4/23 9:37 AM, Xu Kuohai wrote:
> From: Xu Kuohai <xukuohai@huawei.com>
> 
> BPF CI has reported the following failure:
> 
> Error: #200/79 sockmap_listen/sockmap VSOCK test_vsock_redir
>    Error: #200/79 sockmap_listen/sockmap VSOCK test_vsock_redir
>    ./test_progs:vsock_unix_redir_connectible:1506: egress: write: Transport endpoint is not connected
>    vsock_unix_redir_connectible:FAIL:1506
>    ./test_progs:vsock_unix_redir_connectible:1506: ingress: write: Transport endpoint is not connected
>    vsock_unix_redir_connectible:FAIL:1506
>    ./test_progs:vsock_unix_redir_connectible:1506: egress: write: Transport endpoint is not connected
>    vsock_unix_redir_connectible:FAIL:1506
>    ./test_progs:vsock_unix_redir_connectible:1514: ingress: recv() err, errno=11
>    vsock_unix_redir_connectible:FAIL:1514
>    ./test_progs:vsock_unix_redir_connectible:1518: ingress: vsock socket map failed, a != b
>    vsock_unix_redir_connectible:FAIL:1518
>    ./test_progs:vsock_unix_redir_connectible:1525: ingress: want pass count 1, have 0
> 
> It’s because the recv(... MSG_DONTWAIT) syscall in the test case is
> called before the queued work sk_psock_backlog() in the kernel finishes
> executing. So the data to be read is still queued in psock->ingress_skb
> and cannot be read by the user program. Therefore, the non-blocking
> recv() reads nothing and reports an EAGAIN error.
> 
> So replace recv(... MSG_DONTWAIT) with xrecv_nonblock(), which calls
> select() to wait for data to be readable or timeout before calls recv().
> 
> Fixes: d61bd8c1fd02 ("selftests/bpf: add a test case for vsock sockmap")
> Signed-off-by: Xu Kuohai <xukuohai@huawei.com>

This is unfortunately still flaky and showing up from time to time in BPF CI, e.g. a
very recent one can be found here:

https://github.com/kernel-patches/bpf/actions/runs/6021475685/job/16335248421

[...]
Error: #211 sockmap_listen
Error: #211/79 sockmap_listen/sockmap VSOCK test_vsock_redir
   Error: #211/79 sockmap_listen/sockmap VSOCK test_vsock_redir
   ./test_progs:vsock_unix_redir_connectible:1501: egress: write: Transport endpoint is not connected
   vsock_unix_redir_connectible:FAIL:1501
   ./test_progs:vsock_unix_redir_connectible:1501: ingress: write: Transport endpoint is not connected
   vsock_unix_redir_connectible:FAIL:1501
   ./test_progs:vsock_unix_redir_connectible:1501: egress: write: Transport endpoint is not connected
   vsock_unix_redir_connectible:FAIL:1501

Could you continue to look into it to make the test more robust?

Thanks a lot,
Daniel
Xu Kuohai Aug. 30, 2023, 8:55 a.m. UTC | #2
On 8/30/2023 4:10 PM, Daniel Borkmann wrote:
> Hi Xu,
> 
> On 8/4/23 9:37 AM, Xu Kuohai wrote:
>> From: Xu Kuohai <xukuohai@huawei.com>
>>
>> BPF CI has reported the following failure:
>>
>> Error: #200/79 sockmap_listen/sockmap VSOCK test_vsock_redir
>>    Error: #200/79 sockmap_listen/sockmap VSOCK test_vsock_redir
>>    ./test_progs:vsock_unix_redir_connectible:1506: egress: write: Transport endpoint is not connected
>>    vsock_unix_redir_connectible:FAIL:1506
>>    ./test_progs:vsock_unix_redir_connectible:1506: ingress: write: Transport endpoint is not connected
>>    vsock_unix_redir_connectible:FAIL:1506
>>    ./test_progs:vsock_unix_redir_connectible:1506: egress: write: Transport endpoint is not connected
>>    vsock_unix_redir_connectible:FAIL:1506
>>    ./test_progs:vsock_unix_redir_connectible:1514: ingress: recv() err, errno=11
>>    vsock_unix_redir_connectible:FAIL:1514
>>    ./test_progs:vsock_unix_redir_connectible:1518: ingress: vsock socket map failed, a != b
>>    vsock_unix_redir_connectible:FAIL:1518
>>    ./test_progs:vsock_unix_redir_connectible:1525: ingress: want pass count 1, have 0
>>
>> It’s because the recv(... MSG_DONTWAIT) syscall in the test case is
>> called before the queued work sk_psock_backlog() in the kernel finishes
>> executing. So the data to be read is still queued in psock->ingress_skb
>> and cannot be read by the user program. Therefore, the non-blocking
>> recv() reads nothing and reports an EAGAIN error.
>>
>> So replace recv(... MSG_DONTWAIT) with xrecv_nonblock(), which calls
>> select() to wait for data to be readable or timeout before calls recv().
>>
>> Fixes: d61bd8c1fd02 ("selftests/bpf: add a test case for vsock sockmap")
>> Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
> 
> This is unfortunately still flaky and showing up from time to time in BPF CI, e.g. a
> very recent one can be found here:
> 
> https://github.com/kernel-patches/bpf/actions/runs/6021475685/job/16335248421
> 
> [...]
> Error: #211 sockmap_listen
> Error: #211/79 sockmap_listen/sockmap VSOCK test_vsock_redir
>    Error: #211/79 sockmap_listen/sockmap VSOCK test_vsock_redir
>    ./test_progs:vsock_unix_redir_connectible:1501: egress: write: Transport endpoint is not connected
>    vsock_unix_redir_connectible:FAIL:1501
>    ./test_progs:vsock_unix_redir_connectible:1501: ingress: write: Transport endpoint is not connected
>    vsock_unix_redir_connectible:FAIL:1501
>    ./test_progs:vsock_unix_redir_connectible:1501: egress: write: Transport endpoint is not connected
>    vsock_unix_redir_connectible:FAIL:1501
> 
> Could you continue to look into it to make the test more robust?
> 

OK, it looks like I only noticed the recv failure and ignored the
write failure. I'll take it a look.

> Thanks a lot,
> Daniel
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
index b4f6f3a50ae5..ba35bcc66e7e 100644
--- a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
+++ b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
@@ -1432,7 +1432,7 @@  static void vsock_unix_redir_connectible(int sock_mapfd, int verd_mapfd,
 	if (n < 1)
 		goto out;
 
-	n = recv(mode == REDIR_INGRESS ? u0 : u1, &b, sizeof(b), MSG_DONTWAIT);
+	n = xrecv_nonblock(mode == REDIR_INGRESS ? u0 : u1, &b, sizeof(b), 0);
 	if (n < 0)
 		FAIL("%s: recv() err, errno=%d", log_prefix, errno);
 	if (n == 0)