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 489D55A026E for ; Fri, 04 Dec 2026 09:54:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796374493; 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=zyGrF4V+xTnfdzAkC3S5R69HxlLrq6z/AVkbCaufUvg=; b=K+ryWZjFqnMIhoHhNLs6Hel48FAviTLn0CohyBs2+ddmqM6y+Qp4PReAwcwHc8Kiz4fFLE /s4zbCfg1WnBq9URgKHQd9RgyiDHSPyLI3Pd2GWE1wiOY+cQXBBlDBrz6/ryIPtal+OoqV 2TuWhnwLfWgX9ukQJDL8SFXKYaIKmIM= X-MC-Rep: binary re single Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-520-X4LSBZ2yM2unBeoTRGoRaA-1; Fri, 4 Dec 2026 08:54:51 +0000 X-MC-Unique: X4LSBZ2yM2unBeoTRGoRaA-1 X-Mimecast-MFC-AGG-ID: X4LSBZ2yM2unBeoTRGoRaA_1796374490 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-4cb2e59c263so427812f8f.1 for ; Fri, 04 Dec 2026 00:54:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796374490; x=1796979290; 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: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: by 2002:a05:6000:3cf:b0:491:1e3f:a427 with SMTP id ffacd0b85a97d-4d1ec44b186mr2448849f8f.42.1796374490274; Fri, 04 Dec 2026 00:54:50 -0800 (PST) X-Received: by 2002:a05:6000:3cf:b0:491:1e3f:a427 with SMTP id ffacd0b85a97d-4d1ec44b186mr2448794f8f.42.1796374489709; Fri, 04 Dec 2026 00:54:49 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d17435dbccsm4199730f8f.47.2026.12.04.00.54.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 00:54:49 -0800 (PST) From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH] migrate, tcp: Account for bytes acknowledged before migration Message-ID: <20261204095447.07a7a9ad@elisabeth> In-Reply-To: <7ef804de-1c2a-479a-8e6e-15a2d9d95352@redhat.com> References: <20261203171808.445429-1-lvivier@redhat.com> <20261204073103.6e7f12c6@elisabeth> <7ef804de-1c2a-479a-8e6e-15a2d9d95352@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 09:54:48 +0100 (CET) X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 5Q5QyZVVMBolyleC4V4QGHzNZqL0EbESWZH5xDBVdis_1796374490 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: WJHQBOIQJFPAMHI5XKTVIGXFN5NRW4U6 X-Message-ID-Hash: WJHQBOIQJFPAMHI5XKTVIGXFN5NRW4U6 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 Fri, 4 Dec 2026 08:57:16 +0100 Laurent Vivier wrote: > On 12/4/26 07:31, Stefano Brivio wrote: > > 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. > > Yes, I explored this way and I think it was a good solution but I kept a separate > bytes_acked to show clearly where this value comes from. But if the size matters, we can > of course do like that. Yeah, I'd say it risks mattering a lot the next time we need to store something else there. > > > > That is, something like this (very lightly tested, without comment > > updates, and probably we could avoid dumping tcp_info twice on the > > source): > > But what about migration from and older passt to a newer one? Oops, you're right, I didn't think about that. > The value will not be correct. Perhaps it's better to do this on the destination side? > > What do you think of: > > diff --git a/tcp.c b/tcp.c > index b1065545aeea..43295bd6bfab 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -3936,6 +3936,12 @@ 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->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"); I wasn't sure whether t.sndq is guaranteed to exactly reflect unacknowledged bytes, but what SIOCOUTQ returns in tcp_ioctl() is: answ = READ_ONCE(tp->write_seq) - tp->snd_una; and tcp_snd_una_update() updates tp->bytes_acked as well as tp->snd_una at the same time, so it looks safe to me. Maybe in that comment I would also try to explain *why* we're doing that at all. Perhaps: [...] * * 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(). */ -- Stefano