Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F6E871 for ; Wed, 21 Apr 2021 01:01:05 +0000 (UTC) IronPort-SDR: eflPJLeTNNew2k7KCTq++mm7RaffGhvnQfEvETbdaq2fhVUwdzZaeP+IXrIBY81LZiEzSq623B TGquoPxGddxA== X-IronPort-AV: E=McAfee;i="6200,9189,9960"; a="216253411" X-IronPort-AV: E=Sophos;i="5.82,238,1613462400"; d="scan'208";a="216253411" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2021 18:01:04 -0700 IronPort-SDR: 5vm8c2A+rw3fm9ZVCwCEwNlS9Cozv9IOvNdtl1Y2VaOCnzhCmI2nJ8CkqXxABgiisC2YpBLvAt XX7QzSwwRvDA== X-IronPort-AV: E=Sophos;i="5.82,238,1613462400"; d="scan'208";a="423368665" Received: from unknown (HELO [10.212.231.73]) ([10.212.231.73]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2021 18:01:03 -0700 Date: Tue, 20 Apr 2021 18:01:03 -0700 (PDT) From: Mat Martineau To: Jianguo Wu cc: mptcp@lists.linux.dev, matthieu.baerts@tessares.net, Florian Westphal , pabeni@redhat.com Subject: Re: [PATCH] mptcp: store remote token in mptcp sock In-Reply-To: <4e1d608e-4bcd-a432-03b7-860cd3e007c2@163.com> Message-ID: <4cf0e328-db13-9c37-e87f-f84910d01070@linux.intel.com> References: <4e1d608e-4bcd-a432-03b7-860cd3e007c2@163.com> X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII On Tue, 20 Apr 2021, Jianguo Wu wrote: > From: Jianguo Wu > > 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. > > Signed-off-by: Jianguo Wu > --- > net/mptcp/protocol.c | 5 +++-- > net/mptcp/protocol.h | 1 + > net/mptcp/subflow.c | 7 +++---- > 3 files changed, 7 insertions(+), 6 deletions(-) > > diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c > index a8180a9..607fb30 100644 > --- a/net/mptcp/protocol.c > +++ b/net/mptcp/protocol.c > @@ -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); > diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h > index edc0128..abd8e31 100644 > --- a/net/mptcp/protocol.h > +++ b/net/mptcp/protocol.h > @@ -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; > diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c > index 82e91b0..ddd8c03 100644 > --- a/net/mptcp/subflow.c > +++ b/net/mptcp/subflow.c > @@ -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) > 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; 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? > subflow->local_id = local_id; > subflow->remote_id = remote_id; > subflow->request_join = 1; > -- > 1.8.3.1 > > -- Mat Martineau Intel