From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: passt.top; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=PGF8ewK3; dkim-atps=neutral Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by passt.top (Postfix) with ESMTPS id 295CE5A004E for ; Fri, 17 Jan 2025 23:09:39 +0100 (CET) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5d3d0205bd5so3937778a12.3 for ; Fri, 17 Jan 2025 14:09:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737151779; x=1737756579; darn=passt.top; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=XxWJt7vMg8HEzcChWeewww178yhKsckOUrymoyMFD/k=; b=PGF8ewK3R4enm8NjhvLqBsLDPzM4IoeV8YMBTJh3c+Bcwt4Q/lryNaRxYx8c70ScEB 7ZYdQrA+jQbJ7bPGuDmwt35iotb9xRkc/kh03r+L/+y0DBFmQtqtBQX9AeblWtNz+bJ6 EbZS91eDfe7tf3sQe1th2NomkZANtHV0WIatHA7jL/pEgeGFaApEqn8KEykjowNme5uZ 0GkUgN+PZkQaavVgpQyDpR0WJrduKnyOU1ZEYDTv9efNHncempS3uT8ff0AbYXcQweOE 7o3v8EmVtdt60chT91GW4y5pOdlrc+1z8UwjzgJWkIgvY3AplOJ49tuXhdFbdjTX/RHS Uvvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737151779; x=1737756579; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XxWJt7vMg8HEzcChWeewww178yhKsckOUrymoyMFD/k=; b=eMNBF24DgkHwCne6FV93ZRNshPkDS7sNOU60MO8drbDL52DgkUOfddDNWQ5IcSamO0 qN58R5AyioDhdVmeiIoGYzU3oDE+JSWatWQDmLGQhzU+wI1cMa2wpcSIOqWanxFn08IX hBPlWxz1Nuvxs4IX5YLZAKWxfk1DSCg6VchwguXBubUKiqsrCOgcJVHIkHw7d7NjpM4Y vSS5lmP/X5R6el4Flc4s6oEbRViK2L3FdgH1KLElUnP8WZI2hoibbd6jCqvt98dTTH3d FrbnsIlE5+RHQx8gbMDN+0wQuBCQmCZm+73ZOFvRU/sJzaIcMm/ok6Fb32qrsqDHhqTV gjHQ== X-Forwarded-Encrypted: i=1; AJvYcCUf/MA8AiY7cy9m1cuELoTXKVRQCN5yU07tp72ZGuVEYA9ajpmV/br3pje2oMUt4CSuYb9ppWLTaBg=@passt.top X-Gm-Message-State: AOJu0YzguWCRXnXFXs5ReeZHjXlHUlSaf+wHu0CdukiJRh4EDF++yKxr KJBI9IW9/H/eggqpJPr9X85z+G31akBfaulcBshNCZchhkwb0zc1hSKKTKUi3bZxUVD64+uo7KU nO3KQUCdwRRiBbUJ8dZZ+khIXXkIFIBImTa8W X-Gm-Gg: ASbGncum2AkUzjl68PGWZIXlF58BhyJ+j7tRqsiJsPvCr3aQZXkthMm6iEIYKA2TdF8 Uhux5oPQmy3w5Y63SKCvOJrxcpD6zP9TtJysC3Rw= X-Google-Smtp-Source: AGHT+IHBpLn7CckltR9Iv3FEUwqti86dy6iZKoFZ11zkG4eqmbDpfEUKhkGffGpmmJ25ruXFZ3HQY0wLc7SXoZuaxqs= X-Received: by 2002:a05:6402:3487:b0:5d4:1ac2:277f with SMTP id 4fb4d7f45d1cf-5db7d2f5efdmr3530043a12.9.1737151778437; Fri, 17 Jan 2025 14:09:38 -0800 (PST) MIME-Version: 1.0 References: <20250117214035.2414668-1-jmaloy@redhat.com> In-Reply-To: <20250117214035.2414668-1-jmaloy@redhat.com> From: Eric Dumazet Date: Fri, 17 Jan 2025 23:09:27 +0100 X-Gm-Features: AbW1kvbbFQPAzAZTxBmIhZC7XdXJqVnCoapPkbiNBZUDhk7bt9XvflitbtApGpU Message-ID: Subject: Re: [net,v2] tcp: correct handling of extreme memory squeeze To: jmaloy@redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-MailFrom: edumazet@google.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation Message-ID-Hash: 3T2AW7NOPDE2ZLU7QPWPB6NPY2X5U2F3 X-Message-ID-Hash: 3T2AW7NOPDE2ZLU7QPWPB6NPY2X5U2F3 X-Mailman-Approved-At: Sat, 18 Jan 2025 00:41:41 +0100 CC: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org, passt-dev@passt.top, sbrivio@redhat.com, lvivier@redhat.com, dgibson@redhat.com, imagedong@tencent.com, eric.dumazet@gmail.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 Fri, Jan 17, 2025 at 10:40=E2=80=AFPM wrote: > > From: Jon Maloy > > Testing with iperf3 using the "pasta" protocol splicer has revealed > a bug in the way tcp handles window advertising in extreme memory > squeeze situations. > > Under memory pressure, a socket endpoint may temporarily advertise > a zero-sized window, but this is not stored as part of the socket data. > The reasoning behind this is that it is considered a temporary setting > which shouldn't influence any further calculations. > > However, if we happen to stall at an unfortunate value of the current > window size, the algorithm selecting a new value will consistently fail > to advertise a non-zero window once we have freed up enough memory. > This means that this side's notion of the current window size is > different from the one last advertised to the peer, causing the latter > to not send any data to resolve the sitution. > > The problem occurs on the iperf3 server side, and the socket in question > is a completely regular socket with the default settings for the > fedora40 kernel. We do not use SO_PEEK or SO_RCVBUF on the socket. > > The following excerpt of a logging session, with own comments added, > shows more in detail what is happening: > > // tcp_v4_rcv(->) > // tcp_rcv_established(->) > [5201<->39222]: =3D=3D=3D=3D Activating log @ net/ipv4/tcp_input.c/tc= p_data_queue()/5257 =3D=3D=3D=3D > [5201<->39222]: tcp_data_queue(->) > [5201<->39222]: DROPPING skb [265600160..265665640], reason: SKB_D= ROP_REASON_PROTO_MEM > [rcv_nxt 265600160, rcv_wnd 262144, snt_ack 265469= 200, win_now 131184] > [copied_seq 259909392->260034360 (124968), unread = 5565800, qlen 85, ofoq 0] > [5201<->39222]: tcp_data_queue(<-) OFO queue: gap: 65480, len: 0 > [5201<->39222]: __tcp_transmit_skb(->) > [5201<->39222]: tcp_select_window(->) tp->rcv_wup: 265469200, tp->r= cv_wnd: 262144, tp->rcv_nxt 265600160 > [5201<->39222]: (inet_csk(sk)->icsk_ack.pending & ICSK_ACK_NOMEM)= --> TRUE > [5201<->39222]: tcp_select_window(<-) tp->rcv_wup: 265469200, tp->r= cv_wnd: 262144, tp->rcv_nxt 265600160, returning 0 > [5201<->39222]: ADVERTISING WIN 0, ACK_SEQ: 265600160 > [5201<->39222]: __tcp_transmit_skb(<-) tp->rcv_wup: 265469200, tp->rc= v_wnd: 262144, tp->rcv_nxt 265600160 > [5201<->39222]: tcp_rcv_established(<-) > [5201<->39222]: tcp_v4_rcv(<-) > > // Receive queue is at 85 buffers and we are out of memory. > // We drop the incoming buffer, although it is in sequence, and decide > // to send an advertisement with a window of zero. > // We don't update tp->rcv_wnd and tp->rcv_wup accordingly, which means > // we unconditionally shrink the window. > > [5201<->39222]: tcp_recvmsg_locked(->) > [5201<->39222]: __tcp_cleanup_rbuf(->) tp->rcv_wup: 265469200, tp->rcv_= wnd: 262144, tp->rcv_nxt 265600160 > [5201<->39222]: [new_win =3D 0, win_now =3D 131184, 2 * win_now =3D 2= 62368] > [5201<->39222]: [new_win >=3D (2 * win_now) ? --> time_to_ack =3D 0] > [5201<->39222]: NOT calling tcp_send_ack() > [5201<->39222]: __tcp_cleanup_rbuf(<-) tp->rcv_wup: 265469200, tp->rcv_= wnd: 262144, tp->rcv_nxt 265600160 > [5201<->39222]: tcp_recvmsg_locked(<-) returning 6104 bytes. > [rcv_nxt 265600160, rcv_wnd 262144, snt_ack 265469200, wi= n_now 131184] > [copied_seq 260040464->260040464 (0), unread 5559696, qle= n 85, ofoq 0] > > // After each read, the algorithm for calculating the new receive > // window in __tcp_cleanup_rbuf() finds it is too small to advertise > // or to update tp->rcv_wnd. > // Meanwhile, the peer thinks the window is zero, and will not send > // any more data to trigger an update from the interrupt mode side. > > [5201<->39222]: tcp_recvmsg_locked(->) > [5201<->39222]: __tcp_cleanup_rbuf(->) tp->rcv_wup: 265469200, tp->rcv_= wnd: 262144, tp->rcv_nxt 265600160 > [5201<->39222]: [new_win =3D 262144, win_now =3D 131184, 2 * win_now = =3D 262368] > [5201<->39222]: [new_win >=3D (2 * win_now) ? --> time_to_ack =3D 0] > [5201<->39222]: NOT calling tcp_send_ack() > [5201<->39222]: __tcp_cleanup_rbuf(<-) tp->rcv_wup: 265469200, tp->rcv_= wnd: 262144, tp->rcv_nxt 265600160 > [5201<->39222]: tcp_recvmsg_locked(<-) returning 131072 bytes. > [rcv_nxt 265600160, rcv_wnd 262144, snt_ack 265469200, wi= n_now 131184] > [copied_seq 260099840->260171536 (71696), unread 5428624,= qlen 83, ofoq 0] > > // The above pattern repeats again and again, since nothing changes > // between the reads. > > [...] > > [5201<->39222]: tcp_recvmsg_locked(->) > [5201<->39222]: __tcp_cleanup_rbuf(->) tp->rcv_wup: 265469200, tp->rcv_= wnd: 262144, tp->rcv_nxt 265600160 > [5201<->39222]: [new_win =3D 262144, win_now =3D 131184, 2 * win_now = =3D 262368] > [5201<->39222]: [new_win >=3D (2 * win_now) ? --> time_to_ack =3D 0] > [5201<->39222]: NOT calling tcp_send_ack() > [5201<->39222]: __tcp_cleanup_rbuf(<-) tp->rcv_wup: 265469200, tp->rcv_= wnd: 262144, tp->rcv_nxt 265600160 > [5201<->39222]: tcp_recvmsg_locked(<-) returning 131072 bytes. > [rcv_nxt 265600160, rcv_wnd 262144, snt_ack 265469200, wi= n_now 131184] > [copied_seq 265469200->265545488 (76288), unread 54672, q= len 1, ofoq 0] > > [5201<->39222]: tcp_recvmsg_locked(->) > [5201<->39222]: __tcp_cleanup_rbuf(->) tp->rcv_wup: 265469200, tp->rcv_= wnd: 262144, tp->rcv_nxt 265600160 > [5201<->39222]: [new_win =3D 262144, win_now =3D 131184, 2 * win_now = =3D 262368] > [5201<->39222]: [new_win >=3D (2 * win_now) ? --> time_to_ack =3D 0] > [5201<->39222]: NOT calling tcp_send_ack() > [5201<->39222]: __tcp_cleanup_rbuf(<-) tp->rcv_wup: 265469200, tp->rcv_= wnd: 262144, tp->rcv_nxt 265600160 > [5201<->39222]: tcp_recvmsg_locked(<-) returning 54672 bytes. > [rcv_nxt 265600160, rcv_wnd 262144, snt_ack 265469200, wi= n_now 131184] > [copied_seq 265600160->265600160 (0), unread 0, qlen 0, o= foq 0] > > // The receive queue is empty, but no new advertisement has been sent. > // The peer still thinks the receive window is zero, and sends nothing. > // We have ended up in a deadlock situation. > > Furthermore, we have observed that in these situations this side may > send out an updated 'th->ack_seq=C2=B4 which is not stored in tp->rcv_wup > as it should be. Backing ack_seq seems to be harmless, but is of > course still wrong from a protocol viewpoint. > > We fix this by setting tp->rcv_wnd and tp->rcv_wup even when a packet > has been dropped because of memory exhaustion and we have to advertize > a zero window. > > Further testing shows that the connection recovers neatly from the > squeeze situation, and traffic can continue indefinitely. > > Fixes: e2142825c120 ("net: tcp: send zero-window ACK when no memory") > Reviewed-by: Stefano Brivio > Signed-off-by: Jon Maloy > --- > v1: -Posted on Apr 6, 2024 Could you post the link, this was a long time ago and I forgot the context. > v2: -Improved commit log to clarify how we end up in this situation. > -After feedback from Eric Dumazet, removed references to use of > SO_PEEK and SO_PEEK_OFF which may lead to a misunderstanding > about how this situation occurs. Those flags are used at the > peer side's incoming connection, and not on this one. > --- > net/ipv4/tcp_output.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c > index 0e5b9a654254..ba295f798e5e 100644 > --- a/net/ipv4/tcp_output.c > +++ b/net/ipv4/tcp_output.c > @@ -265,11 +265,13 @@ static u16 tcp_select_window(struct sock *sk) > u32 cur_win, new_win; > > /* Make the window 0 if we failed to queue the data because we > - * are out of memory. The window is temporary, so we don't store > - * it on the socket. > + * are out of memory. > */ > - if (unlikely(inet_csk(sk)->icsk_ack.pending & ICSK_ACK_NOMEM)) > + if (unlikely(inet_csk(sk)->icsk_ack.pending & ICSK_ACK_NOMEM)) { > + tp->rcv_wnd =3D 0; > + tp->rcv_wup =3D tp->rcv_nxt; I wonder if we should not clear tp->pred_flags here ? Also, any chance you could provide a packetdrill test ? Your changelog contains traces that are hard to follow. Thanks.