From nobody Fri Oct 18 07:54:21 2024 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XVH655jJ6z5Yt2b; Fri, 18 Oct 2024 07:54:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XVH654QTQz4hJB; Fri, 18 Oct 2024 07:54:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729238061; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NGG6LXotAv6fAA6FIRpCTuYc6o+HszFpBIl+S/Irmnc=; b=YC4HA0cybq9MOYV0bGVoB9S7Oee6CwyfeG9dyVLKfAbVkOFY29ID9etOW7LvC/u2PLZ5e7 BCUZbcfQUTBHskVfdUkTGrlDvYA9aE0N5S5+CmF80Uf7v7BvUpLxds+4GYyj5kC6vhnkgu dvJ5TuIulvZ/d4ba4AoMBEl+ATUmP7HfdSMb4RhnuQMiN6SwK6a+f2qESrAHxzr/9wJjyh OqMf4yyQUOnfd2mKu/nPTN9e/fI6GBUzr0OJzLYMwn4KR8FOlDYY62egAgVHl2ulCsm787 L2B7ZZIKIaXP1F/J2lf/j6jYykO96hsaJ6pHdowH3SduYGGSLHK4TIzIzYhj9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729238061; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NGG6LXotAv6fAA6FIRpCTuYc6o+HszFpBIl+S/Irmnc=; b=FGYkl8hgKNdDZQi5OicdLINld5dZxcj4Ti5GecVTEMWpbwpB7328NZW2/x+o0cU3HaKfGC 70jZJ8zoqG92t4gcUnCSCrwajK1x8gzW9+DTbGw5mZSS1VxxOp/gBkLUWgwz5fHxhrk558 CBzedKITWsxdGPjwm2JNwHEg0qfSVArwZ0ZjSVXXSEN+qVa3smsiNaUwY7NdgHIjUM+/W+ +HjqoZO517aYpG+0hMNyqILIdDCJ4YW0cDb9URNipzhtywbk5uXb1MZ2Aa/yXEMWr+oWZ2 2mUsxLOL9xtB0/zq8DJ9NaE8dW/UajrQxJn/iRDvzO1sW/EUjSgNi2+zYZpfIg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729238061; a=rsa-sha256; cv=none; b=gPf/dlikEDbYmfnd8/5CcAXyE2mZ9WuYpIJXQ7aAsvAjSt537C4KNbHbwivQXF923/3yOp mNYj9+ON8aPte3ISQwkO6xEyFdsF6w+/ykVnVtHijs+5ETN0FojEFtoijBwpyT3ARkcTzC a6Vpgv9AXcczTDLZQ/GCAu8PudUWGihzY9XnwOF3VqLpWXBg49hRW6CA4OWkni2+wG6Q7m B5vKVyTwNpXDu6FzDU6SSWpqClBTy1KH6xU6+rilRjqzN3bK/kDWbaNwE4w11CB3KZr8Q3 u8uSp4hL7Q5kO5BDOLsjctQn96aOhtSmjqGg5kjnu9FGij9lBv6NXnfP8rOOZw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XVH6541MKzQHW; Fri, 18 Oct 2024 07:54:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49I7sLRn001546; Fri, 18 Oct 2024 07:54:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49I7sL9X001543; Fri, 18 Oct 2024 07:54:21 GMT (envelope-from git) Date: Fri, 18 Oct 2024 07:54:21 GMT Message-Id: <202410180754.49I7sL9X001543@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Richard Scheffenegger Subject: git: 6b2977c5978b - stable/14 - tcp: fix duplicate retransmissions when RTO happens during SACK loss recovery List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rscheff X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 6b2977c5978b58718d9cddc0a8c31e1bd9aa0361 Auto-Submitted: auto-generated The branch stable/14 has been updated by rscheff: URL: https://cgit.FreeBSD.org/src/commit/?id=6b2977c5978b58718d9cddc0a8c31e1bd9aa0361 commit 6b2977c5978b58718d9cddc0a8c31e1bd9aa0361 Author: Richard Scheffenegger AuthorDate: 2024-10-10 10:50:22 +0000 Commit: Richard Scheffenegger CommitDate: 2024-10-18 07:51:38 +0000 tcp: fix duplicate retransmissions when RTO happens during SACK loss recovery When snd_nxt doesn't track snd_max, partial SACK ACKs may elicit unexpected duplicate retransmissions. This is usually masked by LRO not necessarily ACKing every individual segment, and prior to RFC6675 SACK loss recovery, harder to trigger even when an RTO happens while SACK loss recovery is ongoing. Address this by improving the logic when to start a SACK loss recovery and how to deal with a RTO, as well as improvements to the adjusted congestion window during transmission selection. Reviewed By: tuexen, cc, #transport Sponsored by: NetApp, Inc. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D43355 (cherry picked from commit 440f4ba18e3ab7be912858bbcb96a419fcf14809) --- sys/netinet/tcp_input.c | 16 ++++++++++------ sys/netinet/tcp_output.c | 27 +++++++++++++++++---------- sys/netinet/tcp_sack.c | 42 +++++++++++++++++++++++++++--------------- sys/netinet/tcp_var.h | 2 +- 4 files changed, 55 insertions(+), 32 deletions(-) diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index 500d208b7756..83f85a50ed40 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -2723,9 +2723,7 @@ enter_recovery: tp->snd_nxt - tp->snd_una); } if (tcp_is_sack_recovery(tp, &to)) { - TCPSTAT_INC( - tcps_sack_recovery_episode); - tp->snd_recover = tp->snd_nxt; + TCPSTAT_INC(tcps_sack_recovery_episode); tp->snd_cwnd = maxseg; (void) tcp_output(tp); if (SEQ_GT(th->th_ack, tp->snd_una)) @@ -2768,8 +2766,12 @@ enter_recovery: __func__)); if (tp->t_dupacks == 1) tp->snd_limited = 0; - tp->snd_cwnd = - (tp->snd_nxt - tp->snd_una) + + if ((tp->snd_nxt == tp->snd_max) && + (tp->t_rxtshift == 0)) + tp->snd_cwnd = + SEQ_SUB(tp->snd_nxt, + tp->snd_una); + tp->snd_cwnd += (tp->t_dupacks - tp->snd_limited) * maxseg; /* @@ -2815,7 +2817,9 @@ enter_recovery: * counted as dupacks here. */ if (tcp_is_sack_recovery(tp, &to) && - (sack_changed != SACK_NOCHANGE)) { + (((tp->t_rxtshift == 0) && (sack_changed != SACK_NOCHANGE)) || + ((tp->t_rxtshift > 0) && (sack_changed == SACK_NEWLOSS))) && + (tp->snd_nxt == tp->snd_max)) { tp->t_dupacks++; /* limit overhead by setting maxseg last */ if (!IN_FASTRECOVERY(tp->t_flags) && diff --git a/sys/netinet/tcp_output.c b/sys/netinet/tcp_output.c index 9269ba443bd9..d1a81123ebad 100644 --- a/sys/netinet/tcp_output.c +++ b/sys/netinet/tcp_output.c @@ -266,6 +266,7 @@ tcp_default_output(struct tcpcb *tp) } } again: + sendwin = 0; /* * If we've recently taken a timeout, snd_max will be greater than * snd_nxt. There may be SACK information that allows us to avoid @@ -273,12 +274,12 @@ again: */ if ((tp->t_flags & TF_SACK_PERMIT) && SEQ_LT(tp->snd_nxt, tp->snd_max)) - tcp_sack_adjust(tp); + sendwin = tcp_sack_adjust(tp); sendalot = 0; tso = 0; mtu = 0; off = tp->snd_nxt - tp->snd_una; - sendwin = min(tp->snd_wnd, tp->snd_cwnd); + sendwin = min(tp->snd_wnd, tp->snd_cwnd + sendwin); flags = tcp_outflags[tp->t_state]; /* @@ -295,7 +296,8 @@ again: sack_bytes_rxmt = 0; len = 0; p = NULL; - if ((tp->t_flags & TF_SACK_PERMIT) && IN_FASTRECOVERY(tp->t_flags) && + if ((tp->t_flags & TF_SACK_PERMIT) && + (IN_FASTRECOVERY(tp->t_flags) || SEQ_LT(tp->snd_nxt, tp->snd_max)) && (p = tcp_sack_output(tp, &sack_bytes_rxmt))) { uint32_t cwin; @@ -397,10 +399,10 @@ after_sack_rexmit: * in which case len is already set. */ if (sack_rxmit == 0) { - if (sack_bytes_rxmt == 0) + if ((sack_bytes_rxmt == 0) || SEQ_LT(tp->snd_nxt, tp->snd_max)) { len = ((int32_t)min(sbavail(&so->so_snd), sendwin) - off); - else { + } else { int32_t cwin; /* @@ -1635,11 +1637,16 @@ timer: tp->snd_max = tp->snd_nxt + xlen; } if ((error == 0) && - (TCPS_HAVEESTABLISHED(tp->t_state) && - (tp->t_flags & TF_SACK_PERMIT) && - tp->rcv_numsacks > 0)) { - /* Clean up any DSACK's sent */ - tcp_clean_dsack_blocks(tp); + (tp->rcv_numsacks > 0) && + TCPS_HAVEESTABLISHED(tp->t_state) && + (tp->t_flags & TF_SACK_PERMIT)) { + /* Clean up any DSACK's sent */ + tcp_clean_dsack_blocks(tp); + } + if ((error == 0) && + sack_rxmit && + SEQ_LT(tp->snd_nxt, SEQ_MIN(p->rxmit, p->end))) { + tp->snd_nxt = SEQ_MIN(p->rxmit, p->end); } if (error) { /* diff --git a/sys/netinet/tcp_sack.c b/sys/netinet/tcp_sack.c index 05aaa0b4a662..f33c7030f21e 100644 --- a/sys/netinet/tcp_sack.c +++ b/sys/netinet/tcp_sack.c @@ -897,8 +897,8 @@ tcp_sack_partialack(struct tcpcb *tp, struct tcphdr *th) if (tp->t_flags & TF_SENTFIN) highdata--; highdata = SEQ_MIN(highdata, tp->snd_recover); - if (th->th_ack != highdata) { - tp->snd_fack = th->th_ack; + if (SEQ_LT(th->th_ack, highdata)) { + tp->snd_fack = SEQ_MAX(th->th_ack, tp->snd_fack); (void)tcp_sackhole_insert(tp, SEQ_MAX(th->th_ack, highdata - maxseg), highdata, NULL); } @@ -991,35 +991,47 @@ tcp_sack_output(struct tcpcb *tp, int *sack_bytes_rexmt) * After a timeout, the SACK list may be rebuilt. This SACK information * should be used to avoid retransmitting SACKed data. This function * traverses the SACK list to see if snd_nxt should be moved forward. + * In addition, cwnd will be inflated by the sacked bytes traversed when + * moving snd_nxt forward. This prevents a traffic burst after the final + * full ACK, and also keeps ACKs coming back. */ -void +int tcp_sack_adjust(struct tcpcb *tp) { + int sacked = 0; struct sackhole *p, *cur = TAILQ_FIRST(&tp->snd_holes); INP_WLOCK_ASSERT(tptoinpcb(tp)); - if (cur == NULL) - return; /* No holes */ - if (SEQ_GEQ(tp->snd_nxt, tp->snd_fack)) - return; /* We're already beyond any SACKed blocks */ - /*- + if (cur == NULL) { + /* No holes */ + return (0); + } + if (SEQ_GEQ(tp->snd_nxt, tp->snd_fack)) { + /* We're already beyond any SACKed blocks */ + return (tp->sackhint.sacked_bytes); + } + /* * Two cases for which we want to advance snd_nxt: * i) snd_nxt lies between end of one hole and beginning of another * ii) snd_nxt lies between end of last hole and snd_fack */ while ((p = TAILQ_NEXT(cur, scblink)) != NULL) { - if (SEQ_LT(tp->snd_nxt, cur->end)) - return; - if (SEQ_GEQ(tp->snd_nxt, p->start)) + if (SEQ_LT(tp->snd_nxt, cur->end)) { + return (sacked); + } + sacked += p->start - cur->end; + if (SEQ_GEQ(tp->snd_nxt, p->start)) { cur = p; - else { + } else { tp->snd_nxt = p->start; - return; + return (sacked); } } - if (SEQ_LT(tp->snd_nxt, cur->end)) - return; + if (SEQ_LT(tp->snd_nxt, cur->end)) { + return (sacked); + } tp->snd_nxt = tp->snd_fack; + return (tp->sackhint.sacked_bytes); } /* diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index 83ea1608abe1..b75210acad33 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -1516,7 +1516,7 @@ void tcp_update_dsack_list(struct tcpcb *, tcp_seq, tcp_seq); void tcp_update_sack_list(struct tcpcb *tp, tcp_seq rcv_laststart, tcp_seq rcv_lastend); void tcp_clean_dsack_blocks(struct tcpcb *tp); void tcp_clean_sackreport(struct tcpcb *tp); -void tcp_sack_adjust(struct tcpcb *tp); +int tcp_sack_adjust(struct tcpcb *tp); struct sackhole *tcp_sack_output(struct tcpcb *tp, int *sack_bytes_rexmt); void tcp_do_prr_ack(struct tcpcb *, struct tcphdr *, struct tcpopt *, sackstatus_t); void tcp_lost_retransmission(struct tcpcb *, struct tcphdr *);