From patchwork Mon May 6 03:05:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shaozhengchao X-Patchwork-Id: 13654856 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CFCC43D962; Mon, 6 May 2024 03:00:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714964458; cv=none; b=dY7+FVOFqu3vFObiwByKr6szLR02QQFYMRVcAHpxqt+SaHN9Y/LjRKG9X+/zZHFTwUC+DoQA5fx/lh8lbrZIFU1ZR2cm8Jaxu3Mp4vlRTWk1irvWWz+DsMqL4i5+9uSbjHZnAbjZV1rzl2oCoktId3qGuBjN9Z5HaM0TDlDfEas= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714964458; c=relaxed/simple; bh=gkHtp+mL6QKdmOppvcNWD0+TOJ5t26m3yhmgs2JS50M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kMtn75uZSE5n6vAoR4hNU5r1a22uiYz7KmMy7GP/1QeFkJ4th4PTjC1eHjpQmFIoTQQpiP2KXKY11WSgc53R37E7HiTCYT08vuFTy0gemSBIoxvrwdZYyJtR0rSCl8v3AJmjqeW/MHYpJXyQCGiPTB2xQb58G3WJBraARkqPHGE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4VXmKk5qpGzxNnj; Mon, 6 May 2024 10:57:30 +0800 (CST) Received: from dggpeml500026.china.huawei.com (unknown [7.185.36.106]) by mail.maildlp.com (Postfix) with ESMTPS id 6690E18007F; Mon, 6 May 2024 11:00:54 +0800 (CST) Received: from huawei.com (10.175.101.6) by dggpeml500026.china.huawei.com (7.185.36.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Mon, 6 May 2024 11:00:53 +0800 From: Zhengchao Shao To: CC: , , , , , , , , , , Subject: [PATCH stable,5.15 1/2] Revert "tcp: Fix NEW_SYN_RECV handling in inet_twsk_purge()" Date: Mon, 6 May 2024 11:05:53 +0800 Message-ID: <20240506030554.3168143-2-shaozhengchao@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240506030554.3168143-1-shaozhengchao@huawei.com> References: <20240506030554.3168143-1-shaozhengchao@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500026.china.huawei.com (7.185.36.106) X-Patchwork-Delegate: kuba@kernel.org This reverts commit 4fa0befa92f2adaef8eb268f724f38a213ab7dcc. In order to revert commit 214a2dfbb84f("tcp: Clean up kernel listener's reqsk in inet_twsk_purge()"), revert this patch. Signed-off-by: Zhengchao Shao --- net/ipv4/inet_timewait_sock.c | 41 +++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c index 25809e06f111..9b891d6296ec 100644 --- a/net/ipv4/inet_timewait_sock.c +++ b/net/ipv4/inet_timewait_sock.c @@ -254,12 +254,12 @@ void __inet_twsk_schedule(struct inet_timewait_sock *tw, int timeo, bool rearm) } EXPORT_SYMBOL_GPL(__inet_twsk_schedule); -/* Remove all non full sockets (TIME_WAIT and NEW_SYN_RECV) for dead netns */ void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family) { + struct inet_timewait_sock *tw; + struct sock *sk; struct hlist_nulls_node *node; unsigned int slot; - struct sock *sk; for (slot = 0; slot <= hashinfo->ehash_mask; slot++) { struct inet_ehash_bucket *head = &hashinfo->ehash[slot]; @@ -268,35 +268,38 @@ void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family) rcu_read_lock(); restart: sk_nulls_for_each_rcu(sk, node, &head->chain) { - int state = inet_sk_state_load(sk); + if (sk->sk_state != TCP_TIME_WAIT) { + /* A kernel listener socket might not hold refcnt for net, + * so reqsk_timer_handler() could be fired after net is + * freed. Userspace listener and reqsk never exist here. + */ + if (unlikely(sk->sk_state == TCP_NEW_SYN_RECV && + hashinfo->pernet)) { + struct request_sock *req = inet_reqsk(sk); + + inet_csk_reqsk_queue_drop_and_put(req->rsk_listener, req); + } - if ((1 << state) & ~(TCPF_TIME_WAIT | - TCPF_NEW_SYN_RECV)) continue; + } - if (sk->sk_family != family || - refcount_read(&sock_net(sk)->ns.count)) + tw = inet_twsk(sk); + if ((tw->tw_family != family) || + refcount_read(&twsk_net(tw)->ns.count)) continue; - if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt))) + if (unlikely(!refcount_inc_not_zero(&tw->tw_refcnt))) continue; - if (unlikely(sk->sk_family != family || - refcount_read(&sock_net(sk)->ns.count))) { - sock_gen_put(sk); + if (unlikely((tw->tw_family != family) || + refcount_read(&twsk_net(tw)->ns.count))) { + inet_twsk_put(tw); goto restart; } rcu_read_unlock(); local_bh_disable(); - if (state == TCP_TIME_WAIT) { - inet_twsk_deschedule_put(inet_twsk(sk)); - } else { - struct request_sock *req = inet_reqsk(sk); - - inet_csk_reqsk_queue_drop_and_put(req->rsk_listener, - req); - } + inet_twsk_deschedule_put(tw); local_bh_enable(); goto restart_rcu; } From patchwork Mon May 6 03:05:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shaozhengchao X-Patchwork-Id: 13654857 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C40B33D962; Mon, 6 May 2024 03:01:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714964464; cv=none; b=AwTt1a7PcXJFp9JU5KrycooXqG2EQjtZ5HOv40Kw0v1OgyImfkyoR1N+dOn/8Q006YZo4BNXGN4g0XSAcw8pql9H5qgH1hlCbqfFhw1JsW8iGJcCGLAdU1tdZhaKTnbssY32Jix0ptdGr4v0TRAvwGzYOIUsVVIaaHWwl11zS4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714964464; c=relaxed/simple; bh=G82w4oC74SxKbCo4N1C/GZmobpclwQOErUQo48U/lF0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Srz8IjQzs3+u5kPTeOkKXlUEDFb6aZadtdeuYGY2FCbcpgpX+4LkF47jEmOV8b5rCnTVPimVNGkegLvyj1Gd4oNxi2o6oSHfJ63KI0NHQTRzvaLP1QDmNjxycwhGCi+JUVJ/W2PSMHDmhFdNhQJ25UPTk29Z+C2T5vFhO70o5mU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4VXmKw33Rcz2Ccv8; Mon, 6 May 2024 10:57:40 +0800 (CST) Received: from dggpeml500026.china.huawei.com (unknown [7.185.36.106]) by mail.maildlp.com (Postfix) with ESMTPS id EC9B0140155; Mon, 6 May 2024 11:00:54 +0800 (CST) Received: from huawei.com (10.175.101.6) by dggpeml500026.china.huawei.com (7.185.36.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Mon, 6 May 2024 11:00:54 +0800 From: Zhengchao Shao To: CC: , , , , , , , , , , Subject: [PATCH stable,5.15 2/2] Revert "tcp: Clean up kernel listener's reqsk in inet_twsk_purge()" Date: Mon, 6 May 2024 11:05:54 +0800 Message-ID: <20240506030554.3168143-3-shaozhengchao@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240506030554.3168143-1-shaozhengchao@huawei.com> References: <20240506030554.3168143-1-shaozhengchao@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500026.china.huawei.com (7.185.36.106) X-Patchwork-Delegate: kuba@kernel.org This reverts commit 214a2dfbb84fcbdada0b1909ce843b7671b29d27. There's no "pernet" variable in the struct hashinfo. The "pernet" variable is introduced from v6.1-rc1. Revert this patch. Signed-off-by: Zhengchao Shao --- net/ipv4/inet_timewait_sock.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c index 9b891d6296ec..437afe392e66 100644 --- a/net/ipv4/inet_timewait_sock.c +++ b/net/ipv4/inet_timewait_sock.c @@ -268,21 +268,8 @@ void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family) rcu_read_lock(); restart: sk_nulls_for_each_rcu(sk, node, &head->chain) { - if (sk->sk_state != TCP_TIME_WAIT) { - /* A kernel listener socket might not hold refcnt for net, - * so reqsk_timer_handler() could be fired after net is - * freed. Userspace listener and reqsk never exist here. - */ - if (unlikely(sk->sk_state == TCP_NEW_SYN_RECV && - hashinfo->pernet)) { - struct request_sock *req = inet_reqsk(sk); - - inet_csk_reqsk_queue_drop_and_put(req->rsk_listener, req); - } - + if (sk->sk_state != TCP_TIME_WAIT) continue; - } - tw = inet_twsk(sk); if ((tw->tw_family != family) || refcount_read(&twsk_net(tw)->ns.count))