From nobody Tue Jun 16 09:59:43 2026 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEEF7394497 for ; Wed, 22 Apr 2026 02:46:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776826004; cv=none; b=E//ueD00R/84s7gbxiyakM/m+0Eugp6nya0EqSlVI3WtH2MwCG46MX/ldDaEDSltVv+S6Qz/q4YdB8ahvPNaQtT3gvNp95ZG00RcZe6sdxngk864cFUMVtPIGn5Vi5aKyGRBcApXjvZGCtRuRjVBZjEfg7sq2GWlqcyRE4n87M8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776826004; c=relaxed/simple; bh=54mdUmpSfgqjXDGwvG814qjfvfFiFaCFWzugdgFYZ/s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OxFjVKGsHFt/gTFebNnoT0CJ1wzECwU0+KAXtiFe5E7789fXpQ3abnuzCSn3PYEgBADt7TtIIdxygGVapcuIJMhoWVdNIMjObz6Qkh5ypgkK3hbu8beLgdo+wTrKYatAHlzkTYYt+X4IBmiKpxxQaQ5uEToaROnMtOqDrNlXTDY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HlCKI4rc; arc=none smtp.client-ip=209.85.215.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HlCKI4rc" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-c70c112cb61so3285987a12.0 for ; Tue, 21 Apr 2026 19:46:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776825992; x=1777430792; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Fcd+LZFK9AMyl2emRFE9iJQXg1L+/s8eBXtgz15uq2o=; b=HlCKI4rcIT6GzPAm1eX0Dxdabz54vsziUFvzkUy73YnLUgbD8Ia/n8B8aqzSiKj8s5 aK9uYActb3pA6MwqlsO6lFSYkCpDap7nfZDhe0YKmHJmfpdt5+z5m7Kq0T+3Y4JafZHG gx2OgQ4yPXDOXSDFbn1IrabDS2Aa1OILkds2ImPDKvV3f3Q2glXQVLm6Tb/7DJbJU/S1 AMojfLiJlwxw8y8w9ZEsDSlTJ6Wap6Jt4s1bPs/GUPGC5EB7D8peYKvzxJLTccbag96n Ne5tGr5DaymAMfBM/iVjMhVqk3H0hHj7XBM4MIhPkk1PJTgOF5dtrHjkGG8XJmxg3zsJ AJPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776825992; x=1777430792; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Fcd+LZFK9AMyl2emRFE9iJQXg1L+/s8eBXtgz15uq2o=; b=tR2bBYgQtLoV2xGBvFWELCK2pbpFQ4JYUs355bB25/7aJbKTthB5M3bLRI4BZfF92D A6lqQMNUBK2AflglftN/LJWMq5bx62VGPOKRMA13RKF9dLoqlqdpWxoVMUPEMykK+Tt1 4TCqFZbiSM99JrSuhYdquyGz8E88BFncKQ+UsARSIdqwsxCLesXDVxrbcNPJoTkqT6bE 5ghGkIfL2DeFs9trlm98SVxN89XOz8sqU3xaAkwZE/DdIfZsv5RAUYi7sy5s7VaRn9F4 X/KXx16hv1dowdEk8Pn7/2lGuIC3ss8hx1CVCaxLeF+xPAaRze7BFwlynpTqAZ60Vl/Q OhFA== X-Forwarded-Encrypted: i=1; AFNElJ8C8haJAw+CDt+pQp8qRlCfgIlgUVfQfJpHPLjAcEftU3tUyokSra/xNZECAt2G3akbAd9vb9xgYvbfQDY=@vger.kernel.org X-Gm-Message-State: AOJu0YxxmvuYeTQsVA9plwT0NxfHvQMRYU2vHQqe2CokzObkT8MfG6Uh jxMTsn8+t/PVti2bSU+DBMigUwxllOP73EGpHVw9X3DASYwEfYj57sWj X-Gm-Gg: AeBDiesFLmAOpxIWjXTJRsInLyUZSSnaryLZ8WzDlIXWsBp0RCdVSetJPDAV3RiGVUR pY4fWzAbGBabUyQV9bBJsNNHNJXesm3DhuC27AVzbWSOAmDNEVWlTqvw6q1Ik4jUKMGLyYkqnC0 Ka39p9djKZEFDfgIxJBL3zUgxX+hPOH+OMFgvv67rj/v78qE1/6CfsNDtMlZSenYQXgGNatEXHY RWVzM7ECruF+1tyCFDiDi4y2li/gzNwBH+D7H1MHg+xOxbBso8z9JPm8KCvBq0MT2p8pX4OikNK q+CcizRFCAEZ4LvYxzOcGVvEqRpjAtlV/9Z8VkV8eLxoBc5VFf83M5Zbv7zH2KCjlVme3Er7kWR t+Fl17yFBydyoJnbbI/2fRI64D2po2GRs9MvL9F/rfsxhxe8SH9BMGC2TdS/8m+okFOIre5c8BU lQVdSqYGO0g2hdqTnDOf/2m4Y/5mnxq7EHYJmt/SpOXNXZkYMJtbppDFoOxbZ17g== X-Received: by 2002:a05:6a20:9187:b0:3a2:dd8a:5084 with SMTP id adf61e73a8af0-3a2dd8a5be1mr8799899637.37.1776825991972; Tue, 21 Apr 2026 19:46:31 -0700 (PDT) Received: from DESKTOP-MUHC17F.tail07b66e.ts.net ([188.253.121.151]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c7976f92183sm10656632a12.3.2026.04.21.19.46.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2026 19:46:31 -0700 (PDT) From: Zhenzhong Wu To: netdev@vger.kernel.org Cc: edumazet@google.com, ncardwell@google.com, kuniyu@google.com, davem@davemloft.net, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, shuah@kernel.org, tamird@kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Zhenzhong Wu , stable@vger.kernel.org Subject: [PATCH net v4 1/2] tcp: call sk_data_ready() after listener migration Date: Wed, 22 Apr 2026 10:45:53 +0800 Message-ID: <20260422024554.130346-2-jt26wzz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260422024554.130346-1-jt26wzz@gmail.com> References: <20260422024554.130346-1-jt26wzz@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When inet_csk_listen_stop() migrates an established child socket from a closing listener to another socket in the same SO_REUSEPORT group, the target listener gets a new accept-queue entry via inet_csk_reqsk_queue_add(), but that path never notifies the target listener's waiters. A nonblocking accept() still works because it checks the queue directly, but poll()/epoll_wait() waiters and blocking accept() callers can also remain asleep indefinitely. Call READ_ONCE(nsk->sk_data_ready)(nsk) after a successful migration in inet_csk_listen_stop(). However, after inet_csk_reqsk_queue_add() succeeds, the ref acquired in reuseport_migrate_sock() is effectively transferred to nreq->rsk_listener. Another CPU can then dequeue nreq via accept() or listener shutdown, hit reqsk_put(), and drop that listener ref. Since listeners are SOCK_RCU_FREE, wrap the post-queue_add() dereferences of nsk in rcu_read_lock()/rcu_read_unlock(), which also covers the existing sock_net(nsk) access in that path. The reqsk_timer_handler() path does not need the same changes for two reasons: half-open requests become readable only after the final ACK, where tcp_child_process() already wakes the listener; and once nreq is visible via inet_ehash_insert(), the success path no longer touches nsk directly. Fixes: 54b92e841937 ("tcp: Migrate TCP_ESTABLISHED/TCP_SYN_RECV sockets in = accept queues.") Cc: stable@vger.kernel.org Suggested-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima Signed-off-by: Zhenzhong Wu Reviewed-by: Eric Dumazet --- net/ipv4/inet_connection_sock.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_soc= k.c index 4ac3ae1bc..928654c34 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -1479,16 +1479,19 @@ void inet_csk_listen_stop(struct sock *sk) if (nreq) { refcount_set(&nreq->rsk_refcnt, 1); =20 + rcu_read_lock(); if (inet_csk_reqsk_queue_add(nsk, nreq, child)) { __NET_INC_STATS(sock_net(nsk), LINUX_MIB_TCPMIGRATEREQSUCCESS); reqsk_migrate_reset(req); + READ_ONCE(nsk->sk_data_ready)(nsk); } else { __NET_INC_STATS(sock_net(nsk), LINUX_MIB_TCPMIGRATEREQFAILURE); reqsk_migrate_reset(nreq); __reqsk_free(nreq); } + rcu_read_unlock(); =20 /* inet_csk_reqsk_queue_add() has already * called inet_child_forget() on failure case. --=20 2.43.0 From nobody Tue Jun 16 09:59:43 2026 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EFE1392C21 for ; Wed, 22 Apr 2026 02:46:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776826009; cv=none; b=CgbGVYxUTDBd2KUnhnjqmjcF5YGV74uUIrb5cpIVl2iaT00Hq/DyI81LeuQZGswDzPee1/K8ts2o0fV+i/FAqv3dxv+q9yekKzpr0gzmgITh2wrKaUxAVhimTbC42A+qtOJpDa2fq4TY+k24ZkYG7pVaFuGJdLeYJcKxSkMHVp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776826009; c=relaxed/simple; bh=0sA2sLWOI1+YrADOtn/nn5LqfxqcE06IldheBa+ejVk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AHZRDvsiudR7VJ8sHTLMMZhXxa4Ikt2J2vsIWTAQ3HrCBzDVvze7TRjnYUWBLKZv8LEkOnl3lH0+5KzeBsxp+OUweCKBnBdjShSnR57Kp44N17rK5xQ/1cNoIQUxBaTX6IE/LVX6pomtPrTD0BEfSWwQx2LQNy6NaJecZFgvMZ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=pikjsedV; arc=none smtp.client-ip=209.85.215.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pikjsedV" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-c7963df6f17so3271826a12.0 for ; Tue, 21 Apr 2026 19:46:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776825999; x=1777430799; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lS/6+OQwHBm0U4E/bt3m5g//SPZTdfGBYdVOL3eGpDw=; b=pikjsedV/6GXojXW6P3fNbkfSD/yuiKE62Q2hOY9r3IVyzRPPoSJecEYQ/6QplW3IU UeJSINZG+lkosuUVyjBCF8oJjqLW+1AirhSLsKfsKPL7XnlDaZSBUSP8UDp9+mtkZEqr rOXj+aJSkOMTSy1102dXwJeKZWbNJibAsjhZGEbtD1Hja4GCTqbmcHr0CHBfzVDRVonY M6BjClsCLIiMcSkWvyepNz66U6HAoJlLL4EHYibdVFaDKQKTjX2w/Avjx9jCAkQ8dn+G Iu2RTIY2e67W0XKDqLIFygz2yE24Q7cftRn3Y638OWsgOURs9D5sgMYiDF7KWdzD+CqL eXLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776825999; x=1777430799; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=lS/6+OQwHBm0U4E/bt3m5g//SPZTdfGBYdVOL3eGpDw=; b=sFlVPVYvd6OmMG/juIWX5/6WqEoJbPi5CMcJ2DOv/P+iWPGQcT8uBDDC8NiRZlpJ7b 5NcI2lZEYkLinwQtaMm6GEtdydyMosG4dkKCQWzUECvSn/EB+rv29s7z8VG27DKu/7OE XUVne3dt7YuyDLYQ9/oFZuX6BIfd06Exd/O7KwszU4+P7k1FLi7reNk3/l70O9kI+IRU R5bcqyWXK2kKvJnvV79vEyq0Rls5lmdlryeXlrcIPYDBHdpR3ZkaV7JagcmZ/sAHKCGB 18RmkikqY8jVUhexz7+mbTptTLcs+c4TeNtQK6WY7BK2QwIYam6zaaKdYXSfd8isPTYs sceg== X-Forwarded-Encrypted: i=1; AFNElJ+fBVJOASWYMs9yvEtyJBemwnhEiPLNe7ShdiD7+pbLHVLU0h83sBkpnRydA8kGjOKK+agGjGPWpTCSifE=@vger.kernel.org X-Gm-Message-State: AOJu0YxdvECx0oIrBUtcNmBZKUOMIpGYs+LTSzJuz7r4XCnRIgOV41H2 SSFeN7FXOX8wo1YhBtCCIOWPeTQOhUK/xKkrXBjjJXIIRIIFjo9pbPZ/ X-Gm-Gg: AeBDiev8vGTjmMPDfl8wS1kNn4eUsP/5In4zzayt3oxN76orhbJkCrySAJHE11fi0gL 3ANey5Kdw0VpuDCLpUGnI1alGzjWLz52xc6SUlsO6rKhuesTOeznFa0WO+78vEoTo9xENkq38MU XSPM6vCX3dzHKG9nFeOI2cT+Yr3g9Ov9kwwjY3fPKlw6jc7qF4yLFHIi4wyUeSCZ4t1EdcOpm0q Jj/MKOa+SutlBtAABNGxOTPyLTOPZXrjbwK6ArrlHh2To9NPj8jIY8BhF3NevduoCFjyMMrqSHp AtlzYJmaIx/u+Lj8cHqI2YNbkZpMbunvpgLfTyebbDF/7yqoalxvI6TTiYNGI+pGnXAWO8+nUqp U+TkVBtK4/FAsBcU/PzZRBIcmFOIFKZli+aJpAjMBwV84CXct+H0YYsz+bWvaiRbwSpSqVqU27v x7a4f0FeSB8sDiQ04evd1bLp3CAcqf4gW9rcxk2pYLOKIUnU0XW3CK/GdmGJt1UQ== X-Received: by 2002:a05:6a21:32a1:b0:3a2:f402:50fb with SMTP id adf61e73a8af0-3a2f402551emr4604812637.34.1776825999302; Tue, 21 Apr 2026 19:46:39 -0700 (PDT) Received: from DESKTOP-MUHC17F.tail07b66e.ts.net ([188.253.121.151]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c7976f92183sm10656632a12.3.2026.04.21.19.46.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2026 19:46:38 -0700 (PDT) From: Zhenzhong Wu To: netdev@vger.kernel.org Cc: edumazet@google.com, ncardwell@google.com, kuniyu@google.com, davem@davemloft.net, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, shuah@kernel.org, tamird@kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Zhenzhong Wu Subject: [PATCH net v4 2/2] selftests/bpf: check epoll readiness during reuseport migration Date: Wed, 22 Apr 2026 10:45:54 +0800 Message-ID: <20260422024554.130346-3-jt26wzz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260422024554.130346-1-jt26wzz@gmail.com> References: <20260422024554.130346-1-jt26wzz@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Inside migrate_dance(), add epoll checks around shutdown() to verify that the target listener is not ready before shutdown() and becomes ready immediately after shutdown() triggers migration. Cover TCP_ESTABLISHED and TCP_SYN_RECV. Exclude TCP_NEW_SYN_RECV as it depends on later handshake completion. Suggested-by: Kuniyuki Iwashima Reviewed-by: Kuniyuki Iwashima Signed-off-by: Zhenzhong Wu --- .../bpf/prog_tests/migrate_reuseport.c | 49 ++++++++++++++++--- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/migrate_reuseport.c b/t= ools/testing/selftests/bpf/prog_tests/migrate_reuseport.c index 653b0a20f..c62907732 100644 --- a/tools/testing/selftests/bpf/prog_tests/migrate_reuseport.c +++ b/tools/testing/selftests/bpf/prog_tests/migrate_reuseport.c @@ -7,24 +7,29 @@ * 3. call listen() for 1 server socket. (migration target) * 4. update a map to migrate all child sockets * to the last server socket (migrate_map[cookie] =3D 4) - * 5. call shutdown() for first 4 server sockets + * 5. for TCP_ESTABLISHED and TCP_SYN_RECV cases, verify via epoll + * that the last server socket is not ready before migration. + * 6. call shutdown() for first 4 server sockets * and migrate the requests in the accept queue * to the last server socket. - * 6. call listen() for the second server socket. - * 7. call shutdown() for the last server + * 7. for TCP_ESTABLISHED and TCP_SYN_RECV cases, verify via epoll + * that the last server socket is ready after migration. + * 8. call listen() for the second server socket. + * 9. call shutdown() for the last server * and migrate the requests in the accept queue * to the second server socket. - * 8. call listen() for the last server. - * 9. call shutdown() for the second server + * 10. call listen() for the last server. + * 11. 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. + * 12. call accept() for the last server socket. * * Author: Kuniyuki Iwashima */ =20 #include #include +#include =20 #include "test_progs.h" #include "test_migrate_reuseport.skel.h" @@ -350,21 +355,51 @@ static int update_maps(struct migrate_reuseport_test_= case *test_case, =20 static int migrate_dance(struct migrate_reuseport_test_case *test_case) { + struct epoll_event ev =3D { + .events =3D EPOLLIN, + }; + int epoll =3D -1, nfds; int i, err; =20 + if (test_case->state !=3D BPF_TCP_NEW_SYN_RECV) { + epoll =3D epoll_create1(0); + if (!ASSERT_NEQ(epoll, -1, "epoll_create1")) + return -1; + + ev.data.fd =3D test_case->servers[MIGRATED_TO]; + if (!ASSERT_OK(epoll_ctl(epoll, EPOLL_CTL_ADD, + test_case->servers[MIGRATED_TO], &ev), + "epoll_ctl")) + goto close_epoll; + + nfds =3D epoll_wait(epoll, &ev, 1, 0); + if (!ASSERT_EQ(nfds, 0, "epoll_wait 1")) + goto close_epoll; + } + /* Migrate TCP_ESTABLISHED and TCP_SYN_RECV requests * to the last listener based on eBPF. */ for (i =3D 0; i < MIGRATED_TO; i++) { err =3D shutdown(test_case->servers[i], SHUT_RDWR); if (!ASSERT_OK(err, "shutdown")) - return -1; + goto close_epoll; } =20 /* No dance for TCP_NEW_SYN_RECV to migrate based on eBPF */ if (test_case->state =3D=3D BPF_TCP_NEW_SYN_RECV) return 0; =20 + nfds =3D epoll_wait(epoll, &ev, 1, 0); + if (!ASSERT_EQ(nfds, 1, "epoll_wait 2")) { +close_epoll: + if (epoll >=3D 0) + close(epoll); + return -1; + } + + close(epoll); + /* Note that we use the second listener instead of the * first one here. * --=20 2.43.0