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

Configure Feed

Select the types of activity you want to include in your feed.

selftests: tls: avoid flakiness in data_steal

We see the following failure a few times a week:

# RUN global.data_steal ...
# tls.c:3280:data_steal:Expected recv(cfd, buf2, sizeof(buf2), MSG_DONTWAIT) (10000) == -1 (-1)
# data_steal: Test failed
# FAIL global.data_steal
not ok 8 global.data_steal

The 10000 bytes read suggests that the child process did a recv()
of half of the data using the TLS ULP and we're now getting the
remaining half. The intent of the test is to get the child to
enter _TCP_ recvmsg handler, so it needs to enter the syscall before
parent installed the TLS recvmsg with setsockopt(SOL_TLS).

Instead of the 10msec sleep send 1 byte of data and wait for the
child to consume it.

Reviewed-by: Sabrina Dubroca <sd@queasysnail.net>
Link: https://patch.msgid.link/20260106200205.1593915-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+12 -4
+12 -4
tools/testing/selftests/net/tls.c
··· 3260 3260 ASSERT_EQ(setsockopt(cfd, IPPROTO_TCP, TCP_ULP, "tls", sizeof("tls")), 0); 3261 3261 3262 3262 /* Spawn a child and get it into the read wait path of the underlying 3263 - * TCP socket. 3263 + * TCP socket (before kernel .recvmsg is replaced with the TLS one). 3264 3264 */ 3265 3265 pid = fork(); 3266 3266 ASSERT_GE(pid, 0); 3267 3267 if (!pid) { 3268 - EXPECT_EQ(recv(cfd, buf, sizeof(buf) / 2, MSG_WAITALL), 3269 - sizeof(buf) / 2); 3268 + EXPECT_EQ(recv(cfd, buf, sizeof(buf) / 2 + 1, MSG_WAITALL), 3269 + sizeof(buf) / 2 + 1); 3270 3270 exit(!__test_passed(_metadata)); 3271 3271 } 3272 3272 3273 - usleep(10000); 3273 + /* Send a sync byte and poll until it's consumed to ensure 3274 + * the child is in recv() before we proceed to install TLS. 3275 + */ 3276 + ASSERT_EQ(send(fd, buf, 1, 0), 1); 3277 + do { 3278 + usleep(500); 3279 + } while (recv(cfd, buf, 1, MSG_PEEK | MSG_DONTWAIT) == 1); 3280 + EXPECT_EQ(errno, EAGAIN); 3281 + 3274 3282 ASSERT_EQ(setsockopt(fd, SOL_TLS, TLS_TX, &tls, tls.len), 0); 3275 3283 ASSERT_EQ(setsockopt(cfd, SOL_TLS, TLS_RX, &tls, tls.len), 0); 3276 3284