Skip to contentSkip to conversation

mptcp: more fastopen follow-up

PATCH In review Paolo Abeni 2 participants 4 messages Nov 15, 2022 – Nov 17, 2022

Subsystems (2)
lore
Share & tools
lore

Paolo Abeni

author maintainer
#0 lore raw

cover mptcp: more fastopen follow-up

The last bunch of mptcp fast open follow-up I have planned.

This aims at reducing the number of unnecessary mptcp_crypto_key_sha() invocation, calling such primitive at most once per MPC subflow and caching the result as subflow level.

The first patch should be inserted just before

"mptcp: implement delayed seq generation for passive fastopen"

while the 2nd one is a squash-to, still to the above.

Note that this will cause a trivial conflict in "DO-NOT-MERGE: mptcp:
use kmalloc on kasan build"

Signature · 1 line
2.38.1
author maintainer
#1 lore raw

PATCH 1/2 mptcp: consolidate initial ack seq generation

Currently the initial ack sequence is generated on demand whenever it's requested and the remote key is handy. The relevant code is scattered in different places and can lead to multiple, unneeded, crypto operations.

This change consolidate the ack sequence generation code in a single helper, storing the sequence number at the subflow level.

The above additionally save a few conditional in fast-path and will simplify the upcoming fast-open implementation.

---
 net/mptcp/options.c  |  5 ++--
 net/mptcp/protocol.c | 19 +--------------
 net/mptcp/protocol.h |  9 ++++---
 net/mptcp/subflow.c  | 57 +++++++++++++++++++++++++++-----------------
 4 files changed, 45 insertions(+), 45 deletions(-)
net/mptcp/options.c +3 -2
index 784a205e80da..ae076468fcb9 100644
@@ -953,8 +953,9 @@ static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
 		return subflow->mp_capable;
 	}
 
-	if (((mp_opt->suboptions & OPTION_MPTCP_DSS) && mp_opt->use_ack) ||
-	    ((mp_opt->suboptions & OPTION_MPTCP_ADD_ADDR) && !mp_opt->echo)) {
+	if (subflow->remote_key_valid &&
+	    (((mp_opt->suboptions & OPTION_MPTCP_DSS) && mp_opt->use_ack) ||
+	     ((mp_opt->suboptions & OPTION_MPTCP_ADD_ADDR) && !mp_opt->echo))) {
 		/* subflows are fully established as soon as we get any
 		 * additional ack, including ADD_ADDR.
 		 */
net/mptcp/protocol.c +1 -18
index 37876e06d4c4..00de7f4fce10 100644
@@ -3046,7 +3046,6 @@ struct sock *mptcp_sk_clone(const struct sock *sk,
 	struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
 	struct sock *nsk = sk_clone_lock(sk, GFP_ATOMIC);
 	struct mptcp_sock *msk;
-	u64 ack_seq;
 
 	if (!nsk)
 		return NULL;
@@ -3072,15 +3071,6 @@ struct sock *mptcp_sk_clone(const struct sock *sk,
 	msk->wnd_end = msk->snd_nxt + req->rsk_rcv_wnd;
 	msk->setsockopt_seq = mptcp_sk(sk)->setsockopt_seq;
 
-	if (mp_opt->suboptions & OPTIONS_MPTCP_MPC) {
-		msk->can_ack = true;
-		msk->remote_key = mp_opt->sndr_key;
-		mptcp_crypto_key_sha(msk->remote_key, NULL, &ack_seq);
-		ack_seq++;
-		WRITE_ONCE(msk->ack_seq, ack_seq);
-		atomic64_set(&msk->rcv_wnd_sent, ack_seq);
-	}
-
 	sock_reset_flag(nsk, SOCK_RCU_FREE);
 	/* will be fully established after successful MPC subflow creation */
 	inet_sk_state_store(nsk, TCP_SYN_RECV);
@@ -3353,7 +3343,6 @@ void mptcp_finish_connect(struct sock *ssk)
 	struct mptcp_subflow_context *subflow;
 	struct mptcp_sock *msk;
 	struct sock *sk;
-	u64 ack_seq;
 
 	subflow = mptcp_subflow_ctx(ssk);
 	sk = subflow->conn;
@@ -3361,22 +3350,16 @@ 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);
-	ack_seq++;
-	subflow->map_seq = ack_seq;
+	subflow->map_seq = subflow->iasn;
 	subflow->map_subflow_seq = 1;
 
 	/* the socket is not connected yet, no msk/subflow ops can access/race
 	 * accessing the field below
 	 */
-	WRITE_ONCE(msk->remote_key, subflow->remote_key);
 	WRITE_ONCE(msk->local_key, subflow->local_key);
 	WRITE_ONCE(msk->write_seq, subflow->idsn + 1);
 	WRITE_ONCE(msk->snd_nxt, msk->write_seq);
-	WRITE_ONCE(msk->ack_seq, ack_seq);
-	WRITE_ONCE(msk->can_ack, 1);
 	WRITE_ONCE(msk->snd_una, msk->write_seq);
-	atomic64_set(&msk->rcv_wnd_sent, ack_seq);
 
 	mptcp_pm_new_connection(msk, ssk, 0);
 
net/mptcp/protocol.h +6 -3
index 6a09ab99a12d..b5abea3d1a9c 100644
@@ -467,7 +467,7 @@ struct mptcp_subflow_context {
 		send_fastclose : 1,
 		send_infinite_map : 1,
 		rx_eof : 1,
-		can_ack : 1,        /* only after processing the remote a key */
+		remote_key_valid : 1,        /* received the peer key from */
 		disposable : 1,	    /* ctx can be free at ulp release time */
 		stale : 1,	    /* unable to snd/rcv data, do not use for xmit */
 		local_id_valid : 1, /* local_id is correctly initialized */
@@ -477,7 +477,10 @@ struct mptcp_subflow_context {
 	u64	thmac;
 	u32	local_nonce;
 	u32	remote_token;
-	u8	hmac[MPTCPOPT_HMAC_LEN];
+	union {
+		u8	hmac[MPTCPOPT_HMAC_LEN]; /* MPJ subflow only */
+		u64	iasn;	    /* initial ack sequence number, MPC subflows only */
+	};
 	u8	local_id;
 	u8	remote_id;
 	u8	reset_seen:1;
@@ -603,7 +606,7 @@ unsigned int mptcp_stale_loss_cnt(const struct net *net);
 int mptcp_get_pm_type(const struct net *net);
 void mptcp_copy_inaddrs(struct sock *msk, const struct sock *ssk);
 void mptcp_subflow_fully_established(struct mptcp_subflow_context *subflow,
-				     struct mptcp_options_received *mp_opt);
+				     const struct mptcp_options_received *mp_opt);
 bool __mptcp_retransmit_pending_data(struct sock *sk);
 void mptcp_check_and_set_pending(struct sock *sk);
 void __mptcp_push_pending(struct sock *sk, unsigned int flags);
net/mptcp/subflow.c +35 -22

126 lines not on this page · raw message

Signature · 1 line
2.38.1
author maintainer
#2 lore raw

PATCH 2/2 Squash-to "mptcp: implement delayed seq generation for passive fastopen"

In reply to Paolo Abeni

After "mptcp: consolidate initial ack seq generation" we don't need anymore to do the crypto hash in the fastopen code, the caller already did it for us.

Just drop the duplicated code.

---
 net/mptcp/fastopen.c | 8 --------
 1 file changed, 8 deletions(-)
net/mptcp/fastopen.c +0 -8
index ee6cfbba6c05..19c332af0834 100644
@@ -11,16 +11,8 @@ void mptcp_fastopen_gen_msk_ackseq(struct mptcp_sock *msk, struct mptcp_subflow_
 {
 	struct sock *sk = (struct sock *)msk;
 	struct sk_buff *skb;
-	u64 ack_seq;
-
-	mptcp_crypto_key_sha(mp_opt->sndr_key, NULL, &ack_seq);
-	ack_seq++;
 
 	mptcp_data_lock(sk);
-	WRITE_ONCE(msk->can_ack, true);
-	WRITE_ONCE(msk->ack_seq, ack_seq);
-	atomic64_set(&msk->rcv_wnd_sent, ack_seq);
-	msk->remote_key = mp_opt->sndr_key;
 	skb = skb_peek_tail(&sk->sk_receive_queue);
 	if (skb) {
 		WARN_ON_ONCE(MPTCP_SKB_CB(skb)->end_seq);
Signature · 1 line
2.38.1
#3 lore raw
In reply to Paolo Abeni

Hi Paolo,

Quoted 6 lines · Paolo Abeni

The last bunch of mptcp fast open follow-up I have planned.

This aims at reducing the number of unnecessary mptcp_crypto_key_sha() invocation, calling such primitive at most once per MPC subflow and caching the result as subflow level.

Quoted 8 lines

The first patch should be inserted just before

"mptcp: implement delayed seq generation for passive fastopen"

while the 2nd one is a squash-to, still to the above.

Note that this will cause a trivial conflict in "DO-NOT-MERGE: mptcp:
use kmalloc on kasan build"

Thank you for the patches and the notes here above!

New patches for t/upstream:
- cccf62e31b88: mptcp: consolidate initial ack seq generation
- b4c09c888e0b: conflict in t/DO-NOT-MERGE-mptcp-use-kmalloc-on-kasan-build
- Results: dc870dc49415..ee79be9e1648 (export)

- 23c22cf366e6: "squashed" patch 2/2 in "mptcp: implement delayed seq generation for passive fastopen"
- Results: ee79be9e1648..42fdee53dc8e (export)

Tests are now in progress:

https://cirrus-ci.com/github/multipath-tcp/mptcp_net-next/export/20221117T182326

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net