Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4724388iob; Sun, 8 May 2022 23:20:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJxIjT1zKfDA0Lc7+jrO9kYYMtejWYrQ78q7P6zLXKJkyYHT56yjL7Css/VUexdd0pcLI6 X-Received: by 2002:a05:6a00:2402:b0:4e1:3df2:5373 with SMTP id z2-20020a056a00240200b004e13df25373mr14725771pfh.40.1652077238946; Sun, 08 May 2022 23:20:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652077238; cv=none; d=google.com; s=arc-20160816; b=qfktAU9ZrLtEjv1pQjhTPNbFDGQN5Os8/yj/RtaoyEC8g8ftytcPvx8yGo59shfxdB Q7pCHGC/Ic61ebDkI49VTCr0iHoAi9YqoWHOrL0RMtcTmomqVUBWlrNBze5dl2t16wHe 6cS/0PIxdPIJ4G24RwdTu2N2ylCXwf/DAX+EO47pCmRBihC8CVQEvfARhi3NwcI40gC2 GE70rQOV03WCvSKJGinTzUxfvBfq6hoUkm4c6iOMaOkqY/v6VeqbOO+QzFPQSbcTY+hh RuamxyhJJ1cndqTiboMsqsTU4x/wGagttnJu8pz3yw3y9eSLzVOF/A2DTdQPLhlus/C5 uScw== 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=44gJXd9vOW/FmsYO9qq0m8HIN8XZlFajEu2IZBjyqI4=; b=gpOY7H12Ls/qOdZ+43LYOU/g5/uM0B0pcqp6QofkxkR5cRdzkN1VpNfdyU/K/bp+ON yyhYn6DEDQp12sLoQsurzDnoea89+zT5+Y7E7Qotrj3TAOMCBSTD9SoF0Xc0F6HclGI+ 8SpyRGGQeJlHL+87kq0APlkUwkXEBUDH/jIrSPly7YDAWdUO5oJs9tLlEke0P9vj+ZbI l8niTo3CisZXmuELMx8usEJb30X3bE9h652l7ztO2z0Onlp2ABllhip1DqzG1rAWKgIH Z7SlZAxYuKj4FfFDq+2Kn/nQvJjQOusFw+aG/qMPsReM/2QUj3dudyhk0HKZ8QWVXEEj mkdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dIWNHpkC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q18-20020a056a00151200b0050daf6ed35bsi14125739pfu.308.2022.05.08.23.20.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 23:20:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dIWNHpkC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9226A225; Sun, 8 May 2022 23:19:10 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356188AbiEDRWO (ORCPT + 99 others); Wed, 4 May 2022 13:22:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356145AbiEDREz (ORCPT ); Wed, 4 May 2022 13:04:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B05A506C7; Wed, 4 May 2022 09:53:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 26760616F8; Wed, 4 May 2022 16:53:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 675A6C385AA; Wed, 4 May 2022 16:53:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651683233; bh=dnzaqGXBBJIvI/n5Ws4cMPAF+KjiNExyNeJrmtj7ppc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dIWNHpkCILo84mvGI369nQZezKc33UpMJNG66+XYkjjOhAjcPuV75EKLP/25i6l/G Fu8vEhOA2DVMEI6WKzOTF8dNfGQmRoTDVPGPpdVQyiUMHcLn3aL1FotmGNPZCyve6S P1wk90OD5DCN9+kPnW7UoTVv4oSUNym/xSAnQhb4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pengcheng Yang , Paolo Abeni , Neal Cardwell , Eric Dumazet , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 086/177] tcp: ensure to use the most recently sent skb when filling the rate sample Date: Wed, 4 May 2022 18:44:39 +0200 Message-Id: <20220504153100.801021821@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504153053.873100034@linuxfoundation.org> References: <20220504153053.873100034@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pengcheng Yang [ Upstream commit b253a0680ceadc5d7b4acca7aa2d870326cad8ad ] If an ACK (s)acks multiple skbs, we favor the information from the most recently sent skb by choosing the skb with the highest prior_delivered count. But in the interval between receiving ACKs, we send multiple skbs with the same prior_delivered, because the tp->delivered only changes when we receive an ACK. We used RACK's solution, copying tcp_rack_sent_after() as tcp_skb_sent_after() helper to determine "which packet was sent last?". Later, we will use tcp_skb_sent_after() instead in RACK. Fixes: b9f64820fb22 ("tcp: track data delivery rate for a TCP connection") Signed-off-by: Pengcheng Yang Cc: Paolo Abeni Acked-by: Neal Cardwell Tested-by: Neal Cardwell Reviewed-by: Eric Dumazet Link: https://lore.kernel.org/r/1650422081-22153-1-git-send-email-yangpc@wangsu.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- include/net/tcp.h | 6 ++++++ net/ipv4/tcp_rate.c | 11 ++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 31d384c3778a..71a9aeae693d 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1026,6 +1026,7 @@ struct rate_sample { int losses; /* number of packets marked lost upon ACK */ u32 acked_sacked; /* number of packets newly (S)ACKed upon ACK */ u32 prior_in_flight; /* in flight before this ACK */ + u32 last_end_seq; /* end_seq of most recently ACKed packet */ bool is_app_limited; /* is sample from packet with bubble in pipe? */ bool is_retrans; /* is sample from retransmission? */ bool is_ack_delayed; /* is this (likely) a delayed ACK? */ @@ -1148,6 +1149,11 @@ void tcp_rate_gen(struct sock *sk, u32 delivered, u32 lost, bool is_sack_reneg, struct rate_sample *rs); void tcp_rate_check_app_limited(struct sock *sk); +static inline bool tcp_skb_sent_after(u64 t1, u64 t2, u32 seq1, u32 seq2) +{ + return t1 > t2 || (t1 == t2 && after(seq1, seq2)); +} + /* These functions determine how the current flow behaves in respect of SACK * handling. SACK is negotiated with the peer, and therefore it can vary * between different flows. diff --git a/net/ipv4/tcp_rate.c b/net/ipv4/tcp_rate.c index 0de693565963..6ab197928abb 100644 --- a/net/ipv4/tcp_rate.c +++ b/net/ipv4/tcp_rate.c @@ -73,26 +73,31 @@ void tcp_rate_skb_sent(struct sock *sk, struct sk_buff *skb) * * If an ACK (s)acks multiple skbs (e.g., stretched-acks), this function is * called multiple times. We favor the information from the most recently - * sent skb, i.e., the skb with the highest prior_delivered count. + * sent skb, i.e., the skb with the most recently sent time and the highest + * sequence. */ void tcp_rate_skb_delivered(struct sock *sk, struct sk_buff *skb, struct rate_sample *rs) { struct tcp_sock *tp = tcp_sk(sk); struct tcp_skb_cb *scb = TCP_SKB_CB(skb); + u64 tx_tstamp; if (!scb->tx.delivered_mstamp) return; + tx_tstamp = tcp_skb_timestamp_us(skb); if (!rs->prior_delivered || - after(scb->tx.delivered, rs->prior_delivered)) { + tcp_skb_sent_after(tx_tstamp, tp->first_tx_mstamp, + scb->end_seq, rs->last_end_seq)) { rs->prior_delivered = scb->tx.delivered; rs->prior_mstamp = scb->tx.delivered_mstamp; rs->is_app_limited = scb->tx.is_app_limited; rs->is_retrans = scb->sacked & TCPCB_RETRANS; + rs->last_end_seq = scb->end_seq; /* Record send time of most recently ACKed packet: */ - tp->first_tx_mstamp = tcp_skb_timestamp_us(skb); + tp->first_tx_mstamp = tx_tstamp; /* Find the duration of the "send phase" of this window: */ rs->interval_us = tcp_stamp_us_delta(tp->first_tx_mstamp, scb->tx.first_tx_mstamp); -- 2.35.1