From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Pc/DMZbY; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id E6E975A0279 for ; Thu, 11 Sep 2025 01:48:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757548093; 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=Y0AZtm1obfRVi4CXUKAAWEN9yFRrma1FS/290v70Auc=; b=Pc/DMZbYVGi79Ax7X8KOt690JYpEE8IvuQ43FcL0c/xZnQw/aOS+v9lv92Md2f0rB/x0z+ JVYE70ad+wpxkzlOoZllxYO+HVvi7cAFKAHy5Q1xEf5Gt1AgBsXR0WYJV6h0KTXEZ3mUBP fScS8WdKxiZejjX/0nEcHJjc2f9L5Eg= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-633-Fm3ti19qOQKIonUvyJ1HJw-1; Wed, 10 Sep 2025 19:48:07 -0400 X-MC-Unique: Fm3ti19qOQKIonUvyJ1HJw-1 X-Mimecast-MFC-AGG-ID: Fm3ti19qOQKIonUvyJ1HJw_1757548087 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-812ae9acaecso23614685a.1 for ; Wed, 10 Sep 2025 16:48:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757548087; x=1758152887; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Y0AZtm1obfRVi4CXUKAAWEN9yFRrma1FS/290v70Auc=; b=jTlhswxI1GlIIB6EQfdTChpaGH8aZUGeePfD3HNbkt7KranwOPDNXp3Ym6Y2LNwl+S EoG3iZDLdLo5voyufHjPvt1rPQFMggiuZ28hyI0nyRDozrBcS4kceDCbVw71OmIBW7+u uZzf89s0/aAN72v9/pm0DeGihF/Kyzx1gRGZjId2XS3Lvod/72sM307t40ItYQjicEM5 mlLtfWFUs8tGiBpQSaJGKJbyCSYLN0PbDPeIR8rp1ozqsX6NGUCkdaUBoofop34Eorge p/VXM5xdEG+HKXCTGJtqEKGas9g29nPD9397CivhY9EVvJOiECvpctVoZtFB86L9ceEE c3xw== X-Forwarded-Encrypted: i=1; AJvYcCX1s5H094oGFeKBhgbuduky8iaOeyFoBP4WjVanrkt/PuorU2GWShY5i61FmMNILEwEXd7KLMtDEJg=@passt.top X-Gm-Message-State: AOJu0YyNApU+Osb95mZlSKVfL6bRxyIyCGWDTSKhA6uuF5sgXMpbvxTq 1oDXV1eCJoqyUgdriZCLwCYrc+8V6sRF4oKx43KVytt29WS+yWebmuqTARxoNR0xp2Xf1E5FZZW EUjsMFL1CtwjpiJ1GYa7VQGFnpIfB9hPxhPInCWRyXbtCjp/nTqonkQ== X-Gm-Gg: ASbGncvWgr9PGsThk7lUOTkoVWsMhq7ffyOs0hAKZ4hen+lqvyFoVykxPFjsLV/8w2y SbkKjKzF20Ig+K99GTB0HZNwKGJqEukIw7HOwIs2Staa28aRsTbYswbXBHS+CEScbxGcwf3NDFd Trf0fRDALs0p4VBhrxDCMVr0Y22ESKGJX2wU2Eh2Knw4oEFjbVJJs60CxEVU3Vp/1/ATntkQxu0 djhDbA25lPLTOa/BFvl/22oXVi6gcH2VlYZyJrKP75Kb94uJTNtyegvVLwVAMooSX7XdyfG1j4h Yz1pP/+WU6/RArTW+rsvS8seS8unRdi8OIVpttw4doWcz2Jl++6QTORWg9YI651G+2iISNGNu7O dGHzpTKHVNw== X-Received: by 2002:a05:620a:2908:b0:7e8:147a:73c5 with SMTP id af79cd13be357-813c1f89b11mr1811391085a.3.1757548087050; Wed, 10 Sep 2025 16:48:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH1UBRntR3euYrcSUHMfFqmG0yDId9vy3KSYS6yFMjIz8muKHPgR85uuh43L5uD4h/pgy1YQg== X-Received: by 2002:a05:620a:2908:b0:7e8:147a:73c5 with SMTP id af79cd13be357-813c1f89b11mr1811388285a.3.1757548086496; Wed, 10 Sep 2025 16:48:06 -0700 (PDT) Received: from ?IPV6:2001:4958:2206:8901:6025:1483:4146:72dd? ([2001:4958:2206:8901:6025:1483:4146:72dd]) by smtp.gmail.com with ESMTPSA id af79cd13be357-820cd7041ddsm3136385a.32.2025.09.10.16.48.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 10 Sep 2025 16:48:06 -0700 (PDT) Message-ID: <3b670965-fca2-44fe-a260-987fc7cce37d@redhat.com> Date: Wed, 10 Sep 2025 19:48:05 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 3/8] tcp: Rewind sequence when guest shrinks window to zero To: Stefano Brivio , passt-dev@passt.top References: <20250909181655.2990223-1-sbrivio@redhat.com> <20250909181655.2990223-4-sbrivio@redhat.com> From: Jon Maloy In-Reply-To: <20250909181655.2990223-4-sbrivio@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: OHMxHTSk521KvG2qtEwfgzk9rxNKijen5BOmro6X82E_1757548087 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: UCC57NFKFTG2PQQYIN2PJZ3KAS5ML56X X-Message-ID-Hash: UCC57NFKFTG2PQQYIN2PJZ3KAS5ML56X X-MailFrom: jmaloy@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: Paul Holzinger , David Gibson 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 2025-09-09 14:16, Stefano Brivio wrote: > A window shrunk to zero means by definition that anything else that > might be in flight is now out of window. Restart from the currently > acknowledged sequence. > > We need to do that both in tcp_tap_window_update(), where we already > check for zero-window updates, as well as in tcp_data_from_tap(), > because we might get one of those updates in a batch of packets that > also contains a non-zero window update. > > Suggested-by: Jon Maloy > Signed-off-by: Stefano Brivio Reviewed-by: Jon Maloy But see nit below. > --- > tcp.c | 34 +++++++++++++++++++++++++--------- > 1 file changed, 25 insertions(+), 9 deletions(-) > > diff --git a/tcp.c b/tcp.c > index 86e08f1..12d42e0 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -1268,19 +1268,25 @@ static void tcp_get_tap_ws(struct tcp_tap_conn *conn, > > /** > * tcp_tap_window_update() - Process an updated window from tap side > + * @c: Execution context > * @conn: Connection pointer > * @wnd: Window value, host order, unscaled > */ > -static void tcp_tap_window_update(struct tcp_tap_conn *conn, unsigned wnd) > +static void tcp_tap_window_update(const struct ctx *c, > + struct tcp_tap_conn *conn, unsigned wnd) > { > wnd = MIN(MAX_WINDOW, wnd << conn->ws_from_tap); > > /* Work-around for bug introduced in peer kernel code, commit > - * e2142825c120 ("net: tcp: send zero-window ACK when no memory"). > - * We don't update if window shrank to zero. > + * e2142825c120 ("net: tcp: send zero-window ACK when no memory"): don't > + * update the window if it shrank to zero, so that we'll eventually > + * retry to send data, but rewind the sequence as that obviously implies > + * that no data beyond the updated window will ever be acknowledged. Agree with David, a strong statement. > */ > - if (!wnd && SEQ_LT(conn->seq_ack_from_tap, conn->seq_to_tap)) > + if (!wnd && SEQ_LT(conn->seq_ack_from_tap, conn->seq_to_tap)) { > + tcp_rewind_seq(c, conn); > return; > + } > > conn->wnd_from_tap = MIN(wnd >> conn->ws_from_tap, USHRT_MAX); > > @@ -1709,7 +1715,8 @@ static int tcp_data_from_tap(const struct ctx *c, struct tcp_tap_conn *conn, > tcp_timer_ctl(c, conn); > > if (p->count == 1) { > - tcp_tap_window_update(conn, ntohs(th->window)); > + tcp_tap_window_update(c, conn, > + ntohs(th->window)); > return 1; > } > > @@ -1728,6 +1735,15 @@ static int tcp_data_from_tap(const struct ctx *c, struct tcp_tap_conn *conn, > ack_seq == max_ack_seq && > ntohs(th->window) == max_ack_seq_wnd; > > + /* See tcp_tap_window_update() for details. On > + * top of that, we also need to check here if a > + * zero-window update is contained in a batch of > + * packets that includes a non-zero window as > + * well. > + */ Two pleonasms in the same sentence ;-) Could possibly be shortened. > + if (!ntohs(th->window)) > + tcp_rewind_seq(c, conn); > + > max_ack_seq_wnd = ntohs(th->window); > max_ack_seq = ack_seq; > } > @@ -1791,7 +1807,7 @@ static int tcp_data_from_tap(const struct ctx *c, struct tcp_tap_conn *conn, > if (ack && !tcp_sock_consume(conn, max_ack_seq)) > tcp_update_seqack_from_tap(c, conn, max_ack_seq); > > - tcp_tap_window_update(conn, max_ack_seq_wnd); > + tcp_tap_window_update(c, conn, max_ack_seq_wnd); > > if (retr) { > flow_trace(conn, > @@ -1880,7 +1896,7 @@ static void tcp_conn_from_sock_finish(const struct ctx *c, > const struct tcphdr *th, > const char *opts, size_t optlen) > { > - tcp_tap_window_update(conn, ntohs(th->window)); > + tcp_tap_window_update(c, conn, ntohs(th->window)); > tcp_get_tap_ws(conn, opts, optlen); > > /* First value is not scaled */ > @@ -2085,7 +2101,7 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af, > if (!th->ack) > goto reset; > > - tcp_tap_window_update(conn, ntohs(th->window)); > + tcp_tap_window_update(c, conn, ntohs(th->window)); > > tcp_data_from_sock(c, conn); > > @@ -2097,7 +2113,7 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af, > if (conn->events & TAP_FIN_RCVD) { > tcp_sock_consume(conn, ntohl(th->ack_seq)); > tcp_update_seqack_from_tap(c, conn, ntohl(th->ack_seq)); > - tcp_tap_window_update(conn, ntohs(th->window)); > + tcp_tap_window_update(c, conn, ntohs(th->window)); > tcp_data_from_sock(c, conn); > > if (conn->events & SOCK_FIN_RCVD &&