public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH] migrate, tcp: Account for bytes acknowledged before migration
@ 2026-12-03 17:18 Laurent Vivier
  2026-12-03 22:44 ` Jon Maloy
  2026-12-04  6:31 ` Stefano Brivio
  0 siblings, 2 replies; 5+ messages in thread
From: Laurent Vivier @ 2026-12-03 17:18 UTC (permalink / raw)
  To: passt-dev; +Cc: Laurent Vivier

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 add a per-flow offset, bytes_acked, to the target
socket's tcpi_bytes_acked when computing seq_ack_to_tap.

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 <lvivier@redhat.com>
---
 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;
 };
 
 /**
-- 
2.56.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] migrate, tcp: Account for bytes acknowledged before migration
  2026-12-03 17:18 [PATCH] migrate, tcp: Account for bytes acknowledged before migration Laurent Vivier
@ 2026-12-03 22:44 ` Jon Maloy
  2026-12-04  6:31 ` Stefano Brivio
  1 sibling, 0 replies; 5+ messages in thread
From: Jon Maloy @ 2026-12-03 22:44 UTC (permalink / raw)
  To: Laurent Vivier, passt-dev

On 2026-12-03 12:18, 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.
> 
> 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.


This seems to be the issue that kept Stefano from merging Lynxes' "tcp: 
Don't
add peers to low RTT table before RTT is measured", from the thread at:

   https://archives.passt.top/passt-dev/avz8R6lrK91ZS4qJ@gractus.seuss/

where migrate/rampstream_out started failing with it.
That one can now be applied as soon as this one is in place.
It's also nice that this doesn't need the low RTT table to be migrated,
which David had objections to.

> 
> 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.
> 
> 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 <lvivier@redhat.com>
> ---
>   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;
>   	}
>   
[...]

> --- 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;

There should be a @bytes_acked line in the comment above the struct.
Maybe also a name that makes it clearer it's an offset added to
tcpi_bytes_acked, such as bytes_acked_base?

The fix itself looks correct: (seq_from_tap - sndq) - seq_init_from_tap
is exactly what the peer acknowledged at migration time. Since it is
recomputed on each migration, it should also work if we migrate again.

With the struct comment fixed:

Reviewed-by: Jon Maloy <jmaloy@redhat.com>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] migrate, tcp: Account for bytes acknowledged before migration
  2026-12-03 17:18 [PATCH] migrate, tcp: Account for bytes acknowledged before migration Laurent Vivier
  2026-12-03 22:44 ` Jon Maloy
@ 2026-12-04  6:31 ` Stefano Brivio
  2026-12-04  7:57   ` Laurent Vivier
  1 sibling, 1 reply; 5+ messages in thread
From: Stefano Brivio @ 2026-12-04  6:31 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: passt-dev, Jon Maloy, David Gibson, Lynxes Exe

On Thu,  3 Dec 2026 18:18:08 +0100
Laurent Vivier <lvivier@redhat.com> 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 <lvivier@redhat.com>
> ---
>  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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] migrate, tcp: Account for bytes acknowledged before migration
  2026-12-04  6:31 ` Stefano Brivio
@ 2026-12-04  7:57   ` Laurent Vivier
  2026-12-04  8:54     ` Stefano Brivio
  0 siblings, 1 reply; 5+ messages in thread
From: Laurent Vivier @ 2026-12-04  7:57 UTC (permalink / raw)
  To: Stefano Brivio; +Cc: passt-dev, Jon Maloy, David Gibson, Lynxes Exe

On 12/4/26 07:31, Stefano Brivio wrote:
> On Thu,  3 Dec 2026 18:18:08 +0100
> Laurent Vivier <lvivier@redhat.com> 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.

> 
>     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?
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");

Thanks,
Laurent

> ---
> 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 <lvivier@redhat.com>
>> ---
>>   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;
>>   };
>>   
>>   /**
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] migrate, tcp: Account for bytes acknowledged before migration
  2026-12-04  7:57   ` Laurent Vivier
@ 2026-12-04  8:54     ` Stefano Brivio
  0 siblings, 0 replies; 5+ messages in thread
From: Stefano Brivio @ 2026-12-04  8:54 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: passt-dev, Jon Maloy, David Gibson, Lynxes Exe

On Fri, 4 Dec 2026 08:57:16 +0100
Laurent Vivier <lvivier@redhat.com> wrote:

> On 12/4/26 07:31, Stefano Brivio wrote:
> > On Thu,  3 Dec 2026 18:18:08 +0100
> > Laurent Vivier <lvivier@redhat.com> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-04  8:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03 17:18 [PATCH] migrate, tcp: Account for bytes acknowledged before migration Laurent Vivier
2026-12-03 22:44 ` Jon Maloy
2026-12-04  6:31 ` Stefano Brivio
2026-12-04  7:57   ` Laurent Vivier
2026-12-04  8:54     ` 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).