public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH v2] tcp: Clear ACK_FROM_TAP_DUE also on unchanged ACK sequence from peer
@ 2023-03-24  8:02 Stefano Brivio
  0 siblings, 0 replies; only message in thread
From: Stefano Brivio @ 2023-03-24  8:02 UTC (permalink / raw)
  To: passt-dev; +Cc: David Gibson

Since commit cc6d8286d104 ("tcp: Reset ACK_FROM_TAP_DUE flag only as
needed, update timer"), we don't clear ACK_FROM_TAP_DUE whenever we
process an ACK segment, but, more correctly, only if we're really not
waiting for a further ACK segment, that is, only if the acknowledged
sequence matches what we sent.

In the new function implementing this, tcp_update_seqack_from_tap(),
we also reset the retransmission counter and store the updated ACK
sequence. Both should be done iff forward progress is acknowledged,
implied by the fact that the new ACK sequence is greater than the
one we previously stored.

At that point, it looked natural to also include the statements that
clear and set the ACK_FROM_TAP_DUE flag inside the same conditional
block: if we're not making forward progress, the need for an ACK, or
lack thereof, should remain unchanged.

There's a case where this isn't true, though: if a tap-side client
initiates a connection, and the server doesn't send any data, we'll
never, in the established state of the connection, call
tcp_update_seqack_from_tap() with reported forward progress.

In that case, we'll never reset the initial ACK_FROM_TAP_DUE (used
to trigger handshake timeouts), interpret the trigger as the need for
a retransmission (which won't actually retransmit anything), and
eventually time out a perfectly healthy connection once we reach the
maximum retransmission count.

This is relatively simple to reproduce if we switch back to 30s
iperf3 test runs, but it depends on the timing of the iperf3 client:
sometimes the first ACK from the client (part of the three-way
handshake) will come with data (and we'll hit the problem), sometimes
data will be sent later (and we call to tcp_update_seqack_from_tap()
from tcp_data_from_tap() later, avoiding the issue).

A reliable reproducer is a simpler:

  $ strace -e accept,shutdown socat TCP-LISTEN:1111 STDIO &
  [2] 2202832
  $ pasta --config-net -- sh -c '(sleep 30; echo a) | socat STDIN TCP:88.198.0.161:1111'
  accept(5, {sa_family=AF_INET, sin_port=htons(57200), sin_addr=inet_addr("127.0.0.1")}, [16]) = 6
  shutdown(6, SHUT_RDWR)                  = 0
  --- SIGTTOU {si_signo=SIGTTOU, si_code=SI_KERNEL} ---
  --- stopped by SIGTTOU ---
  2023/03/23 16:05:06 socat[3] E write(5, 0x5645dbca9000, 2): Connection reset by peer

where the socat client connects, and no data exchange happens for 30s
in either direction. Here, I'm using the default gateway address to
reach the socat server on the host.

Fix this by clearing the ACK_FROM_TAP_DUE flag regardless of reported
forward progress. If we clear it when it's already unset, conn_flag()
will do nothing with it.

Fixes: cc6d8286d104 ("tcp: Reset ACK_FROM_TAP_DUE flag only as needed, update timer")
Reported-by: David Gibson <david@gibson.dropbear.id.au>
Analysed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
v2: Don't reschedule the timer if no forward progress was made. Fix
    a couple of things in the commit message based on David's
    observations

 tcp.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tcp.c b/tcp.c
index f156287..e640a4a 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1610,10 +1610,12 @@ out:
 static void tcp_update_seqack_from_tap(const struct ctx *c,
 				       struct tcp_tap_conn *conn, uint32_t seq)
 {
+	if (seq == conn->seq_to_tap)
+		conn_flag(c, conn, ~ACK_FROM_TAP_DUE);
+
 	if (SEQ_GT(seq, conn->seq_ack_from_tap)) {
-		if (seq == conn->seq_to_tap)
-			conn_flag(c, conn, ~ACK_FROM_TAP_DUE);
-		else
+		/* Forward progress, but more data to acknowledge: reschedule */
+		if (SEQ_LT(seq, conn->seq_to_tap))
 			conn_flag(c, conn, ACK_FROM_TAP_DUE);
 
 		conn->retrans = 0;
-- 
@@ -1610,10 +1610,12 @@ out:
 static void tcp_update_seqack_from_tap(const struct ctx *c,
 				       struct tcp_tap_conn *conn, uint32_t seq)
 {
+	if (seq == conn->seq_to_tap)
+		conn_flag(c, conn, ~ACK_FROM_TAP_DUE);
+
 	if (SEQ_GT(seq, conn->seq_ack_from_tap)) {
-		if (seq == conn->seq_to_tap)
-			conn_flag(c, conn, ~ACK_FROM_TAP_DUE);
-		else
+		/* Forward progress, but more data to acknowledge: reschedule */
+		if (SEQ_LT(seq, conn->seq_to_tap))
 			conn_flag(c, conn, ACK_FROM_TAP_DUE);
 
 		conn->retrans = 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-24  8:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-24  8:02 [PATCH v2] tcp: Clear ACK_FROM_TAP_DUE also on unchanged ACK sequence from peer Stefano Brivio

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).