From mboxrd@z Thu Jan 1 00:00:00 1970 From: Willem de Bruijn Subject: [PATCH net] tcp: allow MSG_ZEROCOPY transmission also in CLOSE_WAIT state Date: Thu, 10 Jan 2019 14:40:33 -0500 Message-ID: <20190110194033.92255-1-willemdebruijn.kernel@gmail.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: davem@davemloft.net, edumazet@google.com, Willem de Bruijn , Marek Majkowski , Yuchung Cheng , Neal Cardwell , Soheil Hassas Yeganeh , Alexey Kodanev To: netdev@vger.kernel.org Return-path: Received: from mail-qt1-f194.google.com ([209.85.160.194]:36496 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727653AbfAJTkq (ORCPT ); Thu, 10 Jan 2019 14:40:46 -0500 Received: by mail-qt1-f194.google.com with SMTP id t13so14964510qtn.3 for ; Thu, 10 Jan 2019 11:40:46 -0800 (PST) Sender: netdev-owner@vger.kernel.org List-ID: From: Willem de Bruijn TCP transmission with MSG_ZEROCOPY fails if the peer closes its end of the connection and so transitions this socket to CLOSE_WAIT state. Transmission in close wait state is acceptable. Other similar tests in the stack (e.g., in FastOpen) accept both states. Relax this test, too. Link: https://www.mail-archive.com/netdev@vger.kernel.org/msg276886.html Link: https://www.mail-archive.com/netdev@vger.kernel.org/msg227390.html Fixes: f214f915e7db ("tcp: enable MSG_ZEROCOPY") Reported-by: Marek Majkowski Signed-off-by: Willem de Bruijn CC: Yuchung Cheng CC: Neal Cardwell CC: Soheil Hassas Yeganeh CC: Alexey Kodanev --- This is a narrow fix. Alexey Kodanev suggested a while ago that the entire check might be removed, also opening up more cases for zerocopy with fastopen. For net-next, I will take another look at that and also at adding a tcp_data_sending_states() helper to avoid open coding this test everywhere. --- net/ipv4/tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 27e2f6837062..2079145a3b7c 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1186,7 +1186,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) flags = msg->msg_flags; if (flags & MSG_ZEROCOPY && size && sock_flag(sk, SOCK_ZEROCOPY)) { - if (sk->sk_state != TCP_ESTABLISHED) { + if ((1 << sk->sk_state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) { err = -EINVAL; goto out_err; } -- 2.20.1.97.g81188d93c3-goog