From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=fail (p=quarantine dis=none) header.from=redhat.com Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id A84395A026E for ; Fri, 04 Dec 2026 11:49:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796381393; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sh8P0xN3lqNwTdq8rurubcj1zRgheX2vMevny9EC/hs=; b=FmvnlhMFvfw+Zw/02p1AyIcJzAvCzCTayRZGCGp9G6Y7vlYLLZRYiYHgKJy1CDb59Z4pjG s3wSrsbagBXTzNYojbehWTcA7JVKM0+N64s4u/JsRw3jsB0fDymREfhTtwdkYEOWvu+7cM BTNZYE/JXRNdBRfPZodGpOOA3KZ082w= X-MC-Rep: binary re single Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-502-3sJNqMb_NnC-AxO9grvQBw-1; Fri, 4 Dec 2026 10:49:51 +0000 X-MC-Unique: 3sJNqMb_NnC-AxO9grvQBw-1 X-Mimecast-MFC-AGG-ID: 3sJNqMb_NnC-AxO9grvQBw_1796381390 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 36944190E485 for ; Fri, 4 Dec 2026 10:49:50 +0000 (UTC) Received: from lvivier-thinkpadp1gen8.rmtfr.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6BD241809B40; Fri, 4 Dec 2026 10:49:49 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v2] migrate, tcp: Account for bytes acknowledged before migration Date: Fri, 4 Dec 2026 11:49:48 +0100 Message-ID: <20261204104948.1211558-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: DgS_aO1GkkAc32zbO1MCzCyH5D8Xipyq0n8FnQqqo_Q_1796381390 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: NLQTA4ECBA4OVHWUGJATA5PCBGKZVIU5 X-Message-ID-Hash: NLQTA4ECBA4OVHWUGJATA5PCBGKZVIU5 X-MailFrom: lvivier@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 CC: Laurent Vivier 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: The repaired socket starts with tcpi_bytes_acked at zero. Even though seq_ack_to_tap is migrated, ACKs computed afterward from tcpi_bytes_acked are missing the progress made on the source. If the target uses this counter, it can send an ACK older than the last ACK the guest received before migration. The guest keeps retransmitting the first segment it is still waiting for passt to acknowledge, and rampstream_out can stall. A bug in tcp_rtt_dst_check() hid this in our tests. On a repaired socket, tcpi_min_rtt is ~0U until the first RTT sample. The cast to int turned ~0U into -1, so the target added the peer to low_rtt_dst[] and used seq_from_tap for ACKs. To fix that, we set seq_init_from_tap on the target using the state already sent by the source: seq_init_from_tap = seq_from_tap - t.sndq seq_from_tap is the next sequence number passt expects from the guest. t.sndq includes both unsent bytes and sent bytes awaiting an ACK, so subtracting it gives the guest sequence at the head of the restored send queue. tcp_update_seqack_wnd() adds the repaired socket's tcpi_bytes_acked to this base when computing the ACK sent to the guest. This also works when migrating from an older passt using the v2 format. Signed-off-by: Laurent Vivier --- Notes: v2: Reuse seq_init_from_tap on the target and drop bytes_acked tcp.c | 14 +++++++++++++- tcp_conn.h | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/tcp.c b/tcp.c index b1065545aeea..1267af02d359 100644 --- a/tcp.c +++ b/tcp.c @@ -220,7 +220,7 @@ * @seq_from_tap: next sequence for packets from tap/guest (expected) * @seq_ack_to_tap: last ACK number sent to tap/guest * - * @seq_init_from_tap: initial sequence number from tap/guest + * @seq_init_from_tap: guest sequence base for bytes acknowledged by the peer * @seq_init_to_tap: initial sequence number from tap/guest * * @wnd_from_tap: last window size received from tap, never scaled @@ -3936,6 +3936,18 @@ int tcp_flow_migrate_target_ext(struct ctx *c, struct tcp_tap_conn *conn, return -EINVAL; } + /* The target socket's tcpi_bytes_acked starts at zero after migration. + * Subtract the length of the current sending queue from the accepted + * guest sequence to recover the amount of bytes the peer had already + * acknowledged. + * + * Add this offset to the initial sequence number, to correctly adjust + * the acknowledgement sequence number we send to the guest, as + * calculated by tcp_update_seqack_wnd(). + */ + + conn->seq_init_from_tap = conn->seq_from_tap - t.sndq; + if (read_all_buf(fd, tcp_migrate_snd_queue, t.sndq)) { rc = -errno; flow_perror(conn, "Failed to read send queue data"); diff --git a/tcp_conn.h b/tcp_conn.h index 3173ddb945e3..89994530dc23 100644 --- a/tcp_conn.h +++ b/tcp_conn.h @@ -34,7 +34,7 @@ * @seq_ack_from_tap: Last ACK number received from tap * @seq_from_tap: Next sequence for packets from tap (not actually sent) * @seq_ack_to_tap: Last ACK number sent to tap - * @seq_init_from_tap: Initial sequence number from tap + * @seq_init_from_tap: Guest sequence base for bytes acknowledged by the peer */ struct tcp_tap_conn { /* Must be first element */ @@ -136,7 +136,7 @@ struct tcp_tap_conn { * @seq_ack_from_tap: Last ACK number received from tap * @seq_from_tap: Next sequence for packets from tap (not actually sent) * @seq_ack_to_tap: Last ACK number sent to tap - * @seq_init_from_tap: Initial sequence number from tap + * @seq_init_from_tap: Guest sequence base for bytes acknowledged by the peer */ struct tcp_tap_transfer { uint8_t pif[SIDES]; -- 2.56.0