Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1030961ybe; Wed, 4 Sep 2019 11:25:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqzL4I6tNvQdX5KXgP3Dro5hBhUyNeB0HInEwfsOZLMDIPVu/vfi5I6D6XIaMfXkO5EMsS8k X-Received: by 2002:a65:4507:: with SMTP id n7mr24591231pgq.86.1567621525953; Wed, 04 Sep 2019 11:25:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567621525; cv=none; d=google.com; s=arc-20160816; b=LPe4qHNYSceun7yJatRA0i9xy/qyXBXNQ322/RkwcSTKGmkdyRhtwrTtRVy7xIVW7X MiYze6E1jDUkkdECtx5NXSujBlJksqwkUhYrNzdqqhDrRXFbPWQLbyqGSJuCxIkBHyvB Mh87KfBdjmPd5PA2e9+2qTr7FNLiFFK3TfspzOC0L3BShCCRT2bJemhQoJPmW59WyrQ/ 9jk9nAh7STlWnX9z80oodDudYfz2a/WCrgCJm5spjRHqfUw2e5U6wqT6ao0lO7BSBFs4 rjlNSNFgrXGuaUMM+UpGjKzQ4FNbqnjuea9gvTZud0m2PS3LyhcT66a2UqLRlRwzU9vm 72sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+oAs5WU74ClzjVWvP+/V7k9Mvp3w0e2VrU8ezAgJkjo=; b=hNCNVFiL4YPCan2nHvJFhnehiS9wIjuKabpIgAYXnf0n/kXe9DOTmBeNA+aGKfBXPk zTsZveYWrHhh5kmo6DruegQORQ6+r5PqNVCI8YNNQ96yicX28Rhuu0sa8ZWI2Tk3ki+M mIEpV92hfOVIIcg3k0gwxQVhH7RFdCsY2tibWKUIexzslXIRo8GeANyYZ9c6stMBYvSB 5qslFsDIRgJuWVmFyvKCuyStLYZGUBfhWzD3umUBZYlkEVlSiK8jQkV4NGaOPXEwxWsX 5G/1yFJQM4FjJ9NKIiyac576XQGml0MsknvqCG2NMkgf5T3fkT7oVQRKDSConV7vXtRI boOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NmSzNQyD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 125si15269092pgh.229.2019.09.04.11.25.09; Wed, 04 Sep 2019 11:25:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NmSzNQyD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388868AbfIDSDF (ORCPT + 99 others); Wed, 4 Sep 2019 14:03:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:43332 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388284AbfIDSDD (ORCPT ); Wed, 4 Sep 2019 14:03:03 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DD26523697; Wed, 4 Sep 2019 18:03:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620182; bh=H+dch+YFeYG4YZLYOpmbLkkC1J9RsxRQVN+Y3N93/zE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NmSzNQyDtqVGvNqZYW5PBcJAZWI7fp+WFSZ805mhM5R2/X0WJHQbrW/xiMluwgqpm xVKZVygGYATmDHbKCNA55xV+t6aB5hLGeJH7sDhSsGs1wDSa7cla0xcltZ1F4x4coW aB2SDaY4KeHpGxtGRFXt5WncGNvC1GGD3lYETpJw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Jason Baron , Vladimir Rutsky , Soheil Hassas Yeganeh , Neal Cardwell , "David S. Miller" Subject: [PATCH 4.14 20/57] tcp: make sure EPOLLOUT wont be missed Date: Wed, 4 Sep 2019 19:53:48 +0200 Message-Id: <20190904175303.918854334@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175301.777414715@linuxfoundation.org> References: <20190904175301.777414715@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet [ Upstream commit ef8d8ccdc216f797e66cb4a1372f5c4c285ce1e4 ] As Jason Baron explained in commit 790ba4566c1a ("tcp: set SOCK_NOSPACE under memory pressure"), it is crucial we properly set SOCK_NOSPACE when needed. However, Jason patch had a bug, because the 'nonblocking' status as far as sk_stream_wait_memory() is concerned is governed by MSG_DONTWAIT flag passed at sendmsg() time : long timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT); So it is very possible that tcp sendmsg() calls sk_stream_wait_memory(), and that sk_stream_wait_memory() returns -EAGAIN with SOCK_NOSPACE cleared, if sk->sk_sndtimeo has been set to a small (but not zero) value. This patch removes the 'noblock' variable since we must always set SOCK_NOSPACE if -EAGAIN is returned. It also renames the do_nonblock label since we might reach this code path even if we were in blocking mode. Fixes: 790ba4566c1a ("tcp: set SOCK_NOSPACE under memory pressure") Signed-off-by: Eric Dumazet Cc: Jason Baron Reported-by: Vladimir Rutsky Acked-by: Soheil Hassas Yeganeh Acked-by: Neal Cardwell Acked-by: Jason Baron Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/core/stream.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) --- a/net/core/stream.c +++ b/net/core/stream.c @@ -120,7 +120,6 @@ int sk_stream_wait_memory(struct sock *s int err = 0; long vm_wait = 0; long current_timeo = *timeo_p; - bool noblock = (*timeo_p ? false : true); DEFINE_WAIT_FUNC(wait, woken_wake_function); if (sk_stream_memory_free(sk)) @@ -133,11 +132,8 @@ int sk_stream_wait_memory(struct sock *s if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)) goto do_error; - if (!*timeo_p) { - if (noblock) - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); - goto do_nonblock; - } + if (!*timeo_p) + goto do_eagain; if (signal_pending(current)) goto do_interrupted; sk_clear_bit(SOCKWQ_ASYNC_NOSPACE, sk); @@ -169,7 +165,13 @@ out: do_error: err = -EPIPE; goto out; -do_nonblock: +do_eagain: + /* Make sure that whenever EAGAIN is returned, EPOLLOUT event can + * be generated later. + * When TCP receives ACK packets that make room, tcp_check_space() + * only calls tcp_new_space() if SOCK_NOSPACE is set. + */ + set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); err = -EAGAIN; goto out; do_interrupted: