Received: by 10.213.65.68 with SMTP id h4csp248311imn; Fri, 23 Mar 2018 03:53:48 -0700 (PDT) X-Google-Smtp-Source: AG47ELtQ8t4tU727Zv9rHhSrTwkTSm+yuNELZnIcjLtuJnVVLln+wTNNReC/2+sfZd+A9GQwAIGq X-Received: by 10.99.123.19 with SMTP id w19mr19931747pgc.405.1521802428299; Fri, 23 Mar 2018 03:53:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521802428; cv=none; d=google.com; s=arc-20160816; b=Q/XWpoxJwhhi9jjxqnYQUMhdslVz8oH4GwR5sz72HVtmR3AC/kAa7NdR3nqsCObe9A Gg5epJGQP21phTqpDkbX6Up4Nk71eXsQN4fcp5Bf/Lxe5PqODH0uTQGVs9KjNGCyqz0i 5znuZnuFyGDiqXt/4laIO6E8zOBNDVoyaLwmrnk3C8gLqDtG58/HNOMqdywrDMvgCGw0 dwXC5Dy6dZYX1Y2JMqRwvrXBIhCq28OILmQi63DF9e/pncQNKYr6poom3z0SUUJxgHOG eU34z6dI86Oz2mc9b3MNtl/2VQF/dHG68YEFGXNC/+ilR75lCzlY8Or9I++mAhANB8JF cSZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=YfYXgSBYn76hOaymaB+2WDBO3U0IdiTiLkz7A7bQd6Q=; b=H4ADBr6Xy4mexArDwa2wo2o7AScwmS3daFopqk8AhaknUI/bJNWDrpa5gUFxO1hNC+ Fc37FuaeOsTNUBPS/cDOKzlEY0XBU6iHQq/VApLaAp7312Jd5BviX1MtglRT79fqF8c5 n/vA50w/7rhDpsqM60uLVnK72AGgt6v3jKoi6nEr54Ux4tMy1xQqWRlUr+OFRmDJzSrf vhJcPTXiORZj2Jw2aJyQkjZn+HbnHVLBC6C0mL8bZIphX9P4dNN21s+U8orJM7kUDJIF iHMUQ8/4ygCs9xNODHeuVhpP6KzN2i8mqqoXhxDzDZL+jzFpR756kTuYSlFHwrVrxEnG BBqQ== ARC-Authentication-Results: i=1; mx.google.com; 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 l25si6423218pff.16.2018.03.23.03.53.33; Fri, 23 Mar 2018 03:53:48 -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; 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 S1755957AbeCWKN7 (ORCPT + 99 others); Fri, 23 Mar 2018 06:13:59 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45014 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755901AbeCWKN4 (ORCPT ); Fri, 23 Mar 2018 06:13:56 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0F6F7122A; Fri, 23 Mar 2018 10:13:55 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Yuchung Cheng , "David S. Miller" , Sasha Levin Subject: [PATCH 4.4 28/97] tcp: remove poll() flakes with FastOpen Date: Fri, 23 Mar 2018 10:54:15 +0100 Message-Id: <20180323094159.200488589@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323094157.535925724@linuxfoundation.org> References: <20180323094157.535925724@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit 0f9fa831aecfc297b7b45d4f046759bcefcf87f0 ] When using TCP FastOpen for an active session, we send one wakeup event from tcp_finish_connect(), right before the data eventually contained in the received SYNACK is queued to sk->sk_receive_queue. This means that depending on machine load or luck, poll() users might receive POLLOUT events instead of POLLIN|POLLOUT To fix this, we need to move the call to sk->sk_state_change() after the (optional) call to tcp_rcv_fastopen_synack() Signed-off-by: Eric Dumazet Acked-by: Yuchung Cheng Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- net/ipv4/tcp_input.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -5464,10 +5464,6 @@ void tcp_finish_connect(struct sock *sk, else tp->pred_flags = 0; - if (!sock_flag(sk, SOCK_DEAD)) { - sk->sk_state_change(sk); - sk_wake_async(sk, SOCK_WAKE_IO, POLL_OUT); - } } static bool tcp_rcv_fastopen_synack(struct sock *sk, struct sk_buff *synack, @@ -5531,6 +5527,7 @@ static int tcp_rcv_synsent_state_process struct tcp_sock *tp = tcp_sk(sk); struct tcp_fastopen_cookie foc = { .len = -1 }; int saved_clamp = tp->rx_opt.mss_clamp; + bool fastopen_fail; tcp_parse_options(skb, &tp->rx_opt, 0, &foc); if (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr) @@ -5633,10 +5630,15 @@ static int tcp_rcv_synsent_state_process tcp_finish_connect(sk, skb); - if ((tp->syn_fastopen || tp->syn_data) && - tcp_rcv_fastopen_synack(sk, skb, &foc)) - return -1; + fastopen_fail = (tp->syn_fastopen || tp->syn_data) && + tcp_rcv_fastopen_synack(sk, skb, &foc); + if (!sock_flag(sk, SOCK_DEAD)) { + sk->sk_state_change(sk); + sk_wake_async(sk, SOCK_WAKE_IO, POLL_OUT); + } + if (fastopen_fail) + return -1; if (sk->sk_write_pending || icsk->icsk_accept_queue.rskq_defer_accept || icsk->icsk_ack.pingpong) {