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.129.124]) by passt.top (Postfix) with ESMTP id A61E45A0280 for ; Fri, 5 Apr 2024 21:37:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712345862; 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=hcDrSUUd5i3jB0DtmcfEqk2GvHtZ4jsDAesYu0An20c=; b=QnSXIBu+BZ/20scZza5+asTrPnqlnIwMoo2DZr03F/aZo/uG5KeIwB4ft8YVYUMaTt5B/v IuRgwQnovzfnAE0IhyIZQz0YlBTDhcd1lTwl2ypI26BUKeA0sE25g6DFgsBgWQVjOkJBtl QagT+F6MqNJi0QUG/INCnMrisdodupQ= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-125-V4hGhHogOASlwaIcnEvp_g-1; Fri, 05 Apr 2024 15:37:41 -0400 X-MC-Unique: V4hGhHogOASlwaIcnEvp_g-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-69909a4a432so22449596d6.2 for ; Fri, 05 Apr 2024 12:37:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712345860; x=1712950660; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hcDrSUUd5i3jB0DtmcfEqk2GvHtZ4jsDAesYu0An20c=; b=s4dRf088dKgfRdLtZgJotFnxUtPXlQUVqicq4fpgNjZcXnNDbyCb/JCsZOG9Bvuune Nl0+wL0aRRcIH4rduedZfhjLAUVdxmBtPzHs45IzYFeuttFlyrx1Y+vPeQ2Cl/y27vLU 7A+Hxxh/Dcsk8ERCWseXdsMmdwkN2mo52OR2NcfVP310Sho5tcvkWJDgl/2lxedqiOYs FGi8je6FjJ/UiNPXFHXialLxS+jEWavk59T7tN896eVzpR13ldgFcgNH12+yyOzby+O7 2MLsRxkhS8U1sItfeKzFZ8R0db2SaPs7HdYLIMt/mO0/VTfjKXtUxhkrbb73FEOZOjNR yAUA== X-Gm-Message-State: AOJu0YxvhtW11+r6S2VSpPAHjjO1B9i7l0WHo5USkFVkerHj8s+2AsRr eQcvpNOu+3TgLc90dZ6fpZNYQYM3O6jsPdvCv3cBDiZqDU6y0Cew0X4faH/6JQ0WQbbI/JLAAvZ 0+F8C/qKQUKowgJ5c/uqt3qJ4I9B/d1yxVY/4u2MP44AJRvPBeA== X-Received: by 2002:ad4:5caa:0:b0:699:2552:f881 with SMTP id q10-20020ad45caa000000b006992552f881mr3079504qvh.38.1712345860432; Fri, 05 Apr 2024 12:37:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjfCKe3SJR5Mxj1qLv9Bw00dMpfNbethDvbNUkX5/HDWJnm6Q2fxLRcqMHNB+LOOASHxZtlw== X-Received: by 2002:ad4:5caa:0:b0:699:2552:f881 with SMTP id q10-20020ad45caa000000b006992552f881mr3079488qvh.38.1712345860124; Fri, 05 Apr 2024 12:37:40 -0700 (PDT) Received: from [10.0.0.97] ([24.225.234.80]) by smtp.gmail.com with ESMTPSA id g4-20020a0cf844000000b006992a743046sm864777qvo.121.2024.04.05.12.37.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 05 Apr 2024 12:37:39 -0700 (PDT) Message-ID: <0294decd-e966-2176-bfb9-2a91eb47beff@redhat.com> Date: Fri, 5 Apr 2024 15:37:38 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [net-next 2/2] tcp: correct handling of extreme menory squeeze To: Stefano Brivio References: <20240403225833.123346-1-jmaloy@redhat.com> <20240403225833.123346-3-jmaloy@redhat.com> <20240405195529.569ca5df@elisabeth> From: Jon Maloy In-Reply-To: <20240405195529.569ca5df@elisabeth> X-Mimecast-Spam-Score: 0 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: SPKS4WZPENYKPTQQH2VYE4IBKE2IZILJ X-Message-ID-Hash: SPKS4WZPENYKPTQQH2VYE4IBKE2IZILJ 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: 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 2024-04-05 13:55, Stefano Brivio wrote: > On Wed, 3 Apr 2024 18:58:33 -0400 > Jon Maloy wrote: > >> Testing of the previous commit ("tcp: add support for SO_PEEK_OFF") >> in this series along with the pasta protocol splicer revealed a bug in >> the way tcp handles window advertising during extreme memory squeeze >> situations. >> >> The excerpt of the below logging session shows what is happeing: >> >> [5201<->54494]: ==== Activating log @ tcp_select_window()/268 ==== >> [5201<->54494]: (inet_csk(sk)->icsk_ack.pending & ICSK_ACK_NOMEM) --> TRUE >> [5201<->54494]: tcp_select_window(<-) tp->rcv_wup: 2812454294, tp->rcv_wnd: 5812224, tp->rcv_nxt 2818016354, returning 0 >> [5201<->54494]: ADVERTISING WINDOW SIZE 0 >> [5201<->54494]: __tcp_transmit_skb(<-) tp->rcv_wup: 2812454294, tp->rcv_wnd: 5812224, tp->rcv_nxt 2818016354 >> >> [5201<->54494]: tcp_recvmsg_locked(->) >> [5201<->54494]: __tcp_cleanup_rbuf(->) tp->rcv_wup: 2812454294, tp->rcv_wnd: 5812224, tp->rcv_nxt 2818016354 >> [5201<->54494]: (win_now: 250164, new_win: 262144 >= (2 * win_now): 500328))? --> time_to_ack: 0 >> [5201<->54494]: NOT calling tcp_send_ack() >> [5201<->54494]: __tcp_cleanup_rbuf(<-) tp->rcv_wup: 2812454294, tp->rcv_wnd: 5812224, tp->rcv_nxt 2818016354 >> [5201<->54494]: tcp_recvmsg_locked(<-) returning 131072 bytes, window now: 250164, qlen: 83 >> >> [...] >> >> [5201<->54494]: tcp_recvmsg_locked(->) >> [5201<->54494]: __tcp_cleanup_rbuf(->) tp->rcv_wup: 2812454294, tp->rcv_wnd: 5812224, tp->rcv_nxt 2818016354 >> [5201<->54494]: (win_now: 250164, new_win: 262144 >= (2 * win_now): 500328))? --> time_to_ack: 0 >> [5201<->54494]: NOT calling tcp_send_ack() >> [5201<->54494]: __tcp_cleanup_rbuf(<-) tp->rcv_wup: 2812454294, tp->rcv_wnd: 5812224, tp->rcv_nxt 2818016354 >> [5201<->54494]: tcp_recvmsg_locked(<-) returning 131072 bytes, window now: 250164, qlen: 1 >> >> [5201<->54494]: tcp_recvmsg_locked(->) >> [5201<->54494]: __tcp_cleanup_rbuf(->) tp->rcv_wup: 2812454294, tp->rcv_wnd: 5812224, tp->rcv_nxt 2818016354 >> [5201<->54494]: (win_now: 250164, new_win: 262144 >= (2 * win_now): 500328))? --> time_to_ack: 0 >> [5201<->54494]: NOT calling tcp_send_ack() >> [5201<->54494]: __tcp_cleanup_rbuf(<-) tp->rcv_wup: 2812454294, tp->rcv_wnd: 5812224, tp->rcv_nxt 2818016354 >> [5201<->54494]: tcp_recvmsg_locked(<-) returning 57036 bytes, window now: 250164, qlen: 0 >> >> [5201<->54494]: tcp_recvmsg_locked(->) >> [5201<->54494]: __tcp_cleanup_rbuf(->) tp->rcv_wup: 2812454294, tp->rcv_wnd: 5812224, tp->rcv_nxt 2818016354 >> [5201<->54494]: NOT calling tcp_send_ack() >> [5201<->54494]: __tcp_cleanup_rbuf(<-) tp->rcv_wup: 2812454294, tp->rcv_wnd: 5812224, tp->rcv_nxt 2818016354 >> [5201<->54494]: tcp_recvmsg_locked(<-) returning -11 bytes, window now: 250164, qlen: 0 >> >> We can see that although we are adverising a window size of zero, >> tp->rcv_wnd is not updated accordingly. This leads to a discrepancy >> between this side's and the peer's view of the current window size. >> - The peer thinks the window is zero, and stops sending. >> - This side ends up in a cycle where it repeatedly caclulates a new >> window size it finds too small to advertise. >> >> Hence no messages are received, and no acknowledges are sent, and >> the situation remains locked even after the last queued receive buffer >> has been consumed. >> >> We fix this by setting tp->rcv_wnd to 0 before we return from the >> function tcp_select_window() in this particular case. >> Further testing shows that the connection recovers neatly from the >> squeeze situation, and traffic can continue indefinitely. >> >> Signed-off-by: Jon Maloy >> --- >> net/ipv4/tcp_output.c | 5 ++++- >> 1 file changed, 4 insertions(+), 1 deletion(-) >> >> diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c >> index e3167ad96567..5803fd402708 100644 >> --- a/net/ipv4/tcp_output.c >> +++ b/net/ipv4/tcp_output.c >> @@ -264,8 +264,11 @@ static u16 tcp_select_window(struct sock *sk) >> * are out of memory. The window is temporary, so we don't store >> * it on the socket. > One nit: now that you do store it on the socket, you should probably > change this comment as well. > >> */ >> - 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 = 0; >> + tp->rcv_wup = tp->rcv_nxt; > ...I'm wondering if you should set 'pred_flags' to 0, as it's done at > the end of the function for other cases where the window is advertised > as zero. > > At least according to the comment to tcp_rcv_established() it looks > like it's needed: > > * - A zero window was announced from us - zero window probing > * is only handled properly in the slow path. > >> return 0; >> + } >> >> cur_win = tcp_receive_window(tp); >> new_win = __tcp_select_window(sk); > The rest, including 1/2, looks good to me. > Good points. I'll fix those and post the patches with your "Reviewed-by:" /thx