Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp662309pxb; Wed, 13 Jan 2021 12:48:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJzU7N255v7wdl4gYep+lJbRzIAosV8FKhHn2Ot1ludvVfHRPv1iCC6Xg9H1kSvhhMeA1sBJ X-Received: by 2002:a17:906:3fc4:: with SMTP id k4mr2808366ejj.137.1610570898631; Wed, 13 Jan 2021 12:48:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610570898; cv=none; d=google.com; s=arc-20160816; b=jJ/d6GjMsb649B2aXNQLblSDqKIqI2B5Jum/S1453VnC7Z6Twxty0FhMgrH8E83oBQ djNWhBKTcMcxB0xO8Q47QJ4pvs+QdfAvEv46FdGUz0ihvQGKs+Odiqpp/Uc/vbR4lLnc mAbww1VsmUZX0o1deYcJv0DsgHr+eWwE9kehXwmuQyfRn09RcIjMVc3wQoYqPLsuDpJv ziLS+VJUI6H2pt8sJmwl84RZSdmQj29TUUtKgpAK/JtDVvQxBkgYIb89cjKn06mIzHOp nj51SdzJK9A+pt2O1enmmIlz6lTy11YEe40j8M1JOAUQ1wti6z2u9IJ+FQAZcAZ8PXc3 vAww== 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=bcsZ0rrV2OrGbInLd4zaRlSsy95HROED9dlorTGYBOo=; b=BIN8eigzHI1Z534eFPPqQdyKO9IZz81Cq2j2vz8d0wQLceonyxB6MbIK2IGxB83aHy OT0i7aRAGB4+QtMovXKC4ILklDSlZpFjt389ilUMeI1rozPtnUk24vEurRhLcWyCTs53 vk0jYFFyFgjA8VmGXHTDJZE4FaiUVEmqeQXkaoKFwE/F8rq/2LVyTrc7AybvnOoApO7e 87qPSYhuBY/RA7NnKy6Bq1PiJ06+EF09AeT93+GX2fTFmJ2urvl7GX3vx5sgS8p8ELqQ DQbTXVUIRCVWPQkgQtrgwUT37poKGWEt8zaokpLPsNM77u9CM/5PL/VKUGJIgrS3HJVq ahwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=FG5v29ge; 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 s8si1513462edd.534.2021.01.13.12.47.54; Wed, 13 Jan 2021 12:48:18 -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=FG5v29ge; 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 S1728847AbhAMUpF (ORCPT + 99 others); Wed, 13 Jan 2021 15:45:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728380AbhAMUpE (ORCPT ); Wed, 13 Jan 2021 15:45:04 -0500 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34273C061575 for ; Wed, 13 Jan 2021 12:44:24 -0800 (PST) Received: by mail-io1-xd31.google.com with SMTP id d13so3654832ioy.4 for ; Wed, 13 Jan 2021 12:44:24 -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=bcsZ0rrV2OrGbInLd4zaRlSsy95HROED9dlorTGYBOo=; b=FG5v29geTRr7VK3oR2AU9J8Ju6h050uLhd81MZQBkuP5L0ay/xl1YbKVrMJscN/N3z A/k16/bI6qIw+EnKV91HEQ2LQLt0/zIKOFPWOwZYtZqbnGzfoBwKQG0IYi0Koxjj9QUf 6HXtuT2+i1ctGbAU5N9VAtp32N1T388EzWrxYZBLQNa2U8C9XeOUOvWbxj7k1MI6/eCD h7LA3ud+zSQOrrEUeTjmsJszyz9snuVXFgeX/49aeHI2omZ8fHrpcnDp8cOW/HrAru50 XrMWP2p47lC0FmB51svWEVtTalh0Ybck2Qz1DHD6+sMex1XqDTM1KQk1+Qsizo2L3KQV Id5Q== 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=bcsZ0rrV2OrGbInLd4zaRlSsy95HROED9dlorTGYBOo=; b=cMpBIaI6tnlSf7JsSH95VhMChDoKKmUWd/rqiICa6OAg59o46XGzM8izdbOlmJK0fe LDEroCMGXzXBiE7T236GvNyz4BwiU1aFQtsL1fpy+I8ogYcdyZK0NWqSxJqVP3GOHf2F So4mn22HKru7BIG87i5xLxZnNfCRUE6OIgvp/gi+x1v2aYFK5qZhxu3Ud0dLvXFzBr3U a+vgli4QIQFLsxgH7Pe8FX0BPfs08kuU/IVDcvGesNgCYl1tH3PPQyj9RR5USDbjPMNq HTLtSzr7q5l2pVxs9b9oIbgmdVUz4fNo4hFxNn92eqgy8vya/15telct76XP+rqYBLb2 Kv4A== X-Gm-Message-State: AOAM530FFz8NzXRX5E71Ob+Gohl+wv5QgaXCTnGOpoEx73Y1EUJq3yAR DVFlgBmFR+/fu+d3fa5jaFFBnpfuo4IMigRbXCvsTg== X-Received: by 2002:a92:ce09:: with SMTP id b9mr3808295ilo.69.1610570663201; Wed, 13 Jan 2021 12:44:23 -0800 (PST) MIME-Version: 1.0 References: <20210113201201.GC2274@localhost.localdomain> In-Reply-To: <20210113201201.GC2274@localhost.localdomain> From: Eric Dumazet Date: Wed, 13 Jan 2021 21:44:11 +0100 Message-ID: Subject: Re: [PATCH] tcp: fix TCP_USER_TIMEOUT with zero window To: Enke Chen Cc: "David S. Miller" , Alexey Kuznetsov , Hideaki YOSHIFUJI , Jakub Kicinski , netdev , LKML , Jonathan Maxwell , William McCall Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 13, 2021 at 9:12 PM Enke Chen wrote: > > From: Enke Chen > > The TCP session does not terminate with TCP_USER_TIMEOUT when data > remain untransmitted due to zero window. > > The number of unanswered zero-window probes (tcp_probes_out) is > reset to zero with incoming acks irrespective of the window size, > as described in tcp_probe_timer(): > > RFC 1122 4.2.2.17 requires the sender to stay open indefinitely > as long as the receiver continues to respond probes. We support > this by default and reset icsk_probes_out with incoming ACKs. > > This counter, however, is the wrong one to be used in calculating the > duration that the window remains closed and data remain untransmitted. > Thanks to Jonathan Maxwell for diagnosing the > actual issue. > > In this patch a separate counter is introduced to track the number of > zero-window probes that are not answered with any non-zero window ack. > This new counter is used in determining when to abort the session with > TCP_USER_TIMEOUT. > I think one possible issue would be that local congestion (full qdisc) would abort early, because tcp_model_timeout() assumes linear backoff. Neal or Yuchung can further comment on that, it is late for me in France. packetdrill test would be : 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 +0 bind(3, ..., ...) = 0 +0 listen(3, 1) = 0 +0 < S 0:0(0) win 0 +0 > S. 0:0(0) ack 1 +.1 < . 1:1(0) ack 1 win 65530 +0 accept(3, ..., ...) = 4 +0 setsockopt(4, SOL_TCP, TCP_USER_TIMEOUT, [3000], 4) = 0 +0 write(4, ..., 24) = 24 +0 > P. 1:25(24) ack 1 +.1 < . 1:1(0) ack 25 win 65530 +0 %{ assert tcpi_probes == 0, tcpi_probes; \ assert tcpi_backoff == 0, tcpi_backoff }% // install a qdisc dropping all packets +0 `tc qdisc delete dev tun0 root 2>/dev/null ; tc qdisc add dev tun0 root pfifo limit 0` +0 write(4, ..., 24) = 24 // When qdisc is congested we retry every 500ms therefore in theory // we'd retry 6 times before hitting 3s timeout. However, since we // estimate the elapsed time based on exp backoff of actual RTO (300ms), // we'd bail earlier with only 3 probes. +2.1 write(4, ..., 24) = -1 +0 %{ assert tcpi_probes == 3, tcpi_probes; \ assert tcpi_backoff == 0, tcpi_backoff }% +0 close(4) = 0 > Cc: stable@vger.kernel.org > Fixes: 9721e709fa68 ("tcp: simplify window probe aborting on USER_TIMEOUT") > Reported-by: William McCall > Signed-off-by: Enke Chen > --- > include/linux/tcp.h | 5 +++++ > net/ipv4/tcp.c | 1 + > net/ipv4/tcp_input.c | 3 ++- > net/ipv4/tcp_output.c | 2 ++ > net/ipv4/tcp_timer.c | 5 +++-- > 5 files changed, 13 insertions(+), 3 deletions(-) > > diff --git a/include/linux/tcp.h b/include/linux/tcp.h > index 2f87377e9af7..c9415b30fa67 100644 > --- a/include/linux/tcp.h > +++ b/include/linux/tcp.h > @@ -352,6 +352,11 @@ struct tcp_sock { > > int linger2; > > + /* While icsk_probes_out is for unanswered 0 window probes, this > + * counter is for 0-window probes that are not answered with any > + * non-zero window (nzw) acks. > + */ > + u8 probes_nzw; > > /* Sock_ops bpf program related variables */ > #ifdef CONFIG_BPF > diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c > index ed42d2193c5c..af6a41a5a5ac 100644 > --- a/net/ipv4/tcp.c > +++ b/net/ipv4/tcp.c > @@ -2940,6 +2940,7 @@ int tcp_disconnect(struct sock *sk, int flags) > icsk->icsk_rto = TCP_TIMEOUT_INIT; > icsk->icsk_rto_min = TCP_RTO_MIN; > icsk->icsk_delack_max = TCP_DELACK_MAX; > + tp->probes_nzw = 0; > tp->snd_ssthresh = TCP_INFINITE_SSTHRESH; > tp->snd_cwnd = TCP_INIT_CWND; > tp->snd_cwnd_cnt = 0; > diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c > index c7e16b0ed791..4812a969c18a 100644 > --- a/net/ipv4/tcp_input.c > +++ b/net/ipv4/tcp_input.c > @@ -3377,13 +3377,14 @@ static void tcp_ack_probe(struct sock *sk) > { > struct inet_connection_sock *icsk = inet_csk(sk); > struct sk_buff *head = tcp_send_head(sk); > - const struct tcp_sock *tp = tcp_sk(sk); > + struct tcp_sock *tp = tcp_sk(sk); > > /* Was it a usable window open? */ > if (!head) > return; > if (!after(TCP_SKB_CB(head)->end_seq, tcp_wnd_end(tp))) { > icsk->icsk_backoff = 0; > + tp->probes_nzw = 0; > inet_csk_clear_xmit_timer(sk, ICSK_TIME_PROBE0); > /* Socket must be waked up by subsequent tcp_data_snd_check(). > * This function is not for random using! > diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c > index f322e798a351..1b64cdabc299 100644 > --- a/net/ipv4/tcp_output.c > +++ b/net/ipv4/tcp_output.c > @@ -4084,10 +4084,12 @@ void tcp_send_probe0(struct sock *sk) > /* Cancel probe timer, if it is not required. */ > icsk->icsk_probes_out = 0; > icsk->icsk_backoff = 0; > + tp->probes_nzw = 0; > return; > } > > icsk->icsk_probes_out++; > + tp->probes_nzw++; > if (err <= 0) { > if (icsk->icsk_backoff < net->ipv4.sysctl_tcp_retries2) > icsk->icsk_backoff++; > diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c > index 6c62b9ea1320..87e9f5998b8e 100644 > --- a/net/ipv4/tcp_timer.c > +++ b/net/ipv4/tcp_timer.c > @@ -349,6 +349,7 @@ static void tcp_probe_timer(struct sock *sk) > > if (tp->packets_out || !skb) { > icsk->icsk_probes_out = 0; > + tp->probes_nzw = 0; > return; > } > > @@ -360,8 +361,8 @@ static void tcp_probe_timer(struct sock *sk) > * corresponding system limit. We also implement similar policy when > * we use RTO to probe window in tcp_retransmit_timer(). > */ > - if (icsk->icsk_user_timeout) { > - u32 elapsed = tcp_model_timeout(sk, icsk->icsk_probes_out, > + if (icsk->icsk_user_timeout && tp->probes_nzw) { > + u32 elapsed = tcp_model_timeout(sk, tp->probes_nzw, > tcp_probe0_base(sk)); > > if (elapsed >= icsk->icsk_user_timeout) > -- > 2.29.2 >