From nobody Wed Jun 17 01:52:43 2026 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 2751B35A3A4 for ; Tue, 21 Apr 2026 12:31:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776774689; cv=none; b=Qp/ghy4eF1QNskPpsNsXIVtp3RvkZ/7TjF6HuR3aYx6Zqn243grlqMoR8XiRXdnGTqKkdqlIbcOItXO1nCNTVZkCiM2/GGffiF2AW+DcGPxlv1kNF3mZSUE8HNkhOc+n0mMRZQV9sLKJF3CAGWSj9IzcY3v5Fr6kVDkP/0S1dEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776774689; c=relaxed/simple; bh=usACHL7JFJ+Iojq2WMGOR+XEp5pZozfvJwRKATA+b/g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fjMFC929PqYY4gdyXtiQ2i4dX4BbQSwx3E0g4G+okF7znYH2RUFeXlFoAYgsKBzCy6I87D42NBFI6EPf3dUU2l9S8KGMiAiUaG6FJ8tOBLG/r0v0q5JfW23TZFIUa9B1pt6B+VdnAtZixKWfylsRCx3tP6dCP0k+/IXFw7UefBU= 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=oZqwRoox; arc=none smtp.client-ip=209.85.214.175 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="oZqwRoox" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2b25cf1b5f0so22894875ad.3 for ; Tue, 21 Apr 2026 05:31:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776774684; x=1777379484; 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=2qCHQt+5njpxpDnHvEMfTt2VrNOBnIxuj1+x6opPunc=; b=oZqwRooxG1EQH9IR+N9JAP7ZGi/X6mEnWAfgIFe7c9aTqD7y+/Z73H9SZ3hweSWuGH vT/mns5SFKsLhas35xVi2T3C7uJecCWP01AM24PuEgeYmcWiSxBYWYEU8IvV94A0SzjQ uWoht621Kw/J3Gis5Ne5txUs+fodLf81/IAPS+VMNqjI3lFPsDhqEP8z07bIzbg2Avj5 lStzqXo9B9dcY+549BVBnpEUBtnbTTWc2a6AXd9MssAqL3nFuf0iIkSGNwfxRXSUq9Ss zfWtF+5zsaty7+rlLN4JGRlik78MrXiq2EmLUQcQ/EQShIDoVDsZrLO5RDXEcjqh3taV YWlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776774684; x=1777379484; 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=2qCHQt+5njpxpDnHvEMfTt2VrNOBnIxuj1+x6opPunc=; b=NCZ6gleoCYA+RQiTO6/BLYSYl1Syeb12JZ2pU1RbK9VI5TFGrh0ouJBH6hqHlBM/GL Z9aJDc8DyRpyiZArj9T0kfRq1wMvd7o0+g8UDX83TEly/BnsX95fUZptjILmSeIlt0dK NMWawR/Qrg/FH9K11IkxJSksoFrKqsMQ9aZOznd5FRn1cR0GUBNZs9U3pZ0/W4HQ7+Tx OVJ9cmCHgLoYXzMSZnjRmv4AzLgV61qA7STeXqTVpLsPS9Nbi9y8pYhXxAImucLa+L0F iOaaeDp+/QyR7OGiIOPGjhcjnS3ie/CDNrY1RdRs26XXeHgeMd6B3CDidCqSYBtb4ns8 +jNA== X-Forwarded-Encrypted: i=1; AFNElJ/eHzPuUhzle0904p+Hs2qqiuMVO3X5BIUauBpgdoxE1GjvFvjHsxW9WvB2msIv+ODlrPOiTr/Icfco78A=@vger.kernel.org X-Gm-Message-State: AOJu0YytmxWD5l6xEQZZ7oI2PB32blhX3GeBdIJ+tPUc3N+SYT0XgBae hBzSRa+8Gq13eqrXVtzdBiv7qC6qn1qsh1o+V39HUdNfdLsnVXMSZFYM X-Gm-Gg: AeBDieukAssuFa/bRp7fTElVZcNAR3YDONieXSqcXEu1j3cNP67jXzjHqv/PWrrcppX Ug+92qkTzjDqwCdBKkUeqxsiwJGEAudvCVZRt3Bt1+D8Bjah955Hpthq8lWjiXCxFKWSbB1a0FC x9Y1Llg53RrU9byA6iYpsJLOOf/GSkapZBdq6z8pKv26YOgjoEmx+AbyuVDtXpbAyEwklW0wi1w 81RVGdDmRg0gz7PTQMEPd+oXXEp7YRpzVaCoO3sVJCGkSk06CoOqZRb3MfXhCa7ip8FdGBKkwpi hSMU242cS0w90eiMaBMzNluHNeO5JZVtASpeoVJZkjcI9BufRQGfvOXlQSnXu1RYP0WnXxfkyTJ nIc7tsz5wXVQ8Ddz3CXj2qA4EEno2xWenWf5mpuSupjwHe34DObSxUU7mH5UoAofJxWBg9NGrqk Fopf7dGkquHZHR6oK/scX6Y4QVMOT2CMOAmzZ/vmHsQy0Lag0vt8FmXW75qsS7ag== X-Received: by 2002:a17:902:db10:b0:2b2:4a9a:b149 with SMTP id d9443c01a7336-2b5f9e79dcfmr197068945ad.9.1776774683926; Tue, 21 Apr 2026 05:31:23 -0700 (PDT) Received: from DESKTOP-MUHC17F.tail07b66e.ts.net ([188.253.121.151]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b5fa9ff409sm169724315ad.14.2026.04.21.05.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2026 05:31:23 -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 v3 1/2] tcp: call sk_data_ready() after listener migration Date: Tue, 21 Apr 2026 20:31:05 +0800 Message-ID: <20260421123106.142299-2-jt26wzz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260421123106.142299-1-jt26wzz@gmail.com> References: <20260421123106.142299-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 Signed-off-by: Zhenzhong Wu Reviewed-by: Kuniyuki Iwashima --- 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 Wed Jun 17 01:52:43 2026 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (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 73E723CB2DC for ; Tue, 21 Apr 2026 12:31:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776774694; cv=none; b=Pd5WAJaTubvZBw2n8sfzXtkPKfbxnikKfsgi0L0xxtsUXF0qT98EwB4l2Xpik6qKnPSArfHOdxFAO/CUNO8+8fxlYatapR7C9vb3CO6VIyM49Fi4zoAgXzbuI9USSWv+8XEV+IeEEvyBxIrWXUvmEn0CC3RmQGv8pmHicO5Ccrk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776774694; c=relaxed/simple; bh=w884/R5pRr4A9Ao3FZ4s632FkuobTk5hiTXn9qCtIm8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MFE+AkhxtKaUsD8TLWow/AnAj/e4aiQ7njQ62EFnXy3EREvvidRVrBDMVXZZuW7IpPc1FVbZAZDmZhhB8KYM4ZU0bXROu1PMa7igj6OYYZ+8nxDE9OQ7CEwObErAZAi1XcDbCYgMTjLmSSMk2gWNxGr9sJhg6SnWcLvTSWYgoWo= 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=lAFCK7qZ; arc=none smtp.client-ip=209.85.215.176 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="lAFCK7qZ" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-c795a47186bso1639503a12.0 for ; Tue, 21 Apr 2026 05:31:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776774689; x=1777379489; 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=MfSMMYYOulor7sfQhsaown6uCtV1QzJ0oZSRjmjzgNk=; b=lAFCK7qZfgCVLE2+iHUNp76bMMvpI5XdqYHfJC++v1x1nV2sxfP1mGU+XZF49eY3Qg GY8/l8VeSKedA68mv63mRQO/AOePhkriKrZCCSpWimFlIiEYWg2/3LUWWdpzTVjFEdGc Y+NeGfcHfB0u76IeKYVEgDPb18UY8RFbcfd2eBfRQBkHCid8LGdMgTEpqtBER0GCdMly VFJ0/WBignMqLlCs5+DRddlJPh+9T8+92b5cNWeVKb6/Hdfm8gGAXIAZEv9v3dKU/b1p 6uOhwfChOVgUs/ObL6xV7kdZ74eIuKsLm/ZkF50I4T88vcgF0uAEpzaTJa6TwelkgHBh bZZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776774689; x=1777379489; 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=MfSMMYYOulor7sfQhsaown6uCtV1QzJ0oZSRjmjzgNk=; b=nySjCpUmJXnlSoq7V1fG1+ujEcnNqOLza1+RVNz4yfvT4GEsvgpmF90LaDkIanbTlq CfkxCVaw9KS2HVUqcNDBUC++WI6CixemsufxPzyzg4ML+glhccddXFP8UbjVjeizM/u1 1IeBkJ3o8NPJBTVcoZy4yYSy3FJEJYyLZquGLEFLzdBQTiMkbxOJvP1IkpGCpOl4D2XN 92aLUrRrMlEr2zwk4JNxEV06eO34nl/BiNnUkqgDbYBEJAW+fA9F6aK2xZCdf/AfgqIP OSmxKDT9RwXfuBWMMBq0QI9zNDVnDic+dIdNq0aaDViWKjghPeRN0i5RgvVQFR96SUkF 6yjA== X-Forwarded-Encrypted: i=1; AFNElJ9eeLYt0OJicBei3IY9HKNLjZBxlekjv3pXnu7o8NG/0V3KFBm6Yarm7je4YWF2yWYmkxSp6oMbF2OfUAQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yzi72xH4SssSN9edMBGRcp7vnAXQiB8/Q4bn9h1J9SWRd3fuVAx hifK+3h1fnMYBhS4/aOJp7bZNHEihkQ3HiqJJ1NjNeOd5uUmM8CTOnK6 X-Gm-Gg: AeBDietj/2KNKVQ5SH+nrvn/eYb+GI3Cd7dHmPBDwJ9nWw1buSCv7mtnda4pjeeo5Cq 3h2oGBK5AlJ0K/96g01O9zczR6k/11uf5M2Btc7nASeu6Rzfhkw1QkRRAMQM/ygNPshlNGOJeB6 rGEsJgbeFxo5Sl5Aut3EzjlERr08Oo6Y8ClNQ2sEgHpmtxl3jj1Wisz4kWUSS673JIy8VMEnmgT rcnBGxmXVWXZwj4U3E4M1f7dm5jmgnEJkSfHGegTMqAhfSQhoaDQoBXFDo0bJEAt0hL8283OaT/ k/HUuNA6qaH2TnS/5j07o1L5pu+HDLZ3LsOHrbeGWHyjxSN9XfpmkMv87oxW0fWio/j8biYaZXz JgM3X0Pv1l9ET5JFZCOtPiPQKziaxPiaWMmGzFwp9WhD71kkmS9udw1PKwMm2rzWcJam7f0WQcd BayXER4i2MOCvSLThaMiba28bn3IRUhxLqNBxWufXm40+vcTXrxrOoO/5ErM7ZiN/p2WIrsT8L X-Received: by 2002:a17:902:bb96:b0:2b2:5168:2f82 with SMTP id d9443c01a7336-2b5f9ed4d0cmr96165515ad.24.1776774689295; Tue, 21 Apr 2026 05:31:29 -0700 (PDT) Received: from DESKTOP-MUHC17F.tail07b66e.ts.net ([188.253.121.151]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b5fa9ff409sm169724315ad.14.2026.04.21.05.31.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2026 05:31:28 -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 v3 2/2] selftests/bpf: check epoll readiness during reuseport migration Date: Tue, 21 Apr 2026 20:31:06 +0800 Message-ID: <20260421123106.142299-3-jt26wzz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260421123106.142299-1-jt26wzz@gmail.com> References: <20260421123106.142299-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 Signed-off-by: Zhenzhong Wu Reviewed-by: Kuniyuki Iwashima --- .../bpf/prog_tests/migrate_reuseport.c | 46 ++++++++++++++++--- 1 file changed, 40 insertions(+), 6 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..6180a79a7 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,8 +355,28 @@ static int update_maps(struct migrate_reuseport_test_c= ase *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. */ @@ -365,6 +390,15 @@ static int migrate_dance(struct migrate_reuseport_test= _case *test_case) 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: + close(epoll); + return -1; + } + + close(epoll); + /* Note that we use the second listener instead of the * first one here. * --=20 2.43.0