Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp62161pxb; Tue, 12 Jan 2021 20:10:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJxosIBpmNfyHL4T8QcrMXQm9kbKgp8ASN/5JKzqkGwrTPNhwA6aTEfWjZN4K5XOYhbzfWX7 X-Received: by 2002:a17:907:118e:: with SMTP id uz14mr154399ejb.83.1610511015452; Tue, 12 Jan 2021 20:10:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610511015; cv=none; d=google.com; s=arc-20160816; b=bjoe4VQL1JtcVVK3/p9rEaImvrylJ5WmQRR15Wbuu5YUCTkn4vosQp/8R+AgpvLNrb r37daeCUAhhU/0FTmN2GGM/AM/niHzBC/06NuXJtFQc8Q1PTC/vzwwlyQBNWdei+dj6Q RAQCk6Cg9qmbzNWNbh1SgStQEIN5AalKtFw7UZF402tQW9IMI4uecg87EvKHRd1MG13K 02WJRGU8RePXNv2GV9rsdELLOkACnLG0YuGn3aXKc44HOTrBXEmg5RCl29Fu3xYbA8Nk 12AIIv3rEgI2AdkHpShKrKStXqevsByiFdMDjZInl2DBJ8xhPw6qK22vWwfNCbJ0JLSo BWug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ArlcvqJC9q51hscbwB0x0D1UTjuMUpHLsr6hfqKDboU=; b=jU+zmtnX9IFNHP+4AwOC2QdfC0wStYtbpIkLXk4kMqEGW7jw+T7Ahg6JaZKeZD720H tHydb81UgmeFTTIXid8/9I3t9Tno9Hj0Eefsw5+xqydNM+ZEH3TxYKGPY+66Sti/SR1s O/qHqE3wvp/WFBoxEGi8IIO4rUsREEeVV7lp14QjTAglebqJ+jgTsHGgGJbDbimhAIe9 tng7RX7iBbUvtDEpMoMQh8CNuAX3u3DW4/+8loAiFeLeGV0gpN/PBDzczd1P3Z/xJpQC V6oBQTp6eG5F/+vH2T0NizHwrKUtcnq25kXNz7xclFvifu3Lhz+Ho9ME1PIslCf90B7P As9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Z+UVCsDE; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dj28si420940edb.352.2021.01.12.20.09.29; Tue, 12 Jan 2021 20:10:15 -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=@google.com header.s=20161025 header.b=Z+UVCsDE; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394760AbhALWtU (ORCPT + 99 others); Tue, 12 Jan 2021 17:49:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732390AbhALWtU (ORCPT ); Tue, 12 Jan 2021 17:49:20 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05F59C061786 for ; Tue, 12 Jan 2021 14:48:40 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id g25so2586505wmh.1 for ; Tue, 12 Jan 2021 14:48:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ArlcvqJC9q51hscbwB0x0D1UTjuMUpHLsr6hfqKDboU=; b=Z+UVCsDEuZ+jOvAGZqP7xaXkuN3UW1kYQK/efl9+WKHVo5u+O5SwRfH9Gsl0sizrYu PWd1gJIoe+vCvbB8U2ExGkGY14jFqmrYonaEsAABcHzAF7RvqVXwIIsMU8HCsfCiUcAR jIA8E6eIoa7S+WSV/y3R3DB3b+kd271uJz+/uQWxIhENojaxqCrWLwd9Ydu/bYIdDYRe Lqk9g0KZysiZrjQc99BSYfvFWea4LcZGJQ0oj1euEnZxafWG7VOV4PQIP0EdkiOJu1C+ rlCGXPpqFwNAp45H833PPgC6zYSs97/jdS6WV7CH59XPci3wFJacCMv1/vXLXQUyC+/v /Nbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ArlcvqJC9q51hscbwB0x0D1UTjuMUpHLsr6hfqKDboU=; b=pdowDf+JJmfnktq5LIaoQNAkUwwY+k88Y42RKvVz50lfQocc6BtTbQp2h3nXbOK/tn sfNuaGV2j8NFL0/6Dbg83EHazWmhu2SEls7fOEavjCZtN0OtiZhtEoY0gtHOORLv1NCw 34tVju/6dBDbL1yXgcV/KEzLYakH95EcWp1si4+wsvWMxgLu2zhv7Z16VE+txA1gXol1 XY2murU01IieHoZPhsd/2or4zG96sCqLGCCAgSbGSj03f3ADDnP15xOfqgPBU59HTnVL gOLlpVt8x3OmM7jNBwfu3M3INFcoMWH3LGc+8W+lhh95A6aKNaVV/E3jLa6zwElsMotk C4Eg== X-Gm-Message-State: AOAM5304keQLv6o0/aZ2mILIgUzDBPnT3j4Q0iyp8H40yhu0GRJULW4c p+xHiRVE9FUBg46JxSEUdb3Ng9Meds+79duCb+jTag== X-Received: by 2002:a1c:4907:: with SMTP id w7mr967923wma.118.1610491718575; Tue, 12 Jan 2021 14:48:38 -0800 (PST) MIME-Version: 1.0 References: <20210112192544.GA12209@localhost.localdomain> In-Reply-To: <20210112192544.GA12209@localhost.localdomain> From: Yuchung Cheng Date: Tue, 12 Jan 2021 14:48:01 -0800 Message-ID: Subject: Re: [PATCH] tcp: keepalive fixes To: Enke Chen Cc: Eric Dumazet , "David S. Miller" , Alexey Kuznetsov , Hideaki YOSHIFUJI , Jakub Kicinski , netdev , LKML , Neal Cardwell Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 12, 2021 at 2:31 PM Enke Chen wrote: > > From: Enke Chen > > In this patch two issues with TCP keepalives are fixed: > > 1) TCP keepalive does not timeout when there are data waiting to be > delivered and then the connection got broken. The TCP keepalive > timeout is not evaluated in that condition. hi enke Do you have an example to demonstrate this issue -- in theory when there is data inflight, an RTO timer should be pending (which considers user-timeout setting). based on the user-timeout description (man tcp), the user timeout should abort the socket per the specified time after data commences. some data would help to understand the issue. > > The fix is to remove the code that prevents TCP keepalive from > being evaluated for timeout. > > 2) With the fix for #1, TCP keepalive can erroneously timeout after > the 0-window probe kicks in. The 0-window probe counter is wrongly > applied to TCP keepalives. > > The fix is to use the elapsed time instead of the 0-window probe > counter in evaluating TCP keepalive timeout. > > Cc: stable@vger.kernel.org > Signed-off-by: Enke Chen > --- > net/ipv4/tcp_timer.c | 15 +++------------ > 1 file changed, 3 insertions(+), 12 deletions(-) > > diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c > index 6c62b9ea1320..40953aa40d53 100644 > --- a/net/ipv4/tcp_timer.c > +++ b/net/ipv4/tcp_timer.c > @@ -696,12 +696,6 @@ static void tcp_keepalive_timer (struct timer_list *t) > ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT))) > goto out; > > - elapsed = keepalive_time_when(tp); > - > - /* It is alive without keepalive 8) */ > - if (tp->packets_out || !tcp_write_queue_empty(sk)) > - goto resched; > - > elapsed = keepalive_time_elapsed(tp); > > if (elapsed >= keepalive_time_when(tp)) { > @@ -709,16 +703,15 @@ static void tcp_keepalive_timer (struct timer_list *t) > * to determine when to timeout instead. > */ > if ((icsk->icsk_user_timeout != 0 && > - elapsed >= msecs_to_jiffies(icsk->icsk_user_timeout) && > - icsk->icsk_probes_out > 0) || > + elapsed >= msecs_to_jiffies(icsk->icsk_user_timeout)) || > (icsk->icsk_user_timeout == 0 && > - icsk->icsk_probes_out >= keepalive_probes(tp))) { > + (elapsed >= keepalive_time_when(tp) + > + keepalive_intvl_when(tp) * keepalive_probes(tp)))) { > tcp_send_active_reset(sk, GFP_ATOMIC); > tcp_write_err(sk); > goto out; > } > if (tcp_write_wakeup(sk, LINUX_MIB_TCPKEEPALIVE) <= 0) { > - icsk->icsk_probes_out++; > elapsed = keepalive_intvl_when(tp); > } else { > /* If keepalive was lost due to local congestion, > @@ -732,8 +725,6 @@ static void tcp_keepalive_timer (struct timer_list *t) > } > > sk_mem_reclaim(sk); > - > -resched: > inet_csk_reset_keepalive_timer (sk, elapsed); > goto out; > > -- > 2.29.2 >