Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2185848pxb; Fri, 5 Feb 2021 11:00:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJxHt1m8EwRL4fn//m/i7+LEj6y/RwBJaaWSJS/XD70KI1UCY+7J6pXvuWAFE8Hyb0YQbQ9G X-Received: by 2002:a17:906:5659:: with SMTP id v25mr5489856ejr.8.1612551605142; Fri, 05 Feb 2021 11:00:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612551605; cv=none; d=google.com; s=arc-20160816; b=MR228fCuv2xjF9cRN32+jnSjqFd6Rx18XCNThO7v8Pd1TUHhaJXJnvbmLft/zSIGcC dlwf872NdnJNrEWxRstrDcQhAXNUSVqXf2jbakCPk3PwPXbiviQltSSGc594X62K1k49 bNC7RH1EQBtk9aRwWLc6L9DWVe2bc9IDfPp87mHus+WSaAuBqBGzut1DLXfARfkGOnW7 6M/WzQYsjnm+5vUmTtpBhN6H87k4jyWHQBlXuQo//pYOfcxDm30igYEOkthKVrFRvJkr bMbIJJjubtqGmb9/ltJhZFHH8DMH9Y0Y7J9HIGBaefT3MOCD0mlRpuuxxHILSXhbhoae BUFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=m81XtOSz7wcOBLmHyQCk6afY/tS1AXAS4x/BGOPg5GQ=; b=UgruhlxPhntfhPG0yZXW/+UZ6+IdBtBWBv0siVmJZSb/Pbmi72LcG9QFyZs0cLr8Hw zBt2G4OUuSuWQvL6VzpAYMzP5WT16BPWwPt2IL+gWxGk2PgMZq3Nqpm4y7NjJp8p7kTZ TGPs2nJ7h+y15gCJEOyAFNoWhzEIA6UMvWPxNfciOark/qPlWDdRP5eJYIGn1IXxQnjf IKF7WgOe7OoNbR66/BrFsel9ER/AFkS0jRhkcxA3DKADfvadQdlkfEuYP0X+z6bdQVcy N4QoZ+tjs0gIhCVg7DsjsqbUoMqXszZr7cTviqS7fG36vbhL4BgypV8dwfNGsswum8I7 kJGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JCrPTL72; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hx20si6629070ejc.602.2021.02.05.10.59.40; Fri, 05 Feb 2021 11:00:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JCrPTL72; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233540AbhBEROZ (ORCPT + 99 others); Fri, 5 Feb 2021 12:14:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:54888 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233532AbhBEQCZ (ORCPT ); Fri, 5 Feb 2021 11:02:25 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 95B766505E; Fri, 5 Feb 2021 14:12:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612534355; bh=yfv70gwnos9Z7HA1DVypdXAtxcMJb28Q00haM7IyWyI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JCrPTL72s3EDCqE7Ch1dv+P+j3l0F/uH2ZppJ9Gl8cs/GC1y5oQqPGagjX5+wMGJI iuNLACJSuihhmPgqgrfqDBjj+78PmO8HI2XREL0hJG5U9Ymbrou/sy+ZG63jilCFwk 9efkNlRDkxNfiFU9IzGvBr2uoFy/iwpE2L5Vs45k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Enke Chen , Neal Cardwell , Eric Dumazet , Jakub Kicinski Subject: [PATCH 5.4 08/32] tcp: make TCP_USER_TIMEOUT accurate for zero window probes Date: Fri, 5 Feb 2021 15:07:23 +0100 Message-Id: <20210205140652.694199892@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210205140652.348864025@linuxfoundation.org> References: <20210205140652.348864025@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Enke Chen commit 344db93ae3ee69fc137bd6ed89a8ff1bf5b0db08 upstream. The TCP_USER_TIMEOUT is checked by the 0-window probe timer. As the timer has backoff with a max interval of about two minutes, the actual timeout for TCP_USER_TIMEOUT can be off by up to two minutes. In this patch the TCP_USER_TIMEOUT is made more accurate by taking it into account when computing the timer value for the 0-window probes. This patch is similar to and builds on top of the one that made TCP_USER_TIMEOUT accurate for RTOs in commit b701a99e431d ("tcp: Add tcp_clamp_rto_to_user_timeout() helper to improve accuracy"). Fixes: 9721e709fa68 ("tcp: simplify window probe aborting on USER_TIMEOUT") Signed-off-by: Enke Chen Reviewed-by: Neal Cardwell Signed-off-by: Eric Dumazet Link: https://lore.kernel.org/r/20210122191306.GA99540@localhost.localdomain Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- include/net/tcp.h | 1 + net/ipv4/tcp_input.c | 1 + net/ipv4/tcp_output.c | 2 ++ net/ipv4/tcp_timer.c | 18 ++++++++++++++++++ 4 files changed, 22 insertions(+) --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -619,6 +619,7 @@ static inline void tcp_clear_xmit_timers unsigned int tcp_sync_mss(struct sock *sk, u32 pmtu); unsigned int tcp_current_mss(struct sock *sk); +u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when); /* Bound MSS / TSO packet size with the half of the window */ static inline int tcp_bound_to_half_wnd(struct tcp_sock *tp, int pktsize) --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -3295,6 +3295,7 @@ static void tcp_ack_probe(struct sock *s } else { unsigned long when = tcp_probe0_when(sk, TCP_RTO_MAX); + when = tcp_clamp_probe0_to_user_timeout(sk, when); tcp_reset_xmit_timer(sk, ICSK_TIME_PROBE0, when, TCP_RTO_MAX, NULL); } --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -3850,6 +3850,8 @@ void tcp_send_probe0(struct sock *sk) */ timeout = TCP_RESOURCE_PROBE_INTERVAL; } + + timeout = tcp_clamp_probe0_to_user_timeout(sk, timeout); tcp_reset_xmit_timer(sk, ICSK_TIME_PROBE0, timeout, TCP_RTO_MAX, NULL); } --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -40,6 +40,24 @@ static u32 tcp_clamp_rto_to_user_timeout return min_t(u32, icsk->icsk_rto, msecs_to_jiffies(remaining)); } +u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when) +{ + struct inet_connection_sock *icsk = inet_csk(sk); + u32 remaining; + s32 elapsed; + + if (!icsk->icsk_user_timeout || !icsk->icsk_probes_tstamp) + return when; + + elapsed = tcp_jiffies32 - icsk->icsk_probes_tstamp; + if (unlikely(elapsed < 0)) + elapsed = 0; + remaining = msecs_to_jiffies(icsk->icsk_user_timeout) - elapsed; + remaining = max_t(u32, remaining, TCP_TIMEOUT_MIN); + + return min_t(u32, remaining, when); +} + /** * tcp_write_err() - close socket and save error info * @sk: The socket the error has appeared on.