Skip to contentSkip to conversation

tcp: Make SYN ACK RTO tunable by BPF programs with TFO

PATCH Applied Jie Meng 5 participants 5 messages Aug 16, 2022 – Aug 17, 2022

Subsystems (4)
lore
Share & tools
lore

Jie Meng

author
#0 lore raw

PATCH 1/1 tcp: Make SYN ACK RTO tunable by BPF programs with TFO

Instead of the hardcoded TCP_TIMEOUT_INIT, this diff calls tcp_timeout_init to initiate req->timeout like the non TFO SYN ACK case.

Tested using the following packetdrill script, on a host with a BPF program that sets the initial connect timeout to 10ms.

../../common/defaults.sh

// Initialize connection

    0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3

+0 setsockopt(3, SOL_TCP, TCP_FASTOPEN, [1], 4) = 0 +0 bind(3, ..., ...) = 0
+0 listen(3, 1) = 0

+0 < S 0:0(0) win 32792 <mss 1000,sackOK,FO TFO_COOKIE> +0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK> +.01 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK> +.02 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK> +.04 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK> +.01 < . 1:1(0) ack 1 win 32792

+0 accept(3, ..., ...) = 4

---
 net/ipv4/tcp_fastopen.c | 3 ++-
 net/ipv4/tcp_timer.c    | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
net/ipv4/tcp_fastopen.c +2 -1
index 825b216d11f5..45cc7f1ca296 100644
@@ -272,8 +272,9 @@ static struct sock *tcp_fastopen_create_child(struct sock *sk,
 	 * The request socket is not added to the ehash
 	 * because it's been added to the accept queue directly.
 	 */
+	req->timeout = tcp_timeout_init(child);
 	inet_csk_reset_xmit_timer(child, ICSK_TIME_RETRANS,
-				  TCP_TIMEOUT_INIT, TCP_RTO_MAX);
+				  req->timeout, TCP_RTO_MAX);
 
 	refcount_set(&req->rsk_refcnt, 2);
 
net/ipv4/tcp_timer.c +1 -1
index b4dfb82d6ecb..cb79127f45c3 100644
@@ -428,7 +428,7 @@ static void tcp_fastopen_synack_timer(struct sock *sk, struct request_sock *req)
 	if (!tp->retrans_stamp)
 		tp->retrans_stamp = tcp_time_stamp(tp);
 	inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
-			  TCP_TIMEOUT_INIT << req->num_timeout, TCP_RTO_MAX);
+			  req->timeout << req->num_timeout, TCP_RTO_MAX);
 }
 
 
Signature · 1 line
2.30.2
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 50 lines · Jie Meng

Instead of the hardcoded TCP_TIMEOUT_INIT, this diff calls tcp_timeout_init to initiate req->timeout like the non TFO SYN ACK case.

Tested using the following packetdrill script, on a host with a BPF program that sets the initial connect timeout to 10ms.

../../common/defaults.sh

// Initialize connection

    0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3

+0 setsockopt(3, SOL_TCP, TCP_FASTOPEN, [1], 4) = 0 +0 bind(3, ..., ...) = 0
+0 listen(3, 1) = 0

   +0 < S 0:0(0) win 32792 <mss 1000,sackOK,FO TFO_COOKIE>
   +0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK>
   +.01 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK>
   +.02 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK>
   +.04 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK>
   +.01 < . 1:1(0) ack 1 win 32792

   +0 accept(3, ..., ...) = 4
---
 net/ipv4/tcp_fastopen.c | 3 ++-
 net/ipv4/tcp_timer.c    | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
net/ipv4/tcp_fastopen.c +2 -1
index 825b216d11f5..45cc7f1ca296 100644
@@ -272,8 +272,9 @@ static struct sock *tcp_fastopen_create_child(struct sock *sk,
         * The request socket is not added to the ehash
         * because it's been added to the accept queue directly.
         */
+       req->timeout = tcp_timeout_init(child);
        inet_csk_reset_xmit_timer(child, ICSK_TIME_RETRANS,
-                                 TCP_TIMEOUT_INIT, TCP_RTO_MAX);
+                                 req->timeout, TCP_RTO_MAX);
 
        refcount_set(&req->rsk_refcnt, 2);
 
net/ipv4/tcp_timer.c +0 -0
index b4dfb82d6ecb..cb79127f45c3 100644

net/ipv4/tcp_timer.c static void tcp_fastopen_synack_timer(struct sock *sk, struct request_sock *req)

Quoted 9 lines
net/ipv4/tcp_timer.c +1 -2
@@ -428,7 +428,7 @@ static void tcp_fastopen_synack_timer(struct sock *sk, struct request_sock *req)
        if (!tp->retrans_stamp)
                tp->retrans_stamp = tcp_time_stamp(tp);
        inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
-                         TCP_TIMEOUT_INIT << req->num_timeout, TCP_RTO_MAX);
+                         req->timeout << req->num_timeout, TCP_RTO_MAX);
 }
 
 
--

Looks good to me. Thanks for the feature!

neal

Acked-by
#2 lore raw
Quoted 60 lines · Neal Cardwell
Quoted 58 lines · Jie Meng

Instead of the hardcoded TCP_TIMEOUT_INIT, this diff calls tcp_timeout_init to initiate req->timeout like the non TFO SYN ACK case.

Tested using the following packetdrill script, on a host with a BPF program that sets the initial connect timeout to 10ms.

../../common/defaults.sh

// Initialize connection

    0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3

+0 setsockopt(3, SOL_TCP, TCP_FASTOPEN, [1], 4) = 0 +0 bind(3, ..., ...) = 0
+0 listen(3, 1) = 0

   +0 < S 0:0(0) win 32792 <mss 1000,sackOK,FO TFO_COOKIE>
   +0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK>
   +.01 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK>
   +.02 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK>
   +.04 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK>
   +.01 < . 1:1(0) ack 1 win 32792

   +0 accept(3, ..., ...) = 4
---
 net/ipv4/tcp_fastopen.c | 3 ++-
 net/ipv4/tcp_timer.c    | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
net/ipv4/tcp_fastopen.c +2 -1
index 825b216d11f5..45cc7f1ca296 100644
@@ -272,8 +272,9 @@ static struct sock *tcp_fastopen_create_child(struct sock *sk,
         * The request socket is not added to the ehash
         * because it's been added to the accept queue directly.
         */
+       req->timeout = tcp_timeout_init(child);
        inet_csk_reset_xmit_timer(child, ICSK_TIME_RETRANS,
-                                 TCP_TIMEOUT_INIT, TCP_RTO_MAX);
+                                 req->timeout, TCP_RTO_MAX);
 
        refcount_set(&req->rsk_refcnt, 2);
 
net/ipv4/tcp_timer.c +1 -1
index b4dfb82d6ecb..cb79127f45c3 100644
@@ -428,7 +428,7 @@ static void tcp_fastopen_synack_timer(struct sock *sk, struct request_sock *req)
        if (!tp->retrans_stamp)
                tp->retrans_stamp = tcp_time_stamp(tp);
        inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
-                         TCP_TIMEOUT_INIT << req->num_timeout, TCP_RTO_MAX);
+                         req->timeout << req->num_timeout, TCP_RTO_MAX);
 }
 
 
Quoted 5 lines
Quoted 1 line

--

Looks good to me. Thanks for the feature!

Would be great to have a companion patch on SYN timeout as well.

Quoted 2 lines

neal

Acked-by on v1 1/1
#3 lore raw
In reply to Jie Meng
Quoted 14 lines · Jie Meng

Instead of the hardcoded TCP_TIMEOUT_INIT, this diff calls tcp_timeout_init to initiate req->timeout like the non TFO SYN ACK case.

Tested using the following packetdrill script, on a host with a BPF program that sets the initial connect timeout to 10ms.

../../common/defaults.sh

// Initialize connection

    0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3

+0 setsockopt(3, SOL_TCP, TCP_FASTOPEN, [1], 4) = 0 +0 bind(3, ..., ...) = 0
+0 listen(3, 1) = 0

Quoted 8 lines
   +0 < S 0:0(0) win 32792 <mss 1000,sackOK,FO TFO_COOKIE>
   +0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK>
   +.01 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK>
   +.02 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK>
   +.04 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK>
   +.01 < . 1:1(0) ack 1 win 32792

   +0 accept(3, ..., ...) = 4
#4 lore raw
In reply to Jie Meng
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 9 lines · On Mon, 15 Aug 2022 13:29:00 -0700 you wrote:

Instead of the hardcoded TCP_TIMEOUT_INIT, this diff calls tcp_timeout_init to initiate req->timeout like the non TFO SYN ACK case.

Tested using the following packetdrill script, on a host with a BPF program that sets the initial connect timeout to 10ms.

../../common/defaults.sh

[...]

Here is the summary with links:
- [net-next] tcp: Make SYN ACK RTO tunable by BPF programs with TFO

    https://git.kernel.org/netdev/net-next/c/8ea731d4c2ce

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html