public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH] tcp: Don't discard window information on keep-alive segments
@ 2025-02-11 19:50 Stefano Brivio
  2025-02-12  0:42 ` David Gibson
  0 siblings, 1 reply; 3+ messages in thread
From: Stefano Brivio @ 2025-02-11 19:50 UTC (permalink / raw)
  To: passt-dev; +Cc: David Gibson, Jon Maloy

It looks like a detail, but it's critical if we're dealing with
somebody, such as near-future self, using TCP_REPAIR to migrate TCP
connections in the guest or container.

The last packet sent from the 'source' process/guest/container
typically reports a small window, or zero, because the guest/container
hadn't been draining it for a while.

The next packet, appearing as the target sets TCP_REPAIR_OFF on the
migrated socket, is a keep-alive (also called "window probe" in CRIU
or TCP_REPAIR-related code), and it comes with an updated window
value, reflecting the pre-migration "regular" value.

If we ignore it, it might take a while/forever before we realise we
can actually restart sending.

Fixes: 238c69f9af45 ("tcp: Acknowledge keep-alive segments, ignore them for the rest")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 tcp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tcp.c b/tcp.c
index af6bd95..2addf4a 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1664,8 +1664,10 @@ static int tcp_data_from_tap(const struct ctx *c, struct tcp_tap_conn *conn,
 			tcp_send_flag(c, conn, ACK);
 			tcp_timer_ctl(c, conn);
 
-			if (p->count == 1)
+			if (p->count == 1) {
+				tcp_tap_window_update(conn, ntohs(th->window));
 				return 1;
+			}
 
 			continue;
 		}
-- 
@@ -1664,8 +1664,10 @@ static int tcp_data_from_tap(const struct ctx *c, struct tcp_tap_conn *conn,
 			tcp_send_flag(c, conn, ACK);
 			tcp_timer_ctl(c, conn);
 
-			if (p->count == 1)
+			if (p->count == 1) {
+				tcp_tap_window_update(conn, ntohs(th->window));
 				return 1;
+			}
 
 			continue;
 		}
-- 
2.43.0


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

* Re: [PATCH] tcp: Don't discard window information on keep-alive segments
  2025-02-11 19:50 [PATCH] tcp: Don't discard window information on keep-alive segments Stefano Brivio
@ 2025-02-12  0:42 ` David Gibson
  2025-02-12  1:20   ` Stefano Brivio
  0 siblings, 1 reply; 3+ messages in thread
From: David Gibson @ 2025-02-12  0:42 UTC (permalink / raw)
  To: Stefano Brivio; +Cc: passt-dev, Jon Maloy

[-- Attachment #1: Type: text/plain, Size: 2129 bytes --]

On Tue, Feb 11, 2025 at 08:50:51PM +0100, Stefano Brivio wrote:
> It looks like a detail, but it's critical if we're dealing with
> somebody, such as near-future self, using TCP_REPAIR to migrate TCP
> connections in the guest or container.
> 
> The last packet sent from the 'source' process/guest/container
> typically reports a small window, or zero, because the guest/container
> hadn't been draining it for a while.
> 
> The next packet, appearing as the target sets TCP_REPAIR_OFF on the
> migrated socket, is a keep-alive (also called "window probe" in CRIU
> or TCP_REPAIR-related code), and it comes with an updated window
> value, reflecting the pre-migration "regular" value.
> 
> If we ignore it, it might take a while/forever before we realise we
> can actually restart sending.
> 
> Fixes: 238c69f9af45 ("tcp: Acknowledge keep-alive segments, ignore them for the rest")
> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

Although...

> ---
>  tcp.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tcp.c b/tcp.c
> index af6bd95..2addf4a 100644
> --- a/tcp.c
> +++ b/tcp.c
> @@ -1664,8 +1664,10 @@ static int tcp_data_from_tap(const struct ctx *c, struct tcp_tap_conn *conn,
>  			tcp_send_flag(c, conn, ACK);
>  			tcp_timer_ctl(c, conn);
>  
> -			if (p->count == 1)
> +			if (p->count == 1) {

... not really this patch, but this condition seems wrong to me.  IIUC
it's attempting to detect the last packet in the batch, which isn't
necessarily the same thing as the _only_ packet in the batch.
Admittedly, it probably will be for a keep-alive, but I'm having a
hard time convincing myself it absolutely has to be.

Should this maybe be (i + 1 == p->count) instead?

> +				tcp_tap_window_update(conn, ntohs(th->window));
>  				return 1;
> +			}
>  
>  			continue;
>  		}

-- 
David Gibson (he or they)	| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you, not the other way
				| around.
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] tcp: Don't discard window information on keep-alive segments
  2025-02-12  0:42 ` David Gibson
@ 2025-02-12  1:20   ` Stefano Brivio
  0 siblings, 0 replies; 3+ messages in thread
From: Stefano Brivio @ 2025-02-12  1:20 UTC (permalink / raw)
  To: David Gibson; +Cc: passt-dev, Jon Maloy

On Wed, 12 Feb 2025 11:42:54 +1100
David Gibson <david@gibson.dropbear.id.au> wrote:

> On Tue, Feb 11, 2025 at 08:50:51PM +0100, Stefano Brivio wrote:
> > It looks like a detail, but it's critical if we're dealing with
> > somebody, such as near-future self, using TCP_REPAIR to migrate TCP
> > connections in the guest or container.
> > 
> > The last packet sent from the 'source' process/guest/container
> > typically reports a small window, or zero, because the guest/container
> > hadn't been draining it for a while.
> > 
> > The next packet, appearing as the target sets TCP_REPAIR_OFF on the
> > migrated socket, is a keep-alive (also called "window probe" in CRIU
> > or TCP_REPAIR-related code), and it comes with an updated window
> > value, reflecting the pre-migration "regular" value.
> > 
> > If we ignore it, it might take a while/forever before we realise we
> > can actually restart sending.
> > 
> > Fixes: 238c69f9af45 ("tcp: Acknowledge keep-alive segments, ignore them for the rest")
> > Signed-off-by: Stefano Brivio <sbrivio@redhat.com>  
> 
> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> 
> Although...
> 
> > ---
> >  tcp.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tcp.c b/tcp.c
> > index af6bd95..2addf4a 100644
> > --- a/tcp.c
> > +++ b/tcp.c
> > @@ -1664,8 +1664,10 @@ static int tcp_data_from_tap(const struct ctx *c, struct tcp_tap_conn *conn,
> >  			tcp_send_flag(c, conn, ACK);
> >  			tcp_timer_ctl(c, conn);
> >  
> > -			if (p->count == 1)
> > +			if (p->count == 1) {  
> 
> ... not really this patch, but this condition seems wrong to me.  IIUC
> it's attempting to detect the last packet in the batch, which isn't
> necessarily the same thing as the _only_ packet in the batch.

No, not really, I just want to select one-packet batches on purpose. If
a keep-alive is part of a batch 1. it's not a keep-alive and 2. it
would probably need a more complicated handling which I hadn't really
time to think about.

See previous discussion on this:

  https://archives.passt.top/passt-dev/Zz01CDMNyFN-Ze68@zatzit

> Admittedly, it probably will be for a keep-alive, but I'm having a
> hard time convincing myself it absolutely has to be.

It is, because it makes no sense to batch keep-alives...

> Should this maybe be (i + 1 == p->count) instead?

-- 
Stefano


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

end of thread, other threads:[~2025-02-12  1:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-11 19:50 [PATCH] tcp: Don't discard window information on keep-alive segments Stefano Brivio
2025-02-12  0:42 ` David Gibson
2025-02-12  1:20   ` 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).