[PATCH net v2 2/2] selftests/bpf: check epoll readiness after reuseport migration

Zhenzhong Wu
2026-04-18T18:14:05Z

After migrate_dance() moves established children to the target
listener, add it to an epoll set and verify that epoll_wait(..., 0)
reports it ready before accept().

This adds epoll coverage for the TCP_ESTABLISHED reuseport migration
case in migrate_reuseport.

Keep the check limited to TCP_ESTABLISHED cases. TCP_SYN_RECV and
TCP_NEW_SYN_RECV still depend on asynchronous handshake completion,
so a zero-timeout epoll_wait() would race there.

Signed-off-by: Zhenzhong Wu <jt26wzz@gmail.com>
---
.../bpf/prog_tests/migrate_reuseport.c | 32 ++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/migrate_reuseport.c b/tools/testing/selftests/bpf/prog_tests/migrate_reuseport.c
index 653b0a20f..580a53424 100644
--- a/tools/testing/selftests/bpf/prog_tests/migrate_reuseport.c
+++ b/tools/testing/selftests/bpf/prog_tests/migrate_reuseport.c
@@ -18,13 +18,16 @@
* 9. call shutdown() for the second server
* and migrate the requests in the accept queue
* to the last server socket.
- * 10. call accept() for the last server socket.
+ * 10. for TCP_ESTABLISHED cases, call epoll_wait(..., 0)
+ * for the last server socket.
+ * 11. call accept() for the last server socket.
*
* Author: Kuniyuki Iwashima <kuniyu@amazon.co.jp>
*/

#include <bpf/bpf.h>
#include <bpf/libbpf.h>
+#include <sys/epoll.h>

#include "test_progs.h"
#include "test_migrate_reuseport.skel.h"
@@ -522,6 +525,33 @@ static void run_test(struct migrate_reuseport_test_case *test_case,
goto close_clients;
}

+ /* Only TCP_ESTABLISHED has already-migrated accept-queue entries
+ * here. Later states still depend on follow-up handshake work.
+ */
+ if (test_case->state == BPF_TCP_ESTABLISHED) {
+ struct epoll_event ev = {
+ .events = EPOLLIN,
+ };
+ int epfd;
+ int nfds;
+
+ epfd = epoll_create1(EPOLL_CLOEXEC);
+ if (!ASSERT_NEQ(epfd, -1, "epoll_create1"))
+ goto close_clients;
+
+ ev.data.fd = test_case->servers[MIGRATED_TO];
+ if (!ASSERT_OK(epoll_ctl(epfd, EPOLL_CTL_ADD,
+ test_case->servers[MIGRATED_TO], &ev),
+ "epoll_ctl"))
+ goto close_epfd;
+
+ nfds = epoll_wait(epfd, &ev, 1, 0);
+ ASSERT_EQ(nfds, 1, "epoll_wait");
+
+close_epfd:
+ close(epfd);
+ }
+
count_requests(test_case, skel);

close_clients:
--
2.43.0