From patchwork Wed Mar 6 18:01:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soheil Hassas Yeganeh X-Patchwork-Id: 1052432 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="AEBWjZHB"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44F1mX38n3z9ryj for ; Thu, 7 Mar 2019 05:01:47 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727221AbfCFSBp (ORCPT ); Wed, 6 Mar 2019 13:01:45 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:33323 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726275AbfCFSBp (ORCPT ); Wed, 6 Mar 2019 13:01:45 -0500 Received: by mail-qk1-f194.google.com with SMTP id x9so7357824qkf.0 for ; Wed, 06 Mar 2019 10:01:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=z1nBaOxlYJ17qxhrGFby034+O5wbgBH53Csp7fM4nm8=; b=AEBWjZHBMMDWGsLmZ3E3YNhwG0Alu52dEZqDtAlxcte529vSggMEZdMXspxAScjBFK lVfgoVS9msp2kdbjhCu8PrJLuwTGojpdrlVsvm2I8//TCm7nBg7kFOeQBkyV7fJSS+kh +DTeQEo30zfSBuXNnE4WeKRCJBlaS2FdyF//29TFNDT4X6h2+L/XCKSlMzefRn+1IMrb TeVFATGZPB7tK3TJq1LlEq+CM6v/L/sGBivBQMWFSaYZUasQ15WOIBCMOql/HHTekHZX sQOdNTni4Wh2/lQ1uHdDUVo3wU9oAa+e3OjVmTk/fkmxDXTnF/9AbPTXu5UlQ6cOxlGJ 2xGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=z1nBaOxlYJ17qxhrGFby034+O5wbgBH53Csp7fM4nm8=; b=LLweTUJO/gC1/cgczUPDCa1i9bQl+9Lk7C0HLRNflnBITDSO1xoUxT8f21TWksC85B jPhisRs+owAn7F8mA+x5whyRJFYTZmfqOUdnQQRIFCu7DU7Un8aZkS9h283cM2LejLpd ITuR6kUkgXSqP1huuEGMDY9ITLI6LAc7g2dTrHcqgUiU6u2KzQQXS/90elJUdxisLWDT m5S1AV8ETVZOPY2RRrzvZmRctWqXSSMUo++OcUSA2ve0us+e8+vDMr3mduz9t73pPB0d UdoM7QJ01CIWH4mRgU1qqexgtVoEvEO1RViBERDu4CNsXtx2G2UH0grgIUVTqxdYFqqu PQkA== X-Gm-Message-State: APjAAAWXB6s96vO5iHiF9QoykpmC9AmCwlZ9RlIdzsTP2jhPd4gghxza 2vQ3kxcjYivByDUyxD0QrbI= X-Google-Smtp-Source: APXvYqxNqiVLKKqJUFmDthdjtCJaOvlK/+VOQUhi74tuAFf762XnRwrt7cEE1hPOFMZfuCbykZnxrg== X-Received: by 2002:ae9:f809:: with SMTP id x9mr6733380qkh.84.1551895304247; Wed, 06 Mar 2019 10:01:44 -0800 (PST) Received: from soheil24.nyc.corp.google.com ([2620:0:1003:315:d7ab:1a20:d24a:a109]) by smtp.gmail.com with ESMTPSA id c19sm1220664qkg.88.2019.03.06.10.01.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Mar 2019 10:01:43 -0800 (PST) From: Soheil Hassas Yeganeh To: davem@davemloft.net, netdev@vger.kernel.org Cc: edumazet@google.com, ycheng@google.com, ncardwell@google.com, Soheil Hassas Yeganeh Subject: [PATCH net] tcp: do not report TCP_CM_INQ of 0 for closed connections Date: Wed, 6 Mar 2019 13:01:36 -0500 Message-Id: <20190306180136.68112-1-soheil.kdev@gmail.com> X-Mailer: git-send-email 2.21.0.352.gf09ad66450-goog MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Soheil Hassas Yeganeh Returning 0 as inq to userspace indicates there is no more data to read, and the application needs to wait for EPOLLIN. For a connection that has received FIN from the remote peer, however, the application must continue reading until getting EOF (return value of 0 from tcp_recvmsg) or an error, if edge-triggered epoll (EPOLLET) is being used. Otherwise, the application will never receive a new EPOLLIN, since there is no epoll edge after the FIN. Return 1 when there is no data left on the queue but the connection has received FIN, so that the applications continue reading. Fixes: b75eba76d3d72 (tcp: send in-queue bytes in cmsg upon read) Signed-off-by: Soheil Hassas Yeganeh Acked-by: Neal Cardwell Signed-off-by: Eric Dumazet Acked-by: Yuchung Cheng --- net/ipv4/tcp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index ad07dd71063da..8b25017e0dc93 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1933,6 +1933,11 @@ static int tcp_inq_hint(struct sock *sk) inq = tp->rcv_nxt - tp->copied_seq; release_sock(sk); } + /* After receiving a FIN, tell the user-space to continue reading + * by returning a non-zero inq. + */ + if (inq == 0 && sock_flag(sk, SOCK_DONE)) + inq = 1; return inq; }