From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id E7AF65A9D25 for ; Thu, 9 May 2024 05:00:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715223625; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=52Lmudz4hx9Yo8KFnmFRcoLmU7/HfgXx+h10zVnvC6w=; b=hZGkkLJ++/csmhsWGBO2qZl4PUwjicJtkzDQH5DXPJLB/5DzhTp/Th4Vj25eaYmhkU1z97 PONLzXxSDzbowkaN06T4nL7e9wY5r1SYcdsK+TEzGAuZKf7TIkpvEnbNKGAG9z5Pb0AAft Kmb4Ud2Q1e1u4wINTiSd+9DdEYT+rZg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-681-eNnCa_wrM0-WfoZuhKY0Fw-1; Wed, 08 May 2024 23:00:24 -0400 X-MC-Unique: eNnCa_wrM0-WfoZuhKY0Fw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 22FA7185A78E for ; Thu, 9 May 2024 03:00:24 +0000 (UTC) Received: from fenrir.redhat.com (unknown [10.22.33.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id B3264200AD74; Thu, 9 May 2024 03:00:23 +0000 (UTC) From: Jon Maloy To: passt-dev@passt.top, sbrivio@redhat.com, lvivier@redhat.com, dgibson@redhat.com, jmaloy@redhat.com Subject: [PATCH] tcp: move seq_to_tap update to when frame is queued Date: Wed, 8 May 2024 23:00:23 -0400 Message-ID: <20240509030023.4153802-1-jmaloy@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: U5MRXFA4OH3Y4GTB3JUVWPFF2SW2KTUJ X-Message-ID-Hash: U5MRXFA4OH3Y4GTB3JUVWPFF2SW2KTUJ X-MailFrom: jmaloy@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: commit a469fc393fa1 ("tcp, tap: Don't increase tap-side sequence counter for dropped frames") delayed update of conn->seq_to_tap until the moment the corresponding frame has been successfully pushed out. This has the advantage that we immediately can retransmit a buffer that we fail to trasnmit, rather than waiting for the peer side to discover the loss and initiate fast retransmit. This approach has turned out to cause a problem with spurious sequence number updates during peer-initiated retransmits, and we have realized it may not be the best way to solve te above issue. We now restore the previous method, by updating the said field at the moment a frame is added to the outqueue. To retain the advantage of fast retansmit based on local failure detection, we now scan through the part of the outqueue that had do be dropped, and restore the sequence counter for each affected connection to the most appropriate value. Signed-off-by: Jon Maloy --- tcp.c | 52 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/tcp.c b/tcp.c index 21d0af0..58fdbc9 100644 --- a/tcp.c +++ b/tcp.c @@ -412,11 +412,13 @@ static union inany_addr low_rtt_dst[LOW_RTT_TABLE_SIZE]; /** * tcp_buf_seq_update - Sequences to update with length of frames once sent - * @seq: Pointer to sequence number sent to tap-side, to be updated + * @conn: Pointer to connection corresponding to frame. May need update + * @seq: Sequence number of the corresponding frame * @len: TCP payload length */ struct tcp_buf_seq_update { - uint32_t *seq; + struct tcp_tap_conn *conn; + uint32_t seq; uint16_t len; }; @@ -1261,25 +1263,52 @@ static void tcp_flags_flush(const struct ctx *c) tcp4_flags_used = 0; } +/** + * tcp_revert_seq() - Revert affected conn->seq_to_tap after failed transmission + * @seq_update: Array with connection and sequence number data + * @s: Entry corresponding to first dropped frame + * @e: Entry corresponding to last dropped frame + */ +static void tcp_revert_seq(struct tcp_buf_seq_update *seq_update, int s, int e) +{ + struct tcp_tap_conn *conn; + uint32_t lowest_seq; + int i, ii; + + for (i = s; i < e; i++) { + conn = seq_update[i].conn; + lowest_seq = seq_update[i].seq; + + for (ii = i + 1; ii < e; ii++) { + if (seq_update[ii].conn != conn) + continue; + if (SEQ_GT(lowest_seq, seq_update[ii].seq)) + lowest_seq = seq_update[ii].seq; + } + + if (SEQ_GT(conn->seq_to_tap, lowest_seq)) + conn->seq_to_tap = lowest_seq; + } +} + /** * tcp_payload_flush() - Send out buffers for segments with data * @c: Execution context */ static void tcp_payload_flush(const struct ctx *c) { - unsigned i; size_t m; m = tap_send_frames(c, &tcp6_l2_iov[0][0], TCP_NUM_IOVS, tcp6_payload_used); - for (i = 0; i < m; i++) - *tcp6_seq_update[i].seq += tcp6_seq_update[i].len; + if (m != tcp6_payload_used) + tcp_revert_seq(tcp6_seq_update, m, tcp6_payload_used); tcp6_payload_used = 0; m = tap_send_frames(c, &tcp4_l2_iov[0][0], TCP_NUM_IOVS, tcp4_payload_used); - for (i = 0; i < m; i++) - *tcp4_seq_update[i].seq += tcp4_seq_update[i].len; + if (m != tcp4_payload_used) + tcp_revert_seq(tcp4_seq_update, m, tcp4_payload_used); tcp4_payload_used = 0; } @@ -2129,10 +2158,11 @@ static int tcp_sock_consume(const struct tcp_tap_conn *conn, uint32_t ack_seq) static void tcp_data_to_tap(const struct ctx *c, struct tcp_tap_conn *conn, ssize_t dlen, int no_csum, uint32_t seq) { - uint32_t *seq_update = &conn->seq_to_tap; struct iovec *iov; size_t l4len; + conn->seq_to_tap = seq; + if (CONN_V4(conn)) { struct iovec *iov_prev = tcp4_l2_iov[tcp4_payload_used - 1]; const uint16_t *check = NULL; @@ -2142,7 +2172,8 @@ static void tcp_data_to_tap(const struct ctx *c, struct tcp_tap_conn *conn, check = &iph->check; } - tcp4_seq_update[tcp4_payload_used].seq = seq_update; + tcp4_seq_update[tcp4_payload_used].conn = conn; + tcp4_seq_update[tcp4_payload_used].seq = seq; tcp4_seq_update[tcp4_payload_used].len = dlen; iov = tcp4_l2_iov[tcp4_payload_used++]; @@ -2151,7 +2182,8 @@ static void tcp_data_to_tap(const struct ctx *c, struct tcp_tap_conn *conn, if (tcp4_payload_used > TCP_FRAMES_MEM - 1) tcp_payload_flush(c); } else if (CONN_V6(conn)) { - tcp6_seq_update[tcp6_payload_used].seq = seq_update; + tcp6_seq_update[tcp6_payload_used].conn = conn; + tcp6_seq_update[tcp6_payload_used].seq = seq; tcp6_seq_update[tcp6_payload_used].len = dlen; iov = tcp6_l2_iov[tcp6_payload_used++]; -- 2.42.0