Skip to contentSkip to conversation

mptcp: store remote token in mptcp sock

PATCH In review Jianguo Wu 3 participants 7 messages Apr 20, 2021 – Apr 22, 2021

Subsystems (2)
lore
Share & tools
lore

Jianguo Wu

author
#0 lore raw

PATCH 1/1 mptcp: store remote token in mptcp sock

From: Jianguo Wu <[email protected]>

Now every time create a new subflow, it needs to generate remote token in __mptcp_subflow_connect(), the remote token is the same among all subflows in a mptcp connection, so we can store remote token in mptcp sock.

---
 net/mptcp/protocol.c | 5 +++--
 net/mptcp/protocol.h | 1 +
 net/mptcp/subflow.c  | 7 +++----
 3 files changed, 7 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +3 -2
index a8180a9..607fb30 100644
@@ -2736,7 +2736,7 @@ struct sock *mptcp_sk_clone(const struct sock *sk,
 	if (mp_opt->mp_capable) {
 		msk->can_ack = true;
 		msk->remote_key = mp_opt->sndr_key;
-		mptcp_crypto_key_sha(msk->remote_key, NULL, &ack_seq);
+		mptcp_crypto_key_sha(msk->remote_key, &msk->remote_token, &ack_seq);
 		ack_seq++;
 		WRITE_ONCE(msk->ack_seq, ack_seq);
 		WRITE_ONCE(msk->rcv_wnd_sent, ack_seq);
@@ -2967,7 +2967,7 @@ void mptcp_finish_connect(struct sock *ssk)
 
 	pr_debug("msk=%p, token=%u", sk, subflow->token);
 
-	mptcp_crypto_key_sha(subflow->remote_key, NULL, &ack_seq);
+	mptcp_crypto_key_sha(subflow->remote_key, &subflow->remote_token, &ack_seq);
 	ack_seq++;
 	subflow->map_seq = ack_seq;
 	subflow->map_subflow_seq = 1;
@@ -2976,6 +2976,7 @@ void mptcp_finish_connect(struct sock *ssk)
 	 * accessing the field below
 	 */
 	WRITE_ONCE(msk->remote_key, subflow->remote_key);
+	WRITE_ONCE(msk->remote_token, subflow->remote_token);
 	WRITE_ONCE(msk->local_key, subflow->local_key);
 	WRITE_ONCE(msk->write_seq, subflow->idsn + 1);
 	WRITE_ONCE(msk->snd_nxt, msk->write_seq);
net/mptcp/protocol.h +1 -0
index edc0128..abd8e31 100644
@@ -226,6 +226,7 @@ struct mptcp_sock {
 	u64		wnd_end;
 	unsigned long	timer_ival;
 	u32		token;
+	u32		remote_token;
 	int		rmem_released;
 	unsigned long	flags;
 	bool		can_ack;
net/mptcp/subflow.c +3 -4
index 82e91b0..ddd8c03 100644
@@ -1046,6 +1046,7 @@ static bool subflow_check_data_avail(struct sock *ssk)
 				goto fatal;
 			}
 			WRITE_ONCE(msk->remote_key, subflow->remote_key);
+			mptcp_crypto_key_sha(READ_ONCE(msk->remote_key), &msk->remote_token, NULL);
 			WRITE_ONCE(msk->ack_seq, subflow->map_seq);
 			WRITE_ONCE(msk->can_ack, true);
 		}
@@ -1268,7 +1269,6 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
 	int local_id = loc->id;
 	struct socket *sf;
 	struct sock *ssk;
-	u32 remote_token;
 	int addrlen;
 	int err;
 
@@ -1308,10 +1308,9 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
 	if (err)
 		goto failed;
 
-	mptcp_crypto_key_sha(subflow->remote_key, &remote_token, NULL);
 	pr_debug("msk=%p remote_token=%u local_id=%d remote_id=%d", msk,
-		 remote_token, local_id, remote_id);
-	subflow->remote_token = remote_token;
+		 msk->remote_token, local_id, remote_id);
+	subflow->remote_token = msk->remote_token;
 	subflow->local_id = local_id;
 	subflow->remote_id = remote_id;
 	subflow->request_join = 1;
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 61 lines · Jianguo Wu

From: Jianguo Wu <[email protected]>

Now every time create a new subflow, it needs to generate remote token in __mptcp_subflow_connect(), the remote token is the same among all subflows in a mptcp connection, so we can store remote token in mptcp sock.

---

net/mptcp/protocol.c | 5 +++--
net/mptcp/protocol.h | 1 +
net/mptcp/subflow.c  | 7 +++----
3 files changed, 7 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +3 -2
index a8180a9..607fb30 100644
@@ -2736,7 +2736,7 @@ struct sock *mptcp_sk_clone(const struct sock *sk,
 	if (mp_opt->mp_capable) {
 		msk->can_ack = true;
 		msk->remote_key = mp_opt->sndr_key;
-		mptcp_crypto_key_sha(msk->remote_key, NULL, &ack_seq);
+		mptcp_crypto_key_sha(msk->remote_key, &msk->remote_token, &ack_seq);
 		ack_seq++;
 		WRITE_ONCE(msk->ack_seq, ack_seq);
 		WRITE_ONCE(msk->rcv_wnd_sent, ack_seq);
@@ -2967,7 +2967,7 @@ void mptcp_finish_connect(struct sock *ssk)
 
 	pr_debug("msk=%p, token=%u", sk, subflow->token);
 
-	mptcp_crypto_key_sha(subflow->remote_key, NULL, &ack_seq);
+	mptcp_crypto_key_sha(subflow->remote_key, &subflow->remote_token, &ack_seq);
 	ack_seq++;
 	subflow->map_seq = ack_seq;
 	subflow->map_subflow_seq = 1;
@@ -2976,6 +2976,7 @@ void mptcp_finish_connect(struct sock *ssk)
 	 * accessing the field below
 	 */
 	WRITE_ONCE(msk->remote_key, subflow->remote_key);
+	WRITE_ONCE(msk->remote_token, subflow->remote_token);
 	WRITE_ONCE(msk->local_key, subflow->local_key);
 	WRITE_ONCE(msk->write_seq, subflow->idsn + 1);
 	WRITE_ONCE(msk->snd_nxt, msk->write_seq);
net/mptcp/protocol.h +1 -0
index edc0128..abd8e31 100644
@@ -226,6 +226,7 @@ struct mptcp_sock {
 	u64		wnd_end;
 	unsigned long	timer_ival;
 	u32		token;
+	u32		remote_token;
 	int		rmem_released;
 	unsigned long	flags;
 	bool		can_ack;
net/mptcp/subflow.c +0 -0
index 82e91b0..ddd8c03 100644

net/mptcp/subflow.c static bool subflow_check_data_avail(struct sock *ssk) · line 1049

Quoted 4 lines
net/mptcp/subflow.c +1 -0
@@ -1046,6 +1046,7 @@ static bool subflow_check_data_avail(struct sock *ssk)
 				goto fatal;
 			}
 			WRITE_ONCE(msk->remote_key, subflow->remote_key);
+			mptcp_crypto_key_sha(READ_ONCE(msk->remote_key), &msk->remote_token, NULL);

Hi Jianguo, thanks for your patch.

This adds a possible extra SHA calculation in this function, on the server side of a connection that may not ever use the token. This code path is only encountered in rare conditions, though: when an MP_CAPABLE+data packet is late, retransmitted, or out-of-order.

(also, if we move ahead with this patch, the token should be written to a local variable and then copied to msk->remote_token using WRITE_ONCE(). Would also be more efficient to pass subflow->remote_key as the first arg because there's no READ_ONCE() required to read from the subflow structure)

Quoted 12 lines
net/mptcp/subflow.c +0 -1
 			WRITE_ONCE(msk->ack_seq, subflow->map_seq);
 			WRITE_ONCE(msk->can_ack, true);
 		}
@@ -1268,7 +1269,6 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
 	int local_id = loc->id;
 	struct socket *sf;
 	struct sock *ssk;
-	u32 remote_token;
 	int addrlen;
 	int err;
 

net/mptcp/subflow.c int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, · line 1313

Quoted 9 lines
net/mptcp/subflow.c +2 -3
@@ -1308,10 +1308,9 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
 	if (err)
 		goto failed;
 
-	mptcp_crypto_key_sha(subflow->remote_key, &remote_token, NULL);
 	pr_debug("msk=%p remote_token=%u local_id=%d remote_id=%d", msk,
-		 remote_token, local_id, remote_id);
-	subflow->remote_token = remote_token;
+		 msk->remote_token, local_id, remote_id);
+	subflow->remote_token = msk->remote_token;

And here, I think, is the tradeoff: with this patch, there is no need to recalculate the SHA on every outgoing join. That's more common on the client side of a connection, where there will not be a large number of joins initiated so the cost is not very high.

Given the client/server tradeoff and the likely small number of joins on any given connection, do you think this is worth changing?

Quoted 7 lines
net/mptcp/subflow.c +0 -0
 	subflow->local_id = local_id;
 	subflow->remote_id = remote_id;
 	subflow->request_join = 1;
Signature · 1 line
1.8.3.1

--
Mat Martineau
Intel

author
#2 lore raw
Quoted 98 lines · Mat Martineau
Quoted 61 lines · Jianguo Wu

From: Jianguo Wu <[email protected]>

Now every time create a new subflow, it needs to generate remote token in __mptcp_subflow_connect(), the remote token is the same among all subflows in a mptcp connection, so we can store remote token in mptcp sock.

---
net/mptcp/protocol.c | 5 +++--
net/mptcp/protocol.h | 1 +
net/mptcp/subflow.c  | 7 +++----

3 files changed, 7 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +3 -2
index a8180a9..607fb30 100644
@@ -2736,7 +2736,7 @@ struct sock *mptcp_sk_clone(const struct sock *sk,
     if (mp_opt->mp_capable) {
         msk->can_ack = true;
         msk->remote_key = mp_opt->sndr_key;
-        mptcp_crypto_key_sha(msk->remote_key, NULL, &ack_seq);
+        mptcp_crypto_key_sha(msk->remote_key, &msk->remote_token, &ack_seq);
         ack_seq++;
         WRITE_ONCE(msk->ack_seq, ack_seq);
         WRITE_ONCE(msk->rcv_wnd_sent, ack_seq);
@@ -2967,7 +2967,7 @@ void mptcp_finish_connect(struct sock *ssk)
 
     pr_debug("msk=%p, token=%u", sk, subflow->token);
 
-    mptcp_crypto_key_sha(subflow->remote_key, NULL, &ack_seq);
+    mptcp_crypto_key_sha(subflow->remote_key, &subflow->remote_token, &ack_seq);
     ack_seq++;
     subflow->map_seq = ack_seq;
     subflow->map_subflow_seq = 1;
@@ -2976,6 +2976,7 @@ void mptcp_finish_connect(struct sock *ssk)
      * accessing the field below
      */
     WRITE_ONCE(msk->remote_key, subflow->remote_key);
+    WRITE_ONCE(msk->remote_token, subflow->remote_token);
     WRITE_ONCE(msk->local_key, subflow->local_key);
     WRITE_ONCE(msk->write_seq, subflow->idsn + 1);
     WRITE_ONCE(msk->snd_nxt, msk->write_seq);
net/mptcp/protocol.h +1 -0
index edc0128..abd8e31 100644
@@ -226,6 +226,7 @@ struct mptcp_sock {
     u64        wnd_end;
     unsigned long    timer_ival;
     u32        token;
+    u32        remote_token;
     int        rmem_released;
     unsigned long    flags;
     bool        can_ack;
net/mptcp/subflow.c +0 -0
index 82e91b0..ddd8c03 100644

net/mptcp/subflow.c static bool subflow_check_data_avail(struct sock *ssk) · line 1049

Quoted 4 lines
net/mptcp/subflow.c +1 -0
@@ -1046,6 +1046,7 @@ static bool subflow_check_data_avail(struct sock *ssk)
                 goto fatal;
             }
             WRITE_ONCE(msk->remote_key, subflow->remote_key);
+            mptcp_crypto_key_sha(READ_ONCE(msk->remote_key), &msk->remote_token, NULL);

Hi Jianguo, thanks for your patch.

This adds a possible extra SHA calculation in this function, on the server side of a connection that may not ever use the token. This code path is only encountered in rare conditions, though: when an MP_CAPABLE+data packet is late, retransmitted, or out-of-order.

(also, if we move ahead with this patch, the token should be written to a local variable and then copied to msk->remote_token using WRITE_ONCE(). Would also be more efficient to pass subflow->remote_key as the first arg because there's no READ_ONCE() required to read from the subflow structure)

Quoted 12 lines
net/mptcp/subflow.c +0 -1
             WRITE_ONCE(msk->ack_seq, subflow->map_seq);
             WRITE_ONCE(msk->can_ack, true);
         }
@@ -1268,7 +1269,6 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
     int local_id = loc->id;
     struct socket *sf;
     struct sock *ssk;
-    u32 remote_token;
     int addrlen;
     int err;
 

net/mptcp/subflow.c int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, · line 1313

Quoted 9 lines
net/mptcp/subflow.c +2 -3
@@ -1308,10 +1308,9 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
     if (err)
         goto failed;
 
-    mptcp_crypto_key_sha(subflow->remote_key, &remote_token, NULL);
     pr_debug("msk=%p remote_token=%u local_id=%d remote_id=%d", msk,
-         remote_token, local_id, remote_id);
-    subflow->remote_token = remote_token;
+         msk->remote_token, local_id, remote_id);
+    subflow->remote_token = msk->remote_token;

And here, I think, is the tradeoff: with this patch, there is no need to recalculate the SHA on every outgoing join. That's more common on the client side of a connection, where there will not be a large number of joins initiated so the cost is not very high.

Quoted 1 line

Given the client/server tradeoff and the likely small number of joins on any given connection, do you think this is worth changing?

Hi Mat, thanks for your comments!

I think, with high CPS, it can reduce lots of recalculation, and in some scenarios, such as the middle mile, server side can also initiate join subflows, maybe we can generate the token on the first outgoing join and store in msk->remote_token, then the following outgoing joins can reuse msk->remote_token?

Quoted 12 lines
Quoted 8 lines
net/mptcp/subflow.c +0 -0
     subflow->local_id = local_id;
     subflow->remote_id = remote_id;
     subflow->request_join = 1;

--
1.8.3.1

Signature · 2 lines
Mat Martineau
Intel
maintainer
#3 lore raw
Quoted 99 lines · Jianguo Wu
Quoted 98 lines · Mat Martineau
Quoted 61 lines · Jianguo Wu

From: Jianguo Wu <[email protected]>

Now every time create a new subflow, it needs to generate remote token in __mptcp_subflow_connect(), the remote token is the same among all subflows in a mptcp connection, so we can store remote token in mptcp sock.

---

net/mptcp/protocol.c | 5 +++--
net/mptcp/protocol.h | 1 +
net/mptcp/subflow.c  | 7 +++----
3 files changed, 7 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +3 -2
index a8180a9..607fb30 100644
@@ -2736,7 +2736,7 @@ struct sock *mptcp_sk_clone(const struct sock *sk,
    if (mp_opt->mp_capable) {
        msk->can_ack = true;
        msk->remote_key = mp_opt->sndr_key;
-        mptcp_crypto_key_sha(msk->remote_key, NULL, &ack_seq);
+        mptcp_crypto_key_sha(msk->remote_key, &msk->remote_token, &ack_seq);
        ack_seq++;
        WRITE_ONCE(msk->ack_seq, ack_seq);
        WRITE_ONCE(msk->rcv_wnd_sent, ack_seq);
@@ -2967,7 +2967,7 @@ void mptcp_finish_connect(struct sock *ssk)
 
    pr_debug("msk=%p, token=%u", sk, subflow->token);
 
-    mptcp_crypto_key_sha(subflow->remote_key, NULL, &ack_seq);
+    mptcp_crypto_key_sha(subflow->remote_key, &subflow->remote_token, &ack_seq);
    ack_seq++;
    subflow->map_seq = ack_seq;
    subflow->map_subflow_seq = 1;
@@ -2976,6 +2976,7 @@ void mptcp_finish_connect(struct sock *ssk)
     * accessing the field below
     */
    WRITE_ONCE(msk->remote_key, subflow->remote_key);
+    WRITE_ONCE(msk->remote_token, subflow->remote_token);
    WRITE_ONCE(msk->local_key, subflow->local_key);
    WRITE_ONCE(msk->write_seq, subflow->idsn + 1);
    WRITE_ONCE(msk->snd_nxt, msk->write_seq);
net/mptcp/protocol.h +1 -0
index edc0128..abd8e31 100644
@@ -226,6 +226,7 @@ struct mptcp_sock {
    u64        wnd_end;
    unsigned long    timer_ival;
    u32        token;
+    u32        remote_token;
    int        rmem_released;
    unsigned long    flags;
    bool        can_ack;
net/mptcp/subflow.c +0 -0
index 82e91b0..ddd8c03 100644

net/mptcp/subflow.c static bool subflow_check_data_avail(struct sock *ssk) · line 1049

Quoted 4 lines
net/mptcp/subflow.c +1 -0
@@ -1046,6 +1046,7 @@ static bool subflow_check_data_avail(struct sock *ssk)
                goto fatal;
            }
            WRITE_ONCE(msk->remote_key, subflow->remote_key);
+            mptcp_crypto_key_sha(READ_ONCE(msk->remote_key), &msk->remote_token, NULL);

Hi Jianguo, thanks for your patch.

This adds a possible extra SHA calculation in this function, on the server side of a connection that may not ever use the token. This code path is only encountered in rare conditions, though: when an MP_CAPABLE+data packet is late, retransmitted, or out-of-order.

(also, if we move ahead with this patch, the token should be written to a local variable and then copied to msk->remote_token using WRITE_ONCE(). Would also be more efficient to pass subflow->remote_key as the first arg because there's no READ_ONCE() required to read from the subflow structure)

Quoted 12 lines
net/mptcp/subflow.c +0 -1
            WRITE_ONCE(msk->ack_seq, subflow->map_seq);
            WRITE_ONCE(msk->can_ack, true);
        }
@@ -1268,7 +1269,6 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
    int local_id = loc->id;
    struct socket *sf;
    struct sock *ssk;
-    u32 remote_token;
    int addrlen;
    int err;
 

net/mptcp/subflow.c int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, · line 1313

Quoted 9 lines
net/mptcp/subflow.c +2 -3
@@ -1308,10 +1308,9 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
    if (err)
        goto failed;
 
-    mptcp_crypto_key_sha(subflow->remote_key, &remote_token, NULL);
    pr_debug("msk=%p remote_token=%u local_id=%d remote_id=%d", msk,
-         remote_token, local_id, remote_id);
-    subflow->remote_token = remote_token;
+         msk->remote_token, local_id, remote_id);
+    subflow->remote_token = msk->remote_token;

And here, I think, is the tradeoff: with this patch, there is no need to recalculate the SHA on every outgoing join. That's more common on the client side of a connection, where there will not be a large number of joins initiated so the cost is not very high.

Quoted 7 lines
Quoted 1 line

Given the client/server tradeoff and the likely small number of joins on any given connection, do you think this is worth changing?

Hi Mat, thanks for your comments!

I think, with high CPS, it can reduce lots of recalculation, and in some scenarios, such as the middle mile, server side can also initiate join subflows,

Uhmm... In the connections/rate performance test I did, the crypto- related overhead was quite low, almost un-noticeable. Do you have any perf figures for the above scenario (e.g. perf report or flamegraph)?

Additionally, could you please describe the usage scenario with more details? Is that a transparent TCP-MPTCP proxy? or what else?

Quoted 3 lines

maybe we can generate the token on the first outgoing join and store in msk->remote_token, then the following outgoing joins can reuse msk->remote_token?

How many subflows do you expect for each MPTCP connections? the above will provide no gain with the typical 2-subflows use-case.

Thanks!

Paolo

author
#4 lore raw
Quoted 104 lines · Paolo Abeni
Quoted 103 lines · Jianguo Wu
Quoted 98 lines · Mat Martineau
Quoted 61 lines · Jianguo Wu

From: Jianguo Wu <[email protected]>

Now every time create a new subflow, it needs to generate remote token in __mptcp_subflow_connect(), the remote token is the same among all subflows in a mptcp connection, so we can store remote token in mptcp sock.

---

net/mptcp/protocol.c | 5 +++--
net/mptcp/protocol.h | 1 +
net/mptcp/subflow.c  | 7 +++----
3 files changed, 7 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +3 -2
index a8180a9..607fb30 100644
@@ -2736,7 +2736,7 @@ struct sock *mptcp_sk_clone(const struct sock *sk,
    if (mp_opt->mp_capable) {
        msk->can_ack = true;
        msk->remote_key = mp_opt->sndr_key;
-        mptcp_crypto_key_sha(msk->remote_key, NULL, &ack_seq);
+        mptcp_crypto_key_sha(msk->remote_key, &msk->remote_token, &ack_seq);
        ack_seq++;
        WRITE_ONCE(msk->ack_seq, ack_seq);
        WRITE_ONCE(msk->rcv_wnd_sent, ack_seq);
@@ -2967,7 +2967,7 @@ void mptcp_finish_connect(struct sock *ssk)
 
    pr_debug("msk=%p, token=%u", sk, subflow->token);
 
-    mptcp_crypto_key_sha(subflow->remote_key, NULL, &ack_seq);
+    mptcp_crypto_key_sha(subflow->remote_key, &subflow->remote_token, &ack_seq);
    ack_seq++;
    subflow->map_seq = ack_seq;
    subflow->map_subflow_seq = 1;
@@ -2976,6 +2976,7 @@ void mptcp_finish_connect(struct sock *ssk)
     * accessing the field below
     */
    WRITE_ONCE(msk->remote_key, subflow->remote_key);
+    WRITE_ONCE(msk->remote_token, subflow->remote_token);
    WRITE_ONCE(msk->local_key, subflow->local_key);
    WRITE_ONCE(msk->write_seq, subflow->idsn + 1);
    WRITE_ONCE(msk->snd_nxt, msk->write_seq);
net/mptcp/protocol.h +1 -0
index edc0128..abd8e31 100644
@@ -226,6 +226,7 @@ struct mptcp_sock {
    u64        wnd_end;
    unsigned long    timer_ival;
    u32        token;
+    u32        remote_token;
    int        rmem_released;
    unsigned long    flags;
    bool        can_ack;
net/mptcp/subflow.c +0 -0
index 82e91b0..ddd8c03 100644

net/mptcp/subflow.c static bool subflow_check_data_avail(struct sock *ssk) · line 1049

Quoted 4 lines
net/mptcp/subflow.c +1 -0
@@ -1046,6 +1046,7 @@ static bool subflow_check_data_avail(struct sock *ssk)
                goto fatal;
            }
            WRITE_ONCE(msk->remote_key, subflow->remote_key);
+            mptcp_crypto_key_sha(READ_ONCE(msk->remote_key), &msk->remote_token, NULL);

Hi Jianguo, thanks for your patch.

This adds a possible extra SHA calculation in this function, on the server side of a connection that may not ever use the token. This code path is only encountered in rare conditions, though: when an MP_CAPABLE+data packet is late, retransmitted, or out-of-order.

(also, if we move ahead with this patch, the token should be written to a local variable and then copied to msk->remote_token using WRITE_ONCE(). Would also be more efficient to pass subflow->remote_key as the first arg because there's no READ_ONCE() required to read from the subflow structure)

Quoted 12 lines
net/mptcp/subflow.c +0 -1
            WRITE_ONCE(msk->ack_seq, subflow->map_seq);
            WRITE_ONCE(msk->can_ack, true);
        }
@@ -1268,7 +1269,6 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
    int local_id = loc->id;
    struct socket *sf;
    struct sock *ssk;
-    u32 remote_token;
    int addrlen;
    int err;
 

net/mptcp/subflow.c int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, · line 1313

Quoted 9 lines
net/mptcp/subflow.c +2 -3
@@ -1308,10 +1308,9 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
    if (err)
        goto failed;
 
-    mptcp_crypto_key_sha(subflow->remote_key, &remote_token, NULL);
    pr_debug("msk=%p remote_token=%u local_id=%d remote_id=%d", msk,
-         remote_token, local_id, remote_id);
-    subflow->remote_token = remote_token;
+         msk->remote_token, local_id, remote_id);
+    subflow->remote_token = msk->remote_token;

And here, I think, is the tradeoff: with this patch, there is no need to recalculate the SHA on every outgoing join. That's more common on the client side of a connection, where there will not be a large number of joins initiated so the cost is not very high.

Quoted 1 line

Given the client/server tradeoff and the likely small number of joins on any given connection, do you think this is worth changing?

Hi Mat, thanks for your comments!

Quoted 8 lines
Quoted 3 lines

I think, with high CPS, it can reduce lots of recalculation, and in some scenarios, such as the middle mile, server side can also initiate join subflows,

Uhmm... In the connections/rate performance test I did, the crypto- related overhead was quite low, almost un-noticeable. Do you have any perf figures for the above scenario (e.g. perf report or flamegraph)?

Sorry, I haven't do performance test.

Quoted 3 lines

Additionally, could you please describe the usage scenario with more details? Is that a transparent TCP-MPTCP proxy? or what else?

In CDN, we may use MPTCP between CDN nodes, which clients are not be behind NAT.

Quoted 5 lines
Quoted 3 lines

maybe we can generate the token on the first outgoing join and store in msk->remote_token, then the following outgoing joins can reuse msk->remote_token?

How many subflows do you expect for each MPTCP connections? the above

typically, 2-subflows

Quoted 2 lines

will provide no gain with the typical 2-subflows use-case.

yes, no gain with 2-subflows, but also no regression, and it is beneficial when more than 2-subflows, I am not sure whether it is worth to use the extra 32-bit memory for this trade-off?

Thansk!

Quoted 4 lines

Thanks!

Paolo

maintainer
#5 lore raw
Quoted 110 lines · Jianguo Wu
Quoted 108 lines · Paolo Abeni
Quoted 106 lines · Jianguo Wu
Quoted 98 lines · Mat Martineau
Quoted 61 lines · Jianguo Wu

From: Jianguo Wu <[email protected]>

Now every time create a new subflow, it needs to generate remote token in __mptcp_subflow_connect(), the remote token is the same among all subflows in a mptcp connection, so we can store remote token in mptcp sock.

---

net/mptcp/protocol.c | 5 +++--
net/mptcp/protocol.h | 1 +
net/mptcp/subflow.c  | 7 +++----
3 files changed, 7 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +3 -2
index a8180a9..607fb30 100644
@@ -2736,7 +2736,7 @@ struct sock *mptcp_sk_clone(const struct sock *sk,
    if (mp_opt->mp_capable) {
        msk->can_ack = true;
        msk->remote_key = mp_opt->sndr_key;
-        mptcp_crypto_key_sha(msk->remote_key, NULL, &ack_seq);
+        mptcp_crypto_key_sha(msk->remote_key, &msk->remote_token, &ack_seq);
        ack_seq++;
        WRITE_ONCE(msk->ack_seq, ack_seq);
        WRITE_ONCE(msk->rcv_wnd_sent, ack_seq);
@@ -2967,7 +2967,7 @@ void mptcp_finish_connect(struct sock *ssk)
 
    pr_debug("msk=%p, token=%u", sk, subflow->token);
 
-    mptcp_crypto_key_sha(subflow->remote_key, NULL, &ack_seq);
+    mptcp_crypto_key_sha(subflow->remote_key, &subflow->remote_token, &ack_seq);
    ack_seq++;
    subflow->map_seq = ack_seq;
    subflow->map_subflow_seq = 1;
@@ -2976,6 +2976,7 @@ void mptcp_finish_connect(struct sock *ssk)
     * accessing the field below
     */
    WRITE_ONCE(msk->remote_key, subflow->remote_key);
+    WRITE_ONCE(msk->remote_token, subflow->remote_token);
    WRITE_ONCE(msk->local_key, subflow->local_key);
    WRITE_ONCE(msk->write_seq, subflow->idsn + 1);
    WRITE_ONCE(msk->snd_nxt, msk->write_seq);
net/mptcp/protocol.h +1 -0
index edc0128..abd8e31 100644
@@ -226,6 +226,7 @@ struct mptcp_sock {
    u64        wnd_end;
    unsigned long    timer_ival;
    u32        token;
+    u32        remote_token;
    int        rmem_released;
    unsigned long    flags;
    bool        can_ack;
net/mptcp/subflow.c +0 -0
index 82e91b0..ddd8c03 100644

net/mptcp/subflow.c static bool subflow_check_data_avail(struct sock *ssk) · line 1049

Quoted 4 lines
net/mptcp/subflow.c +1 -0
@@ -1046,6 +1046,7 @@ static bool subflow_check_data_avail(struct sock *ssk)
                goto fatal;
            }
            WRITE_ONCE(msk->remote_key, subflow->remote_key);
+            mptcp_crypto_key_sha(READ_ONCE(msk->remote_key), &msk->remote_token, NULL);

Hi Jianguo, thanks for your patch.

This adds a possible extra SHA calculation in this function, on the server side of a connection that may not ever use the token. This code path is only encountered in rare conditions, though: when an MP_CAPABLE+data packet is late, retransmitted, or out-of-order.

(also, if we move ahead with this patch, the token should be written to a local variable and then copied to msk->remote_token using WRITE_ONCE(). Would also be more efficient to pass subflow->remote_key as the first arg because there's no READ_ONCE() required to read from the subflow structure)

Quoted 12 lines
net/mptcp/subflow.c +0 -1
            WRITE_ONCE(msk->ack_seq, subflow->map_seq);
            WRITE_ONCE(msk->can_ack, true);
        }
@@ -1268,7 +1269,6 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
    int local_id = loc->id;
    struct socket *sf;
    struct sock *ssk;
-    u32 remote_token;
    int addrlen;
    int err;
 

net/mptcp/subflow.c int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, · line 1313

Quoted 9 lines
net/mptcp/subflow.c +2 -3
@@ -1308,10 +1308,9 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
    if (err)
        goto failed;
 
-    mptcp_crypto_key_sha(subflow->remote_key, &remote_token, NULL);
    pr_debug("msk=%p remote_token=%u local_id=%d remote_id=%d", msk,
-         remote_token, local_id, remote_id);
-    subflow->remote_token = remote_token;
+         msk->remote_token, local_id, remote_id);
+    subflow->remote_token = msk->remote_token;

And here, I think, is the tradeoff: with this patch, there is no need to recalculate the SHA on every outgoing join. That's more common on the client side of a connection, where there will not be a large number of joins initiated so the cost is not very high.

Quoted 1 line

Given the client/server tradeoff and the likely small number of joins on any given connection, do you think this is worth changing?

Hi Mat, thanks for your comments!

I think, with high CPS, it can reduce lots of recalculation, and in some scenarios, such as the middle mile, server side can also initiate join subflows,

Quoted 6 lines
Quoted 4 lines

Uhmm... In the connections/rate performance test I did, the crypto- related overhead was quite low, almost un-noticeable. Do you have any perf figures for the above scenario (e.g. perf report or flamegraph)?

Sorry, I haven't do performance test.

Ok, than I think you should really start from there, collecting the perf data in your reference scenario (or in a testbed doing similar works) and see if something interesting and addressable pops up.

For the records, there are a bunch of items which will improve performances with no drawback:

https://github.com/multipath-tcp/mptcp_net-next/issues/42
https://github.com/multipath-tcp/mptcp_net-next/issues/15

(the above 2 are related)

https://github.com/multipath-tcp/mptcp_net-next/issues/41
https://github.com/multipath-tcp/mptcp_net-next/issues/24

Thanks!

Paolo

author
#6 lore raw
Quoted 116 lines · Paolo Abeni
Quoted 115 lines · Jianguo Wu
Quoted 112 lines · Paolo Abeni
Quoted 99 lines · Jianguo Wu
Quoted 98 lines · Mat Martineau
Quoted 61 lines · Jianguo Wu

From: Jianguo Wu <[email protected]>

Now every time create a new subflow, it needs to generate remote token in __mptcp_subflow_connect(), the remote token is the same among all subflows in a mptcp connection, so we can store remote token in mptcp sock.

---

net/mptcp/protocol.c | 5 +++--
net/mptcp/protocol.h | 1 +
net/mptcp/subflow.c  | 7 +++----
3 files changed, 7 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +3 -2
index a8180a9..607fb30 100644
@@ -2736,7 +2736,7 @@ struct sock *mptcp_sk_clone(const struct sock *sk,
    if (mp_opt->mp_capable) {
        msk->can_ack = true;
        msk->remote_key = mp_opt->sndr_key;
-        mptcp_crypto_key_sha(msk->remote_key, NULL, &ack_seq);
+        mptcp_crypto_key_sha(msk->remote_key, &msk->remote_token, &ack_seq);
        ack_seq++;
        WRITE_ONCE(msk->ack_seq, ack_seq);
        WRITE_ONCE(msk->rcv_wnd_sent, ack_seq);
@@ -2967,7 +2967,7 @@ void mptcp_finish_connect(struct sock *ssk)
 
    pr_debug("msk=%p, token=%u", sk, subflow->token);
 
-    mptcp_crypto_key_sha(subflow->remote_key, NULL, &ack_seq);
+    mptcp_crypto_key_sha(subflow->remote_key, &subflow->remote_token, &ack_seq);
    ack_seq++;
    subflow->map_seq = ack_seq;
    subflow->map_subflow_seq = 1;
@@ -2976,6 +2976,7 @@ void mptcp_finish_connect(struct sock *ssk)
     * accessing the field below
     */
    WRITE_ONCE(msk->remote_key, subflow->remote_key);
+    WRITE_ONCE(msk->remote_token, subflow->remote_token);
    WRITE_ONCE(msk->local_key, subflow->local_key);
    WRITE_ONCE(msk->write_seq, subflow->idsn + 1);
    WRITE_ONCE(msk->snd_nxt, msk->write_seq);
net/mptcp/protocol.h +1 -0
index edc0128..abd8e31 100644
@@ -226,6 +226,7 @@ struct mptcp_sock {
    u64        wnd_end;
    unsigned long    timer_ival;
    u32        token;
+    u32        remote_token;
    int        rmem_released;
    unsigned long    flags;
    bool        can_ack;
net/mptcp/subflow.c +0 -0
index 82e91b0..ddd8c03 100644

net/mptcp/subflow.c static bool subflow_check_data_avail(struct sock *ssk) · line 1049

Quoted 4 lines
net/mptcp/subflow.c +1 -0
@@ -1046,6 +1046,7 @@ static bool subflow_check_data_avail(struct sock *ssk)
                goto fatal;
            }
            WRITE_ONCE(msk->remote_key, subflow->remote_key);
+            mptcp_crypto_key_sha(READ_ONCE(msk->remote_key), &msk->remote_token, NULL);

Hi Jianguo, thanks for your patch.

This adds a possible extra SHA calculation in this function, on the server side of a connection that may not ever use the token. This code path is only encountered in rare conditions, though: when an MP_CAPABLE+data packet is late, retransmitted, or out-of-order.

(also, if we move ahead with this patch, the token should be written to a local variable and then copied to msk->remote_token using WRITE_ONCE(). Would also be more efficient to pass subflow->remote_key as the first arg because there's no READ_ONCE() required to read from the subflow structure)

Quoted 12 lines
net/mptcp/subflow.c +0 -1
            WRITE_ONCE(msk->ack_seq, subflow->map_seq);
            WRITE_ONCE(msk->can_ack, true);
        }
@@ -1268,7 +1269,6 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
    int local_id = loc->id;
    struct socket *sf;
    struct sock *ssk;
-    u32 remote_token;
    int addrlen;
    int err;
 

net/mptcp/subflow.c int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, · line 1313

Quoted 9 lines
net/mptcp/subflow.c +2 -3
@@ -1308,10 +1308,9 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
    if (err)
        goto failed;
 
-    mptcp_crypto_key_sha(subflow->remote_key, &remote_token, NULL);
    pr_debug("msk=%p remote_token=%u local_id=%d remote_id=%d", msk,
-         remote_token, local_id, remote_id);
-    subflow->remote_token = remote_token;
+         msk->remote_token, local_id, remote_id);
+    subflow->remote_token = msk->remote_token;

And here, I think, is the tradeoff: with this patch, there is no need to recalculate the SHA on every outgoing join. That's more common on the client side of a connection, where there will not be a large number of joins initiated so the cost is not very high.

Quoted 7 lines
Quoted 1 line

Given the client/server tradeoff and the likely small number of joins on any given connection, do you think this is worth changing?

Hi Mat, thanks for your comments!

I think, with high CPS, it can reduce lots of recalculation, and in some scenarios, such as the middle mile, server side can also initiate join subflows,

Uhmm... In the connections/rate performance test I did, the crypto- related overhead was quite low, almost un-noticeable. Do you have any perf figures for the above scenario (e.g. perf report or flamegraph)?

Quoted 6 lines
Quoted 1 line

Sorry, I haven't do performance test.

Ok, than I think you should really start from there, collecting the perf data in your reference scenario (or in a testbed doing similar works) and see if something interesting and addressable pops up.

OK, Thanks!

Quoted 15 lines

For the records, there are a bunch of items which will improve performances with no drawback:

https://github.com/multipath-tcp/mptcp_net-next/issues/42
https://github.com/multipath-tcp/mptcp_net-next/issues/15

(the above 2 are related)

https://github.com/multipath-tcp/mptcp_net-next/issues/41
https://github.com/multipath-tcp/mptcp_net-next/issues/24

Thanks!

Paolo