aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorJon Maloy <jmaloy@redhat.com>2024-07-12 15:04:50 -0400
committerStefano Brivio <sbrivio@redhat.com>2024-07-15 18:05:08 +0200
commita740e16fd1b9bdca8d259aa6d37f942a3874425c (patch)
tree08c8ef03767030509675a66b3990b4d8a4b91779
parente63d281871efff5e411275ce2ba1509314c75898 (diff)
downloadpasst-a740e16fd1b9bdca8d259aa6d37f942a3874425c.tar
passt-a740e16fd1b9bdca8d259aa6d37f942a3874425c.tar.gz
passt-a740e16fd1b9bdca8d259aa6d37f942a3874425c.tar.bz2
passt-a740e16fd1b9bdca8d259aa6d37f942a3874425c.tar.lz
passt-a740e16fd1b9bdca8d259aa6d37f942a3874425c.tar.xz
passt-a740e16fd1b9bdca8d259aa6d37f942a3874425c.tar.zst
passt-a740e16fd1b9bdca8d259aa6d37f942a3874425c.zip
tcp: handle shrunk window advertisements from guest
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. 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 <sbrivio@redhat.com> Signed-off-by: Jon Maloy <jmaloy@redhat.com> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> [sbrivio: Minor fix in commit title and commit reference in comment to workaround Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--tcp.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/tcp.c b/tcp.c
index 78c4add..e606603 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1425,6 +1425,14 @@ 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 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.
+ */
+ 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