From patchwork Tue Jul 16 01:53:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13733979 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 2B39C322B for ; Tue, 16 Jul 2024 01:54:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721094847; cv=none; b=aaDfVE5OGMCbf7NvadnZKDDNs8AdfT/SFGrU39aGMM4Qcrj/LsmjZ4EHQy3WKiuoc/EwdEkBHEPgx+IJZBsTWK93BF+ecqhMZO7A6BaZz0DYAt0j0xbiKIx2LqFJmx3In4bbVisijDXV8Cu4h3YCQdzki5i9sf3QtYFkpKbaAnc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721094847; c=relaxed/simple; bh=rm7/4TMvJM9CsjR2LCBye9H2VHF/rr9uBtUeHt0WqMM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Er4L2wHCo3P0vWPhAMtbW+OwIaqIHPk1Taq88ijZgOjBQULdt4gD9X5sqfpeGOHtjQbKIfFdHJkdEx6Kn74mv5PWR351bsRSVUDdXUNl7asmWVYXOJns6QmSr85VaOjUd0JsBc7uUW/6FgOpHh69eOnxF2e6SfySq0kLLStvrqE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=IxGvqTuQ; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="IxGvqTuQ" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-65fdbfb8fe9so47449137b3.1 for ; Mon, 15 Jul 2024 18:54:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721094845; x=1721699645; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=cbW+1a3Lpqm3iHtH6XEfkAnexD0Pxnb0QkbIQ/mKzlc=; b=IxGvqTuQimPecaeAKC1/j9sXJ1z4u8JBIQY2oGPgQD8BKxkZsmyBN84BcwAwg1eBom 7Kuuy4w579KAatkWNyw6g71tO0KHxEXa7RkS2KoR67jUNRdPZsbzQNx/+4e2dxffc+iX gTXcrNM3m4EC5IUOGbLuB7HYQxp9fuGqJNMBuu33QeI1eLweAPsZ2vmIlGFppd7eDwA5 HGM/uWSHcOlY2rxpyAA0p2QJG1S23EkOBsj2mh7ZYBlBABLul9GOdaBllP6vmohQAH4u ZdSVQ6IdfxpK3jzHGSFVOpGkWZFmJ5TCaWxJYc6PQH5jtgRcDMxgLqVsNzBLsI7HF3WH dgOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721094845; x=1721699645; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cbW+1a3Lpqm3iHtH6XEfkAnexD0Pxnb0QkbIQ/mKzlc=; b=icfphwl1O9WhDi42eDXlodJTCcy9fz4CH7f1Uesc0sC7aVd2hRZl8Qd30Sc1g9GMCC 6jt8z3GAwbgHAI3bnKvgk8k9rT32UjfqkOAcZHIfhO3Bba/BZsBET5DU9rMBb4veCbtx d2+g4HPJO3ZzE8MhnuQAOpxCI5ajsj7j1VMHM+XcH7gVOQPtbTxgzNPwIPigN76+zk8Q s0GftmFtNCi4xi+wdGvwtBnYSCAe+D7U3Ico7LISgC0n1MjR3y/iMx5470TOkjzLIFBY IXo351hxAGB7JTHdWghVqGgGvgOnU0PxIHd/Q0/MHp7pkx7NN18O3pmzu9QLjqfvmo0D HxPg== X-Forwarded-Encrypted: i=1; AJvYcCW3VSgTh7MGX34OuKt41GMH9HucMO6npcjNI1Vjoh8C3EdAyQ7QIBWGsaZx6im7rvTZ0jXPVOKZkmfhnceMifIjFl+3JlYx X-Gm-Message-State: AOJu0YyxIiTPEmnk/Jp4YfadAHvrJEMhs4yPTEOh7sRpVywgRlY00W+k lOWl6iPDkbhgUWKttvKIII0aHwsSwPAbbC3U4Eufd8r5/Vmx8rVPcIwFFplTjjAzElJNVM2UkDM r2Ka7iO7rcg== X-Google-Smtp-Source: AGHT+IHDIOL1rhb+Vtx2I26UVtAqiCBLbwEkQTzaHO7G8bmvN0bkX8YmHNP6ntgeys+fjZgkKPHc0ZKuQ9T3aQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:690c:2b02:b0:648:afcb:a7d0 with SMTP id 00721157ae682-66381ac56acmr142387b3.8.1721094845121; Mon, 15 Jul 2024 18:54:05 -0700 (PDT) Date: Tue, 16 Jul 2024 01:53:57 +0000 In-Reply-To: <20240716015401.2365503-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240716015401.2365503-1-edumazet@google.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog Message-ID: <20240716015401.2365503-2-edumazet@google.com> Subject: [PATCH stable-5.4 1/4] tcp: refactor tcp_retransmit_timer() From: Eric Dumazet To: Greg Kroah-Hartman Cc: "David S . Miller" , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, eric.dumazet@gmail.com, Neal Cardwell , Jason Xing , Jon Maxwell , Kuniyuki Iwashima , Eric Dumazet , Willem de Bruijn , Soheil Hassas Yeganeh X-Patchwork-Delegate: kuba@kernel.org commit 0d580fbd2db084a5c96ee9c00492236a279d5e0f upstream. It appears linux-4.14 stable needs a backport of commit 88f8598d0a30 ("tcp: exit if nothing to retransmit on RTO timeout") Since tcp_rtx_queue_empty() is not in pre 4.15 kernels, let's refactor tcp_retransmit_timer() to only use tcp_rtx_queue_head() I will provide to stable teams the squashed patches. Signed-off-by: Eric Dumazet Cc: Willem de Bruijn Cc: Greg Kroah-Hartman Acked-by: Soheil Hassas Yeganeh Signed-off-by: David S. Miller --- net/ipv4/tcp_timer.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index e20fced3c9cf691c83b494e11e551161e17d6619..e0bd7999d6d51602fcd868a72d00618234bd0c27 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -452,6 +452,7 @@ void tcp_retransmit_timer(struct sock *sk) struct net *net = sock_net(sk); struct inet_connection_sock *icsk = inet_csk(sk); struct request_sock *req; + struct sk_buff *skb; req = rcu_dereference_protected(tp->fastopen_rsk, lockdep_sock_is_held(sk)); @@ -464,7 +465,12 @@ void tcp_retransmit_timer(struct sock *sk) */ return; } - if (!tp->packets_out || WARN_ON_ONCE(tcp_rtx_queue_empty(sk))) + + if (!tp->packets_out) + return; + + skb = tcp_rtx_queue_head(sk); + if (WARN_ON_ONCE(!skb)) return; if (!tp->snd_wnd && !sock_flag(sk, SOCK_DEAD) && @@ -496,7 +502,7 @@ void tcp_retransmit_timer(struct sock *sk) goto out; } tcp_enter_loss(sk); - tcp_retransmit_skb(sk, tcp_rtx_queue_head(sk), 1); + tcp_retransmit_skb(sk, skb, 1); __sk_dst_reset(sk); goto out_reset_timer; } From patchwork Tue Jul 16 01:53:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13733980 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 C2DAD63A9 for ; Tue, 16 Jul 2024 01:54:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721094849; cv=none; b=BTQkU1OQ+bTdJDpiSQSh35UntxltqBaP/+tF+emIjTBa6s4lZCsip+/g3MYDN+Enb5K6T3fkx+Nuz4TyIeZM+b4x4dnbHIEKj12cWOy5IppBEIqhhTQZJli6C1VBgU4gTU04WfHTjoeW1i3zYJtrOfhcCyaC0cpEeclZcliFD9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721094849; c=relaxed/simple; bh=x3SpAdnbMCNabIen2FgGGR6D3ta0bimwzrROf3/CXe8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JLhrHYnV5gIPt9wDlZHOcWFOYxwGtKMkoDtrFzdTNdOpOq7SSGB8lZLhKbxgASGhoq0jDixCAr/EpzZ/yjA1ofnk3p/z2hyJ1raqPFe3AUY+Ts7iqX56+05rQpzn1+DM4CblyWzTNaoAq5gDrLIqDJDY5SM5vnqNy9KtNIECIs0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CxHHb66E; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CxHHb66E" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e035f7b5976so9992462276.0 for ; Mon, 15 Jul 2024 18:54:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721094847; x=1721699647; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=FxjRjv96EaYNUeNOY6gCKi5ZK9ts3UABGiNVlj6fHw0=; b=CxHHb66EQOTbAbFH08wZ4i2rj/c1M4+/eygFRgk0TzVVLNTAx3/1cqVxBDE8nfFP3W TgICsM6vGSysYWtEq2EBB4IS/oatDjSevvu7Mb1mDwZYWpIe5BN6rY6UA5W+1lOXn1Mn vH2VQheMc9JxmvZjPsiU/6IAwf6hEvbjc54mG2tUYh/iBoGhoXXKqKeZHlLJF4CQB2y3 YyMBQjmLRYHavIXFe6BQcqk8FiJ2fav2YIv767KtOEBdrZmZK1LqOThN10kwqSfSGUxX R3pLU0uIpEex+TDwoI5Bkx5jRJuif0awtzzsBc1R6RdbDPyvZx+C52jlcDzDLI5Fdv3T SO+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721094847; x=1721699647; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FxjRjv96EaYNUeNOY6gCKi5ZK9ts3UABGiNVlj6fHw0=; b=R70Sx1pekhhIbeI2nBIDi+4zrbgOhXPcbzuvnoB4TO8EIwuLmFQ/9KsOlwZaLfhAdi J2uX8GwdDw5OzYmIsIehsc/1gushXulBrsAP133YBZczwVscGzwupds8nfZRd8cQdywy jqj6/UhIVxz5L5ArKmBkNp4kKyZNUkO4haTUqtt5kTYc8IDuYmJy8auptm2AH/Vhpkw5 HikpwH+vzoAJlaMdWKr0npXD/tEsucCJ4xk1vMa+sG0y59ZZsGZ2RpbFfe6XiShBo95O TarihNaZpNSVY4MZEOFEJQQlJXHNcC9QqX1lpYt5/d0LEttq5FYvYZvzab+hO5Wnr7j7 jTSw== X-Forwarded-Encrypted: i=1; AJvYcCVbV0hj/QWnCEstaAUJqRq/lAR7yu05ONaE3Ju3Kx6tn53FkY742PnSVQt5A8XllfZeyecT4VnHxiYvjvaTFMN9FSugg0dL X-Gm-Message-State: AOJu0YyiAjUBCFFk9G6ZMxYVBBvNb3eYUSEdmrkGpkSQSZNGoq9JzEE0 3WMiVnbVMQinWEaW0eIkEdhiFFck4Iu8g9qcNB2pbYq5y9XIkZoGwWmKF21ZSD8HZ1sTLk5S4Pr WX1v1VtkUoA== X-Google-Smtp-Source: AGHT+IECjVX8bXcVcLUgpPfZ0RSLETn9wR/B2515wkRjrMUVIlk3+lcSkMKJ9gxnVU9iIDz6dsZ4gh2lLkadRw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:51c1:0:b0:e03:a062:11b7 with SMTP id 3f1490d57ef6-e05d7e8f98dmr1240276.0.1721094846673; Mon, 15 Jul 2024 18:54:06 -0700 (PDT) Date: Tue, 16 Jul 2024 01:53:58 +0000 In-Reply-To: <20240716015401.2365503-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240716015401.2365503-1-edumazet@google.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog Message-ID: <20240716015401.2365503-3-edumazet@google.com> Subject: [PATCH stable-5.4 2/4] net: tcp: fix unexcepted socket die when snd_wnd is 0 From: Eric Dumazet To: Greg Kroah-Hartman Cc: "David S . Miller" , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, eric.dumazet@gmail.com, Neal Cardwell , Jason Xing , Jon Maxwell , Kuniyuki Iwashima , Menglong Dong , Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong commit e89688e3e97868451a5d05b38a9d2633d6785cd4 upstream. In tcp_retransmit_timer(), a window shrunk connection will be regarded as timeout if 'tcp_jiffies32 - tp->rcv_tstamp > TCP_RTO_MAX'. This is not right all the time. The retransmits will become zero-window probes in tcp_retransmit_timer() if the 'snd_wnd==0'. Therefore, the icsk->icsk_rto will come up to TCP_RTO_MAX sooner or later. However, the timer can be delayed and be triggered after 122877ms, not TCP_RTO_MAX, as I tested. Therefore, 'tcp_jiffies32 - tp->rcv_tstamp > TCP_RTO_MAX' is always true once the RTO come up to TCP_RTO_MAX, and the socket will die. Fix this by replacing the 'tcp_jiffies32' with '(u32)icsk->icsk_timeout', which is exact the timestamp of the timeout. However, "tp->rcv_tstamp" can restart from idle, then tp->rcv_tstamp could already be a long time (minutes or hours) in the past even on the first RTO. So we double check the timeout with the duration of the retransmission. Meanwhile, making "2 * TCP_RTO_MAX" as the timeout to avoid the socket dying too soon. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Link: https://lore.kernel.org/netdev/CADxym3YyMiO+zMD4zj03YPM3FBi-1LHi6gSD2XT8pyAMM096pg@mail.gmail.com/ Signed-off-by: Menglong Dong Reviewed-by: Eric Dumazet Signed-off-by: David S. Miller --- net/ipv4/tcp_timer.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index e0bd7999d6d51602fcd868a72d00618234bd0c27..76bd619a89848a2a673b49fdb034037b454ced18 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -434,6 +434,22 @@ static void tcp_fastopen_synack_timer(struct sock *sk, struct request_sock *req) TCP_TIMEOUT_INIT << req->num_timeout, TCP_RTO_MAX); } +static bool tcp_rtx_probe0_timed_out(const struct sock *sk, + const struct sk_buff *skb) +{ + const struct tcp_sock *tp = tcp_sk(sk); + const int timeout = TCP_RTO_MAX * 2; + u32 rcv_delta, rtx_delta; + + rcv_delta = inet_csk(sk)->icsk_timeout - tp->rcv_tstamp; + if (rcv_delta <= timeout) + return false; + + rtx_delta = (u32)msecs_to_jiffies(tcp_time_stamp(tp) - + (tp->retrans_stamp ?: tcp_skb_timestamp(skb))); + + return rtx_delta > timeout; +} /** * tcp_retransmit_timer() - The TCP retransmit timeout handler @@ -497,7 +513,7 @@ void tcp_retransmit_timer(struct sock *sk) tp->snd_una, tp->snd_nxt); } #endif - if (tcp_jiffies32 - tp->rcv_tstamp > TCP_RTO_MAX) { + if (tcp_rtx_probe0_timed_out(sk, skb)) { tcp_write_err(sk); goto out; } From patchwork Tue Jul 16 01:53:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13733981 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 3FF18322B for ; Tue, 16 Jul 2024 01:54:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721094850; cv=none; b=ZW9wJYN5u9tmeYte9RR9OSxT0XRgIjXeqjoL4rrIEJbyOXfcIgljt2ZVFTTJecK9bp7lUhKmRKD6PG2TuQwMTjwyu/S3DWoMoE0V/4UvI7qJaPDfRNnyMoB3I1UJ4KW0jZdtI0U3ORUkSfiCNOKnXF82y8xGtgRXBeRFFnynHsU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721094850; c=relaxed/simple; bh=6/8Tp/q3vT45Y08hNwJQOBWaoevnWiEbiu+oGmlJpFc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=r1HcrXBJmMmt03jX/ljA3JQPtk+5WLgjNOVlyh4bJKF3oCvJ2SoaFOZTSEq6c4pgN79NLAq4sM65K6GRAhYqwHdH1KM2ucq+9wXi8q7JgGYPjkxK7b2vu/4+2804oeezVEMjx+EcQLiMgO0nSoAOK9oZx8sPPz7WMzFMbVzG+vw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=aHlfKT1g; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="aHlfKT1g" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e03654427f6so8963222276.0 for ; Mon, 15 Jul 2024 18:54:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721094848; x=1721699648; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=z5RZkAsr7KLWKX7p2EN8cO7UxkRsrsLG3kKSZAIPNIg=; b=aHlfKT1g5CG8z2ZEAX7W5I1fTk4GvgBSqKUWSVcX/PQcHePwn4D/ksrZMLH/DJ2KA+ ra4Nca1JfCdqRIPZEh4Y2kT9wud2MaapcMWb33zd08L+VvzWVCcmYVVrdZfmWhwlPyF7 j3tze20nYDf/Fss7OPFfNN8A6KSWXdyDwpgyBINupK1bba1fL2955t4Lj15zSIMISa2O XhWJEzRe6EsfZFvc/jwTg70Kb5wWzbrx32FSdYYRJfDEhHA+BD5AWneCI6C+n2Q9M5wd TOkgALOjPPhQd0HO3bmoNMyuelwcd1X1Pf1I2k+LbjzaT8c+8YNILWWdODRDgfRKPR3V wO4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721094848; x=1721699648; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=z5RZkAsr7KLWKX7p2EN8cO7UxkRsrsLG3kKSZAIPNIg=; b=jb4sYxXZ/C/WxUhiJdIxET4C4oKFUAo7pDHCVpJD2RDeT3u+kpGKRtL3gOhZbUUCIl tVlZNr0xRIUgiZd8/SWa0dWAZ+cw5IFWF9DYnvA8NO/LHZBhB/hl+3WwdWm5OqLyNugB /GyhvGY3FPT05cboHrpqgVUF/SSxt1qXdrIv0snhUvpsOFLK22QXyCzpGzyhEisHUjDz xvwIRz+WnfLXDVucrKjTrCiDWbR04q0HJwH7Os+/99e/miXaB8fTuLnRxpu0QHNbzOeL jIXiFNVGrQSl/F/7S1PwYsvTT4nfK5p69LF6LZrT8NLTo1nH/ypSVN2VBBXTWzP2lV25 b56w== X-Forwarded-Encrypted: i=1; AJvYcCUETRkxRw8L8bW/VFuXmc4dEOQzrQ4Tb0laKtnEgL/qkRxOni/wR1P1sv1I6uNUCJ4VLKtPxVv3/eZF/gPkw/le1G4y5WYh X-Gm-Message-State: AOJu0YyTJwG1RcVZZUHpCvGIpyolqQ8Qr1gpSdLPQlHywQvvUCNyoDpK v6B8cK5ES1zIURsNw2WZ43NehNbw9/haZZI0UBY30P+j1lHWjJ8A+xJtCyErT7IWZiGQvzV0KbD yKMC6KtvhYQ== X-Google-Smtp-Source: AGHT+IH61RbCRJgYP/aRn6piDxePFbusYpNCV11qo30Rcg0Y59wb1vm+uC72BDLO8ZI7QUNH+QvVToaGjVZ79A== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:230b:b0:e05:a1b5:adc0 with SMTP id 3f1490d57ef6-e05d57babd5mr38419276.10.1721094848231; Mon, 15 Jul 2024 18:54:08 -0700 (PDT) Date: Tue, 16 Jul 2024 01:53:59 +0000 In-Reply-To: <20240716015401.2365503-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240716015401.2365503-1-edumazet@google.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog Message-ID: <20240716015401.2365503-4-edumazet@google.com> Subject: [PATCH stable-5.4 3/4] tcp: use signed arithmetic in tcp_rtx_probe0_timed_out() From: Eric Dumazet To: Greg Kroah-Hartman Cc: "David S . Miller" , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, eric.dumazet@gmail.com, Neal Cardwell , Jason Xing , Jon Maxwell , Kuniyuki Iwashima , Eric Dumazet , Menglong Dong X-Patchwork-Delegate: kuba@kernel.org commit 36534d3c54537bf098224a32dc31397793d4594d upstream. Due to timer wheel implementation, a timer will usually fire after its schedule. For instance, for HZ=1000, a timeout between 512ms and 4s has a granularity of 64ms. For this range of values, the extra delay could be up to 63ms. For TCP, this means that tp->rcv_tstamp may be after inet_csk(sk)->icsk_timeout whenever the timer interrupt finally triggers, if one packet came during the extra delay. We need to make sure tcp_rtx_probe0_timed_out() handles this case. Fixes: e89688e3e978 ("net: tcp: fix unexcepted socket die when snd_wnd is 0") Signed-off-by: Eric Dumazet Cc: Menglong Dong Acked-by: Neal Cardwell Reviewed-by: Jason Xing Link: https://lore.kernel.org/r/20240607125652.1472540-1-edumazet@google.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/ipv4/tcp_timer.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index 76bd619a89848a2a673b49fdb034037b454ced18..cbd4fde47c1f8d29533bf5ce28bddf4c9a00efe7 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -439,8 +439,13 @@ static bool tcp_rtx_probe0_timed_out(const struct sock *sk, { const struct tcp_sock *tp = tcp_sk(sk); const int timeout = TCP_RTO_MAX * 2; - u32 rcv_delta, rtx_delta; + u32 rtx_delta; + s32 rcv_delta; + /* Note: timer interrupt might have been delayed by at least one jiffy, + * and tp->rcv_tstamp might very well have been written recently. + * rcv_delta can thus be negative. + */ rcv_delta = inet_csk(sk)->icsk_timeout - tp->rcv_tstamp; if (rcv_delta <= timeout) return false; From patchwork Tue Jul 16 01:54:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13733982 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qv1-f74.google.com (mail-qv1-f74.google.com [209.85.219.74]) (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 11D06BA2F for ; Tue, 16 Jul 2024 01:54:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721094852; cv=none; b=SyPpP44HhNPhBhxMBS+yW5SYoNi0t0wN5d0TNTgH7ZPrcaRqpbm9Cya0R2Fvw5Ae76YkAzB3u3CI65qF4s+WmkvsU1s7PujViYWFm+7uRLb2MHa/FhhO64JAWydSCehDvTVDjRMWH0TGa0C3F2EBbYDIhSCuBQG98lbMwAb8NW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721094852; c=relaxed/simple; bh=uet/+OGfvg9XFYp/NRb5KWWoNPkhzgq7fQ/OeHtORM8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tsxxWNhUJYFnYk6wCUQ5bfLMg6yqVDVJXf4F1Pi4kklxlyk3yyy76xleXwdIocyG5TWEfaK6now+rvHslZot/LyMSHVHvIB6w0+fMEuO8yTa/yjI/lnkz69yIvpGDPooSuoAvFiw4o/NQ1ckup9GsO+DXkbxV0r3gmyaTgVQIYw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=FLv+u/fm; arc=none smtp.client-ip=209.85.219.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FLv+u/fm" Received: by mail-qv1-f74.google.com with SMTP id 6a1803df08f44-6b61dbb0005so74088516d6.2 for ; Mon, 15 Jul 2024 18:54:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721094850; x=1721699650; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=sZVdMAxOwZSNDTYnIThXumSVOAN7HqZ/o4fzzTxEf0k=; b=FLv+u/fmDoJf8gLV+M0fzx6ns3kGDF0m10TagEk7/4dLxHoswiHQZB8WlUENhv8/nm qydbAKQai2kS1tblWZx/D/0/MuPO19pWMf2HdwojUhKKfoEdJeXI3wVj+gGY9kTjN/rX CxmKGqhRDSVAfDe2bOFQXCsogTWHwD29UX7DajJVlijW3GHDoyL3wYMsjlD7dOKJymn+ RiIRqZxq5h4JZKevvyzmDJmJxIyV5QtfU+9Wj86nDkP2BJnxWT8Ly6e2Bzn+BEDCnWm6 /m9NpcEYNQs6XsdzzvlYWpMUtdYFvKW2S8XVSc6zNSRV60WCVE4THdMdaVvvZ/0vlm1+ RBwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721094850; x=1721699650; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sZVdMAxOwZSNDTYnIThXumSVOAN7HqZ/o4fzzTxEf0k=; b=jbm5G2/tIgl381mfCqfzlflTr5CDIiW1rp4sqy0hl6jjsgkyPD2eQF8+UiodFktvMH yEtRjYoxNzKiEY23l7fCwDqmYKSj0exuJtnuPg6zvdePzAT087oMeFiBEQriPUF2kxou KOZOGLDLW4KlgM1OaBxLESOS+Ojhw6XCvppFXEAODo2Dmoh0UFZfxfFhLZTIn5cDrcjg eG+M4JsBwltOjTK23ABkDFDa6hRdDkUBX9HjaIevDR3vdeSEFiN0uUnNikQhusDNRTxg MjXW7ENGwWdJ57NR1XgJWplT1FLumFr7Ru8eivGh+HogUX6j48Eh8zc7bZmSsKIZBDSP cmRg== X-Forwarded-Encrypted: i=1; AJvYcCXpD0XQxHzZwlXZq5Xp1bh8fq24V3TeyZk/XUVzfc5YvJrwU90NodPsBI5bm0UNdQylLCaQtp45zVnL88Rrf5YlFYga7XbG X-Gm-Message-State: AOJu0YwpoTREG4xtRMEQOZrvLStO2Rdi8Ni825PwNNhPGd8lc3s9XeU6 cJSXqcx+DzQxASzxDumVLyCZ13IA+hX27vIWHIUBOnMoEkFHQSEdGyPNX957Msb03yfbUQJTVQx l3b13OqOMLQ== X-Google-Smtp-Source: AGHT+IHiCOMDTwpze+I0bxxw2dfcl1BNwsYMeR4VCh9WqrQUA7stzbVkArmTyvBb2tq25tbuKd8PTJl8OqZS0A== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6214:5099:b0:6b2:b82e:78a4 with SMTP id 6a1803df08f44-6b77f4c8981mr151976d6.5.1721094849819; Mon, 15 Jul 2024 18:54:09 -0700 (PDT) Date: Tue, 16 Jul 2024 01:54:00 +0000 In-Reply-To: <20240716015401.2365503-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240716015401.2365503-1-edumazet@google.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog Message-ID: <20240716015401.2365503-5-edumazet@google.com> Subject: [PATCH stable-5.4 4/4] tcp: avoid too many retransmit packets From: Eric Dumazet To: Greg Kroah-Hartman Cc: "David S . Miller" , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, eric.dumazet@gmail.com, Neal Cardwell , Jason Xing , Jon Maxwell , Kuniyuki Iwashima , Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org commit 97a9063518f198ec0adb2ecb89789de342bb8283 upstream. If a TCP socket is using TCP_USER_TIMEOUT, and the other peer retracted its window to zero, tcp_retransmit_timer() can retransmit a packet every two jiffies (2 ms for HZ=1000), for about 4 minutes after TCP_USER_TIMEOUT has 'expired'. The fix is to make sure tcp_rtx_probe0_timed_out() takes icsk->icsk_user_timeout into account. Before blamed commit, the socket would not timeout after icsk->icsk_user_timeout, but would use standard exponential backoff for the retransmits. Also worth noting that before commit e89688e3e978 ("net: tcp: fix unexcepted socket die when snd_wnd is 0"), the issue would last 2 minutes instead of 4. Fixes: b701a99e431d ("tcp: Add tcp_clamp_rto_to_user_timeout() helper to improve accuracy") Signed-off-by: Eric Dumazet Cc: Neal Cardwell Reviewed-by: Jason Xing Reviewed-by: Jon Maxwell Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20240710001402.2758273-1-edumazet@google.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/ipv4/tcp_timer.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index cbd4fde47c1f8d29533bf5ce28bddf4c9a00efe7..a386e9b84984ab0be41b0c38ea015e4ae3377edf 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -437,16 +437,28 @@ static void tcp_fastopen_synack_timer(struct sock *sk, struct request_sock *req) static bool tcp_rtx_probe0_timed_out(const struct sock *sk, const struct sk_buff *skb) { + const struct inet_connection_sock *icsk = inet_csk(sk); + u32 user_timeout = READ_ONCE(icsk->icsk_user_timeout); const struct tcp_sock *tp = tcp_sk(sk); - const int timeout = TCP_RTO_MAX * 2; + int timeout = TCP_RTO_MAX * 2; u32 rtx_delta; s32 rcv_delta; + if (user_timeout) { + /* If user application specified a TCP_USER_TIMEOUT, + * it does not want win 0 packets to 'reset the timer' + * while retransmits are not making progress. + */ + if (rtx_delta > user_timeout) + return true; + timeout = min_t(u32, timeout, msecs_to_jiffies(user_timeout)); + } + /* Note: timer interrupt might have been delayed by at least one jiffy, * and tp->rcv_tstamp might very well have been written recently. * rcv_delta can thus be negative. */ - rcv_delta = inet_csk(sk)->icsk_timeout - tp->rcv_tstamp; + rcv_delta = icsk->icsk_timeout - tp->rcv_tstamp; if (rcv_delta <= timeout) return false;