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 9EC155A0276 for ; Fri, 5 Apr 2024 19:56:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712339792; 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=XLa8vNLwTcNK10kOlomnbACyE56ii0YltroaTRkhhaw=; b=QNrPhFuPkVjvtzkLP5VEm8SEM8JhTgY+Gb9kxwr3chlI0/VG+uBfl22/JpWeKF7xNdP8kC 7WbkGMVn+4LEH3M3dsvl1z80JQOkQXLhoYleuLHZD+wfu/apYMKJBKAX6PRsv9PxEj8z+s YS1UC1xTaMTMg6LOGT0WoJ0CH6MSiGY= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-628-y4AustnQO4ythjjHbEWy2g-1; Fri, 05 Apr 2024 13:56:31 -0400 X-MC-Unique: y4AustnQO4ythjjHbEWy2g-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a474ac232e9so148445766b.2 for ; Fri, 05 Apr 2024 10:56:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712339788; x=1712944588; 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=XLa8vNLwTcNK10kOlomnbACyE56ii0YltroaTRkhhaw=; b=xGzHwlO2ChdFvZpb6IBmBPrRVcHk02vSfmIDchRWQHAEyH7pTpaEfZ9pebEWLkvRbD R6EYIlMaYXHG5QRDE2VkKFfR9HvsLTFkibT5asz5DGGWP94awpfDESNZVaO0hLXQNB4P +x14ntww455WtwXeZU68nj+osasLBpB/wNNcB/MUzYMEz4fxLwRB5giDqL6/3vX4iq1J 4hl0rIaLhdQjWlXgvdETYZotTHHNStHwrRxgHo2KrF5TMiqGtWeMwz9NRzw+9u8quNXT DydIb4oIRfEUUvF56hgJfHmpvVbRinxW1uNUK3PD6mazzWL0/dRvl1cIkO54oGrNwlAQ YJ7w== X-Gm-Message-State: AOJu0YyGFuftR/S9aLB3XMhcJR8yJ0XSN9xZRxvZpjDr+pf2VR+1Ow5G atnO05WTaGMcYR7Fg8Nwww20JhVtRxwsKhCMMxgXOpKvU5Bq8QdUAxmGfhrmfBtTfRvIjkPcqTs jLo+cmH3kEzugbmo0N+TX7EtTYGsKr3cW5oYSMpz8b8HFzPBgPAYsjGBbFL4/MYdeTOQvmj8xyQ fWTwPPoO+80ZJ7P/7Isjo4G7FtY03vY3kSQ9k= X-Received: by 2002:a17:906:e088:b0:a51:827d:c99b with SMTP id gh8-20020a170906e08800b00a51827dc99bmr1543209ejb.14.1712339787997; Fri, 05 Apr 2024 10:56:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFarYL4vMDx6Ezfdd4CPvs2izEs0DZBVd1EwKa8b9kAaL0aahKkOolNpPTe/EKjFeL0e0dBCA== X-Received: by 2002:a17:906:e088:b0:a51:827d:c99b with SMTP id gh8-20020a170906e08800b00a51827dc99bmr1543184ejb.14.1712339787373; Fri, 05 Apr 2024 10:56:27 -0700 (PDT) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id va12-20020a17090711cc00b00a4eeb5ff4ddsm1069889ejb.152.2024.04.05.10.56.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Apr 2024 10:56:26 -0700 (PDT) Date: Fri, 5 Apr 2024 19:55:29 +0200 From: Stefano Brivio To: Jon Maloy Subject: Re: [net-next 2/2] tcp: correct handling of extreme menory squeeze Message-ID: <20240405195529.569ca5df@elisabeth> In-Reply-To: <20240403225833.123346-3-jmaloy@redhat.com> References: <20240403225833.123346-1-jmaloy@redhat.com> <20240403225833.123346-3-jmaloy@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.36; 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: K7Q6UEL2ZQKBMT555DHZIC5TWWM56H54 X-Message-ID-Hash: K7Q6UEL2ZQKBMT555DHZIC5TWWM56H54 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 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. -- Stefano