From nobody Sat May 4 02:58:57 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 9CDD52F23 for ; Mon, 6 Mar 2023 18:30:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678127430; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aKzd26WHuykUzomNGc0w92bJKsv/tjR5luKYqhaSYgQ=; b=V7pXWoiQrVsbrIHE7VZWsggIPDWDjYzX9S/feZuMsDnqaZTD1uoZUL77DAH8hzL42BcLSR Z5QMgtQd56ss1JgtgcBPLF7IIMww1rNC1xmglKmZFrXj9LjWqa5J+sLWTvcQUHvE8zaqQr LbWwkK6bPyTnqFqtlDWB1wcT54Q6ggk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-629-vRnUZJGtMjqSPAZelNL6uw-1; Mon, 06 Mar 2023 13:30:29 -0500 X-MC-Unique: vRnUZJGtMjqSPAZelNL6uw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A885A811E9C for ; Mon, 6 Mar 2023 18:30:28 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.39.195.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38264175AD for ; Mon, 6 Mar 2023 18:30:28 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next 1/2] mptcp: avoid unneeded address copy Date: Mon, 6 Mar 2023 19:30:20 +0100 Message-Id: In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8"; x-default="true" In the syn_recv fallback path, the msk is unused. We can skip setting the socket address. Signed-off-by: Paolo Abeni Reviewed-by: Matthieu Baerts --- net/mptcp/subflow.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 1ca8d30e9276..f0758b23c6b2 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -821,8 +821,6 @@ static struct sock *subflow_syn_recv_sock(const struct = sock *sk, goto dispose_child; } =20 - if (new_msk) - mptcp_copy_inaddrs(new_msk, child); mptcp_subflow_drop_ctx(child); goto out; } --=20 2.39.2 From nobody Sat May 4 02:58:57 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 3ACF46137 for ; Mon, 6 Mar 2023 18:30:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678127431; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IWELGuxVrarX1Qvkg+rKE0LMkRdNvIoH1Btd5XNDu+o=; b=EtA7yhEiSuF+0lbO2ZDCUwMfsfQhcZwioL3Evg8+ZeRCkog1amAjd+ox9ATmGuX6drkHk/ zzMXFO+dTb3ZDlhBr0EddMI/MAR8jq4PVyUcSlBqb3wwhliAGXWlNa8K9rI0CItSfJvUph Dx47Gt4SVL98r1TdJZz0wFNpT5vRwFo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-37-T1HZcaz5OKOvMnN62NCxSQ-1; Mon, 06 Mar 2023 13:30:29 -0500 X-MC-Unique: T1HZcaz5OKOvMnN62NCxSQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7A8D6857A8E for ; Mon, 6 Mar 2023 18:30:29 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.39.195.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED27E440DF for ; Mon, 6 Mar 2023 18:30:28 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next 2/2] mptcp: simplify subflow_syn_recv_sock() Date: Mon, 6 Mar 2023 19:30:21 +0100 Message-Id: In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8"; x-default="true" Postpone the msk cloning to the child process creation so that we can avoid a bunch of conditionals. Close: https://github.com/multipath-tcp/mptcp_net-next/issues/61 Signed-off-by: Paolo Abeni Reviewed-by: Matthieu Baerts --- net/mptcp/subflow.c | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index f0758b23c6b2..d79926cb9152 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -696,14 +696,6 @@ static bool subflow_hmac_valid(const struct request_so= ck *req, return !crypto_memneq(hmac, mp_opt->hmac, MPTCPOPT_HMAC_LEN); } =20 -static void mptcp_force_close(struct sock *sk) -{ - /* the msk is not yet exposed to user-space, and refcount is 2 */ - inet_sk_state_store(sk, TCP_CLOSE); - sk_common_release(sk); - sock_put(sk); -} - static void subflow_ulp_fallback(struct sock *sk, struct mptcp_subflow_context *old_ctx) { @@ -755,7 +747,6 @@ static struct sock *subflow_syn_recv_sock(const struct = sock *sk, struct mptcp_subflow_request_sock *subflow_req; struct mptcp_options_received mp_opt; bool fallback, fallback_is_fatal; - struct sock *new_msk =3D NULL; struct mptcp_sock *owner; struct sock *child; =20 @@ -784,14 +775,9 @@ static struct sock *subflow_syn_recv_sock(const struct= sock *sk, * options. */ mptcp_get_options(skb, &mp_opt); - if (!(mp_opt.suboptions & OPTIONS_MPTCP_MPC)) { + if (!(mp_opt.suboptions & OPTIONS_MPTCP_MPC)) fallback =3D true; - goto create_child; - } =20 - new_msk =3D mptcp_sk_clone(listener->conn, &mp_opt, req); - if (!new_msk) - fallback =3D true; } else if (subflow_req->mp_join) { mptcp_get_options(skb, &mp_opt); if (!(mp_opt.suboptions & OPTIONS_MPTCP_MPJ) || @@ -820,21 +806,23 @@ static struct sock *subflow_syn_recv_sock(const struc= t sock *sk, subflow_add_reset_reason(skb, MPTCP_RST_EMPTCP); goto dispose_child; } - - mptcp_subflow_drop_ctx(child); - goto out; + goto fallback; } =20 /* ssk inherits options of listener sk */ ctx->setsockopt_seq =3D listener->setsockopt_seq; =20 if (ctx->mp_capable) { - owner =3D mptcp_sk(new_msk); + ctx->conn =3D mptcp_sk_clone(listener->conn, &mp_opt, req); + if (!ctx->conn) + goto fallback; + + owner =3D mptcp_sk(ctx->conn); =20 /* this can't race with mptcp_close(), as the msk is * not yet exposted to user-space */ - inet_sk_state_store((void *)new_msk, TCP_ESTABLISHED); + inet_sk_state_store(ctx->conn, TCP_ESTABLISHED); =20 /* record the newly created socket as the first msk * subflow, but don't link it yet into conn_list @@ -844,11 +832,9 @@ static struct sock *subflow_syn_recv_sock(const struct= sock *sk, /* new mpc subflow takes ownership of the newly * created mptcp socket */ - mptcp_sk(new_msk)->setsockopt_seq =3D ctx->setsockopt_seq; + owner->setsockopt_seq =3D ctx->setsockopt_seq; mptcp_pm_new_connection(owner, child, 1); mptcp_token_accept(subflow_req, owner); - ctx->conn =3D new_msk; - new_msk =3D NULL; =20 /* set msk addresses early to ensure mptcp_pm_get_local_id() * uses the correct data @@ -901,14 +887,10 @@ static struct sock *subflow_syn_recv_sock(const struc= t sock *sk, * soon, but context must be explicitly deleted or will be * leaked */ +fallback: mptcp_subflow_drop_ctx(child); } =20 -out: - /* dispose of the left over mptcp master, if any */ - if (unlikely(new_msk)) - mptcp_force_close(new_msk); - /* check for expected invariant - should never trigger, just help * catching eariler subtle bugs */ --=20 2.39.2