simplify TCP loss marking code
Subsystems (3)
cover simplify TCP loss marking code
The TCP loss marking is implemented by a set of intertwined subroutines. TCP has several loss detection algorithms (RACK, RFC6675/FACK, NewReno, etc) each calls a subset of these routines to mark a packet lost. This has led to various bugs (and fixes and fixes of fixes).
This patch set is to consolidate the loss marking code so all detection algorithms call the same routine tcp_mark_skb_lost().
Yuchung Cheng (4):
tcp: consistently check retransmit hint
tcp: move tcp_mark_skb_lost
tcp: simplify tcp_mark_skb_lost
tcp: consolidate tcp_mark_skb_lost and tcp_skb_mark_lost
net/ipv4/tcp_input.c | 60 +++++++++++++++-------------------------- net/ipv4/tcp_recovery.c | 16 +---------- 2 files changed, 23 insertions(+), 53 deletions(-)
Signature · 1 line
2.28.0.681.g6f77f65b4e-goog
PATCH 1/4 tcp: consistently check retransmit hint
tcp_simple_retransmit() used for path MTU discovery may not adjust the retransmit hint properly by deducting retrans_out before checking it to adjust the hint. This patch fixes this by a correct routine tcp_mark_skb_lost() already used by the RACK loss detection.
--- net/ipv4/tcp_input.c | 9 ++------- net/ipv4/tcp_recovery.c | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-)
net/ipv4/tcp_input.c +2 -7
@@ -2675,13 +2675,8 @@ void tcp_simple_retransmit(struct sock *sk) skb_rbtree_walk(skb, &sk->tcp_rtx_queue) {if (tcp_skb_seglen (skb) > mss && - !(TCP_SKB_CB (skb)->sacked &TCPCB_SACKED_ACKED )) { -if (TCP_SKB_CB (skb)->sacked &TCPCB_SACKED_RETRANS ) { -TCP_SKB_CB (skb)->sacked &= ~TCPCB_SACKED_RETRANS ; - tp->retrans_out -=tcp_skb_pcount (skb); - } -tcp_skb_mark_lost_uncond_verify (tp, skb); - } + !(TCP_SKB_CB (skb)->sacked &TCPCB_SACKED_ACKED )) +tcp_mark_skb_lost (sk, skb); }tcp_clear_retrans_hints_partial (tp);
net/ipv4/tcp_recovery.c +1 -1
@@ -246,6 +246,6 @@ void tcp_newreno_mark_lost(struct sock *sk, bool snd_una_advanced)tcp_fragment (sk,TCP_FRAG_IN_RTX_QUEUE , skb, mss, mss,GFP_ATOMIC ); -tcp_skb_mark_lost_uncond_verify (tp, skb); +tcp_mark_skb_lost (sk, skb); } }
Signature · 1 line
2.28.0.681.g6f77f65b4e-goog
PATCH 2/4 tcp: move tcp_mark_skb_lost
In reply to Yuchung ChengA pure refactor to move tcp_mark_skb_lost to tcp_input.c to prepare for the later loss marking consolidation.
--- net/ipv4/tcp_input.c | 14 ++++++++++++++ net/ipv4/tcp_recovery.c | 14 -------------- 2 files changed, 14 insertions(+), 14 deletions(-)
net/ipv4/tcp_input.c +14 -0
@@ -1016,6 +1016,20 @@ static void tcp_verify_retransmit_hint(struct tcp_sock *tp, struct sk_buff *skb) tp->retransmit_skb_hint = skb; } +void tcp_mark_skb_lost (struct sock *sk,struct sk_buff *skb) +{ +struct tcp_sock *tp =tcp_sk (sk); + +tcp_skb_mark_lost_uncond_verify (tp, skb); +if (TCP_SKB_CB (skb)->sacked &TCPCB_SACKED_RETRANS ) { +/* Account for retransmits that are lost again */ +TCP_SKB_CB (skb)->sacked &= ~TCPCB_SACKED_RETRANS ; + tp->retrans_out -=tcp_skb_pcount (skb); +NET_ADD_STATS (sock_net (sk),LINUX_MIB_TCPLOSTRETRANSMIT , +tcp_skb_pcount (skb)); + } +} +/* Sum the number of packets on the wire we have marked as lost. * There are two cases we care about here: * a) Packet hasn't been marked lost (nor retransmitted),
net/ipv4/tcp_recovery.c +0 -14
@@ -2,20 +2,6 @@#include <linux/tcp.h> #include <net/tcp.h> -void tcp_mark_skb_lost (struct sock *sk,struct sk_buff *skb) -{ -struct tcp_sock *tp =tcp_sk (sk); - -tcp_skb_mark_lost_uncond_verify (tp, skb); -if (TCP_SKB_CB (skb)->sacked &TCPCB_SACKED_RETRANS ) { -/* Account for retransmits that are lost again */ -TCP_SKB_CB (skb)->sacked &= ~TCPCB_SACKED_RETRANS ; - tp->retrans_out -=tcp_skb_pcount (skb); -NET_ADD_STATS (sock_net (sk),LINUX_MIB_TCPLOSTRETRANSMIT , -tcp_skb_pcount (skb)); - } -} -static bool tcp_rack_sent_after (u64 t1,u64 t2,u32 seq1,u32 seq2) {return t1 > t2 || (t1 == t2 &&after (seq1, seq2));
Signature · 1 line
2.28.0.681.g6f77f65b4e-goog
PATCH 3/4 tcp: simplify tcp_mark_skb_lost
In reply to Yuchung ChengThis patch consolidates and simplifes the loss marking logic used by a few loss detections (RACK, RFC6675, NewReno). Previously each detection uses a subset of several intertwined subroutines. This unncessary complexity has led to bugs (and fixes of bug fixes).
tcp_mark_skb_lost now is the single one routine to mark a packet loss when a loss detection caller deems an skb ist lost:
1. rewind tp->retransmit_hint_skb if skb has lower sequence or all lost ones have been retransmitted.
2. book-keeping: adjust flags and counts depending on if skb was retransmitted or not.
--- net/ipv4/tcp_input.c | 59 +++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 37 deletions(-)
net/ipv4/tcp_input.c +22 -37
@@ -1006,7 +1006,11 @@ static void tcp_check_sack_reordering(struct sock *sk, const u32 low_seq, ts ? LINUX_MIB_TCPTSREORDER : LINUX_MIB_TCPSACKREORDER); } -/* This must be called before lost_out is incremented */ +/* This must be called before lost_out or retrans_out are updated +* on a new loss, because we want to know if all skbs previously +* known to be lost have already been retransmitted, indicating +* that this newly lost skb is our next skb to retransmit. +*/ static void tcp_verify_retransmit_hint (struct tcp_sock *tp,struct sk_buff *skb) { if ((!tp->retransmit_skb_hint && tp->retrans_out >= tp->lost_out) ||
@@ -1018,32 +1022,25 @@ static void tcp_verify_retransmit_hint(struct tcp_sock *tp, struct sk_buff *skb)void tcp_mark_skb_lost (struct sock *sk,struct sk_buff *skb) { +__u8 sacked =TCP_SKB_CB (skb)->sacked;struct tcp_sock *tp =tcp_sk (sk); -tcp_skb_mark_lost_uncond_verify (tp, skb); -if (TCP_SKB_CB (skb)->sacked &TCPCB_SACKED_RETRANS ) { -/* Account for retransmits that are lost again */ -TCP_SKB_CB (skb)->sacked &= ~TCPCB_SACKED_RETRANS ; - tp->retrans_out -=tcp_skb_pcount (skb); -NET_ADD_STATS (sock_net (sk),LINUX_MIB_TCPLOSTRETRANSMIT , -tcp_skb_pcount (skb)); - } -} - -/* Sum the number of packets on the wire we have marked as lost. -* There are two cases we care about here: -* a) Packet hasn't been marked lost (nor retransmitted), -* and this is the first loss. -* b) Packet has been marked both lost and retransmitted, -* and this means we think it was lost again. -*/ -static void tcp_sum_lost (struct tcp_sock *tp,struct sk_buff *skb) -{ -__u8 sacked =TCP_SKB_CB (skb)->sacked; +if (sacked &TCPCB_SACKED_ACKED ) +return ; -if (!(sacked &TCPCB_LOST ) || - ((sacked &TCPCB_LOST ) && (sacked &TCPCB_SACKED_RETRANS ))) - tp->lost +=tcp_skb_pcount (skb); +tcp_verify_retransmit_hint (tp, skb); +if (sacked &TCPCB_LOST ) { +if (sacked &TCPCB_SACKED_RETRANS ) { +/* Account for retransmits that are lost again */ +TCP_SKB_CB (skb)->sacked &= ~TCPCB_SACKED_RETRANS ; + tp->retrans_out -=tcp_skb_pcount (skb); +NET_ADD_STATS (sock_net (sk),LINUX_MIB_TCPLOSTRETRANSMIT , +tcp_skb_pcount (skb)); + } + }else { + tp->lost_out +=tcp_skb_pcount (skb); +TCP_SKB_CB (skb)->sacked |=TCPCB_LOST ; + } }static void tcp_skb_mark_lost (struct tcp_sock *tp,struct sk_buff *skb)
@@ -1057,17 +1054,6 @@ static void tcp_skb_mark_lost(struct tcp_sock *tp, struct sk_buff *skb) } } -void tcp_skb_mark_lost_uncond_verify (struct tcp_sock *tp,struct sk_buff *skb) -{ -tcp_verify_retransmit_hint (tp, skb); - -tcp_sum_lost (tp, skb); -if (!(TCP_SKB_CB (skb)->sacked & (TCPCB_LOST |TCPCB_SACKED_ACKED ))) { - tp->lost_out +=tcp_skb_pcount (skb); -TCP_SKB_CB (skb)->sacked |=TCPCB_LOST ; - } -} -/* Updates the delivered and delivered_ce counts */ static void tcp_count_delivered (struct tcp_sock *tp,u32 delivered,bool ece_ack)
@@ -2688,8 +2674,7 @@ void tcp_simple_retransmit(struct sock *sk)unsigned int mss =tcp_current_mss (sk); skb_rbtree_walk(skb, &sk->tcp_rtx_queue) { -if (tcp_skb_seglen (skb) > mss && - !(TCP_SKB_CB (skb)->sacked &TCPCB_SACKED_ACKED )) +if (tcp_skb_seglen (skb) > mss)tcp_mark_skb_lost (sk, skb); }
Signature · 1 line
2.28.0.681.g6f77f65b4e-goog
PATCH 4/4 tcp: consolidate tcp_mark_skb_lost and tcp_skb_mark_lost
In reply to Yuchung Chengtcp_skb_mark_lost is used by RFC6675-SACK and can easily be replaced with the new tcp_mark_skb_lost handler.
--- net/ipv4/tcp_input.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
net/ipv4/tcp_input.c +2 -12
@@ -1043,17 +1043,6 @@ void tcp_mark_skb_lost(struct sock *sk, struct sk_buff *skb) } } -static void tcp_skb_mark_lost (struct tcp_sock *tp,struct sk_buff *skb) -{ -if (!(TCP_SKB_CB (skb)->sacked & (TCPCB_LOST |TCPCB_SACKED_ACKED ))) { -tcp_verify_retransmit_hint (tp, skb); - - tp->lost_out +=tcp_skb_pcount (skb); -tcp_sum_lost (tp, skb); -TCP_SKB_CB (skb)->sacked |=TCPCB_LOST ; - } -} -/* Updates the delivered and delivered_ce counts */ static void tcp_count_delivered (struct tcp_sock *tp,u32 delivered,bool ece_ack)
@@ -2308,7 +2297,8 @@ static void tcp_mark_head_lost(struct sock *sk, int packets, int mark_head)if (cnt > packets)break ; -tcp_skb_mark_lost (tp, skb); +if (!(TCP_SKB_CB (skb)->sacked &TCPCB_LOST )) +tcp_mark_skb_lost (sk, skb);if (mark_head)break ;
Signature · 1 line
2.28.0.681.g6f77f65b4e-goog
David Miller
maintainerFrom: Yuchung Cheng <[email protected]>
Date: Fri, 25 Sep 2020 10:04:27 -0700
Quoted 8 lines
The TCP loss marking is implemented by a set of intertwined subroutines. TCP has several loss detection algorithms (RACK, RFC6675/FACK, NewReno, etc) each calls a subset of these routines to mark a packet lost. This has led to various bugs (and fixes and fixes of fixes).
This patch set is to consolidate the loss marking code so all detection algorithms call the same routine
tcp_mark_skb_lost().
Looks good, series applied.
Thanks.