Skip to content

Commit 71ba088

Browse files
Paolo Abenidavem330
authored andcommitted
mptcp: cleanup accept and poll
After the previous patch, msk->subflow will never be deleted during the whole msk lifetime. We don't need anymore to acquire references to it in mptcp_stream_accept() and we can use the listener subflow accept queue to simplify mptcp_poll() for listener socket. Overall this removes a lock pair and 4 more atomic operations per accept(). Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b29fcfb commit 71ba088

File tree

3 files changed

+7
-20
lines changed

3 files changed

+7
-20
lines changed

net/mptcp/protocol.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3493,17 +3493,9 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
34933493

34943494
pr_debug("msk=%p", msk);
34953495

3496-
lock_sock(sock->sk);
3497-
if (sock->sk->sk_state != TCP_LISTEN)
3498-
goto unlock_fail;
3499-
35003496
ssock = __mptcp_nmpc_socket(msk);
35013497
if (!ssock)
3502-
goto unlock_fail;
3503-
3504-
clear_bit(MPTCP_DATA_READY, &msk->flags);
3505-
sock_hold(ssock->sk);
3506-
release_sock(sock->sk);
3498+
return -EINVAL;
35073499

35083500
err = ssock->ops->accept(sock, newsock, flags, kern);
35093501
if (err == 0 && !mptcp_is_tcpsk(newsock->sk)) {
@@ -3543,14 +3535,7 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
35433535
release_sock(newsk);
35443536
}
35453537

3546-
if (inet_csk_listen_poll(ssock->sk))
3547-
set_bit(MPTCP_DATA_READY, &msk->flags);
3548-
sock_put(ssock->sk);
35493538
return err;
3550-
3551-
unlock_fail:
3552-
release_sock(sock->sk);
3553-
return -EINVAL;
35543539
}
35553540

35563541
static __poll_t mptcp_check_readable(struct mptcp_sock *msk)
@@ -3596,8 +3581,12 @@ static __poll_t mptcp_poll(struct file *file, struct socket *sock,
35963581

35973582
state = inet_sk_state_load(sk);
35983583
pr_debug("msk=%p state=%d flags=%lx", msk, state, msk->flags);
3599-
if (state == TCP_LISTEN)
3600-
return test_bit(MPTCP_DATA_READY, &msk->flags) ? EPOLLIN | EPOLLRDNORM : 0;
3584+
if (state == TCP_LISTEN) {
3585+
if (WARN_ON_ONCE(!msk->subflow || !msk->subflow->sk))
3586+
return 0;
3587+
3588+
return inet_csk_listen_poll(msk->subflow->sk);
3589+
}
36013590

36023591
if (state != TCP_SYN_SENT && state != TCP_SYN_RECV) {
36033592
mask |= mptcp_check_readable(msk);

net/mptcp/protocol.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@
111111
#define MPTCP_RST_TRANSIENT BIT(0)
112112

113113
/* MPTCP socket flags */
114-
#define MPTCP_DATA_READY 0
115114
#define MPTCP_NOSPACE 1
116115
#define MPTCP_WORK_RTX 2
117116
#define MPTCP_WORK_EOF 3

net/mptcp/subflow.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,6 @@ static void subflow_data_ready(struct sock *sk)
12931293
if (reqsk_queue_empty(&inet_csk(sk)->icsk_accept_queue))
12941294
return;
12951295

1296-
set_bit(MPTCP_DATA_READY, &msk->flags);
12971296
parent->sk_data_ready(parent);
12981297
return;
12991298
}

0 commit comments

Comments
 (0)