Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1019702ybe; Wed, 4 Sep 2019 11:14:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwRuEx6guiE/KCZf/rtaj3zMRqNOd1MlD1I/8CauPSshBxCSP68+rDRUEofOFk2x/YXJUoL X-Received: by 2002:a62:87c8:: with SMTP id i191mr47786649pfe.133.1567620861060; Wed, 04 Sep 2019 11:14:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620861; cv=none; d=google.com; s=arc-20160816; b=I1JUbOASTL7gughvjohnyi893EGkoCDXIpuIGqUK2Y/IECzmK1ltqP4nF41+lmHdlw 8gnAv1jZujH24GtQOcZPW66DJszEPtpu9k4npbLgorKpi4g1fFcew473M9tfM06pnDO9 MqrYBxNjxfMIOgxIb1PA1qbk3sLkFtNDeSzPWTWY5yqQS73158j2elmdEFh0yQSGQ6bD dPDEH/deWB3ffzpciTl/iGR9mhQ1+IlfjiXEO9ytTx3+wvfkumgBF18yOdzvLEuXNfRu ZlZ8Fvuiyfbf3kY6kHNLF5Ezy6njZRc/aB4olOaTssSDCH91SmcTzNIenGrkAam22Rkd g7yQ== 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=z5OZT1W7hm9SrioSDIuWQSHw2TTpGj2rOCXJAorEz6KnvSAk5GDEVCDY+BF9oo/gtS 6Sz3ecoK405gjAxi+mH7rFluiRszhOQrq7lzhSDvT6W4xA2p9Ey2DL+htxdwrjW1pZ4X nnFvx7zrgfKCnfLftm+HzpYd2GkDPNmI79wtZcR7WGFbJxVaD/52EkZM+gLIgv7YtgKl dEbPiCHqfwqEclenvZzUjR/vwc6X4q0RW9iwOx7UqkDfV1K8Uvwl6oz2PE2QYygMsLBU +9q838mEIPlH6blf1e7OYOmhBRJKaCbUSjrtvWtIMDpfUAuUFuJtXhllVddNABXrsw97 Z4Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=n6uapoh5; 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 k142si21246530pfd.217.2019.09.04.11.14.06; Wed, 04 Sep 2019 11:14:21 -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=n6uapoh5; 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 S2389911AbfIDSL3 (ORCPT + 99 others); Wed, 4 Sep 2019 14:11:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:55446 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390274AbfIDSLY (ORCPT ); Wed, 4 Sep 2019 14:11:24 -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 3F999206BA; Wed, 4 Sep 2019 18:11:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620683; bh=H+dch+YFeYG4YZLYOpmbLkkC1J9RsxRQVN+Y3N93/zE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n6uapoh509eTn9a0CtT9aEe1z/+qRr0oh2nlaeIPAc3C3G9KeyI3Sr9+PxBws0Uj2 fT4nyAX84bavwIY9jFriFWZ4S/VOPZhuTyS2/eekjRZxmR9VSLI1eE5z6EHRVnIAYX eCSiVGQ2xyW0uOEath5nRtynNp5LZMb6P4CuNkes= 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 5.2 054/143] tcp: make sure EPOLLOUT wont be missed Date: Wed, 4 Sep 2019 19:53:17 +0200 Message-Id: <20190904175316.182242667@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@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: