From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 2719B5A004F for ; Fri, 12 Jul 2024 16:20:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720794053; 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=v189tRysYhszjaUoIuQAoWEARGuqlXbarG08ANaYQoc=; b=X3IosUwIqSNUgaPPGd9Emo/NxVN5jiLUJXVje8s6uTLWQXJPjEBw2dGwD6S7MXjpnZDY0l BR1gD2ERPpiO/vJvI4+wwgfQtBRAh1+g1pkpVHW3kC5ehUgxjnRfUpyZDIONkdQL5somTQ EEVtOAuG8sNZ+l5WkyJTka8KxOck9gE= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-416-JHgjJmJSOlWE9uHaT_q7zw-1; Fri, 12 Jul 2024 10:20:52 -0400 X-MC-Unique: JHgjJmJSOlWE9uHaT_q7zw-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7a1419b065cso260923185a.3 for ; Fri, 12 Jul 2024 07:20:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720794052; x=1721398852; 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=v189tRysYhszjaUoIuQAoWEARGuqlXbarG08ANaYQoc=; b=RNtIA5ggSlFVnXIkkP8pUXwqaQTubEXtS6+CY9YyoLmYK+rF0i3Ar4pXMibB/EiNyW vExVgxGxrud0sHm6gxk4xEu4seZ+p+JJ5I+zjmQo1ABQjXnwumX9SYiZVGqDrWobHzYJ RuOMFzBCGEfH7c3UZ0Q8QRto4RD30fRE/G7Pe1/dHF3hm+LLtopH7dulSOnOBv1Xu7tU R5OvitQVqDO6HjHIN6WuqshZNQwqvc7LhDbGKj2xBS+xyJuhlMr6o5RjlHFgX9DoPCG7 mQBmKC82Yng9iewsiCpYHkrrGF4/B4ZDx/A+aqbM8BeBhA1K0kQ5d1VoqY0drY6rseUg CYZw== X-Gm-Message-State: AOJu0YwQjEMw1fWquzkZqwk9BRES68q813NTDiPEw1aSi0C+/+z+OsAd lLpYOBmUsbU0JV7TAHYrJaMiJWDROmvxf9TRz50j0DhrUGxIuXk3wW4bLn9PvGwVzCSXR82xC60 MVES8PqCqE73i5SfbSVCfGjUSMOGems2OSKyjMMpwgpfuUjKchG5sRpnLD3sty7kK5sDZdiqLpd hBYvI4U3o7z7wGOtFw5UiM9ZDA8owX6Cfuz70= X-Received: by 2002:a05:620a:2086:b0:79f:7da:3d7f with SMTP id af79cd13be357-79f19bf1205mr1205053585a.62.1720794051874; Fri, 12 Jul 2024 07:20:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEm+LTuqpAJXpkTs/7U82gK+Fe/dzH44xcSaEHfM/srGq2hmSbeg2+RKtqu3W9OjHlSUzAUjw== X-Received: by 2002:a05:620a:2086:b0:79f:7da:3d7f with SMTP id af79cd13be357-79f19bf1205mr1205050985a.62.1720794051464; Fri, 12 Jul 2024 07:20:51 -0700 (PDT) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id af79cd13be357-79f18ff67d8sm408080285a.23.2024.07.12.07.20.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jul 2024 07:20:50 -0700 (PDT) Date: Fri, 12 Jul 2024 16:20:16 +0200 From: Stefano Brivio To: Jon Maloy Subject: Re: [PATCH v8 2/2] tcp: handle shrunk window advertisemenst from guest Message-ID: <20240712162016.7566d601@elisabeth> In-Reply-To: <20240711222631.1073408-3-jmaloy@redhat.com> References: <20240711222631.1073408-1-jmaloy@redhat.com> <20240711222631.1073408-3-jmaloy@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: VNMOXVWG62N65XDVFGTV34OXMV5YOVMT X-Message-ID-Hash: VNMOXVWG62N65XDVFGTV34OXMV5YOVMT 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, lvivier@redhat.com, dgibson@redhat.com 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 Thu, 11 Jul 2024 18:26:31 -0400 Jon Maloy wrote: > A bug in kernel TCP may lead to a deadlock where a zero window is sent > from the guest peer, while it is unable to send out window updates even > after socket reads have freed up enough buffer space to permit a larger > window. In this situation, new window advertisements from the peer can > only be triggered by data packets arriving from this side. > > However, currently such packets are never sent, because the zero-window > condition prevents this side from sending out any packets whatsoever > to the peer. > > We notice that the above bug is triggered *only* after the peer has > dropped one or more arriving packets because of severe memory squeeze, > and that we hence always enter a retransmission situation when this > occurs. This also means that the implementation goes against the > RFC-9293 recommendation that a previously advertised window never > should shrink. > > RFC-9293 seems to permit that we can continue sending up to the right > edge of the last advertised non-zero window in such situations, so that > is what we do to resolve this situation. > > It turns out that this solution is extremely simple to implememt in the > code: We just omit to save the advertised zero-window when we see that > it has shrunk, i.e., if the acknowledged sequence number in the > advertisement message is lower than that of the last data byte sent > from our side. I'm glad it worked, I wasn't so sure. :) > When that is the case, the following happens: > - The 'retr' flag in tcp_data_from_tap() will be 'false', so no > retransmission will occur at this occasion. > - The data stream will soon reach the right edge of the previously > advertised window. In fact, in all observed cases we have seen that > it is already there when the zero-advertisement arrives. > - At that moment, the flags STALLED and ACK_FROM_TAP_DUE will be set, > unless they already have been, meaning that only the next timer > expiration will open for data retransmission or transmission. > - When that happens, the memory squeeze at the guest will normally have > abated, and the data flow can resume. > > It should be noted that although this solves the problem we have at > hand, it is a work-around, and not a genuine solution to the described > kernel bug. > > Suggested-by: Stefano Brivio > Signed-off-by: Jon Maloy > --- > tcp.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/tcp.c b/tcp.c > index 1a8a8df..4e58a37 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -1421,6 +1421,11 @@ static void tcp_get_tap_ws(struct tcp_tap_conn *conn, > static void tcp_tap_window_update(struct tcp_tap_conn *conn, unsigned wnd) > { > wnd = MIN(MAX_WINDOW, wnd << conn->ws_from_tap); > + > + /* Work-around for peer bug: Don't update if window shrank to zero */ Given that you found out the exact Linux kernel commit introducing the issue, could you perhaps mention that in the comment instead of a generic "peer bug"? I can also add that on merge if you prefer. > + if (!wnd && SEQ_LT(conn->seq_ack_from_tap, conn->seq_to_tap)) > + return; > + > conn->wnd_from_tap = MIN(wnd >> conn->ws_from_tap, USHRT_MAX); > > /* FIXME: reflect the tap-side receiver's window back to the sock-side -- Stefano