net: tcp: don't allocate fast clones for fastopen SYN
Subsystems (3)
Jakub Kicinski
maintainerPATCH 1/1 net: tcp: don't allocate fast clones for fastopen SYN
When receiver does not accept TCP Fast Open it will only ack the SYN, and not the data. We detect this and immediately queue the data for (re)transmission in tcp_rcv_fastopen_synack().
In DC networks with very low RTT and without RFS the SYN-ACK may arrive before NIC driver reported Tx completion on the original SYN. In which case skb_still_in_host_queue() returns true and sender will need to wait for the retransmission timer to fire milliseconds later.
Revert back to non-fast clone skbs, this way skb_still_in_host_queue() won't prevent the recovery flow from completing.
--- net/ipv4/tcp_output.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
net/ipv4/tcp_output.c +8 -1
@@ -3759,9 +3759,16 @@ static int tcp_send_syn_data(struct sock *sk, struct sk_buff *syn)/* limit to order-0 allocations */ space =min_t (size_t, space,SKB_MAX_HEAD (MAX_TCP_HEADER )); - syn_data =sk_stream_alloc_skb (sk, space, sk->sk_allocation, false); + syn_data =alloc_skb (MAX_TCP_HEADER + space, sk->sk_allocation);if (!syn_data) goto fallback; +if (!sk_wmem_schedule (sk, syn_data->truesize)) { +__kfree_skb (syn_data); + goto fallback; + } +skb_reserve (syn_data,MAX_TCP_HEADER ); +INIT_LIST_HEAD (&syn_data->tcp_tsorted_anchor); + syn_data->ip_summed =CHECKSUM_PARTIAL ;memcpy (syn_data->cb, syn->cb,sizeof (syn->cb));if (space) {
Signature · 1 line
2.26.2
Quoted 11 lines · Jakub Kicinski
When receiver does not accept TCP Fast Open it will only ack the SYN, and not the data. We detect this and immediately queue the data for (re)transmission in
tcp_rcv_fastopen_synack().In DC networks with very low RTT and without RFS the SYN-ACK may arrive before NIC driver reported Tx completion on the original SYN. In which case
skb_still_in_host_queue()returns true and sender will need to wait for the retransmission timer to fire milliseconds later.
Quoted 6 lines
Revert back to non-fast clone skbs, this way
skb_still_in_host_queue()won't prevent the recovery flow from completing.Suggested-by Eric Dumazet <[email protected]>Fixes 355a901e6cf1 ("tcp: make connect() mem charging friendly")
Hmmm, not sure if this Fixes: tag makes sense.
Really, if we delay TX completions by say 10 ms, other parts of the stack will misbehave anyway.
Also, backporting this patch up to linux-3.19 is going to be tricky.
The real issue here is that skb_still_in_host_queue() can give a false positive.
I have mixed feelings here, as you can read my answer :/
Maybe skb_still_in_host_queue() signal should not be used when a part of the SKB has been received/acknowledged by the remote peer (in this case the SYN part).
Alternative is that drivers unable to TX complete their skbs in a reasonable time should call skb_orphan()
to avoid skb_unclone() penalties (and this skb_still_in_host_queue() issue)
If you really want to play and delay TX completions, maybe provide a way to disable skb_still_in_host_queue() globally,
using a static key ?
My personal WIP/hack was something like :
net/ipv4/tcp_input.c +0 -0
100644
net/ipv4/tcp_input.c +0 -0
@@ -5995,7 +5995,8 @@ static bool tcp_rcv_fastopen_synack(struct sock
*sk, struct sk_buff *synack,
else
tp->fastopen_client_fail = TFO_DATA_NOT_ACKED;
skb_rbtree_walk_from(data) {- if (__tcp_retransmit_skb(sk, data, 1))
+ /* segs = -1 to bypassskb_still_in_host_queue() check */
+ if (__tcp_retransmit_skb(sk, data, -1))
break;
}
tcp_rearm_rto(sk);net/ipv4/tcp_output.c +0 -0
100644
net/ipv4/tcp_output.c +0 -0
@@ -3155,8 +3155,12 @@ int __tcp_retransmit_skb(struct sock *sk,
struct sk_buff *skb, int segs)
sk->sk_sndbuf))
return -EAGAIN;- if (skb_still_in_host_queue(sk, skb))
- return -EBUSY;
+ if (segs > 0) {
+ if (skb_still_in_host_queue(sk, skb))
+ return -EBUSY;
+ } else {
+ segs = -segs;
+ }
if (before(TCP_SKB_CB(skb)->seq, tp->snd_una)) {
if (unlikely(before(TCP_SKB_CB(skb)->end_seq, tp->snd_una))) {Quoted 31 lines
Signed-off-by Neil Spring <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>--- net/ipv4/tcp_output.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)net/ipv4/tcp_output.c +8
-2@@ -3759,9 +3759,16 @@ static int tcp_send_syn_data(struct sock *sk, struct sk_buff *syn)/* limit to order-0 allocations */ space =min_t (size_t, space,SKB_MAX_HEAD (MAX_TCP_HEADER )); - syn_data =sk_stream_alloc_skb (sk, space, sk->sk_allocation, false); + syn_data =alloc_skb (MAX_TCP_HEADER + space, sk->sk_allocation);if (!syn_data) goto fallback; +if (!sk_wmem_schedule (sk, syn_data->truesize)) { +__kfree_skb (syn_data); + goto fallback; + } +skb_reserve (syn_data,MAX_TCP_HEADER ); +INIT_LIST_HEAD (&syn_data->tcp_tsorted_anchor); + syn_data->ip_summed =CHECKSUM_PARTIAL ;memcpy (syn_data->cb, syn->cb,sizeof (syn->cb));if (space) { --2.26.2
Jakub Kicinski
maintainerQuoted 19 lines · On Tue, 2 Mar 2021 10:38:46 +0100 Eric Dumazet wrote:
Quoted 11 lines · Jakub Kicinski
When receiver does not accept TCP Fast Open it will only ack the SYN, and not the data. We detect this and immediately queue the data for (re)transmission in
tcp_rcv_fastopen_synack().In DC networks with very low RTT and without RFS the SYN-ACK may arrive before NIC driver reported Tx completion on the original SYN. In which case
skb_still_in_host_queue()returns true and sender will need to wait for the retransmission timer to fire milliseconds later.Quoted 6 lines
Revert back to non-fast clone skbs, this way
skb_still_in_host_queue()won't prevent the recovery flow from completing.Suggested-by Eric Dumazet <[email protected]>Fixes 355a901e6cf1 ("tcp: make connect() mem charging friendly")
Quoted 6 lines
Hmmm, not sure if this Fixes: tag makes sense.
Really, if we delay TX completions by say 10 ms, other parts of the stack will misbehave anyway.
Also, backporting this patch up to linux-3.19 is going to be tricky.
Indeed, the problem is minor in practical terms. Maybe it's enough if I spell that out more in the description? Are you thinking net-next or net without a Fixes tag?
Quoted 7 lines
The real issue here is that
skb_still_in_host_queue()can give a false positive.I have mixed feelings here, as you can read my answer :/
Maybe
skb_still_in_host_queue()signal should not be used when a part of the SKB has been received/acknowledged by the remote peer (in this case the SYN part).
FWIW I was pondering this, when the rtx is requested by the receiver we are relatively sure we can ignore skb_still_in_host_queue() because we know our system should Tx in order so if receiver saw N + 1, N can't be in our queues.
But AFAICT generalizing the test doesn't matter much. In cases other than TFO worst case a loss probe will chase the rtx out. And I don't grasp enough of TCP to implement the general optimization :)
Quoted 7 lines
Alternative is that drivers unable to TX complete their skbs in a reasonable time should call
skb_orphan()
to avoidskb_unclone()penalties (and thisskb_still_in_host_queue()issue)If you really want to play and delay TX completions, maybe provide a way to disable
skb_still_in_host_queue()globally,
using a static key ?
I see the TFO issue with rx and tx completions set to 33us both, with two different NIC vendors, so the timing just influences the likelihood.
Quoted 1 line
My personal WIP/hack was something like :
LGTM, are you happy with that being the fix?
Quoted 38 lines
net/ipv4/tcp_input.c +0
-0100644
net/ipv4/tcp_input.c +1
-1@@ -5995,7 +5995,8 @@ static bool tcp_rcv_fastopen_synack(struct sock *sk, struct sk_buff *synack, else tp->fastopen_client_fail = TFO_DATA_NOT_ACKED;skb_rbtree_walk_from (data) { -if (__tcp_retransmit_skb (sk, data,1 )) +/* segs = -1 to bypass
skb_still_in_host_queue()check */net/ipv4/tcp_input.c +1
-0+if (__tcp_retransmit_skb (sk, data,-1 ))break ; }tcp_rearm_rto (sk);net/ipv4/tcp_output.c +0
-0100644
net/ipv4/tcp_output.c +6
-2@@ -3155,8 +3155,12 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs) sk->sk_sndbuf)) return -EAGAIN; -if (skb_still_in_host_queue (sk, skb)) -return -EBUSY ; +if (segs >0 ) { +if (skb_still_in_host_queue (sk, skb)) +return -EBUSY ; + }else { + segs = -segs; + }if (before (TCP_SKB_CB (skb)->seq, tp->snd_una)) {if (unlikely(before(TCP_SKB_CB(skb)->end_seq, tp->snd_una))) {
Quoted 57 lines · Jakub Kicinski
Quoted 19 lines · On Tue, 2 Mar 2021 10:38:46 +0100 Eric Dumazet wrote:
Quoted 11 lines · Jakub Kicinski
When receiver does not accept TCP Fast Open it will only ack the SYN, and not the data. We detect this and immediately queue the data for (re)transmission in
tcp_rcv_fastopen_synack().In DC networks with very low RTT and without RFS the SYN-ACK may arrive before NIC driver reported Tx completion on the original SYN. In which case
skb_still_in_host_queue()returns true and sender will need to wait for the retransmission timer to fire milliseconds later.Quoted 6 lines
Revert back to non-fast clone skbs, this way
skb_still_in_host_queue()won't prevent the recovery flow from completing.Suggested-by Eric Dumazet <[email protected]>Fixes 355a901e6cf1 ("tcp: make connect() mem charging friendly")Quoted 6 lines
Hmmm, not sure if this Fixes: tag makes sense.
Really, if we delay TX completions by say 10 ms, other parts of the stack will misbehave anyway.
Also, backporting this patch up to linux-3.19 is going to be tricky.
Indeed, the problem is minor in practical terms. Maybe it's enough if I spell that out more in the description? Are you thinking net-next or net without a Fixes tag?
Quoted 7 lines
The real issue here is that
skb_still_in_host_queue()can give a false positive.I have mixed feelings here, as you can read my answer :/
Maybe
skb_still_in_host_queue()signal should not be used when a part of the SKB has been received/acknowledged by the remote peer (in this case the SYN part).FWIW I was pondering this, when the rtx is requested by the receiver we are relatively sure we can ignore
skb_still_in_host_queue()because we know our system should Tx in order so if receiver saw N + 1, N can't be in our queues.But AFAICT generalizing the test doesn't matter much. In cases other than TFO worst case a loss probe will chase the rtx out. And I don't grasp enough of TCP to implement the general optimization :)
Quoted 7 lines
Alternative is that drivers unable to TX complete their skbs in a reasonable time should call
skb_orphan()
to avoidskb_unclone()penalties (and thisskb_still_in_host_queue()issue)If you really want to play and delay TX completions, maybe provide a way to disable
skb_still_in_host_queue()globally,
using a static key ?
Quoted 7 lines
I see the TFO issue with rx and tx completions set to 33us both, with two different NIC vendors, so the timing just influences the likelihood.
Quoted 1 line
My personal WIP/hack was something like :
LGTM, are you happy with that being the fix?
Yes, this seems a bit less intrusive, and net-next should be fine (I guess FB can backport this early if needed)
Quoted 40 lines
Quoted 39 lines
net/ipv4/tcp_input.c +0
-0100644
net/ipv4/tcp_input.c +1
-1@@ -5995,7 +5995,8 @@ static bool tcp_rcv_fastopen_synack(struct sock *sk, struct sk_buff *synack, else tp->fastopen_client_fail = TFO_DATA_NOT_ACKED;skb_rbtree_walk_from (data) { -if (__tcp_retransmit_skb (sk, data,1 )) +/* segs = -1 to bypass
skb_still_in_host_queue()check */net/ipv4/tcp_input.c +1
-0+if (__tcp_retransmit_skb (sk, data,-1 ))break ; }tcp_rearm_rto (sk);net/ipv4/tcp_output.c +0
-0100644
net/ipv4/tcp_output.c +6
-2@@ -3155,8 +3155,12 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs) sk->sk_sndbuf)) return -EAGAIN; -if (skb_still_in_host_queue (sk, skb)) -return -EBUSY ; +if (segs >0 ) { +if (skb_still_in_host_queue (sk, skb)) +return -EBUSY ; + }else { + segs = -segs; + }if (before (TCP_SKB_CB (skb)->seq, tp->snd_una)) {if (unlikely(before(TCP_SKB_CB(skb)->end_seq, tp->snd_una))) {
Quoted 27 lines · Eric Dumazet
Quoted 11 lines · Jakub Kicinski
When receiver does not accept TCP Fast Open it will only ack the SYN, and not the data. We detect this and immediately queue the data for (re)transmission in
tcp_rcv_fastopen_synack().In DC networks with very low RTT and without RFS the SYN-ACK may arrive before NIC driver reported Tx completion on the original SYN. In which case
skb_still_in_host_queue()returns true and sender will need to wait for the retransmission timer to fire milliseconds later.Quoted 6 lines
Revert back to non-fast clone skbs, this way
skb_still_in_host_queue()won't prevent the recovery flow from completing.Suggested-by Eric Dumazet <[email protected]>Fixes 355a901e6cf1 ("tcp: make connect() mem charging friendly")Hmmm, not sure if this Fixes: tag makes sense.
Really, if we delay TX completions by say 10 ms, other parts of the stack will misbehave anyway.
Also, backporting this patch up to linux-3.19 is going to be tricky.
Quoted 7 lines
The real issue here is that
skb_still_in_host_queue()can give a false positive.I have mixed feelings here, as you can read my answer :/
Maybe
skb_still_in_host_queue()signal should not be used when a part of the SKB has been received/acknowledged by the remote peer (in this case the SYN part).
Thank you Eric and Jakub for working on the TFO issue.
I like this option the most because it's more generic and easy to understand. Is it easy to implement by checking snd_una etc?
Quoted 83 lines
Alternative is that drivers unable to TX complete their skbs in a reasonable time should call
skb_orphan()
to avoidskb_unclone()penalties (and thisskb_still_in_host_queue()issue)If you really want to play and delay TX completions, maybe provide a way to disable
skb_still_in_host_queue()globally,
using a static key ?My personal WIP/hack was something like :
net/ipv4/tcp_input.c +0
-0100644
net/ipv4/tcp_input.c +1
-1@@ -5995,7 +5995,8 @@ static bool tcp_rcv_fastopen_synack(struct sock *sk, struct sk_buff *synack, else tp->fastopen_client_fail = TFO_DATA_NOT_ACKED;skb_rbtree_walk_from (data) { -if (__tcp_retransmit_skb (sk, data,1 )) +/* segs = -1 to bypass
skb_still_in_host_queue()check */net/ipv4/tcp_input.c +1
-0+if (__tcp_retransmit_skb (sk, data,-1 ))break ; }tcp_rearm_rto (sk);net/ipv4/tcp_output.c +0
-0100644
net/ipv4/tcp_output.c +6
-2@@ -3155,8 +3155,12 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs) sk->sk_sndbuf)) return -EAGAIN; -if (skb_still_in_host_queue (sk, skb)) -return -EBUSY ; +if (segs >0 ) { +if (skb_still_in_host_queue (sk, skb)) +return -EBUSY ; + }else { + segs = -segs; + }if (before (TCP_SKB_CB (skb)->seq, tp->snd_una)) {if (unlikely(before(TCP_SKB_CB(skb)->end_seq, tp->snd_una))) {Quoted 31 lines
Signed-off-by Neil Spring <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>--- net/ipv4/tcp_output.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)net/ipv4/tcp_output.c +8
-2@@ -3759,9 +3759,16 @@ static int tcp_send_syn_data(struct sock *sk, struct sk_buff *syn)/* limit to order-0 allocations */ space =min_t (size_t, space,SKB_MAX_HEAD (MAX_TCP_HEADER )); - syn_data =sk_stream_alloc_skb (sk, space, sk->sk_allocation, false); + syn_data =alloc_skb (MAX_TCP_HEADER + space, sk->sk_allocation);if (!syn_data) goto fallback; +if (!sk_wmem_schedule (sk, syn_data->truesize)) { +__kfree_skb (syn_data); + goto fallback; + } +skb_reserve (syn_data,MAX_TCP_HEADER ); +INIT_LIST_HEAD (&syn_data->tcp_tsorted_anchor); + syn_data->ip_summed =CHECKSUM_PARTIAL ;memcpy (syn_data->cb, syn->cb,sizeof (syn->cb));if (space) { --2.26.2
Jakub Kicinski
maintainerQuoted 30 lines · On Tue, 2 Mar 2021 12:52:14 -0800 Yuchung Cheng wrote:
Quoted 29 lines · Eric Dumazet
Quoted 10 lines · Jakub Kicinski
When receiver does not accept TCP Fast Open it will only ack the SYN, and not the data. We detect this and immediately queue the data for (re)transmission in
tcp_rcv_fastopen_synack().In DC networks with very low RTT and without RFS the SYN-ACK may arrive before NIC driver reported Tx completion on the original SYN. In which case
skb_still_in_host_queue()returns true and sender will need to wait for the retransmission timer to fire milliseconds later.Quoted 6 lines
Revert back to non-fast clone skbs, this way
skb_still_in_host_queue()won't prevent the recovery flow from completing.Suggested-by Eric Dumazet <[email protected]>Fixes 355a901e6cf1 ("tcp: make connect() mem charging friendly")Hmmm, not sure if this Fixes: tag makes sense.
Really, if we delay TX completions by say 10 ms, other parts of the stack will misbehave anyway.
Also, backporting this patch up to linux-3.19 is going to be tricky.
The real issue here is that
skb_still_in_host_queue()can give a false positive.I have mixed feelings here, as you can read my answer :/
Quoted 7 lines
Quoted 3 lines
Maybe
skb_still_in_host_queue()signal should not be used when a part of the SKB has been received/acknowledged by the remote peer (in this case the SYN part).Thank you Eric and Jakub for working on the TFO issue.
I like this option the most because it's more generic and easy to understand.
I'm assuming by "this" you mean v1 - as far as understanding goes we can polish v2. I think Eric just shared a quick example, but perhaps we could add an explicit bool to __tcp_retransmit_skb() called expl_req or such to signify that the rtx was explicitly requested by the receiver and therefore we can skip the "in queue" check? Or add some flags to the call?
If everyone is okay with targeting -next the new argument won't be an issue.
Quoted 1 line
Is it easy to implement by checking
snd_unaetc?
That is to detect TFO retransmits in __tcp_retransmit_skb() by matching the connections state, like acked == 1?
Quoted 35 lines · Eric Dumazet
Quoted 11 lines · Jakub Kicinski
When receiver does not accept TCP Fast Open it will only ack the SYN, and not the data. We detect this and immediately queue the data for (re)transmission in
tcp_rcv_fastopen_synack().In DC networks with very low RTT and without RFS the SYN-ACK may arrive before NIC driver reported Tx completion on the original SYN. In which case
skb_still_in_host_queue()returns true and sender will need to wait for the retransmission timer to fire milliseconds later.Quoted 6 lines
Revert back to non-fast clone skbs, this way
skb_still_in_host_queue()won't prevent the recovery flow from completing.Suggested-by Eric Dumazet <[email protected]>Fixes 355a901e6cf1 ("tcp: make connect() mem charging friendly")Hmmm, not sure if this Fixes: tag makes sense.
Really, if we delay TX completions by say 10 ms, other parts of the stack will misbehave anyway.
Also, backporting this patch up to linux-3.19 is going to be tricky.
The real issue here is that
skb_still_in_host_queue()can give a false positive.I have mixed feelings here, as you can read my answer :/
Maybe
skb_still_in_host_queue()signal should not be used when a part of the SKB has been received/acknowledged by the remote peer (in this case the SYN part).
Quoted 7 lines
Alternative is that drivers unable to TX complete their skbs in a reasonable time should call
skb_orphan()
to avoidskb_unclone()penalties (and thisskb_still_in_host_queue()issue)If you really want to play and delay TX completions, maybe provide a way to disable
skb_still_in_host_queue()globally,
using a static key ?
The problem as I see it is that the original fclone isn't what we sent out on the wire and that is confusing things. What we sent was a SYN with data, but what we have now is just a data frame that hasn't been put out on the wire yet.
I wonder if we couldn't get away with doing something like adding a fourth option of SKB_FCLONE_MODIFIED that we could apply to fastopen skbs? That would keep the skb_still_in_host queue from triggering as we would be changing the state from SKB_FCLONE_ORIG to SKB_FCLONE_MODIFIED for the skb we store in the retransmit queue. In addition if we have to clone it again and the fclone reference count is 1 we could reset it back to SKB_FCLONE_ORIG.
Jakub Kicinski
maintainerQuoted 38 lines · On Wed, 3 Mar 2021 13:35:53 -0800 Alexander Duyck wrote:
Quoted 37 lines · Eric Dumazet
Quoted 10 lines · Jakub Kicinski
When receiver does not accept TCP Fast Open it will only ack the SYN, and not the data. We detect this and immediately queue the data for (re)transmission in
tcp_rcv_fastopen_synack().In DC networks with very low RTT and without RFS the SYN-ACK may arrive before NIC driver reported Tx completion on the original SYN. In which case
skb_still_in_host_queue()returns true and sender will need to wait for the retransmission timer to fire milliseconds later.Quoted 6 lines
Revert back to non-fast clone skbs, this way
skb_still_in_host_queue()won't prevent the recovery flow from completing.Suggested-by Eric Dumazet <[email protected]>Fixes 355a901e6cf1 ("tcp: make connect() mem charging friendly")Hmmm, not sure if this Fixes: tag makes sense.
Really, if we delay TX completions by say 10 ms, other parts of the stack will misbehave anyway.
Also, backporting this patch up to linux-3.19 is going to be tricky.
The real issue here is that
skb_still_in_host_queue()can give a false positive.I have mixed feelings here, as you can read my answer :/
Maybe
skb_still_in_host_queue()signal should not be used when a part of the SKB has been received/acknowledged by the remote peer (in this case the SYN part).Alternative is that drivers unable to TX complete their skbs in a reasonable time should call
skb_orphan()
to avoidskb_unclone()penalties (and thisskb_still_in_host_queue()issue)
Quoted 8 lines
Quoted 3 lines
If you really want to play and delay TX completions, maybe provide a way to disable
skb_still_in_host_queue()globally,
using a static key ?The problem as I see it is that the original fclone isn't what we sent out on the wire and that is confusing things. What we sent was a SYN with data, but what we have now is just a data frame that hasn't been put out on the wire yet.
Not sure I understand why it's the key distinction here. Is it re-transmitting part of the frame or having different flags? Is re-transmit of half of a GSO skb also considered not the same?
To me the distinction is that the receiver has implicitly asked us for the re-transmission. If it was requested by SACK we should ignore "in_queue" for the first transmission as well, even if the skb state is identical.
Quoted 7 lines
I wonder if we couldn't get away with doing something like adding a fourth option of
SKB_FCLONE_MODIFIEDthat we could apply to fastopen skbs? That would keep theskb_still_in_hostqueue from triggering as we would be changing the state fromSKB_FCLONE_ORIGtoSKB_FCLONE_MODIFIEDfor the skb we store in the retransmit queue. In addition if we have to clone it again and the fclone reference count is 1 we could reset it back toSKB_FCLONE_ORIG.
The unused value of fclone was tempting me as well :)
AFAICT we have at least these options:
1 - don't use a fclone skb [v1]
2 - mark the fclone as "special" at Tx to escape the "in queue" check
3 - indicate to retansmit that we're sure initial tx is out [v2]
4 - same as above but with a bool / flag instead of negative seg
5 - use the fclone bits but mark them at Rx when we see a rtx request
6 - check the skb state in retransmit to match the TFO case (IIUC
Yuchung's suggestion)
#5 is my favorite but I didn't know how to extend it to fast re-transmits so I just stuck to the suggestion from the ML :)
WDYT? Eric, Yuchung?
Quoted 44 lines · Jakub Kicinski
Quoted 42 lines · On Wed, 3 Mar 2021 13:35:53 -0800 Alexander Duyck wrote:
Quoted 40 lines · Eric Dumazet
Quoted 10 lines · Jakub Kicinski
When receiver does not accept TCP Fast Open it will only ack the SYN, and not the data. We detect this and immediately queue the data for (re)transmission in
tcp_rcv_fastopen_synack().In DC networks with very low RTT and without RFS the SYN-ACK may arrive before NIC driver reported Tx completion on the original SYN. In which case
skb_still_in_host_queue()returns true and sender will need to wait for the retransmission timer to fire milliseconds later.Quoted 6 lines
Revert back to non-fast clone skbs, this way
skb_still_in_host_queue()won't prevent the recovery flow from completing.Suggested-by Eric Dumazet <[email protected]>Fixes 355a901e6cf1 ("tcp: make connect() mem charging friendly")Hmmm, not sure if this Fixes: tag makes sense.
Really, if we delay TX completions by say 10 ms, other parts of the stack will misbehave anyway.
Also, backporting this patch up to linux-3.19 is going to be tricky.
The real issue here is that
skb_still_in_host_queue()can give a false positive.I have mixed feelings here, as you can read my answer :/
Maybe
skb_still_in_host_queue()signal should not be used when a part of the SKB has been received/acknowledged by the remote peer (in this case the SYN part).Alternative is that drivers unable to TX complete their skbs in a reasonable time should call
skb_orphan()
to avoidskb_unclone()penalties (and thisskb_still_in_host_queue()issue)If you really want to play and delay TX completions, maybe provide a way to disable
skb_still_in_host_queue()globally,
using a static key ?
Quoted 8 lines
Quoted 4 lines
The problem as I see it is that the original fclone isn't what we sent out on the wire and that is confusing things. What we sent was a SYN with data, but what we have now is just a data frame that hasn't been put out on the wire yet.
Not sure I understand why it's the key distinction here. Is it re-transmitting part of the frame or having different flags? Is re-transmit of half of a GSO skb also considered not the same?
The difference in my mind is the flags. So specifically the clone of the syn_data frame in the case of the TCP fast open isn't actually a clone of the sent frame. Instead we end up modifying the flags so that it becomes the first data frame. We already have the SYN sitting in the retransmit queue before we send the SYN w/ data frame. In addition the SYN packet in the retransmit queue has a reference count of 1 so it is not encumbered by the fclone reference count check so it could theoretically be retransmitted immediately, it is just the data packet that is being held.
If we replay a GSO frame we will get the same frames all over again. In the case of a TCP fast open syn_data packet that isn't the case. The first time out it is one packet, the second time it is two.
Quoted 4 lines
To me the distinction is that the receiver has implicitly asked us for the re-transmission. If it was requested by SACK we should ignore "
in_queue" for the first transmission as well, even if the skb state is identical.
In my mind the distinction is the fact that what we have in the retransmit queue is 2 frames, a SYN and a data. Whereas what we have put on the wire is SYN w/ data.
Quoted 8 lines
Quoted 7 lines
I wonder if we couldn't get away with doing something like adding a fourth option of
SKB_FCLONE_MODIFIEDthat we could apply to fastopen skbs? That would keep theskb_still_in_hostqueue from triggering as we would be changing the state fromSKB_FCLONE_ORIGtoSKB_FCLONE_MODIFIEDfor the skb we store in the retransmit queue. In addition if we have to clone it again and the fclone reference count is 1 we could reset it back toSKB_FCLONE_ORIG.
Quoted 7 lines
The unused value of fclone was tempting me as well :)
AFAICT we have at least these options:
1 - don't use a fclone skb [v1]
2 - mark the fclone as "special" at Tx to escape the "in queue" check
This is what I had in mind. Basically just add a function to transition from SKB_FCLONE_ORIG to SKB_FCLONE_MODIFIED/DIRTY when the clone no longer represents what is actually on the wire.
The added benefit is that we can potentially restore it to SKB_FCLONE_ORIG if we clone it again assuming the reference count fell back to 1.
Quoted 13 lines
3 - indicate to retansmit that we're sure initial tx is out [v2]
4 - same as above but with a bool / flag instead of negative seg
5 - use the fclone bits but mark them at Rx when we see a rtx request
6 - check the skb state in retransmit to match the TFO case (IIUC
Yuchung's suggestion)#5 is my favorite but I didn't know how to extend it to fast re-transmits so I just stuck to the suggestion from the ML :)
WDYT? Eric, Yuchung?
Quoted 94 lines · Alexander Duyck
Quoted 44 lines · Jakub Kicinski
Quoted 42 lines · On Wed, 3 Mar 2021 13:35:53 -0800 Alexander Duyck wrote:
Quoted 40 lines · Eric Dumazet
Quoted 10 lines · Jakub Kicinski
When receiver does not accept TCP Fast Open it will only ack the SYN, and not the data. We detect this and immediately queue the data for (re)transmission in
tcp_rcv_fastopen_synack().In DC networks with very low RTT and without RFS the SYN-ACK may arrive before NIC driver reported Tx completion on the original SYN. In which case
skb_still_in_host_queue()returns true and sender will need to wait for the retransmission timer to fire milliseconds later.Quoted 6 lines
Revert back to non-fast clone skbs, this way
skb_still_in_host_queue()won't prevent the recovery flow from completing.Suggested-by Eric Dumazet <[email protected]>Fixes 355a901e6cf1 ("tcp: make connect() mem charging friendly")Hmmm, not sure if this Fixes: tag makes sense.
Really, if we delay TX completions by say 10 ms, other parts of the stack will misbehave anyway.
Also, backporting this patch up to linux-3.19 is going to be tricky.
The real issue here is that
skb_still_in_host_queue()can give a false positive.I have mixed feelings here, as you can read my answer :/
Maybe
skb_still_in_host_queue()signal should not be used when a part of the SKB has been received/acknowledged by the remote peer (in this case the SYN part).Alternative is that drivers unable to TX complete their skbs in a reasonable time should call
skb_orphan()
to avoidskb_unclone()penalties (and thisskb_still_in_host_queue()issue)If you really want to play and delay TX completions, maybe provide a way to disable
skb_still_in_host_queue()globally,
using a static key ?Quoted 8 lines
Quoted 4 lines
The problem as I see it is that the original fclone isn't what we sent out on the wire and that is confusing things. What we sent was a SYN with data, but what we have now is just a data frame that hasn't been put out on the wire yet.
Not sure I understand why it's the key distinction here. Is it re-transmitting part of the frame or having different flags? Is re-transmit of half of a GSO skb also considered not the same?
The difference in my mind is the flags. So specifically the clone of the
syn_dataframe in the case of the TCP fast open isn't actually a clone of the sent frame. Instead we end up modifying the flags so that it becomes the first data frame. We already have the SYN sitting in the retransmit queue before we send the SYN w/ data frame. In addition the SYN packet in the retransmit queue has a reference count of 1 so it is not encumbered by the fclone reference count check so it could theoretically be retransmitted immediately, it is just the data packet that is being held.If we replay a GSO frame we will get the same frames all over again. In the case of a TCP fast open
syn_datapacket that isn't the case. The first time out it is one packet, the second time it is two.Quoted 4 lines
To me the distinction is that the receiver has implicitly asked us for the re-transmission. If it was requested by SACK we should ignore "
in_queue" for the first transmission as well, even if the skb state is identical.In my mind the distinction is the fact that what we have in the retransmit queue is 2 frames, a SYN and a data. Whereas what we have put on the wire is SYN w/ data.
Quoted 8 lines
Quoted 7 lines
I wonder if we couldn't get away with doing something like adding a fourth option of
SKB_FCLONE_MODIFIEDthat we could apply to fastopen skbs? That would keep theskb_still_in_hostqueue from triggering as we would be changing the state fromSKB_FCLONE_ORIGtoSKB_FCLONE_MODIFIEDfor the skb we store in the retransmit queue. In addition if we have to clone it again and the fclone reference count is 1 we could reset it back toSKB_FCLONE_ORIG.Quoted 7 lines
The unused value of fclone was tempting me as well :)
AFAICT we have at least these options:
1 - don't use a fclone skb [v1]
2 - mark the fclone as "special" at Tx to escape the "in queue" check
Quoted 8 lines
This is what I had in mind. Basically just add a function to transition from
SKB_FCLONE_ORIGto SKB_FCLONE_MODIFIED/DIRTY when the clone no longer represents what is actually on the wire.The added benefit is that we can potentially restore it to
SKB_FCLONE_ORIGif we clone it again assuming the reference count fell back to 1.
I think we are over thinking this really (especially if the fix needs a change in core networking or drivers)
We can reuse TSQ logic to have a chance to recover when the clone is eventually freed.
This will be more generic, not only for the SYN+data of FastOpen.
Can you please test the following patch ?
include/linux/skbuff.h +0 -0
100644
include/linux/skbuff.h +1 -1
@@ -1136,7 +1136,7 @@ static inline bool skb_fclone_busy(const struct sock *sk,return skb->fclone ==SKB_FCLONE_ORIG &&refcount_read (&fclones->fclone_ref) >1 && - fclones->skb2.sk == sk; +READ_ONCE (fclones->skb2.sk) == sk; }/**
net/ipv4/tcp_output.c +0 -0
100644
net/ipv4/tcp_output.c +0 -0
@@ -2775,13 +2775,22 @@ bool tcp_schedule_loss_probe(struct sock *sk,
bool advancing_rto)
* a packet is still in a qdisc or driver queue.
* In this case, there is very little point doing a retransmit ! */
-static bool skb_still_in_host_queue(const struct sock *sk, +static bool skb_still_in_host_queue(struct sock *sk,
const struct sk_buff *skb)
{
if (unlikely(skb_fclone_busy(sk, skb))) {
- NET_INC_STATS(sock_net(sk),
- LINUX_MIB_TCPSPURIOUS_RTX_HOSTQUEUES);
- return true;
+ set_bit(TSQ_THROTTLED, &sk->sk_tsq_flags);
+ /* If TX completion is really slow, we could havereceived an ACK
+ * for a packet not yet freed by the driver.
+ * Setting TSQ_THROTTLED makes sure we will attempt to
retransmit
+ * later when fclone is no longer busy.
+ */
+ smp_mb__after_atomic();
+ if (skb_fclone_busy(sk, skb)) {
+ NET_INC_STATS(sock_net(sk),
+ LINUX_MIB_TCPSPURIOUS_RTX_HOSTQUEUES);
+ return true;
+ }
}
return false;}
Jakub Kicinski
maintainerQuoted 8 lines · On Thu, 4 Mar 2021 13:51:15 +0100 Eric Dumazet wrote:
I think we are over thinking this really (especially if the fix needs a change in core networking or drivers)
We can reuse TSQ logic to have a chance to recover when the clone is eventually freed.
This will be more generic, not only for the SYN+data of FastOpen.Can you please test the following patch ?
#7 - Eric comes up with something much better :)
But so far doesn't seem to quite do it, I'm looking but maybe you'll know right away (FWIW testing a v5.6 backport but I don't think TSQ changed?):
On __tcp_retransmit_skb kretprobe:
==> Hit TFO case ret:-16 ca_state:0 skb:ffff888fdb4bac00!
First hit:
__tcp_retransmit_skb+1
tcp_rcv_state_process+2488
tcp_v6_do_rcv+405
tcp_v6_rcv+2984
ip6_protocol_deliver_rcu+180
ip6_input_finish+17Successful hit:
__tcp_retransmit_skb+1
tcp_retransmit_skb+18
tcp_retransmit_timer+716
tcp_write_timer_handler+136
tcp_write_timer+141
call_timer_fn+43skb:ffff888fdb4bac00 --- delay:51642us bytes_acked:1
Quoted 31 lines · Jakub Kicinski
Quoted 8 lines · On Thu, 4 Mar 2021 13:51:15 +0100 Eric Dumazet wrote:
I think we are over thinking this really (especially if the fix needs a change in core networking or drivers)
We can reuse TSQ logic to have a chance to recover when the clone is eventually freed.
This will be more generic, not only for the SYN+data of FastOpen.Can you please test the following patch ?
#7 - Eric comes up with something much better :)
But so far doesn't seem to quite do it, I'm looking but maybe you'll know right away (FWIW testing a v5.6 backport but I don't think TSQ changed?):
On
__tcp_retransmit_skbkretprobe:==> Hit TFO case ret:-16 ca_state:0 skb:ffff888fdb4bac00!
First hit:
__tcp_retransmit_skb+1 tcp_rcv_state_process+2488 tcp_v6_do_rcv+405 tcp_v6_rcv+2984 ip6_protocol_deliver_rcu+180 ip6_input_finish+17Successful hit:
Quoted 8 lines
__tcp_retransmit_skb+1 tcp_retransmit_skb+18 tcp_retransmit_timer+716 tcp_write_timer_handler+136 tcp_write_timer+141 call_timer_fn+43skb:ffff888fdb4bac00 --- delay:51642us bytes_acked:1
Humm maybe one of the conditions used in tcp_tsq_write() does not hold...
if (tp->lost_out > tp->retrans_out &&
tp->snd_cwnd > tcp_packets_in_flight(tp)) {
tcp_mstamp_refresh(tp);
tcp_xmit_retransmit_queue(sk);
}Maybe FastOpen case is 'special' and tp->lost_out is wrong.
Quoted 45 lines · Eric Dumazet
Quoted 31 lines · Jakub Kicinski
Quoted 8 lines · On Thu, 4 Mar 2021 13:51:15 +0100 Eric Dumazet wrote:
I think we are over thinking this really (especially if the fix needs a change in core networking or drivers)
We can reuse TSQ logic to have a chance to recover when the clone is eventually freed.
This will be more generic, not only for the SYN+data of FastOpen.Can you please test the following patch ?
#7 - Eric comes up with something much better :)
But so far doesn't seem to quite do it, I'm looking but maybe you'll know right away (FWIW testing a v5.6 backport but I don't think TSQ changed?):
On
__tcp_retransmit_skbkretprobe:==> Hit TFO case ret:-16 ca_state:0 skb:ffff888fdb4bac00!
First hit:
__tcp_retransmit_skb+1 tcp_rcv_state_process+2488 tcp_v6_do_rcv+405 tcp_v6_rcv+2984 ip6_protocol_deliver_rcu+180 ip6_input_finish+17Successful hit:
Quoted 8 lines
__tcp_retransmit_skb+1 tcp_retransmit_skb+18 tcp_retransmit_timer+716 tcp_write_timer_handler+136 tcp_write_timer+141 call_timer_fn+43skb:ffff888fdb4bac00 --- delay:51642us bytes_acked:1
Humm maybe one of the conditions used in
tcp_tsq_write()does not hold...
Quoted 7 lines
if (
tp->lost_out>tp->retrans_out&&tp->snd_cwnd > tcp_packets_in_flight(tp)) { tcp_mstamp_refresh(tp); tcp_xmit_retransmit_queue(sk); }Maybe FastOpen case is 'special' and
tp->lost_outis wrong.
It would be nice if tun driver would have the ability to delay TX completions by N usecs,
so that packetdrill tests could be used.
It is probably not too hard to add such a feature.
Quoted 44 lines · Eric Dumazet
Quoted 31 lines · Jakub Kicinski
Quoted 8 lines · On Thu, 4 Mar 2021 13:51:15 +0100 Eric Dumazet wrote:
I think we are over thinking this really (especially if the fix needs a change in core networking or drivers)
We can reuse TSQ logic to have a chance to recover when the clone is eventually freed.
This will be more generic, not only for the SYN+data of FastOpen.Can you please test the following patch ?
#7 - Eric comes up with something much better :)
But so far doesn't seem to quite do it, I'm looking but maybe you'll know right away (FWIW testing a v5.6 backport but I don't think TSQ changed?):
On
__tcp_retransmit_skbkretprobe:==> Hit TFO case ret:-16 ca_state:0 skb:ffff888fdb4bac00!
First hit:
__tcp_retransmit_skb+1 tcp_rcv_state_process+2488 tcp_v6_do_rcv+405 tcp_v6_rcv+2984 ip6_protocol_deliver_rcu+180 ip6_input_finish+17Successful hit:
Quoted 8 lines
__tcp_retransmit_skb+1 tcp_retransmit_skb+18 tcp_retransmit_timer+716 tcp_write_timer_handler+136 tcp_write_timer+141 call_timer_fn+43skb:ffff888fdb4bac00 --- delay:51642us bytes_acked:1
Humm maybe one of the conditions used in
tcp_tsq_write()does not hold...
Quoted 7 lines
if (
tp->lost_out>tp->retrans_out&&tp->snd_cwnd > tcp_packets_in_flight(tp)) { tcp_mstamp_refresh(tp); tcp_xmit_retransmit_queue(sk); }Maybe FastOpen case is 'special' and
tp->lost_outis wrong.
Something like this? (completely untested)
Signature · 1 line
Jonathan
net/ipv4/tcp_input.c +2 -0
@@ -5995,8 +5995,10 @@ static bool tcp_rcv_fastopen_synack(struct sock *sk, struct sk_buff *synack,else tp->fastopen_client_fail =TFO_DATA_NOT_ACKED ;skb_rbtree_walk_from (data) { +tcp_mark_skb_lost (sk, data);if (__tcp_retransmit_skb (sk, data,1 ))break ; + tp->retrans_out +=tcp_skb_pcount (data); }tcp_rearm_rto (sk); NET_INC_STATS(sock_net(sk),
Quoted 65 lines · Jonathan Lemon
Quoted 44 lines · Eric Dumazet
Quoted 31 lines · Jakub Kicinski
Quoted 8 lines · On Thu, 4 Mar 2021 13:51:15 +0100 Eric Dumazet wrote:
I think we are over thinking this really (especially if the fix needs a change in core networking or drivers)
We can reuse TSQ logic to have a chance to recover when the clone is eventually freed.
This will be more generic, not only for the SYN+data of FastOpen.Can you please test the following patch ?
#7 - Eric comes up with something much better :)
But so far doesn't seem to quite do it, I'm looking but maybe you'll know right away (FWIW testing a v5.6 backport but I don't think TSQ changed?):
On
__tcp_retransmit_skbkretprobe:==> Hit TFO case ret:-16 ca_state:0 skb:ffff888fdb4bac00!
First hit:
__tcp_retransmit_skb+1 tcp_rcv_state_process+2488 tcp_v6_do_rcv+405 tcp_v6_rcv+2984 ip6_protocol_deliver_rcu+180 ip6_input_finish+17Successful hit:
Quoted 8 lines
__tcp_retransmit_skb+1 tcp_retransmit_skb+18 tcp_retransmit_timer+716 tcp_write_timer_handler+136 tcp_write_timer+141 call_timer_fn+43skb:ffff888fdb4bac00 --- delay:51642us bytes_acked:1
Humm maybe one of the conditions used in
tcp_tsq_write()does not hold...Quoted 7 lines
if (
tp->lost_out>tp->retrans_out&&tp->snd_cwnd > tcp_packets_in_flight(tp)) { tcp_mstamp_refresh(tp); tcp_xmit_retransmit_queue(sk); }Maybe FastOpen case is 'special' and
tp->lost_outis wrong.Something like this? (completely untested)
--
Jonathannet/ipv4/tcp_input.c +0
-0
net/ipv4/tcp_input.c static bool tcp_rcv_fastopen_synack(struct sock *sk, struct sk_buff *synack, · line 6004
Quoted 10 lines
net/ipv4/tcp_input.c +2
-0@@ -5995,8 +5995,10 @@ static bool tcp_rcv_fastopen_synack(struct sock *sk, struct sk_buff *synack,else tp->fastopen_client_fail =TFO_DATA_NOT_ACKED ;skb_rbtree_walk_from (data) { +tcp_mark_skb_lost (sk, data);if (__tcp_retransmit_skb (sk, data,1 ))break ; + tp->retrans_out +=tcp_skb_pcount (data); }tcp_rearm_rto (sk); NET_INC_STATS(sock_net(sk),
Yes, but the hard part is testing this ;)
Once we properly mark the skb lost, we can call regular tcp_xmit_retransmit_queue() to not have to care of tp->retrans_out
Not that we really need to make sure tcp_xmit_retransmit_queue() can be called anyway from TSQ handler if TX completion is delayed.
Quoted 80 lines · Eric Dumazet
Quoted 65 lines · Jonathan Lemon
Quoted 44 lines · Eric Dumazet
Quoted 31 lines · Jakub Kicinski
Quoted 8 lines · On Thu, 4 Mar 2021 13:51:15 +0100 Eric Dumazet wrote:
I think we are over thinking this really (especially if the fix needs a change in core networking or drivers)
We can reuse TSQ logic to have a chance to recover when the clone is eventually freed.
This will be more generic, not only for the SYN+data of FastOpen.Can you please test the following patch ?
#7 - Eric comes up with something much better :)
But so far doesn't seem to quite do it, I'm looking but maybe you'll know right away (FWIW testing a v5.6 backport but I don't think TSQ changed?):
On
__tcp_retransmit_skbkretprobe:==> Hit TFO case ret:-16 ca_state:0 skb:ffff888fdb4bac00!
First hit:
__tcp_retransmit_skb+1 tcp_rcv_state_process+2488 tcp_v6_do_rcv+405 tcp_v6_rcv+2984 ip6_protocol_deliver_rcu+180 ip6_input_finish+17Successful hit:
Quoted 8 lines
__tcp_retransmit_skb+1 tcp_retransmit_skb+18 tcp_retransmit_timer+716 tcp_write_timer_handler+136 tcp_write_timer+141 call_timer_fn+43skb:ffff888fdb4bac00 --- delay:51642us bytes_acked:1
Humm maybe one of the conditions used in
tcp_tsq_write()does not hold...Quoted 7 lines
if (
tp->lost_out>tp->retrans_out&&tp->snd_cwnd > tcp_packets_in_flight(tp)) { tcp_mstamp_refresh(tp); tcp_xmit_retransmit_queue(sk); }Maybe FastOpen case is 'special' and
tp->lost_outis wrong.Something like this? (completely untested)
--
Jonathannet/ipv4/tcp_input.c +0
-0net/ipv4/tcp_input.c static bool tcp_rcv_fastopen_synack(struct sock *sk, struct sk_buff *synack, · line 6004
Quoted 10 lines
net/ipv4/tcp_input.c +2
-0@@ -5995,8 +5995,10 @@ static bool tcp_rcv_fastopen_synack(struct sock *sk, struct sk_buff *synack,else tp->fastopen_client_fail =TFO_DATA_NOT_ACKED ;skb_rbtree_walk_from (data) { +tcp_mark_skb_lost (sk, data);if (__tcp_retransmit_skb (sk, data,1 ))break ; + tp->retrans_out +=tcp_skb_pcount (data); }tcp_rearm_rto (sk); NET_INC_STATS(sock_net(sk),Yes, but the hard part is testing this ;)
Quoted 5 lines
Once we properly mark the skb lost, we can call regular
tcp_xmit_retransmit_queue()to not have to care oftp->retrans_outNot that we really need to make sure
tcp_xmit_retransmit_queue()can be called anyway from TSQ handler if TX completion is delayed.
I was testing this (note how I also removed the tcp_rearm_rto(sk) call)
net/ipv4/tcp_input.c +0 -0
100644
net/ipv4/tcp_input.c +0 -0
@@ -6471,11 +6471,10 @@ static bool tcp_rcv_fastopen_synack(struct
sock *sk, struct sk_buff *synack,
tcp_fastopen_cache_set(sk, mss, cookie, syn_drop, try_exp);
if (data) { /* Retransmit unacked data in SYN */
- skb_rbtree_walk_from(data) {
- if (__tcp_retransmit_skb(sk, data, 1))
- break;
- }
- tcp_rearm_rto(sk);
+ skb_rbtree_walk_from(data)
+ tcp_mark_skb_lost(sk, data);
+
+ tcp_xmit_retransmit_queue(sk);
NET_INC_STATS(sock_net(sk),
LINUX_MIB_TCPFASTOPENACTIVEFAIL);
return true;Jakub Kicinski
maintainerQuoted 5 lines · On Thu, 4 Mar 2021 22:26:58 +0100 Eric Dumazet wrote:
It would be nice if tun driver would have the ability to delay TX completions by N usecs,
so that packetdrill tests could be used.It is probably not too hard to add such a feature.
Add an ioctl to turn off the skb_orphan, queue the skbs in tun_do_read() to free them from a timer?
Quoted 23 lines
I was testing this (note how I also removed the
tcp_rearm_rto(sk)call)net/ipv4/tcp_input.c +0
-0100644
net/ipv4/tcp_input.c +4
-5@@ -6471,11 +6471,10 @@ static bool tcp_rcv_fastopen_synack(struct sock *sk, struct sk_buff *synack,tcp_fastopen_cache_set (sk ,mss ,cookie ,syn_drop ,try_exp );if (data) {/* Retransmit unacked data in SYN */ -skb_rbtree_walk_from (data) { -if (__tcp_retransmit_skb (sk, data,1 )) -break ; - } -tcp_rearm_rto (sk); +skb_rbtree_walk_from (data) +tcp_mark_skb_lost (sk, data); + +tcp_xmit_retransmit_queue (sk);NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPFASTOPENACTIVEFAIL );
Quoted 1 line
return true;
AFAICT this works great now:
==> TFO case ret:-16 (0) ca_state:0 skb:ffff8881d3513800!
FREED swapper/5 -- skb 0xffff8881d3513800 freed after: 1us
-----
First:
__tcp_retransmit_skb+1
tcp_retransmit_skb+18
tcp_xmit_retransmit_queue.part.70+339
tcp_rcv_state_process+2491
tcp_v6_do_rcv+405
tcp_v6_rcv+2984Second:
__tcp_retransmit_skb+1
tcp_retransmit_skb+18
tcp_xmit_retransmit_queue.part.70+339
tcp_tsq_write.part.71+146
tcp_tsq_handler+53
tcp_tasklet_func+181sk:0xffff8885adc16f00 skb:ffff8881d3513800 --- 61us acked:1
The other case where we hit RTO after __tcp_retransmit_skb() fails is:
==> non-TFO case ret:-11 (0) ca_state:3 skb:ffff8883d71dd400!
-----
First:
__tcp_retransmit_skb+1
tcp_retransmit_skb+18
tcp_xmit_retransmit_queue.part.70+339
tcp_ack+2270
tcp_rcv_established+303
tcp_v6_do_rcv+190Second:
__tcp_retransmit_skb+1
tcp_retransmit_skb+18
tcp_retransmit_timer+716
tcp_write_timer_handler+136
tcp_write_timer+141
call_timer_fn+43sk:0xffff88801772d340 skb:ffff8883d71dd400 --- 51738us acked:47324
Which I believe is this:
if (refcount_read(&sk->sk_wmem_alloc) > min_t(u32, sk->sk_wmem_queued + (sk->sk_wmem_queued >> 2), sk->sk_sndbuf)) return -EAGAIN;
Because __tcp_retransmit_skb() seems to bail before inet6_sk_rebuild_header gets called. Should we arm TSQ here as well?
Quoted 10 lines · Jakub Kicinski
Quoted 5 lines · On Thu, 4 Mar 2021 22:26:58 +0100 Eric Dumazet wrote:
It would be nice if tun driver would have the ability to delay TX completions by N usecs,
so that packetdrill tests could be used.It is probably not too hard to add such a feature.
Add an ioctl to turn off the
skb_orphan, queue the skbs intun_do_read()to free them from a timer?
Yes, I cooked a prototype like that a few hours ago before my night shift to launch our test suite.
I yet have to add a sane limit to the number of delayed skbs so that syzbot does not oom its hosts ;)
Quoted 12 lines
Quoted 12 lines
I was testing this (note how I also removed the
tcp_rearm_rto(sk)call)net/ipv4/tcp_input.c +0
-0100644
net/ipv4/tcp_input.c +0
-0@@ -6471,11 +6471,10 @@ static bool tcp_rcv_fastopen_synack(struct sock *sk, struct sk_buff *synack,tcp_fastopen_cache_set (sk ,mss ,cookie ,syn_drop ,try_exp );
Quoted 15 lines
Quoted 12 lines
net/ipv4/tcp_input.c +4
-5if (data) {/* Retransmit unacked data in SYN */ -skb_rbtree_walk_from (data) { -if (__tcp_retransmit_skb (sk, data,1 )) -break ; - } -tcp_rearm_rto (sk); +skb_rbtree_walk_from (data) +tcp_mark_skb_lost (sk, data); + +tcp_xmit_retransmit_queue (sk);NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPFASTOPENACTIVEFAIL );Quoted 1 line
return true;AFAICT this works great now:
Yes but some packetdrill tests fail, I have to check them (sponge link for Googlers), but at first glance we have more investigations.
Ran 2003 tests: 1990 passed, 13 failed
Sponge: http://sponge2/b0d4c652-3173-4837-86ef-5e8cc59730a1
Failures in //net/tcp/fastopen/client:ipv4-mapped-ipv6:cookie-disabled-prod-conn //net/tcp/fastopen/client:ipv4-mapped-ipv6:syn-data-icmp-unreach-frag-needed //net/tcp/fastopen/client:ipv4-mapped-ipv6:syn-data-icmp-unreach-frag-needed-with-seq //net/tcp/fastopen/client:ipv4-mapped-ipv6:syn-data-only-syn-acked //net/tcp/fastopen/client:ipv4-mapped-ipv6:syn-data-partial-or-over-ack //net/tcp/fastopen/client:ipv4:cookie-disabled-prod-conn //net/tcp/fastopen/client:ipv4:syn-data-icmp-unreach-frag-needed //net/tcp/fastopen/client:ipv4:syn-data-icmp-unreach-frag-needed-with-seq //net/tcp/fastopen/client:ipv4:syn-data-only-syn-acked //net/tcp/fastopen/client:ipv4:syn-data-partial-or-over-ack //net/tcp/fastopen/client:ipv6:cookie-disabled-prod-conn //net/tcp/fastopen/client:ipv6:syn-data-only-syn-acked //net/tcp/fastopen/client:ipv6:syn-data-partial-or-over-ack
Showing test.log for //net/tcp/fastopen/client:ipv4:syn-data-icmp-unreach-frag-needed
syn-data-icmp-unreach-frag-needed.pkt:33: error handling packet: live packet field ipv4_total_length: expected: 800 (0x320) vs actual: 1040 (0x410)
script packet: 0.090624 . 1:761(760) ack 1
actual packet: 0.090619 P. 1:1001(1000) ack 1 win 256
Yes, it looks like Alex patch no longer works
commit c31b70c9968fe9c4194d1b5d06d07596a3b680de
Author: Alexander Duyck <[email protected]> Date: Sat Dec 12 12:31:24 2020 -0800
tcp: Add logic to check for SYN w/ data in tcp_simple_retransmit
Quoted 47 lines
==> TFO case ret:-16 (0) ca_state:0 skb:ffff8881d3513800!
FREED swapper/5 -- skb0xffff8881d3513800freed after: 1us
-----
First:__tcp_retransmit_skb+1 tcp_retransmit_skb+18 tcp_xmit_retransmit_queue.part.70+339 tcp_rcv_state_process+2491 tcp_v6_do_rcv+405 tcp_v6_rcv+2984Second:
__tcp_retransmit_skb+1 tcp_retransmit_skb+18 tcp_xmit_retransmit_queue.part.70+339 tcp_tsq_write.part.71+146 tcp_tsq_handler+53 tcp_tasklet_func+181sk:0xffff8885adc16f00 skb:ffff8881d3513800 --- 61us acked:1
The other case where we hit RTO after
__tcp_retransmit_skb()fails is:==> non-TFO case ret:-11 (0) ca_state:3 skb:ffff8883d71dd400!
-----
First:__tcp_retransmit_skb+1 tcp_retransmit_skb+18 tcp_xmit_retransmit_queue.part.70+339 tcp_ack+2270 tcp_rcv_established+303 tcp_v6_do_rcv+190Second:
__tcp_retransmit_skb+1 tcp_retransmit_skb+18 tcp_retransmit_timer+716 tcp_write_timer_handler+136 tcp_write_timer+141 call_timer_fn+43sk:0xffff88801772d340 skb:ffff8883d71dd400 --- 51738us acked:47324
Which I believe is this:
Quoted 7 lines
if (refcount_read(&sk->sk_wmem_alloc) > min_t(u32, sk->sk_wmem_queued + (sk->sk_wmem_queued >> 2), sk->sk_sndbuf)) return -EAGAIN;Because
__tcp_retransmit_skb()seems to bail beforeinet6_sk_rebuild_headergets called. Should we arm TSQ here as well?
Yes, or make the limit slightly bigger since we now have the fclone more precise thing for standard drivers [1]
if ((refcount_read(&sk->sk_wmem_alloc) >> 1) >
min_t(u32, sk->sk_wmem_queued, sk->sk_sndbuf))
return -EAGAIN;
[1] It is probably wise to keep this code because some drivers do call skb_orphan() in their ndo_start_xmit()
Quoted 68 lines · Eric Dumazet
Quoted 10 lines · Jakub Kicinski
Quoted 5 lines · On Thu, 4 Mar 2021 22:26:58 +0100 Eric Dumazet wrote:
It would be nice if tun driver would have the ability to delay TX completions by N usecs,
so that packetdrill tests could be used.It is probably not too hard to add such a feature.
Add an ioctl to turn off the
skb_orphan, queue the skbs intun_do_read()to free them from a timer?Yes, I cooked a prototype like that a few hours ago before my night shift to launch our test suite.
I yet have to add a sane limit to the number of delayed skbs so that syzbot does not oom its hosts ;)
Quoted 12 lines
Quoted 12 lines
I was testing this (note how I also removed the
tcp_rearm_rto(sk)call)net/ipv4/tcp_input.c +0
-0100644
net/ipv4/tcp_input.c +0
-0@@ -6471,11 +6471,10 @@ static bool tcp_rcv_fastopen_synack(struct sock *sk, struct sk_buff *synack,tcp_fastopen_cache_set (sk ,mss ,cookie ,syn_drop ,try_exp );Quoted 15 lines
Quoted 12 lines
net/ipv4/tcp_input.c +4
-5if (data) {/* Retransmit unacked data in SYN */ -skb_rbtree_walk_from (data) { -if (__tcp_retransmit_skb (sk, data,1 )) -break ; - } -tcp_rearm_rto (sk); +skb_rbtree_walk_from (data) +tcp_mark_skb_lost (sk, data); + +tcp_xmit_retransmit_queue (sk);NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPFASTOPENACTIVEFAIL );Quoted 1 line
return true;AFAICT this works great now:
Yes but some packetdrill tests fail, I have to check them (sponge link for Googlers), but at first glance we have more investigations.
Ran 2003 tests: 1990 passed, 13 failed
Sponge: http://sponge2/b0d4c652-3173-4837-86ef-5e8cc59730a1Failures in //net/tcp/fastopen/client:ipv4-mapped-ipv6:cookie-disabled-prod-conn //net/tcp/fastopen/client:ipv4-mapped-ipv6:syn-data-icmp-unreach-frag-needed //net/tcp/fastopen/client:ipv4-mapped-ipv6:syn-data-icmp-unreach-frag-needed-with-seq //net/tcp/fastopen/client:ipv4-mapped-ipv6:syn-data-only-syn-acked //net/tcp/fastopen/client:ipv4-mapped-ipv6:syn-data-partial-or-over-ack //net/tcp/fastopen/client:ipv4:cookie-disabled-prod-conn //net/tcp/fastopen/client:ipv4:syn-data-icmp-unreach-frag-needed //net/tcp/fastopen/client:ipv4:syn-data-icmp-unreach-frag-needed-with-seq //net/tcp/fastopen/client:ipv4:syn-data-only-syn-acked //net/tcp/fastopen/client:ipv4:syn-data-partial-or-over-ack //net/tcp/fastopen/client:ipv6:cookie-disabled-prod-conn //net/tcp/fastopen/client:ipv6:syn-data-only-syn-acked //net/tcp/fastopen/client:ipv6:syn-data-partial-or-over-ack
Quoted 9 lines
Showing test.log for //net/tcp/fastopen/client:ipv4:syn-data-icmp-unreach-frag-needed
syn-data-icmp-unreach-frag-needed.pkt:33: error handling packet: live packet field
ipv4_total_length: expected: 800 (0x320) vs actual: 1040 (0x410)
script packet: 0.090624 . 1:761(760) ack 1
actual packet: 0.090619 P. 1:1001(1000) ack 1 win 256
Actually this might be a good thing : We now resend the whole data in a TSO packet, now
we call the standard rtx queue mechanism, instead of sending only one MSS
I will look at other test failures today (Friday) before submitting a patch series officially.
Quoted 75 lines
Yes, it looks like Alex patch no longer works
commit
c31b70c9968fe9c4194d1b5d06d07596a3b680deAuthor: Alexander Duyck <[email protected]> Date: Sat Dec 12 12:31:24 2020 -0800tcp: Add logic to check for SYN w/ data in
tcp_simple_retransmitQuoted 47 lines
==> TFO case ret:-16 (0) ca_state:0 skb:ffff8881d3513800!
FREED swapper/5 -- skb0xffff8881d3513800freed after: 1us
-----
First:__tcp_retransmit_skb+1 tcp_retransmit_skb+18 tcp_xmit_retransmit_queue.part.70+339 tcp_rcv_state_process+2491 tcp_v6_do_rcv+405 tcp_v6_rcv+2984Second:
__tcp_retransmit_skb+1 tcp_retransmit_skb+18 tcp_xmit_retransmit_queue.part.70+339 tcp_tsq_write.part.71+146 tcp_tsq_handler+53 tcp_tasklet_func+181sk:0xffff8885adc16f00 skb:ffff8881d3513800 --- 61us acked:1
The other case where we hit RTO after
__tcp_retransmit_skb()fails is:==> non-TFO case ret:-11 (0) ca_state:3 skb:ffff8883d71dd400!
-----
First:__tcp_retransmit_skb+1 tcp_retransmit_skb+18 tcp_xmit_retransmit_queue.part.70+339 tcp_ack+2270 tcp_rcv_established+303 tcp_v6_do_rcv+190Second:
__tcp_retransmit_skb+1 tcp_retransmit_skb+18 tcp_retransmit_timer+716 tcp_write_timer_handler+136 tcp_write_timer+141 call_timer_fn+43sk:0xffff88801772d340 skb:ffff8883d71dd400 --- 51738us acked:47324
Which I believe is this:
Quoted 7 lines
if (refcount_read(&sk->sk_wmem_alloc) > min_t(u32, sk->sk_wmem_queued + (sk->sk_wmem_queued >> 2), sk->sk_sndbuf)) return -EAGAIN;Because
__tcp_retransmit_skb()seems to bail beforeinet6_sk_rebuild_headergets called. Should we arm TSQ here as well?Yes, or make the limit slightly bigger since we now have the fclone more precise thing for standard drivers [1]
if ((
refcount_read(&sk->sk_wmem_alloc)>> 1) >min_t(u32, sk->sk_wmem_queued, sk->sk_sndbuf))return
-EAGAIN;[1] It is probably wise to keep this code because some drivers do call
skb_orphan()in theirndo_start_xmit()
Quoted 7 lines · Eric Dumazet
Actually this might be a good thing : We now resend the whole data in a TSO packet, now
we call the standard rtx queue mechanism, instead of sending only one MSSI will look at other test failures today (Friday) before submitting a patch series officially.
Well, there is also this part to sort out.
WARN_ON(tp->retrans_out != 0);
in tcp_fastretrans_alert()