From: Enke Chen <redacted>
In this patch two issues with TCP keepalives are fixed:
1) TCP keepalive does not timeout when there are data waiting to be
delivered and then the connection got broken. The TCP keepalive
timeout is not evaluated in that condition.
The fix is to remove the code that prevents TCP keepalive from
being evaluated for timeout.
2) With the fix for #1, TCP keepalive can erroneously timeout after
the 0-window probe kicks in. The 0-window probe counter is wrongly
applied to TCP keepalives.
The fix is to use the elapsed time instead of the 0-window probe
counter in evaluating TCP keepalive timeout.
Cc: stable@vger.kernel.org
Signed-off-by: Enke Chen <redacted>
---
net/ipv4/tcp_timer.c | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)
@@ -696,12 +696,6 @@ static void tcp_keepalive_timer (struct timer_list *t)((1<<sk->sk_state)&(TCPF_CLOSE|TCPF_SYN_SENT)))gotoout;-elapsed=keepalive_time_when(tp);--/* It is alive without keepalive 8) */-if(tp->packets_out||!tcp_write_queue_empty(sk))-gotoresched;-elapsed=keepalive_time_elapsed(tp);if(elapsed>=keepalive_time_when(tp)){
@@ -709,16 +703,15 @@ static void tcp_keepalive_timer (struct timer_list *t)*todeterminewhentotimeoutinstead.*/if((icsk->icsk_user_timeout!=0&&-elapsed>=msecs_to_jiffies(icsk->icsk_user_timeout)&&-icsk->icsk_probes_out>0)||+elapsed>=msecs_to_jiffies(icsk->icsk_user_timeout))||(icsk->icsk_user_timeout==0&&-icsk->icsk_probes_out>=keepalive_probes(tp))){+(elapsed>=keepalive_time_when(tp)++keepalive_intvl_when(tp)*keepalive_probes(tp)))){tcp_send_active_reset(sk,GFP_ATOMIC);tcp_write_err(sk);gotoout;}if(tcp_write_wakeup(sk,LINUX_MIB_TCPKEEPALIVE)<=0){-icsk->icsk_probes_out++;elapsed=keepalive_intvl_when(tp);}else{/* If keepalive was lost due to local congestion,
On Tue, Jan 12, 2021 at 2:31 PM Enke Chen [off-list ref] wrote:
From: Enke Chen <redacted>
In this patch two issues with TCP keepalives are fixed:
1) TCP keepalive does not timeout when there are data waiting to be
delivered and then the connection got broken. The TCP keepalive
timeout is not evaluated in that condition.
hi enke
Do you have an example to demonstrate this issue -- in theory when
there is data inflight, an RTO timer should be pending (which
considers user-timeout setting). based on the user-timeout description
(man tcp), the user timeout should abort the socket per the specified
time after data commences. some data would help to understand the
issue.
quoted hunk
The fix is to remove the code that prevents TCP keepalive from
being evaluated for timeout.
2) With the fix for #1, TCP keepalive can erroneously timeout after
the 0-window probe kicks in. The 0-window probe counter is wrongly
applied to TCP keepalives.
The fix is to use the elapsed time instead of the 0-window probe
counter in evaluating TCP keepalive timeout.
Cc: stable@vger.kernel.org
Signed-off-by: Enke Chen <redacted>
---
net/ipv4/tcp_timer.c | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)
@@ -696,12 +696,6 @@ static void tcp_keepalive_timer (struct timer_list *t)((1<<sk->sk_state)&(TCPF_CLOSE|TCPF_SYN_SENT)))gotoout;-elapsed=keepalive_time_when(tp);--/* It is alive without keepalive 8) */-if(tp->packets_out||!tcp_write_queue_empty(sk))-gotoresched;-elapsed=keepalive_time_elapsed(tp);if(elapsed>=keepalive_time_when(tp)){
@@ -709,16 +703,15 @@ static void tcp_keepalive_timer (struct timer_list *t)*todeterminewhentotimeoutinstead.*/if((icsk->icsk_user_timeout!=0&&-elapsed>=msecs_to_jiffies(icsk->icsk_user_timeout)&&-icsk->icsk_probes_out>0)||+elapsed>=msecs_to_jiffies(icsk->icsk_user_timeout))||(icsk->icsk_user_timeout==0&&-icsk->icsk_probes_out>=keepalive_probes(tp))){+(elapsed>=keepalive_time_when(tp)++keepalive_intvl_when(tp)*keepalive_probes(tp)))){tcp_send_active_reset(sk,GFP_ATOMIC);tcp_write_err(sk);gotoout;}if(tcp_write_wakeup(sk,LINUX_MIB_TCPKEEPALIVE)<=0){-icsk->icsk_probes_out++;elapsed=keepalive_intvl_when(tp);}else{/* If keepalive was lost due to local congestion,
From: Eric Dumazet <edumazet@google.com> Date: 2021-01-12 22:53:38
On Tue, Jan 12, 2021 at 11:48 PM Yuchung Cheng [off-list ref] wrote:
On Tue, Jan 12, 2021 at 2:31 PM Enke Chen [off-list ref] wrote:
quoted
From: Enke Chen <redacted>
In this patch two issues with TCP keepalives are fixed:
1) TCP keepalive does not timeout when there are data waiting to be
delivered and then the connection got broken. The TCP keepalive
timeout is not evaluated in that condition.
hi enke
Do you have an example to demonstrate this issue -- in theory when
there is data inflight, an RTO timer should be pending (which
considers user-timeout setting). based on the user-timeout description
(man tcp), the user timeout should abort the socket per the specified
time after data commences. some data would help to understand the
issue.
+1
A packetdrill test would be ideal.
Also, given that there is this ongoing issue with TCP_USER_TIMEOUT,
lets not mix things
or risk added work for backports to stable versions.
Hi, Yuchung:
I have attached the python script that reproduces the keepalive issues.
The script is a slight modification of the one written by Marek Majkowski:
https://github.com/cloudflare/cloudflare-blog/blob/master/2019-09-tcp-keepalives/test-zero.py
Please note that only the TCP keepalive is configured, and not the user timeout.
Thanks. -- Enke
On Tue, Jan 12, 2021 at 02:48:01PM -0800, Yuchung Cheng wrote:
On Tue, Jan 12, 2021 at 2:31 PM Enke Chen [off-list ref] wrote:
quoted
From: Enke Chen <redacted>
In this patch two issues with TCP keepalives are fixed:
1) TCP keepalive does not timeout when there are data waiting to be
delivered and then the connection got broken. The TCP keepalive
timeout is not evaluated in that condition.
hi enke
Do you have an example to demonstrate this issue -- in theory when
there is data inflight, an RTO timer should be pending (which
considers user-timeout setting). based on the user-timeout description
(man tcp), the user timeout should abort the socket per the specified
time after data commences. some data would help to understand the
issue.
Hi, Eric:
Just to clarify: the issues for tcp keepalive and TCP_USER_TIMEOUT are
separate isues, and the fixes would not conflict afaik.
Thanks. -- Enke
On Tue, Jan 12, 2021 at 11:52:43PM +0100, Eric Dumazet wrote:
On Tue, Jan 12, 2021 at 11:48 PM Yuchung Cheng [off-list ref] wrote:
quoted
On Tue, Jan 12, 2021 at 2:31 PM Enke Chen [off-list ref] wrote:
quoted
From: Enke Chen <redacted>
In this patch two issues with TCP keepalives are fixed:
1) TCP keepalive does not timeout when there are data waiting to be
delivered and then the connection got broken. The TCP keepalive
timeout is not evaluated in that condition.
hi enke
Do you have an example to demonstrate this issue -- in theory when
there is data inflight, an RTO timer should be pending (which
considers user-timeout setting). based on the user-timeout description
(man tcp), the user timeout should abort the socket per the specified
time after data commences. some data would help to understand the
issue.
+1
A packetdrill test would be ideal.
Also, given that there is this ongoing issue with TCP_USER_TIMEOUT,
lets not mix things
or risk added work for backports to stable versions.
On Wed, Jan 13, 2021 at 12:06:27PM -0800, Enke Chen wrote:
Hi, Eric:
Just to clarify: the issues for tcp keepalive and TCP_USER_TIMEOUT are
separate isues, and the fixes would not conflict afaik.
Thanks. -- Enke
I have posted patches for both issues, and there is no conflict between
the patches.
Thanks. -- Enke
On Tue, Jan 12, 2021 at 11:52:43PM +0100, Eric Dumazet wrote:
quoted
On Tue, Jan 12, 2021 at 11:48 PM Yuchung Cheng [off-list ref] wrote:
quoted
On Tue, Jan 12, 2021 at 2:31 PM Enke Chen [off-list ref] wrote:
quoted
From: Enke Chen <redacted>
In this patch two issues with TCP keepalives are fixed:
1) TCP keepalive does not timeout when there are data waiting to be
delivered and then the connection got broken. The TCP keepalive
timeout is not evaluated in that condition.
hi enke
Do you have an example to demonstrate this issue -- in theory when
there is data inflight, an RTO timer should be pending (which
considers user-timeout setting). based on the user-timeout description
(man tcp), the user timeout should abort the socket per the specified
time after data commences. some data would help to understand the
issue.
+1
A packetdrill test would be ideal.
Also, given that there is this ongoing issue with TCP_USER_TIMEOUT,
lets not mix things
or risk added work for backports to stable versions.
Hi, Folks:
Please ignore this patch. I will split it into separate ones as suggested
off-list by Neal Cardwell [off-list ref].
Thanks. -- Enke
On Tue, Jan 12, 2021 at 11:25:44AM -0800, Enke Chen wrote:
quoted hunk
From: Enke Chen <redacted>
In this patch two issues with TCP keepalives are fixed:
1) TCP keepalive does not timeout when there are data waiting to be
delivered and then the connection got broken. The TCP keepalive
timeout is not evaluated in that condition.
The fix is to remove the code that prevents TCP keepalive from
being evaluated for timeout.
2) With the fix for #1, TCP keepalive can erroneously timeout after
the 0-window probe kicks in. The 0-window probe counter is wrongly
applied to TCP keepalives.
The fix is to use the elapsed time instead of the 0-window probe
counter in evaluating TCP keepalive timeout.
Cc: stable@vger.kernel.org
Signed-off-by: Enke Chen <redacted>
---
net/ipv4/tcp_timer.c | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)
@@ -696,12 +696,6 @@ static void tcp_keepalive_timer (struct timer_list *t)((1<<sk->sk_state)&(TCPF_CLOSE|TCPF_SYN_SENT)))gotoout;-elapsed=keepalive_time_when(tp);--/* It is alive without keepalive 8) */-if(tp->packets_out||!tcp_write_queue_empty(sk))-gotoresched;-elapsed=keepalive_time_elapsed(tp);if(elapsed>=keepalive_time_when(tp)){
@@ -709,16 +703,15 @@ static void tcp_keepalive_timer (struct timer_list *t)*todeterminewhentotimeoutinstead.*/if((icsk->icsk_user_timeout!=0&&-elapsed>=msecs_to_jiffies(icsk->icsk_user_timeout)&&-icsk->icsk_probes_out>0)||+elapsed>=msecs_to_jiffies(icsk->icsk_user_timeout))||(icsk->icsk_user_timeout==0&&-icsk->icsk_probes_out>=keepalive_probes(tp))){+(elapsed>=keepalive_time_when(tp)++keepalive_intvl_when(tp)*keepalive_probes(tp)))){tcp_send_active_reset(sk,GFP_ATOMIC);tcp_write_err(sk);gotoout;}if(tcp_write_wakeup(sk,LINUX_MIB_TCPKEEPALIVE)<=0){-icsk->icsk_probes_out++;elapsed=keepalive_intvl_when(tp);}else{/* If keepalive was lost due to local congestion,