All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni at redhat.com>
To: mptcp at lists.01.org
Subject: [MPTCP] [PATCH v3 6/7] mptcp: simplify mptcp_nospace
Date: Wed, 18 Nov 2020 19:04:45 +0100	[thread overview]
Message-ID: <f61674a527e842c88b0405cf6e3871fa4ebafcd4.1605718134.git.pabeni@redhat.com> (raw)
In-Reply-To: cover.1605718134.git.pabeni@redhat.com

[-- Attachment #1: Type: text/plain, Size: 3821 bytes --]

Currently mptcp_space has to traverse the whole conn_list
setting the relevant bit on each subflow, because the client
ones will have a different sk_socket.

We can actually leave the NOSPACE always set on all client
subflow and make nospace simpler.

Signed-off-by: Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/protocol.c | 15 +--------------
 net/mptcp/subflow.c  | 31 ++++++++++++++++++++++---------
 2 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 313d488aae15..dacc59d004ad 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1328,23 +1328,9 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 
 static void mptcp_nospace(struct mptcp_sock *msk)
 {
-	struct mptcp_subflow_context *subflow;
-
 	set_bit(MPTCP_NOSPACE, &msk->flags);
 	smp_mb__after_atomic(); /* msk->flags is changed by write_space cb */
 
-	mptcp_for_each_subflow(msk, subflow) {
-		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
-		bool ssk_writeable = sk_stream_is_writeable(ssk);
-		struct socket *sock = READ_ONCE(ssk->sk_socket);
-
-		if (ssk_writeable || !sock)
-			continue;
-
-		/* enables ssk->write_space() callbacks */
-		set_bit(SOCK_NOSPACE, &sock->flags);
-	}
-
 	/* mptcp_data_acked() could run just before we set the NOSPACE bit,
 	 * so explicitly check for snd_una value
 	 */
@@ -3131,6 +3117,7 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
 		slowpath = lock_sock_fast(newsk);
 		mptcp_copy_inaddrs(newsk, msk->first);
 		mptcp_rcv_space_init(msk, msk->first);
+		set_bit(SOCK_NOSPACE, &newsock->flags);
 
 		/* set ssk->sk_socket of accept()ed flows to mptcp socket.
 		 * This is needed so NOSPACE flag can be set from tcp stack.
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 02d757e0ddb7..e53428892122 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -996,19 +996,28 @@ static void subflow_data_ready(struct sock *sk)
 		mptcp_data_ready(parent, sk);
 }
 
-static void subflow_write_space(struct sock *sk)
+static void subflow_write_space(struct sock *ssk)
 {
-	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
-	struct socket *sock = READ_ONCE(sk->sk_socket);
-	struct sock *parent = subflow->conn;
+	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
+	struct sock *sk = subflow->conn;
+	struct socket_wq *wq;
 
-	if (!sk_stream_is_writeable(sk))
+	if (!sk_stream_is_writeable(ssk) || !sk_stream_is_writeable(sk) ||
+	    !sk->sk_socket || !test_bit(MPTCP_NOSPACE, &mptcp_sk(sk)->flags))
 		return;
 
-	if (sock && sk_stream_is_writeable(parent))
-		clear_bit(SOCK_NOSPACE, &sock->flags);
-
-	sk_stream_write_space(parent);
+	/* The following is quite alike sk_stream_write_space, but avoids
+	 * clearing the sk SOCK_NOSPACE bit
+	 */
+	clear_bit(MPTCP_NOSPACE, &mptcp_sk(sk)->flags);
+	rcu_read_lock();
+	wq = rcu_dereference(sk->sk_wq);
+	if (skwq_has_sleeper(wq))
+		wake_up_interruptible_poll(&wq->wait, EPOLLOUT |
+					   EPOLLWRNORM | EPOLLWRBAND);
+	if (wq && wq->fasync_list && !(sk->sk_shutdown & SEND_SHUTDOWN))
+		sock_wake_async(wq, SOCK_WAKE_SPACE, POLL_OUT);
+	rcu_read_unlock();
 }
 
 static struct inet_connection_sock_af_ops *
@@ -1208,6 +1217,10 @@ int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock)
 	SOCK_INODE(sf)->i_uid = SOCK_INODE(sk->sk_socket)->i_uid;
 	SOCK_INODE(sf)->i_gid = SOCK_INODE(sk->sk_socket)->i_gid;
 
+	/* subflows will always call into sk_write_space, and subflow_write_space()
+	 * will be responsible of doing the actual wake-up
+	 */
+	set_bit(SOCK_NOSPACE, &sf->flags);
 	subflow = mptcp_subflow_ctx(sf->sk);
 	pr_debug("subflow=%p", subflow);
 
-- 
2.26.2

                 reply	other threads:[~2020-11-18 18:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f61674a527e842c88b0405cf6e3871fa4ebafcd4.1605718134.git.pabeni@redhat.com \
    --to=unknown@example.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.