Skip to contentSkip to conversation

tcp: allow MSG_ZEROCOPY transmission also in CLOSE_WAIT state

PATCH In review Willem de Bruijn 4 participants 4 messages Jan 10, 2019 – Jan 16, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcp: allow MSG_ZEROCOPY transmission also in CLOSE_WAIT state

From: Willem de Bruijn <[email protected]>

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.

---

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(-)
net/ipv4/tcp.c +1 -1
index 27e2f6837062..2079145a3b7c 100644
@@ -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;
 		}
Signature · 1 line
2.20.1.97.g81188d93c3-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Willem de Bruijn

From: Willem de Bruijn <[email protected]>

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.

Quoted 9 lines

Thank you for the fix!

Quoted 27 lines

---

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(-)
net/ipv4/tcp.c +1 -2
index 27e2f6837062..2079145a3b7c 100644
@@ -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

Reviewed-by
#2 lore raw
Quoted 21 lines · Soheil Hassas Yeganeh
Quoted 9 lines · Willem de Bruijn

From: Willem de Bruijn <[email protected]>

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.

Quoted 9 lines
Quoted 3 lines

Thank you for the fix!

maintainer
#3 lore raw
In reply to Willem de Bruijn

From: Willem de Bruijn <[email protected]>
Date: Thu, 10 Jan 2019 14:40:33 -0500

Quoted 5 lines

From: Willem de Bruijn <[email protected]>

TCP transmission with MSG_ZEROCOPY fails if the peer closes its end of the connection and so transitions this socket to CLOSE_WAIT state.

Quoted 8 lines

Transmission in close wait state is acceptable. Other similar tests in the stack (e.g., in FastOpen) accept both states. Relax this test, too.

Applied and queued up for -stable.