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/bpf: Fix sockmap_multi_channels reliability

Previously I added a FIONREAD test for sockmap, but it can occasionally
fail in CI [1].

The test sends 10 bytes in two segments (2 + 8). For UDP, FIONREAD only
reports the length of the first datagram, not the total queued data.
The original code used recv_timeout() expecting all 10 bytes, but under
high system load, the second datagram may not yet be processed by the
protocol stack, so recv would only return the first 2-byte datagram,
causing a size mismatch failure.

Fix this by receiving exactly the expected bytes (matching FIONREAD) in
the first recv. The remaining datagram is then consumed in a second recv
block, which is only reachable for UDP since TCP's expected already
equals sizeof(buf).

Test:
./test_progs -a sockmap_basic
410/1 sockmap_basic/sockmap create_update_free:OK
...
Summary: 1/35 PASSED, 0 SKIPPED, 0 FAILED

[1] https://github.com/kernel-patches/bpf/actions/runs/22919385910/job/66515395423

Cc: Jiayuan Chen <jiayuan.chen@linux.dev>
Fixes: 17e2ce02bf56 ("selftests/bpf: Add tests for FIONREAD and copied_seq")
Signed-off-by: Jiayuan Chen <jiayuan.chen@shopee.com>
Link: https://lore.kernel.org/r/20260312072549.6766-1-jiayuan.chen@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Jiayuan Chen and committed by
Alexei Starovoitov
d9d7125e 2790db20

+15 -2
+15 -2
tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
··· 1298 1298 avail = wait_for_fionread(p1, expected, IO_TIMEOUT_SEC); 1299 1299 ASSERT_EQ(avail, expected, "ioctl(FIONREAD) full return"); 1300 1300 1301 - recvd = recv_timeout(p1, rcv, sizeof(rcv), MSG_DONTWAIT, 1); 1302 - if (!ASSERT_EQ(recvd, sizeof(buf), "recv_timeout(p1)") || 1301 + recvd = recv_timeout(p1, rcv, expected, MSG_DONTWAIT, 1); 1302 + if (!ASSERT_EQ(recvd, expected, "recv_timeout(p1)") || 1303 1303 !ASSERT_OK(memcmp(buf, rcv, recvd), "data mismatch")) 1304 1304 goto end; 1305 + 1306 + /* process remaining data for udp if secondary data is available */ 1307 + expected = sizeof(buf) - expected; 1308 + if (expected) { 1309 + avail = wait_for_fionread(p1, expected, IO_TIMEOUT_SEC); 1310 + ASSERT_EQ(avail, expected, "second ioctl(FIONREAD) full return"); 1311 + 1312 + recvd = recv_timeout(p1, rcv, expected, MSG_DONTWAIT, 1); 1313 + if (!ASSERT_EQ(recvd, expected, "second recv_timeout(p1)") || 1314 + !ASSERT_OK(memcmp(buf + sizeof(buf) - expected, rcv, recvd), 1315 + "second data mismatch")) 1316 + goto end; 1317 + } 1305 1318 end: 1306 1319 if (c0 >= 0) 1307 1320 close(c0);