Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3336405pxf; Mon, 15 Mar 2021 07:25:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzB5s5+wBBF3sue8mR6WMmIhEAuYd5Nl3IcOCx7wTKxw/JaE4kCFGr48K31ua4Fw8V+AYb0 X-Received: by 2002:a17:906:d790:: with SMTP id pj16mr23523884ejb.255.1615818301632; Mon, 15 Mar 2021 07:25:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615818301; cv=none; d=google.com; s=arc-20160816; b=Gypy2jhTdvssVebiBBqAJX+XW3/ObkHg0/J+9oDuqfND7CsgpmF+Vs+xTE28h78l93 O16i7Rr5q2Ek/dc0zDOPKbDSTskSIebBo8O6KBWm1sQSrRbXpGU2/NJW6edX1RWpukfo IiaMMy8N3HN/QtuRXEv2QUHjoUKPmvOTySQu8XOr5cHcVCLiJBvBIIGhr7kcyHrhr+YD gz/JzAFPpaURx1Az07zl9Jn6kA1Ao2sEVZANn+6YcHbny/ydUxsulwjWiCKOuiFIYzPc 9U/IfOcUZw84cnFi78GxxV8CouKr9v642WQNO024z9VnSg8WD4MSXotbkESvh07yELdD TNPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=S+rZacpmtmLwCJ5xJzG5nz2uUkScxPK/WmyWtb0sfro=; b=TeE16R9mCvuadpsC7I0euqVTnYusMKEVXke+iZW83pfvuk9+tifEXQSexHGg8Ei2aY 2ftOPv1WqeaPJ+37U0r4feTgDEAgm85QZBmFCm72SRD8naSHaYkUKh9bfFVkpqZm0SdP hcKHOjyE3P37YWjlNy+qzqYs80pB5bchZ1F+R7lA5nAfmTJBUtEJ1wT6cE6ovC+TFXxG RhqfQvh1JbaFiNMKRdGUhxxXMu6Y3xkkPuzMeHkN6atI0DIna0lWGUsDLG807u9u9LDh aF28nA+ibCO7AZm50KGkNo1NYywmO8O9dhYB1j2XyWwTAzOczPaEpY3u5Q8zAO8ngGDT 79bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lmtxIz+y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h8si10902302ejj.71.2021.03.15.07.24.35; Mon, 15 Mar 2021 07:25:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lmtxIz+y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237794AbhCOOWE (ORCPT + 99 others); Mon, 15 Mar 2021 10:22:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:36764 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232906AbhCOOAJ (ORCPT ); Mon, 15 Mar 2021 10:00:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B8CAB64EE9; Mon, 15 Mar 2021 13:59:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816783; bh=jYTb5d7v2gYJDX3bUOyQV54hcXxLWvhGXSiovtS5onc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lmtxIz+ybuFHTx/lNEroFhYOexXBbYWPj/dgLtvVxer3mdEdor68nzhj/AZ6otLHv Us+PgIkSDJNnRq4wQ5UIgb4VLaKtWFShg79SIHBHik6vxfoF2quYkD4jUC0F67SgKe S9M01Bt9P2E+bHQtLdb3+NaYpC+nC03EvkwgUPQc= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mat Martineau , Paolo Abeni , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.11 122/306] mptcp: always graft subflow socket to parent Date: Mon, 15 Mar 2021 14:53:05 +0100 Message-Id: <20210315135511.792253111@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Paolo Abeni [ Upstream commit 866f26f2a9c33bc70eb0f07ffc37fd9424ffe501 ] Currently, incoming subflows link to the parent socket, while outgoing ones link to a per subflow socket. The latter is not really needed, except at the initial connect() time and for the first subflow. Always graft the outgoing subflow to the parent socket and free the unneeded ones early. This allows some code cleanup, reduces the amount of memory used and will simplify the next patch Reviewed-by: Mat Martineau Signed-off-by: Paolo Abeni Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/mptcp/protocol.c | 36 ++++++++++-------------------------- net/mptcp/protocol.h | 1 + net/mptcp/subflow.c | 3 +++ 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index b51872b9dd61..3cc7be259396 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -114,11 +114,7 @@ static int __mptcp_socket_create(struct mptcp_sock *msk) list_add(&subflow->node, &msk->conn_list); sock_hold(ssock->sk); subflow->request_mptcp = 1; - - /* accept() will wait on first subflow sk_wq, and we always wakes up - * via msk->sk_socket - */ - RCU_INIT_POINTER(msk->first->sk_wq, &sk->sk_socket->wq); + mptcp_sock_graft(msk->first, sk->sk_socket); return 0; } @@ -2114,9 +2110,6 @@ static struct sock *mptcp_subflow_get_retrans(const struct mptcp_sock *msk) void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, struct mptcp_subflow_context *subflow) { - bool dispose_socket = false; - struct socket *sock; - list_del(&subflow->node); lock_sock_nested(ssk, SINGLE_DEPTH_NESTING); @@ -2124,11 +2117,8 @@ void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, /* if we are invoked by the msk cleanup code, the subflow is * already orphaned */ - sock = ssk->sk_socket; - if (sock) { - dispose_socket = sock != sk->sk_socket; + if (ssk->sk_socket) sock_orphan(ssk); - } subflow->disposable = 1; @@ -2146,8 +2136,6 @@ void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, __sock_put(ssk); } release_sock(ssk); - if (dispose_socket) - iput(SOCK_INODE(sock)); sock_put(ssk); } @@ -2535,6 +2523,12 @@ static void __mptcp_destroy_sock(struct sock *sk) pr_debug("msk=%p", msk); + /* dispose the ancillatory tcp socket, if any */ + if (msk->subflow) { + iput(SOCK_INODE(msk->subflow)); + msk->subflow = NULL; + } + /* be sure to always acquire the join list lock, to sync vs * mptcp_finish_join(). */ @@ -2585,20 +2579,10 @@ cleanup: inet_csk(sk)->icsk_mtup.probe_timestamp = tcp_jiffies32; list_for_each_entry(subflow, &mptcp_sk(sk)->conn_list, node) { struct sock *ssk = mptcp_subflow_tcp_sock(subflow); - bool slow, dispose_socket; - struct socket *sock; + bool slow = lock_sock_fast(ssk); - slow = lock_sock_fast(ssk); - sock = ssk->sk_socket; - dispose_socket = sock && sock != sk->sk_socket; sock_orphan(ssk); unlock_sock_fast(ssk, slow); - - /* for the outgoing subflows we additionally need to free - * the associated socket - */ - if (dispose_socket) - iput(SOCK_INODE(sock)); } sock_orphan(sk); @@ -3040,7 +3024,7 @@ void mptcp_finish_connect(struct sock *ssk) mptcp_rcv_space_init(msk, ssk); } -static void mptcp_sock_graft(struct sock *sk, struct socket *parent) +void mptcp_sock_graft(struct sock *sk, struct socket *parent) { write_lock_bh(&sk->sk_callback_lock); rcu_assign_pointer(sk->sk_wq, &parent->wq); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index dbf62e74fcc1..18fef4273bdc 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -460,6 +460,7 @@ void mptcp_subflow_shutdown(struct sock *sk, struct sock *ssk, int how); void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, struct mptcp_subflow_context *subflow); void mptcp_subflow_reset(struct sock *ssk); +void mptcp_sock_graft(struct sock *sk, struct socket *parent); /* called with sk socket lock held */ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 9d28f6e3dc49..81b7be67d288 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -1165,6 +1165,9 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, if (err && err != -EINPROGRESS) goto failed_unlink; + /* discard the subflow socket */ + mptcp_sock_graft(ssk, sk->sk_socket); + iput(SOCK_INODE(sf)); return err; failed_unlink: -- 2.30.1