Skip to content

Commit ae211fd

Browse files
Xu Kuohaigregkh
Xu Kuohai
authored andcommitted
selftests/bpf: Fix a CI failure caused by vsock write
[ Upstream commit c1970e2 ] While commit 90f0074 ("selftests/bpf: fix a CI failure caused by vsock sockmap test") fixes a receive failure of vsock sockmap test, there is still a write failure: 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 The reason is that the vsock connection in the test is set to ESTABLISHED state by function virtio_transport_recv_pkt, which is executed in a workqueue thread, so when the user space test thread runs before the workqueue thread, this problem occurs. To fix it, before writing the connection, wait for it to be connected. Fixes: d61bd8c ("selftests/bpf: add a test case for vsock sockmap") Signed-off-by: Xu Kuohai <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected] Signed-off-by: Sasha Levin <[email protected]>
1 parent be5879b commit ae211fd

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

tools/testing/selftests/bpf/prog_tests/sockmap_helpers.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,32 @@
179179
__ret; \
180180
})
181181

182+
static inline int poll_connect(int fd, unsigned int timeout_sec)
183+
{
184+
struct timeval timeout = { .tv_sec = timeout_sec };
185+
fd_set wfds;
186+
int r, eval;
187+
socklen_t esize = sizeof(eval);
188+
189+
FD_ZERO(&wfds);
190+
FD_SET(fd, &wfds);
191+
192+
r = select(fd + 1, NULL, &wfds, NULL, &timeout);
193+
if (r == 0)
194+
errno = ETIME;
195+
if (r != 1)
196+
return -1;
197+
198+
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &eval, &esize) < 0)
199+
return -1;
200+
if (eval != 0) {
201+
errno = eval;
202+
return -1;
203+
}
204+
205+
return 0;
206+
}
207+
182208
static inline int poll_read(int fd, unsigned int timeout_sec)
183209
{
184210
struct timeval timeout = { .tv_sec = timeout_sec };

tools/testing/selftests/bpf/prog_tests/sockmap_listen.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,11 +1452,18 @@ static int vsock_socketpair_connectible(int sotype, int *v0, int *v1)
14521452
if (p < 0)
14531453
goto close_cli;
14541454

1455+
if (poll_connect(c, IO_TIMEOUT_SEC) < 0) {
1456+
FAIL_ERRNO("poll_connect");
1457+
goto close_acc;
1458+
}
1459+
14551460
*v0 = p;
14561461
*v1 = c;
14571462

14581463
return 0;
14591464

1465+
close_acc:
1466+
close(p);
14601467
close_cli:
14611468
close(c);
14621469
close_srv:

0 commit comments

Comments
 (0)