Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: net: retry when bind returns EBUSY in xdp_helper

When binding the XDP socket, we may get EBUSY because the deferred
destructor of XDP socket in previous test has not been executed yet. If
that is the case, just sleep and retry some times.

Signed-off-by: Bui Quang Minh <minhquangbui99@gmail.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Link: https://patch.msgid.link/20250425071018.36078-4-minhquangbui99@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Bui Quang Minh and committed by
Jakub Kicinski
b2b4555c 5d346179

+15 -5
+15 -5
tools/testing/selftests/net/lib/xdp_helper.c
··· 38 38 struct sockaddr_xdp sxdp = { 0 }; 39 39 int num_desc = NUM_DESC; 40 40 void *umem_area; 41 + int retry = 0; 41 42 int ifindex; 42 43 int sock_fd; 43 44 int queue; ··· 103 102 } 104 103 } 105 104 106 - if (bind(sock_fd, (struct sockaddr *)&sxdp, sizeof(sxdp)) != 0) { 107 - munmap(umem_area, UMEM_SZ); 108 - perror("bind failed"); 109 - close(sock_fd); 110 - return 1; 105 + while (1) { 106 + if (bind(sock_fd, (struct sockaddr *)&sxdp, sizeof(sxdp)) == 0) 107 + break; 108 + 109 + if (errno == EBUSY && retry < 3) { 110 + retry++; 111 + sleep(1); 112 + continue; 113 + } else { 114 + perror("bind failed"); 115 + munmap(umem_area, UMEM_SZ); 116 + close(sock_fd); 117 + return 1; 118 + } 111 119 } 112 120 113 121 ksft_ready();