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=Wj4r9+DX; dkim-atps=neutral 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 47AA05A0271 for ; Thu, 11 Sep 2025 10:59:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757581153; 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=7P0SzXnkQ49+YvP57FFAkuOU8iVgQCe5B2H29MzQKsE=; b=Wj4r9+DXgb3OMNztMBE8Ftmc6QkDxRDCrqE+1tD/pZQ1fjVCPRyrUJkDONbB0PGvVikLV3 6uwRARWGjs8F8Aul+M5HRkv2gtx3F2Dnx8gauRNyPt5dQIfbdzpYJlQCrgRthY3XWfbQ/3 JgEAkNh0JXDbiEzDLy4wqNDVezqt5jk= 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-76-xwuoGJRRMb6rQnxJqn4oJQ-1; Thu, 11 Sep 2025 04:59:12 -0400 X-MC-Unique: xwuoGJRRMb6rQnxJqn4oJQ-1 X-Mimecast-MFC-AGG-ID: xwuoGJRRMb6rQnxJqn4oJQ_1757581151 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-45de07b831dso3052945e9.1 for ; Thu, 11 Sep 2025 01:59:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757581151; x=1758185951; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=7P0SzXnkQ49+YvP57FFAkuOU8iVgQCe5B2H29MzQKsE=; b=XnW+lxSU4ha5J+g2lR5KHD8LS7Cv+5VfhSIP+1mIimqDNn9gHzgO3V5TtnoMAwAUzu OM3ASueGpfPbG+vVW47DNEGc52JCdjNWRx7cEtQm0v7cKs6QfvZtiXGf60vKyZm9OUQw 749bxi9bv0LDQYCwWLSRu0q+7USGoGld/cYfRK0ZlUkI3bOBHAmzT7OW5xogSla/NH1I aYXxbq1FQUB63vQ8smYQI0WKpjgE4AqXBEEKDt5r9su9R+rvW44H/rY/unS5H+CoO+iz klTOzu64GOr5IEcUd0jSfayLuDh06BGwmsD+DIUhsRnz7kJSGa41yxdg2tFpr5A8A8nD mizg== X-Gm-Message-State: AOJu0YwSKn+rrob6IB2n8dN1H11GQoMPPG4m5iBiVXPe7KTXAcBV5nI6 Z/3YDfLFb3Vs5K4lVyfkQzYIHqKFbVGbjKPMoU4+S88YTzu9ae6PXjuUbiBaNfJW7UDj2OWPB+F NIR2tx5sWYKeRDg51FKlKGZb3GgUyI7oJ2iohg1DidaUeRLcBwWLXZg== X-Gm-Gg: ASbGncvB8BVBjr1qclmuShECoKSmorh5i29GEbjK7xMajuJmf1AxkeAKnU0cKRPy0RD N0Jjc/Y6N7pGXUY5VmzzJbNuWpxVaeuUIcLiZ89Gv7ih2UF4xGaX4vBgxW3d4CtGrtTUIqF9DO9 r2UO+R8o3aMdM3ENBeHA4kh2FYwJw9DfGraSzaXIOefiwQm63T+1OmvBAvPC9k7N6SLBPXDsrZz ve2KpkbN468Recubco1/+KUhxBuGiH9cmZQQyFvb3f/drMBQcrvD2Y8WuRhsUDHljaTiAcyokQf nlK2eDfCxEsmXy44ajOm+gYHD9b2x9QVHjhaCWNs55rJay+x+ck= X-Received: by 2002:a05:600c:c4b7:b0:45d:e211:da8f with SMTP id 5b1f17b1804b1-45df4593aa2mr75018075e9.36.1757581150633; Thu, 11 Sep 2025 01:59:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFK6XROK8DHoMUunWgw4PrT86UsF1MqbKvEndUOToZMFPN6CnfmJ7cK1nR9o/xa0HWCjcRdSw== X-Received: by 2002:a05:600c:c4b7:b0:45d:e211:da8f with SMTP id 5b1f17b1804b1-45df4593aa2mr75017785e9.36.1757581150131; Thu, 11 Sep 2025 01:59:10 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45e0157cc84sm9897025e9.7.2025.09.11.01.59.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Sep 2025 01:59:08 -0700 (PDT) Date: Thu, 11 Sep 2025 10:59:06 +0200 From: Stefano Brivio To: Jon Maloy Subject: Re: [PATCH v4 3/8] tcp: Rewind sequence when guest shrinks window to zero Message-ID: <20250911105906.58638bbd@elisabeth> In-Reply-To: <3b670965-fca2-44fe-a260-987fc7cce37d@redhat.com> References: <20250909181655.2990223-1-sbrivio@redhat.com> <20250909181655.2990223-4-sbrivio@redhat.com> <3b670965-fca2-44fe-a260-987fc7cce37d@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 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: NTenmQBF_Kal5oKotYqIMzA08U-Tyx3sGMvPyS2Wymc_1757581151 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: OMBRQAMSG3EQE7A5PMS4PDT2GPCPNIYV X-Message-ID-Hash: OMBRQAMSG3EQE7A5PMS4PDT2GPCPNIYV 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, 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 Wed, 10 Sep 2025 19:48:05 -0400 Jon Maloy wrote: > 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. Right, see: https://archives.passt.top/passt-dev/20250901220746.1b63e515@elisabeth/ https://archives.passt.top/passt-dev/20250910083748.6b566880@elisabeth/ > > */ > > - 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. Which ones exactly? We don't necessarily have a zero-window update here, and the batch might not include any non-zero window update either. > > + 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 && -- Stefano