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 B402A5A0272 for ; Fri, 04 Dec 2026 07:31:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796365868; 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: in-reply-to:in-reply-to:references:references; bh=kRecNpL7+MkYe5svs/rIetWJH2rXkwGR9euBV3lEZwA=; b=CxRiuxgO12n5S6odQhleeogQzPK565yp9LzvYFlAmI/X08jSbdk/ssXJUKlY4c/ngRMuJJ byirdEKuYjKCTPpefH9Qszmo/EJP3kX5kopmoikWGHeMUXZ0xwJCJ8AkiFpXVBHYxKplrO clc6d0dlaRrlkU/ijMYHaXznN8ez5Bs= X-MC-Rep: binary re single Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-562-hX0oppCSM9SroqlG9fExbA-1; Fri, 4 Dec 2026 06:31:07 +0000 X-MC-Unique: hX0oppCSM9SroqlG9fExbA-1 X-Mimecast-MFC-AGG-ID: hX0oppCSM9SroqlG9fExbA_1796365866 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4ad3d35e899so2529935e9.1 for ; Thu, 03 Dec 2026 22:31:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796365866; x=1796970666; h=date:content-transfer-encoding:content-type:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=kRecNpL7+MkYe5svs/rIetWJH2rXkwGR9euBV3lEZwA=; b=KcRnwr6wsJvbKVtt1YzW72mbqNJciBSM8RvWfT7ICPp5VvqMd3pkaZYZonV7c7mCSL 1kS99Kf8YfpJL0u9yWthlDW0buuiy3oZJ835rxsCZY/X981FC8UCOeD8f3D2kR1DDuwv 9EZt6PYjwInVBsGEPLXnsKqt4bNMDwhntDt5EssSUfBSSLDK8G4DHybPMePbukhj57hN zonEbO5Bp8pj7dNDJ8o36BsL+cnXHG93P1cnLU/fhb4d+fpj6kf4po++00SMto37f7H1 Y3s5giUJTuGO2bGplrTyn61RDxSrT4ZqqXY4ATt6byIGmuqXjU+kbsteqem7jmtSbfqQ Dctw== X-Gm-Message-State: APuU4Z+Jf/1gJHT/+7JtTyi9sAhaYxPERhasaPMMLZiMNkJmhnvdQhu5 BHe4tDZCFjtag/d3C3x0GZKEWRxn4PEbu0ZB0dt+PCIGnwqigwmxNCRM5olPslSRDIBa3bYUIUp DIVNkE8BLffumuxLb1RSet6G+oh194I7CRAWICS+Gybu2DET+/UNHxw== X-Gm-Gg: AZFdTZeQ6BjPNtt4UWCwJU5txjtbGheOL00FcIQzeqxNHPmkydwEUj7irttD9WdTHt4 TnrtZbcxFSdCznEscb2n26v+xyCz5juHTRH3jlzik2P4SLLJkrJo3736jw3NdeTRr91gTwfcRzN L/bxWTKjdzXf/SiFO+uJBVqv/h7qDDSGEt3sigjVSOu9eCHrRUhRrD0VNg8ZguAPlbEoEhzpc0s ILFDIHFQUq4N1MSVKeUYGwHHOM/kE8FOfH/w2Vk6WN9tpmJEgEzt/cR+wCc/BRC+nIEc2MYB1io 4E4Egsz0/1s+8y30EFF4cL9T9h0Va/WC/IgediFXIeXT5CaNablUF8YMSmDHY8BcroXfmfI+mip DCNoEoHnUnFlwBSXTVbuCtCGnXYKnoLCVjBfkLZIR4wG+uDX7aqiXlgpSbXFG4Mh6KUg= X-Received: by 2002:a05:600c:4f84:b0:4bb:6752:8400 with SMTP id 5b1f17b1804b1-4bbeb8d0df0mr16637565e9.17.1796365865838; Thu, 03 Dec 2026 22:31:05 -0800 (PST) X-Received: by 2002:a05:600c:4f84:b0:4bb:6752:8400 with SMTP id 5b1f17b1804b1-4bbeb8d0df0mr16636965e9.17.1796365865288; Thu, 03 Dec 2026 22:31:05 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbe06edeb7sm215114865e9.11.2026.12.03.22.31.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 22:31:04 -0800 (PST) From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH] migrate, tcp: Account for bytes acknowledged before migration Message-ID: <20261204073103.6e7f12c6@elisabeth> In-Reply-To: <20261203171808.445429-1-lvivier@redhat.com> References: <20261203171808.445429-1-lvivier@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 Date: Fri, 04 Dec 2026 07:31:04 +0100 (CET) X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 4T0cYjdYDlkzTTJMrv1q13FqUBSpoH4Ed0HV2yWJA0Y_1796365866 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: ROZVJIW6TCO3NIGDVH5ZOH2IMMQJE6GS X-Message-ID-Hash: ROZVJIW6TCO3NIGDVH5ZOH2IMMQJE6GS X-MailFrom: sbrivio@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: passt-dev@passt.top, Jon Maloy , David Gibson , Lynxes Exe 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: On Thu, 3 Dec 2026 18:18:08 +0100 Laurent Vivier wrote: > 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. Wow, what, no way... crazy that we didn't spot this earlier. Thanks for investigating this successfully, I was really lost. > 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. I guess that's why *sometimes* migrated streams seemed to be a bit slow. > To fix that, we add a per-flow offset, bytes_acked, to the target > socket's tcpi_bytes_acked when computing seq_ack_to_tap. Two comments: 1. long term, one might argue that we should fix this in the kernel, by adding the ability to restore selected fields of struct tcp_info, either with a new socket option or with an existing one. I think we should ensure the fix is reasonably compatible with this future perspective. If tcpi_bytes_acked can be restored, one day, I think we could probe that and decide that we'll sum to that instead of using a separate counter we keep. I don't see any issue with this, I just wanted to raise this topic if somebody has possible concerns. 2. this fix adds a separate counter, which brings us back to 128 bytes for struct tcp_tap_conn (exactly two cachelines on many architectures). It felt pretty reassuring to have 4 spare bytes. Can we keep those by abusing seq_init_from_tap (updating relevant comments, of course)? I don't see it being used in any other way after the connection is established. That is, something like this (very lightly tested, without comment updates, and probably we could avoid dumping tcp_info twice on the source): --- diff --git a/tcp.c b/tcp.c index f55cf26..d519bd4 100644 --- a/tcp.c +++ b/tcp.c @@ -3584,8 +3584,19 @@ int tcp_flow_migrate_source(int fd, struct tcp_tap_conn *conn) .seq_ack_from_tap = htonl(conn->seq_ack_from_tap), .seq_from_tap = htonl(conn->seq_from_tap), .seq_ack_to_tap = htonl(conn->seq_ack_to_tap), - .seq_init_from_tap = htonl(conn->seq_init_from_tap), }; + struct tcp_info_linux tinfo; + socklen_t sl; + + sl = sizeof(tinfo); + if (getsockopt(conn->sock, SOL_TCP, TCP_INFO, &tinfo, &sl)) { + int rc = -errno; + flow_perror(conn, "Querying TCP_INFO"); + return rc; + } + + t.seq_init_from_tap = htonl(conn->seq_init_from_tap + + tinfo.tcpi_bytes_acked); memcpy(&t.pif, conn->f.pif, sizeof(t.pif)); memcpy(&t.side, conn->f.side, sizeof(t.side)); --- ? > We can avoid migrating tcpi_bytes_acked by reconstructing the offset > on each migration from the existing state: > > bytes_acked = (seq_from_tap - t.sndq) - seq_init_from_tap > > 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. Subtracting seq_init_from_tap expresses that position as > an offset from the sequence base passt uses for its ACK calculation. > > This works with the existing v2 migration format. > > Signed-off-by: Laurent Vivier > --- > tcp.c | 9 +++++++++ > tcp_conn.h | 1 + > 2 files changed, 10 insertions(+) > > diff --git a/tcp.c b/tcp.c > index b1065545aeea..7f3e5a0309ad 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -1192,6 +1192,7 @@ int tcp_update_seqack_wnd(const struct ctx *c, struct tcp_tap_conn *conn, > /* cppcheck bug 14191 again, see above */ > /* cppcheck-suppress [uninitvar,unmatchedSuppression] */ > conn->seq_ack_to_tap = tinfo->tcpi_bytes_acked + > + conn->bytes_acked + > conn->seq_init_from_tap; > } > > @@ -3936,6 +3937,14 @@ 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 source send queue from the accepted guest data to recover > + * the offset for bytes the peer had already acknowledged. > + */ > + conn->bytes_acked = conn->seq_from_tap - > + t.sndq - > + conn->seq_init_from_tap; > + > 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..5b37204652fa 100644 > --- a/tcp_conn.h > +++ b/tcp_conn.h > @@ -116,6 +116,7 @@ struct tcp_tap_conn { > uint32_t seq_from_tap; > uint32_t seq_ack_to_tap; > uint32_t seq_init_from_tap; > + uint32_t bytes_acked; > }; > > /** -- Stefano