From nobody Sat Nov 23 10:34:17 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0FEEF178372 for ; Thu, 10 Oct 2024 05:48:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539289; cv=none; b=s+m3Ojpr9HWWXlbQrnX9YkOQ7xBv7kdg3UoLooxM9H0HxBBxzkmsnJUUiFqaoDhHR8JSd4RNkZCWbvkgEcaNPwOZSEaiI3wTfaXsiNOwgd+hBtyjOwq/k9HVJoMdCKjFsMUQxPLqso/WGBkZ9b9rKx0J0NFMiSWR+egaiJVqPSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539289; c=relaxed/simple; bh=w4IB7Gi+aZvqzY2tZoxPCRIf+b19vmSlgzt8LJO8QnI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pETObz7+xWEw1tTQbiUANpBwDJUweXUoh4S4rM95pQm63YGcMwf7jo8SYY7d3+Q+R+s8Jfoym+FMoZXeAuM6v/MwiF3Fcqxn1Rc5RasIjWhikAHBjNUIj/yvUz4yvDw8gPAz1+JaCaHerW5Z/++ZR5JEkoCmTiofhiCtD3c/7m8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=D2JcBhTg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="D2JcBhTg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F9D9C4CEC6; Thu, 10 Oct 2024 05:48:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728539288; bh=w4IB7Gi+aZvqzY2tZoxPCRIf+b19vmSlgzt8LJO8QnI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D2JcBhTgcyZugfHVdnVRJVlEd1JJ8ai/qVww55pN5Bn4P5FCGDDYgRDbKUR7yrilv GRp90lgST8HOnulPlX96IPYYMZtmxXAptk2bBeFOa7IDY/f9VwJ3KNb7IkS/S66h2j 0QkNCNK2ORMkWBXiHWJc528hnWc9Qsli2lVHRNvJ4IdnMAyzsrG5C5bRhGxmeMjYbf /Cd8odjEZD6XUQipV423UvuEU9xs6aCylfBS3aRUpVcM2++VKBT508DcSR8FQ2bWHo Gmy1uXRCi/zpwwAdSNPE7NotClrx0SzHG9RhH+8eySKoeXhyF+9RdyNEsnU3tB+hPs IZwGLG+zdt+sg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 01/15] mptcp: add id parameter for get_addr Date: Thu, 10 Oct 2024 13:47:46 +0800 Message-ID: <9bba98fce51429225615e95b28456642e7ef93c9.1728538975.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang The address id is parsed both in mptcp_pm_nl_get_addr() and mptcp_userspace_pm_get_addr(), this makes the code somewhat repetitive. So this patch adds a new parameter "id" for all get_addr() interfaces. The address id is only parsed in mptcp_pm_nl_get_addr_doit(), then pass it to both mptcp_pm_nl_get_addr() and mptcp_userspace_pm_get_addr(). Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 28 ++++++++++++++++------------ net/mptcp/pm_userspace.c | 11 +++-------- net/mptcp/protocol.h | 2 +- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 78f8d78f0392..c65d0ac4acc2 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1792,19 +1792,14 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, return -EMSGSIZE; } =20 -static int mptcp_pm_nl_get_addr(struct genl_info *info) +static int mptcp_pm_nl_get_addr(u8 id, struct genl_info *info) { - struct nlattr *attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet =3D genl_info_pm_nl(info); - struct mptcp_pm_addr_entry addr, *entry; + struct mptcp_pm_addr_entry *entry; struct sk_buff *msg; void *reply; int ret; =20 - ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); - if (ret < 0) - return ret; - msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) return -ENOMEM; @@ -1818,7 +1813,7 @@ static int mptcp_pm_nl_get_addr(struct genl_info *inf= o) } =20 spin_lock_bh(&pernet->lock); - entry =3D __lookup_addr_by_id(pernet, addr.addr.id); + entry =3D __lookup_addr_by_id(pernet, id); if (!entry) { GENL_SET_ERR_MSG(info, "address not found"); ret =3D -EINVAL; @@ -1842,16 +1837,25 @@ static int mptcp_pm_nl_get_addr(struct genl_info *i= nfo) return ret; } =20 -static int mptcp_pm_get_addr(struct genl_info *info) +static int mptcp_pm_get_addr(u8 id, struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_get_addr(info); - return mptcp_pm_nl_get_addr(info); + return mptcp_userspace_pm_get_addr(id, info); + return mptcp_pm_nl_get_addr(id, info); } =20 int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) { - return mptcp_pm_get_addr(info); + struct nlattr *attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; + struct mptcp_pm_addr_entry addr; + int ret; + + ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); + if (ret < 0) + return ret; + + ret =3D mptcp_pm_get_addr(addr.addr.id, info); + return ret; } =20 static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 512260e4afb2..da617d8bcc09 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -629,10 +629,9 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, return ret; } =20 -int mptcp_userspace_pm_get_addr(struct genl_info *info) +int mptcp_userspace_pm_get_addr(u8 id, struct genl_info *info) { - struct nlattr *attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; - struct mptcp_pm_addr_entry addr, *entry; + struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; struct sk_buff *msg; int ret =3D -EINVAL; @@ -645,10 +644,6 @@ int mptcp_userspace_pm_get_addr(struct genl_info *info) =20 sk =3D (struct sock *)msk; =20 - ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); - if (ret < 0) - goto out; - msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) { ret =3D -ENOMEM; @@ -665,7 +660,7 @@ int mptcp_userspace_pm_get_addr(struct genl_info *info) =20 lock_sock(sk); spin_lock_bh(&msk->pm.lock); - entry =3D mptcp_userspace_pm_lookup_addr_by_id(msk, addr.addr.id); + entry =3D mptcp_userspace_pm_lookup_addr_by_id(msk, id); if (!entry) { GENL_SET_ERR_MSG(info, "address not found"); ret =3D -EINVAL; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index cc5a38684c3a..73ef3087555c 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1125,7 +1125,7 @@ bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, st= ruct mptcp_addr_info *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_add= r_info *skc); int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); -int mptcp_userspace_pm_get_addr(struct genl_info *info); +int mptcp_userspace_pm_get_addr(u8 id, struct genl_info *info); =20 static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *= subflow) { --=20 2.43.0 From nobody Sat Nov 23 10:34:17 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 DC14619ADBF for ; Thu, 10 Oct 2024 05:48:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539290; cv=none; b=NGzq/1bdHouThztHoc1qGRd80DBlGVpupu8MNcmeqTSoIZ5GqdtheVoiK4VM9YO7A8iqsE5CPH2oRXxPw48urCPVk1wD2atLHYaBrKdEhP66QyxY60cF/eftPUUn2tD89x3ZsmEMYPidd1O7I3bb78e182MHJqhb2KDGXgpnhtY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539290; c=relaxed/simple; bh=geYo1LdaKbKJddp+fZP2ZjVF6smiw/+2ce+tHOgdWd0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uNryqIcmGalQs3+nUt6NQ+jk87pcHjYH6kFen4I6uwi4lNF654k7s0qJ6jSrbyzpx4Q1E7GUGMpCNvg34FeQ5N4M7iG5E6toN+Y0qUcp/MAdUJ8YwJjnsrcporWTnVi7geC26lM+atobkYl00VwULmtprIInI4U3l/BNj04l/vQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lJxuNUaR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lJxuNUaR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40D35C4CEC5; Thu, 10 Oct 2024 05:48:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728539290; bh=geYo1LdaKbKJddp+fZP2ZjVF6smiw/+2ce+tHOgdWd0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lJxuNUaR3NQyopZzanHmNWVBmnyZi4qtKRZhAAIEdJdNKm2I9FeFOGKXAqWcuZ5sF WlN1tFSH0FYTNZQ48uh47WBNzkrpp4qJ8mgrgVgHS8ENYl8F16kcb+H7Wn98MiJh+A mNQbWEbTtIT6cKNi935Ittq2mXPn2hbKsZ8IsQu4UtwD1FXeUV1uPCpqcu29YUr16o 5BQyr+ffvqOLVfyYpL8a87zSKfZ+pcT5NcAj5GPBkijuNDgyASW+/dWoWAzh/BIJcr 4OAOEs/nnZUBVYMtzF3jK+n8lI6wAEd0DJwzzBDmJRtMf1GWJDK7dRU0gudUaM5zFK DJ4XgoP3IMqrQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 02/15] mptcp: add addr parameter for get_addr Date: Thu, 10 Oct 2024 13:47:47 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang The netlink messages are sent both in mptcp_pm_nl_get_addr() and mptcp_userspace_pm_get_addr(), this makes the code somewhat repetitive. This is because the netlink PM and userspace PM use different locks to protect the address entry that needs to be sent via the netlink message. The former uses pernet->lock, and the latter uses msk->pm.lock. The current get_addr() flow looks like this: lock(); entry =3D get_entry(); send_nlmsg(entry); unlock(); After holding the lock, get the entry from the list, send the entry, and finally release the lock. This patch changes the process by getting the entry while holding the lock, then making a copy of the entry so that the lock can be released. Finally, the copy of the entry is sent without locking: lock(); entry =3D get_entry(); *copy =3D *entry; unlock(); send_nlmsg(copy); This way we can reuse this send_nlmsg() code between the netlink PM and userspace PM. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 33 ++++++++++++++++++--------------- net/mptcp/pm_userspace.c | 24 +++++++++++++----------- net/mptcp/protocol.h | 3 ++- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index c65d0ac4acc2..76c4520f7cb5 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1792,13 +1792,14 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, return -EMSGSIZE; } =20 -static int mptcp_pm_nl_get_addr(u8 id, struct genl_info *info) +static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, + struct genl_info *info) { struct pm_nl_pernet *pernet =3D genl_info_pm_nl(info); struct mptcp_pm_addr_entry *entry; struct sk_buff *msg; + int ret =3D -EINVAL; void *reply; - int ret; =20 msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) @@ -1814,34 +1815,36 @@ static int mptcp_pm_nl_get_addr(u8 id, struct genl_= info *info) =20 spin_lock_bh(&pernet->lock); entry =3D __lookup_addr_by_id(pernet, id); - if (!entry) { + if (entry) { + *addr =3D *entry; + ret =3D 0; + } + spin_unlock_bh(&pernet->lock); + + if (ret) { GENL_SET_ERR_MSG(info, "address not found"); - ret =3D -EINVAL; - goto unlock_fail; + goto fail; } =20 - ret =3D mptcp_nl_fill_addr(msg, entry); + ret =3D mptcp_nl_fill_addr(msg, addr); if (ret) - goto unlock_fail; + goto fail; =20 genlmsg_end(msg, reply); ret =3D genlmsg_reply(msg, info); - spin_unlock_bh(&pernet->lock); return ret; =20 -unlock_fail: - spin_unlock_bh(&pernet->lock); - fail: nlmsg_free(msg); return ret; } =20 -static int mptcp_pm_get_addr(u8 id, struct genl_info *info) +static int mptcp_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, + struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_get_addr(id, info); - return mptcp_pm_nl_get_addr(id, info); + return mptcp_userspace_pm_get_addr(id, addr, info); + return mptcp_pm_nl_get_addr(id, addr, info); } =20 int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) @@ -1854,7 +1857,7 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, st= ruct genl_info *info) if (ret < 0) return ret; =20 - ret =3D mptcp_pm_get_addr(addr.addr.id, info); + ret =3D mptcp_pm_get_addr(addr.addr.id, &addr, info); return ret; } =20 diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index da617d8bcc09..5c9f740bd9ac 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -629,7 +629,8 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, return ret; } =20 -int mptcp_userspace_pm_get_addr(u8 id, struct genl_info *info) +int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, + struct genl_info *info) { struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; @@ -661,26 +662,27 @@ int mptcp_userspace_pm_get_addr(u8 id, struct genl_in= fo *info) lock_sock(sk); spin_lock_bh(&msk->pm.lock); entry =3D mptcp_userspace_pm_lookup_addr_by_id(msk, id); - if (!entry) { + if (entry) { + *addr =3D *entry; + ret =3D 0; + } + spin_unlock_bh(&msk->pm.lock); + release_sock(sk); + + if (ret) { GENL_SET_ERR_MSG(info, "address not found"); - ret =3D -EINVAL; - goto unlock_fail; + goto fail; } =20 - ret =3D mptcp_nl_fill_addr(msg, entry); + ret =3D mptcp_nl_fill_addr(msg, addr); if (ret) - goto unlock_fail; + goto fail; =20 genlmsg_end(msg, reply); ret =3D genlmsg_reply(msg, info); - spin_unlock_bh(&msk->pm.lock); - release_sock(sk); sock_put(sk); return ret; =20 -unlock_fail: - spin_unlock_bh(&msk->pm.lock); - release_sock(sk); fail: nlmsg_free(msg); out: diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 73ef3087555c..e5319876c5f6 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1125,7 +1125,8 @@ bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, st= ruct mptcp_addr_info *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_add= r_info *skc); int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); -int mptcp_userspace_pm_get_addr(u8 id, struct genl_info *info); +int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, + struct genl_info *info); =20 static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *= subflow) { --=20 2.43.0 From nobody Sat Nov 23 10:34:17 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B756A178372 for ; Thu, 10 Oct 2024 05:48:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539292; cv=none; b=PVnQuZ7Pog46XeggsxNra51qdKGqv6xuGxCyJ6v+5DE4VVup6ZBs2zni3dGdUWK221QkuRFlnsQbOG8CB+GQNKB6y9cl82+VGjXfm2r0G5a2GLBzRVnrgKCZ/LykRhzGdTeTcqXtDkSo7morLNKdHVQVlM0glYJ8nBedNV0hkdE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539292; c=relaxed/simple; bh=krUOwXJLUN+fqjuerSUU4G59lOnIqgt4DUsd1Huazr0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XxhWC7PBdp/kStvqbaMk2HjYhH/5klrJhTrVY2YbzrKO6nMoOl991xrdPNgaq6m0+RlSJ9wNwvv7CSmVBqcN6AFLZl6pVE1nq9STs7BQU25C6j20EZwE+j3XzX89vJ8vNIUnHfDR67R+thpKpu72rf+WOAIYZ9m+NT+byuC3iU0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SLnSbl3i; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SLnSbl3i" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CDDEC4CEC5; Thu, 10 Oct 2024 05:48:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728539292; bh=krUOwXJLUN+fqjuerSUU4G59lOnIqgt4DUsd1Huazr0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SLnSbl3iPKsC+zuRAgOl0UFRkhwJ7CyV42pWlEvXEs6Q3UIbzgZs2hDq0fMz3mAuO 30Fb51X2Lux71loq4yvuSVav+a8BhB+QyksANcVvZ5JOGxR28eqv/lcZCnyHDLb7j8 02XwaSi7r2m/IGTEZZROImuskS7Tb6v1agj1V1edLmYyE1h62KQHGWEhOh2jBLlSZE DgTDezYfiEt60C4LBhuTJ08UhRA3WaSEcgxyMIi6p+TKs0b3XBdBL0Pl2ezSf9XydQ Go8AC6BCfJyF7e0G0S1BF0FE0PzxGRBFFpHBGldW7LmAf8MDqnRpF2/Vjy3QsnVVH6 ae00gg1QHyovQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 03/15] mptcp: reuse sending nlmsg code in get_addr Date: Thu, 10 Oct 2024 13:47:48 +0800 Message-ID: <9fda01ae94466616a138b94f91e4549d410e3a85.1728538976.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang With the previous commit, we can reuse the send_nlmsg() code in get_addr() interfaces between the netlink PM and userspace PM. They only need to implement their own get_addr() interfaces to hold the different locks, get the entry from the different lists, then release the locks. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 58 ++++++++++++++++++++-------------------- net/mptcp/pm_userspace.c | 33 ----------------------- 2 files changed, 29 insertions(+), 62 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 76c4520f7cb5..353878f64e8e 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1797,21 +1797,7 @@ static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_= pm_addr_entry *addr, { struct pm_nl_pernet *pernet =3D genl_info_pm_nl(info); struct mptcp_pm_addr_entry *entry; - struct sk_buff *msg; int ret =3D -EINVAL; - void *reply; - - msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); - if (!msg) - return -ENOMEM; - - reply =3D genlmsg_put_reply(msg, info, &mptcp_genl_family, 0, - info->genlhdr->cmd); - if (!reply) { - GENL_SET_ERR_MSG(info, "not enough space in Netlink message"); - ret =3D -EMSGSIZE; - goto fail; - } =20 spin_lock_bh(&pernet->lock); entry =3D __lookup_addr_by_id(pernet, id); @@ -1821,21 +1807,6 @@ static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_= pm_addr_entry *addr, } spin_unlock_bh(&pernet->lock); =20 - if (ret) { - GENL_SET_ERR_MSG(info, "address not found"); - goto fail; - } - - ret =3D mptcp_nl_fill_addr(msg, addr); - if (ret) - goto fail; - - genlmsg_end(msg, reply); - ret =3D genlmsg_reply(msg, info); - return ret; - -fail: - nlmsg_free(msg); return ret; } =20 @@ -1851,13 +1822,42 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, = struct genl_info *info) { struct nlattr *attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct mptcp_pm_addr_entry addr; + struct sk_buff *msg; + void *reply; int ret; =20 ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) return ret; =20 + msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + reply =3D genlmsg_put_reply(msg, info, &mptcp_genl_family, 0, + info->genlhdr->cmd); + if (!reply) { + GENL_SET_ERR_MSG(info, "not enough space in Netlink message"); + ret =3D -EMSGSIZE; + goto fail; + } + ret =3D mptcp_pm_get_addr(addr.addr.id, &addr, info); + if (ret) { + GENL_SET_ERR_MSG(info, "address not found"); + goto fail; + } + + ret =3D mptcp_nl_fill_addr(msg, &addr); + if (ret) + goto fail; + + genlmsg_end(msg, reply); + ret =3D genlmsg_reply(msg, info); + return ret; + +fail: + nlmsg_free(msg); return ret; } =20 diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 5c9f740bd9ac..4c4693c5aae9 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -634,10 +634,8 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm= _addr_entry *addr, { struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; - struct sk_buff *msg; int ret =3D -EINVAL; struct sock *sk; - void *reply; =20 msk =3D mptcp_userspace_pm_get_sock(info); if (!msk) @@ -645,20 +643,6 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm= _addr_entry *addr, =20 sk =3D (struct sock *)msk; =20 - msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); - if (!msg) { - ret =3D -ENOMEM; - goto out; - } - - reply =3D genlmsg_put_reply(msg, info, &mptcp_genl_family, 0, - info->genlhdr->cmd); - if (!reply) { - GENL_SET_ERR_MSG(info, "not enough space in Netlink message"); - ret =3D -EMSGSIZE; - goto fail; - } - lock_sock(sk); spin_lock_bh(&msk->pm.lock); entry =3D mptcp_userspace_pm_lookup_addr_by_id(msk, id); @@ -669,23 +653,6 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm= _addr_entry *addr, spin_unlock_bh(&msk->pm.lock); release_sock(sk); =20 - if (ret) { - GENL_SET_ERR_MSG(info, "address not found"); - goto fail; - } - - ret =3D mptcp_nl_fill_addr(msg, addr); - if (ret) - goto fail; - - genlmsg_end(msg, reply); - ret =3D genlmsg_reply(msg, info); - sock_put(sk); - return ret; - -fail: - nlmsg_free(msg); -out: sock_put(sk); return ret; } --=20 2.43.0 From nobody Sat Nov 23 10:34:17 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 4733E178372 for ; Thu, 10 Oct 2024 05:48:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539294; cv=none; b=lM0UDNzwhFSiXHoEzlDup/5IheyLYNxCi4yeWk9vJMaECrZFOHB/vpPIZRiKS3HLwl/iBB53G1jPpeOIk5NhwhmLjzWrlbTqkurvdeXTmDqMz7fAvr1ki8Fkb3fvTQ3lAnKZZJHCS1dSuSYQMlNgXx+L0Jl7P4clsZs3g4ghfdQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539294; c=relaxed/simple; bh=vJ2BY1wILGxIuUIk/rIufZZoVxSmrtgXkea5hC+dSf0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RMk67Sy9Hltv5255v06q/cBSSZ2Og/HI57oKaY87SdhawokFgRfFTiyIM+e5pgBcxXG/5kTXI3ySXzey59jvSVA0YUeC+wMJj+P3gnbMnnVwH3eVmID7SLHu2lM7osdQLUy8iVb/g6P2gt+5m9UEetMND5jrYsiMjNkRKMdlkgI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tTtKM1U7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tTtKM1U7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF451C4CEC5; Thu, 10 Oct 2024 05:48:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728539294; bh=vJ2BY1wILGxIuUIk/rIufZZoVxSmrtgXkea5hC+dSf0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tTtKM1U7Wu9+f06Qg9REvDmjQgnMeI3HhF5X6crqpZOSmc1UKVRJrjiLUDXEk4+ll hF6jzk3BK7x+LU31ieFdUNp9YCWXvtNIXxZisyvcv1GbZShyO8TdESKi4+A0tcB8ZT Kidv/362SBGTjR2JFzv7NcmabwTZgIB0wKxTiNouVHK0NzPc3JtOTDWt1RvEAWFpZO 1d1y2EKk3swsKxoImNiZS1gXEx6cIOi0T33OHOWK2VzWniLm0REnSL62KE3X40zGKI CeilH5+dvbxU9FWe6AEnGznsak28MKbBCkl0QF+DO0+qrwidgt5EUUjxT4kvbbQlIv E28ppMyVeob4g== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 04/15] mptcp: change info of get_addr as const Date: Thu, 10 Oct 2024 13:47:49 +0800 Message-ID: <6e7ce5e458e8703a93b71e345a696d4974ca0fdc.1728538976.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang get_addr() interfeces will be invoked by dump_addr(), which using const parameters "info", so this patch changes "info" parameters of get_addr() as const too. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 9 ++++++--- net/mptcp/pm_userspace.c | 2 +- net/mptcp/protocol.h | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 353878f64e8e..2888e4b303c0 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1793,12 +1793,15 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, } =20 static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, - struct genl_info *info) + const struct genl_info *info) { - struct pm_nl_pernet *pernet =3D genl_info_pm_nl(info); + struct net *net =3D genl_info_net(info); struct mptcp_pm_addr_entry *entry; + struct pm_nl_pernet *pernet; int ret =3D -EINVAL; =20 + pernet =3D pm_nl_get_pernet(net); + spin_lock_bh(&pernet->lock); entry =3D __lookup_addr_by_id(pernet, id); if (entry) { @@ -1811,7 +1814,7 @@ static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_p= m_addr_entry *addr, } =20 static int mptcp_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, - struct genl_info *info) + const struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) return mptcp_userspace_pm_get_addr(id, addr, info); diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 4c4693c5aae9..373ff0186bee 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -630,7 +630,7 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, } =20 int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, - struct genl_info *info) + const struct genl_info *info) { struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index e5319876c5f6..3b3a09f5d7fc 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1126,7 +1126,7 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *= msk, struct mptcp_addr_info int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, - struct genl_info *info); + const struct genl_info *info); =20 static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *= subflow) { --=20 2.43.0 From nobody Sat Nov 23 10:34:17 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2FCE118C03D for ; Thu, 10 Oct 2024 05:48:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539296; cv=none; b=gvmEeRd0qkOdvQvqEEVbAvrD+zZWCmH54MTyAlWuVkraWby4jcu7GknFa8j8c8xCQ9AEOt3C09WdrxnKXAbjyh23ZR6Ys6lNIQQjeQ6PmZg/LGUZICZW7l5OiZmPiqNipNa27kn0M0OHbP7IZrbuCXlP/RE5Q8z8uZxscyImSzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539296; c=relaxed/simple; bh=ljjUaWKZc+i/syNmXA6JKF/TvcFFrRPCv1RVTRgAjAE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B1nUtjICn42MJ5+TtUrITwxFK14Z39vECWvg7N2fwuEHLQrInhsF/NzZXLz8FfrED9aSUdi9NektR1vn10gkvckQnZTdD0TGxdb+XujkvtH4F/cPOnXZBEBumP5py0Jt38XB2aKu/oo0ETjcIQr+g24Cv5LIb5u1x75p93rJCmg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=R358iydt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="R358iydt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C170CC4CEC5; Thu, 10 Oct 2024 05:48:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728539296; bh=ljjUaWKZc+i/syNmXA6JKF/TvcFFrRPCv1RVTRgAjAE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R358iydtV+rK+i5sHZhXP9d7L3HqAktRoqok9K8NvsD9DP0zogPwEtji4qSYMwx4H Q77MDie1u1C9KBiWKhJpug5t7XYCtCi1PUWdv+l8nzdFJ0cuuRzCD9MsY+0T10cceB 3KfT4aTnxXtZ6yXyJisWu0SnItDrSa5SsWj81WhvcGg42KPKmKkvJ0j8Wbfly2MVAQ 2B9Ykro/maPe06xB6m83uXoGaUHLUAvfyWvRzzq66RHF1sUNwjRBHIv87ybfga9tU5 M5DYrCR8qnix5xaF8602SbgNUPjRdtlAtkieG+n4m3I/HoCm6kPRYORXhUdJ8iW0w0 z2nktjdOMP/zg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 05/15] mptcp: refactor dump_addr with id bitmap Date: Thu, 10 Oct 2024 13:47:50 +0800 Message-ID: <09fd7d78f9fbade68d72d1c1038fa476d47f7b50.1728538976.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang With the help of get_addr(), we can refactor dump_addr() interfaces to reuse send_nlmsg code between the netlink PM and userspace PM. The current dump_addr() flow looks like this: lock(); for_each_entry(entry) send_nlmsg(entry); unlock(); After holding the lock, get every entry by walking the address list, send each one looply, and finally release the lock. This set changes the process by copying the address list to an id bitmap while holding the lock, then release the lock immediately. After that, without locking, walking the copied id bitmap to get every copy of entry by using get_addr(), and send each one looply. This patch is the first part of refactoring dump_addr(). Without changing the position of the locks, the dump process is split into two parts: copying the ID bitmap first, and then traversing the ID bitmap, use lookup_addr_by_id() to get the entry, then send each one through nlmsg: lock(); for_each_entry(entry) set_bit(bitmap); for_each_bit(bitmap) { entry =3D lookup_addr_by_id(); send_nlmsg(entry); } unlock(); Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 6 ++++- net/mptcp/pm_userspace.c | 54 +++++++++++++++++++++++++++++----------- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 2888e4b303c0..9a544cf47a2b 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1869,16 +1869,20 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *ms= g, { struct net *net =3D sock_net(msg->sk); struct mptcp_pm_addr_entry *entry; + struct mptcp_id_bitmap *bitmap; struct pm_nl_pernet *pernet; int id =3D cb->args[0]; void *hdr; int i; =20 + bitmap =3D (struct mptcp_id_bitmap *)cb->ctx; pernet =3D pm_nl_get_pernet(net); =20 spin_lock_bh(&pernet->lock); + if (!id) + bitmap_copy(bitmap->map, pernet->id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1= ); for (i =3D id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { - if (test_bit(i, pernet->id_bitmap.map)) { + if (test_bit(i, bitmap->map)) { entry =3D __lookup_addr_by_id(pernet, i); if (!entry) break; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 373ff0186bee..2f1afb719ecf 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -582,6 +582,21 @@ int mptcp_userspace_pm_set_flags(struct genl_info *inf= o) return ret; } =20 +static int mptcp_userspace_pm_set_bitmap(struct mptcp_sock *msk, + struct mptcp_id_bitmap *bitmap) +{ + struct mptcp_pm_addr_entry *entry; + + list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { + if (test_bit(entry->addr.id, bitmap->map)) + continue; + + __set_bit(entry->addr.id, bitmap->map); + } + + return 0; +} + int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) { @@ -589,9 +604,11 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct mptcp_pm_addr_entry *entry; struct mptcp_id_bitmap *bitmap; struct mptcp_sock *msk; + int id =3D cb->args[0]; int ret =3D -EINVAL; struct sock *sk; void *hdr; + int i; =20 bitmap =3D (struct mptcp_id_bitmap *)cb->ctx; =20 @@ -603,24 +620,33 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, =20 lock_sock(sk); spin_lock_bh(&msk->pm.lock); - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { - if (test_bit(entry->addr.id, bitmap->map)) - continue; + if (!id) + ret =3D mptcp_userspace_pm_set_bitmap(msk, bitmap); + for (i =3D id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { + if (test_bit(i, bitmap->map)) { + entry =3D mptcp_userspace_pm_lookup_addr_by_id(msk, i); + if (!entry) + break; + + if (id && entry->addr.id <=3D id) + continue; =20 - hdr =3D genlmsg_put(msg, NETLINK_CB(cb->skb).portid, - cb->nlh->nlmsg_seq, &mptcp_genl_family, - NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR); - if (!hdr) - break; + hdr =3D genlmsg_put(msg, NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, &mptcp_genl_family, + NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR); + if (!hdr) + break; =20 - if (mptcp_nl_fill_addr(msg, entry) < 0) { - genlmsg_cancel(msg, hdr); - break; - } + if (mptcp_nl_fill_addr(msg, entry) < 0) { + genlmsg_cancel(msg, hdr); + break; + } =20 - __set_bit(entry->addr.id, bitmap->map); - genlmsg_end(msg, hdr); + id =3D entry->addr.id; + genlmsg_end(msg, hdr); + } } + cb->args[0] =3D id; spin_unlock_bh(&msk->pm.lock); release_sock(sk); ret =3D msg->len; --=20 2.43.0 From nobody Sat Nov 23 10:34:17 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6CE2319ADBF for ; Thu, 10 Oct 2024 05:48:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539298; cv=none; b=Fszpb9H9ke4KfUvGeM0z0iYOj90bV8ZQQ41lm15F5egac0sq2MlW6on6iP4dG3yeEegJSUMsoVKzVpMqpFzKCKmmSm8XgKDba4EnKkesNdlPV+9xB+PA43PziwzfXOVDBGrSi999DnhufU18dxgJveVtzc4IIHpNsFtRZNwfxbE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539298; c=relaxed/simple; bh=w8uVBfMMFSk91XeX7WkJKvpb8039kHGiurzZGYVCqHE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lz3nb7oGUFNZAF+mSlOIMTgqLurXdijVU52J6Qq+x6cQ6dZZdUAKRQDbKkj4PMFKpotum2oFLxCY0uJhx/LQics38R/lkGHcJssDXpoPvXgb618dyjWFGlcSaH0DeivM38Bam7w7YVLX9ttOKtK9gGlMI28ZxtjvIGigGVA3o8A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=geSvcLjB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="geSvcLjB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6C75C4CEC5; Thu, 10 Oct 2024 05:48:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728539298; bh=w8uVBfMMFSk91XeX7WkJKvpb8039kHGiurzZGYVCqHE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=geSvcLjBjt/pEMoLBSsQOGqUCDYC5PLsPe85DCpIm5e9gSoHn1LJPRsjqEYz8EWWJ pYWUljgrZIRipIdSaaTlXdnqMeeuYFmkvd7QAdfEZrNiv8NoDU5j5yAXps2l01XetI PhKAM4mCFyzieMJ2+hwR/6dng1MQfQzFFWAjHqAgWNSWAgegmiGgF9Qeau+KZOu0AW 5NrF/Ew6Tm5L/UjSEFH19qRej3toL2nRhv3+0wfw0Z5GzjH+NK47M6aHRy5oEBacsu PWFK6OQKlFP+UT4lFCYbppInlYjFEG1e1zAHy4gNIcirST7SSscku01ZzBL07UChNA 3/gbBeUnxkt1g== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 06/15] mptcp: refactor dump_addr with get_addr Date: Thu, 10 Oct 2024 13:47:51 +0800 Message-ID: <5e5ca655f0559b196812b9a9fb0870c1a6938f9b.1728538976.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang This patch is the second part of refactoring dump_addr(). With the help of get_addr(), only copy the address list to an id bitmap while holding the lock, then release the lock immediately. After that, without locking, walking the copied id bitmap to get every copy of entry by using get_addr(), and send each one looply: lock(); for_each_entry(entry) set_bit(bitmap); unlock(); for_each_bit(bitmap) { copy =3D get_addr(); send_nlmsg(copy); } Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 20 +++++++++++--------- net/mptcp/pm_userspace.c | 23 ++++++++++++----------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 9a544cf47a2b..0d6e444a9f83 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1867,8 +1867,9 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, st= ruct genl_info *info) static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) { + const struct genl_info *info =3D genl_info_dump(cb); struct net *net =3D sock_net(msg->sk); - struct mptcp_pm_addr_entry *entry; + struct mptcp_pm_addr_entry entry; struct mptcp_id_bitmap *bitmap; struct pm_nl_pernet *pernet; int id =3D cb->args[0]; @@ -1878,16 +1879,18 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *ms= g, bitmap =3D (struct mptcp_id_bitmap *)cb->ctx; pernet =3D pm_nl_get_pernet(net); =20 - spin_lock_bh(&pernet->lock); - if (!id) + if (!id) { + spin_lock_bh(&pernet->lock); bitmap_copy(bitmap->map, pernet->id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1= ); + spin_unlock_bh(&pernet->lock); + } + for (i =3D id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { if (test_bit(i, bitmap->map)) { - entry =3D __lookup_addr_by_id(pernet, i); - if (!entry) + if (mptcp_pm_nl_get_addr(i, &entry, info)) break; =20 - if (entry->addr.id <=3D id) + if (entry.addr.id <=3D id) continue; =20 hdr =3D genlmsg_put(msg, NETLINK_CB(cb->skb).portid, @@ -1896,16 +1899,15 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *ms= g, if (!hdr) break; =20 - if (mptcp_nl_fill_addr(msg, entry) < 0) { + if (mptcp_nl_fill_addr(msg, &entry) < 0) { genlmsg_cancel(msg, hdr); break; } =20 - id =3D entry->addr.id; + id =3D entry.addr.id; genlmsg_end(msg, hdr); } } - spin_unlock_bh(&pernet->lock); =20 cb->args[0] =3D id; return msg->len; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 2f1afb719ecf..ad011a4fad4e 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -601,7 +601,7 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) { const struct genl_info *info =3D genl_info_dump(cb); - struct mptcp_pm_addr_entry *entry; + struct mptcp_pm_addr_entry entry; struct mptcp_id_bitmap *bitmap; struct mptcp_sock *msk; int id =3D cb->args[0]; @@ -618,17 +618,20 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, =20 sk =3D (struct sock *)msk; =20 - lock_sock(sk); - spin_lock_bh(&msk->pm.lock); - if (!id) + if (!id) { + lock_sock(sk); + spin_lock_bh(&msk->pm.lock); ret =3D mptcp_userspace_pm_set_bitmap(msk, bitmap); + spin_unlock_bh(&msk->pm.lock); + release_sock(sk); + } + for (i =3D id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { if (test_bit(i, bitmap->map)) { - entry =3D mptcp_userspace_pm_lookup_addr_by_id(msk, i); - if (!entry) + if (mptcp_userspace_pm_get_addr(i, &entry, info)) break; =20 - if (id && entry->addr.id <=3D id) + if (id && entry.addr.id <=3D id) continue; =20 hdr =3D genlmsg_put(msg, NETLINK_CB(cb->skb).portid, @@ -637,18 +640,16 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, if (!hdr) break; =20 - if (mptcp_nl_fill_addr(msg, entry) < 0) { + if (mptcp_nl_fill_addr(msg, &entry) < 0) { genlmsg_cancel(msg, hdr); break; } =20 - id =3D entry->addr.id; + id =3D entry.addr.id; genlmsg_end(msg, hdr); } } cb->args[0] =3D id; - spin_unlock_bh(&msk->pm.lock); - release_sock(sk); ret =3D msg->len; =20 sock_put(sk); --=20 2.43.0 From nobody Sat Nov 23 10:34:17 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2958C1925AF for ; Thu, 10 Oct 2024 05:48:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539300; cv=none; b=F2uqJheFydYtFM4WHUSBYMqwpQG14Er16I+trbcwu8BaJIhp4+z6zeZ/5xyuiBRI4Y99Jt49wfzABSYesX1JJlX5YvF7txcm0JPyo//wE3g05s46zHOXRC1BnNk4YZu3cuwq0n7meDP/3mBPHUO4MIrbJ8oc+38PuVEreEHO388= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539300; c=relaxed/simple; bh=G8+tUJAR725LeI32UIOej8rBnSQ+X+JipgfcuSo/ELo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r8ql3vqlCWz+0cxGVU4XDKUmmGt/a3k0Sa6jP1lqt7xTb8/arNZ0g4CdSXpHrmjXyyJlGedgnxm6P8nIwUdnn9Wec5XEfCOouxFVpKDc8WDtZRZurV8uE9Xpe59MvqO7Ub6OumDppqRq890JiF7hA1Ut1Cq///gnXxztOMS+iHo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=d8kNfzJC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="d8kNfzJC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A74DFC4CEC5; Thu, 10 Oct 2024 05:48:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728539299; bh=G8+tUJAR725LeI32UIOej8rBnSQ+X+JipgfcuSo/ELo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d8kNfzJCmItWO85BrW53h7Lt4p4qth7MFzgriDibQf3EM6QJK3v0MptawbIklMiuu DG3A8zkEyRoFgmlp9r85Fmhkgx43daq7fkXFG15EOvWr9TGtwdZdtwMXBzJt7plEYN eKrQCNkViwNe//8NVkIErlbZ5ijG6eXP/PaqO9pVG0jTyIBONGpzwKM1UX2lk/kIwk gz8hEa4JWdFN6bZsU7y2WUzlK7Ad5q4V+nHDWvWqswBnMQTpbt9kFK+E6vJ2fSE756 8wn54EsdMXD4aFNRHQuMZukpWQiNGzOGa086TdV4+jVVBei6862boC7HHkucOu8KQ6 sYkThJOJ9VKaA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 07/15] mptcp: reuse sending nlmsg code in dump_addr Date: Thu, 10 Oct 2024 13:47:52 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang With the previous commit, we can reuse the send_nlmsg() code in dump_addr interfaces between the netlink PM and userspace PM. They only need to implement their own dump_addr() interfaces to hold the different locks, copy the different address lists to an id bitmap, then release the locks. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 56 +++++++++++++++++++++------------------- net/mptcp/pm_userspace.c | 50 +++++------------------------------ net/mptcp/protocol.h | 4 +-- 3 files changed, 38 insertions(+), 72 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 0d6e444a9f83..0309f7dbd23b 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1864,33 +1864,50 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, = struct genl_info *info) return ret; } =20 -static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb) +static int mptcp_pm_nl_dump_addr(struct mptcp_id_bitmap *bitmap, + const struct genl_info *info) +{ + struct net *net =3D genl_info_net(info); + struct pm_nl_pernet *pernet; + + pernet =3D pm_nl_get_pernet(net); + + spin_lock_bh(&pernet->lock); + bitmap_copy(bitmap->map, pernet->id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); + spin_unlock_bh(&pernet->lock); + + return 0; +} + +static int mptcp_pm_dump_addr(struct mptcp_id_bitmap *bitmap, + const struct genl_info *info) +{ + if (info->attrs[MPTCP_PM_ATTR_TOKEN]) + return mptcp_userspace_pm_dump_addr(bitmap, info); + return mptcp_pm_nl_dump_addr(bitmap, info); +} + +int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg, + struct netlink_callback *cb) { const struct genl_info *info =3D genl_info_dump(cb); - struct net *net =3D sock_net(msg->sk); struct mptcp_pm_addr_entry entry; struct mptcp_id_bitmap *bitmap; - struct pm_nl_pernet *pernet; int id =3D cb->args[0]; void *hdr; int i; =20 bitmap =3D (struct mptcp_id_bitmap *)cb->ctx; - pernet =3D pm_nl_get_pernet(net); =20 - if (!id) { - spin_lock_bh(&pernet->lock); - bitmap_copy(bitmap->map, pernet->id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1= ); - spin_unlock_bh(&pernet->lock); - } + if (!id) + mptcp_pm_dump_addr(bitmap, info); =20 for (i =3D id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { if (test_bit(i, bitmap->map)) { - if (mptcp_pm_nl_get_addr(i, &entry, info)) + if (mptcp_pm_get_addr(i, &entry, info)) break; =20 - if (entry.addr.id <=3D id) + if (id && entry.addr.id <=3D id) continue; =20 hdr =3D genlmsg_put(msg, NETLINK_CB(cb->skb).portid, @@ -1913,21 +1930,6 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, return msg->len; } =20 -static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback= *cb) -{ - const struct genl_info *info =3D genl_info_dump(cb); - - if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_dump_addr(msg, cb); - return mptcp_pm_nl_dump_addr(msg, cb); -} - -int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg, - struct netlink_callback *cb) -{ - return mptcp_pm_dump_addr(msg, cb); -} - static int parse_limit(struct genl_info *info, int id, unsigned int *limit) { struct nlattr *attr =3D info->attrs[id]; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index ad011a4fad4e..8858877d82b0 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -597,20 +597,12 @@ static int mptcp_userspace_pm_set_bitmap(struct mptcp= _sock *msk, return 0; } =20 -int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb) +int mptcp_userspace_pm_dump_addr(struct mptcp_id_bitmap *bitmap, + const struct genl_info *info) { - const struct genl_info *info =3D genl_info_dump(cb); - struct mptcp_pm_addr_entry entry; - struct mptcp_id_bitmap *bitmap; struct mptcp_sock *msk; - int id =3D cb->args[0]; int ret =3D -EINVAL; struct sock *sk; - void *hdr; - int i; - - bitmap =3D (struct mptcp_id_bitmap *)cb->ctx; =20 msk =3D mptcp_userspace_pm_get_sock(info); if (!msk) @@ -618,39 +610,11 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, =20 sk =3D (struct sock *)msk; =20 - if (!id) { - lock_sock(sk); - spin_lock_bh(&msk->pm.lock); - ret =3D mptcp_userspace_pm_set_bitmap(msk, bitmap); - spin_unlock_bh(&msk->pm.lock); - release_sock(sk); - } - - for (i =3D id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { - if (test_bit(i, bitmap->map)) { - if (mptcp_userspace_pm_get_addr(i, &entry, info)) - break; - - if (id && entry.addr.id <=3D id) - continue; - - hdr =3D genlmsg_put(msg, NETLINK_CB(cb->skb).portid, - cb->nlh->nlmsg_seq, &mptcp_genl_family, - NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR); - if (!hdr) - break; - - if (mptcp_nl_fill_addr(msg, &entry) < 0) { - genlmsg_cancel(msg, hdr); - break; - } - - id =3D entry.addr.id; - genlmsg_end(msg, hdr); - } - } - cb->args[0] =3D id; - ret =3D msg->len; + lock_sock(sk); + spin_lock_bh(&msk->pm.lock); + ret =3D mptcp_userspace_pm_set_bitmap(msk, bitmap); + spin_unlock_bh(&msk->pm.lock); + release_sock(sk); =20 sock_put(sk); return ret; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 3b3a09f5d7fc..d8870ba24d02 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1123,8 +1123,8 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock= *msk, struct mptcp_addr_in bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc); bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info = *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_add= r_info *skc); -int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb); +int mptcp_userspace_pm_dump_addr(struct mptcp_id_bitmap *bitmap, + const struct genl_info *info); int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, const struct genl_info *info); =20 --=20 2.43.0 From nobody Sat Nov 23 10:34:17 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 55762178372 for ; Thu, 10 Oct 2024 05:48:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539302; cv=none; b=Omg5WlNxC1mOMYGXBBaucoPZQ5xL6q58gzu00qvBIEfDL1kEhvW1BtwDfulKvlIsMCb3EIc+gSjtGGZhmE/0q9IuupFopKyV+xZVWQ+QdmDvgrC69kREbk169WuzA3z2a3ICWPu/TelVqf4fsiUDrESsKAPwqqbf/+I9TFc5VOU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539302; c=relaxed/simple; bh=u33sk5osIycHjfP9lOjfe8RW0Fp0teGMDc5JzCiKyoQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IslBRNO1xH0LuTn93bLaIx3ch3D8FZzO9oSsNGziKaCxSRbLY4YpyqIGgimOSGRPtX1bollyjyK8k4aJyQTq37V/7xh/RRoagwjvoVrF7sI+VRu1zW65lmBgkoYGpwLp6AhfKFC9MdYYdCroW0ZB4qrmSspTgbbC2pGgWMizgXc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TKF0Wipm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TKF0Wipm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5933C4CEC5; Thu, 10 Oct 2024 05:48:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728539301; bh=u33sk5osIycHjfP9lOjfe8RW0Fp0teGMDc5JzCiKyoQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TKF0Wipm+/zzlkWkTdCX326gIaXUv1ILCzgcf1F56kV80YsyXEFGCGH5CMdtSsU1H L3vBhi6oPekxbUsco6cOdIRKcbASS1tDNIqUeeGOvVT1zvrcT0Qp1WuxTXM5C2wfqm /6jbbEtYYJwJrjFcJegE7EgmWJazePQkm+ksYK2HGofYv3UCFCIfZa0f+/unlo4+4c 1R40D2L9IvsqmI4ESJG9tdzotrzlReSzcsadfdjbJ9zRkYIuNHDnYGLtupf/OojieA /vLufffzavodSPKS8dlqIMqcA0OtLx/UjqveZxCXMINlnH/baaDAJ4+H7ZTMDkohev MHt3XQKgx9THA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 08/15] mptcp: add loc and rem for set_flags Date: Thu, 10 Oct 2024 13:47:53 +0800 Message-ID: <9c827661f3ea58adf238c4bd2912cbe7212f579c.1728538976.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang This patch updates the interfaces set_flags to reduce repetitive code, adds two more parameters "loc" and "rem" for them. These addresses are parsed in public helper mptcp_pm_nl_set_flags_doit(), then pass them to mptcp_pm_nl_set_flags() and mptcp_userspace_pm_set_flags(). Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 38 ++++++++++++++++++++++++++------------ net/mptcp/pm_userspace.c | 26 +++++++------------------- net/mptcp/protocol.h | 4 +++- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 0309f7dbd23b..96d7ccb355ae 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -2045,25 +2045,21 @@ static int mptcp_nl_set_flags(struct net *net, return ret; } =20 -static int mptcp_pm_nl_set_flags(struct genl_info *info) +static int mptcp_pm_nl_set_flags(struct mptcp_pm_addr_entry *loc, + struct mptcp_addr_info *rem, + struct genl_info *info) { - struct mptcp_pm_addr_entry addr =3D { .addr =3D { .family =3D AF_UNSPEC }= , }; - struct nlattr *attr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; u8 changed, mask =3D MPTCP_PM_ADDR_FLAG_BACKUP | MPTCP_PM_ADDR_FLAG_FULLMESH; + struct mptcp_pm_addr_entry addr =3D *loc; struct net *net =3D genl_info_net(info); struct mptcp_pm_addr_entry *entry; struct pm_nl_pernet *pernet; u8 lookup_by_id =3D 0; u8 bkup =3D 0; - int ret; =20 pernet =3D pm_nl_get_pernet(net); =20 - ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); - if (ret < 0) - return ret; - if (addr.addr.family =3D=3D AF_UNSPEC) { lookup_by_id =3D 1; if (!addr.addr.id) { @@ -2099,16 +2095,34 @@ static int mptcp_pm_nl_set_flags(struct genl_info *= info) return 0; } =20 -static int mptcp_pm_set_flags(struct genl_info *info) +static int mptcp_pm_set_flags(struct mptcp_pm_addr_entry *loc, + struct mptcp_addr_info *rem, + struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_set_flags(info); - return mptcp_pm_nl_set_flags(info); + return mptcp_userspace_pm_set_flags(loc, rem, info); + return mptcp_pm_nl_set_flags(loc, rem, info); } =20 int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info) { - return mptcp_pm_set_flags(info); + struct mptcp_pm_addr_entry loc =3D { .addr =3D { .family =3D AF_UNSPEC },= }; + struct nlattr *attr_rem =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; + struct nlattr *attr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; + struct mptcp_addr_info rem =3D { .family =3D AF_UNSPEC, }; + int ret; + + ret =3D mptcp_pm_parse_entry(attr, info, false, &loc); + if (ret < 0) + return ret; + + if (attr_rem) { + ret =3D mptcp_pm_parse_addr(attr_rem, info, &rem); + if (ret < 0) + return ret; + } + + return mptcp_pm_set_flags(&loc, &rem, info); } =20 static void mptcp_nl_mcast_send(struct net *net, struct sk_buff *nlskb, gf= p_t gfp) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 8858877d82b0..5175c30bcd64 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -536,12 +536,10 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *= skb, struct genl_info *info return err; } =20 -int mptcp_userspace_pm_set_flags(struct genl_info *info) +int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *loc, + struct mptcp_addr_info *rem, + struct genl_info *info) { - struct mptcp_pm_addr_entry loc =3D { .addr =3D { .family =3D AF_UNSPEC },= }; - struct nlattr *attr_rem =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *attr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; - struct mptcp_addr_info rem =3D { .family =3D AF_UNSPEC, }; struct mptcp_sock *msk; int ret =3D -EINVAL; struct sock *sk; @@ -553,28 +551,18 @@ int mptcp_userspace_pm_set_flags(struct genl_info *in= fo) =20 sk =3D (struct sock *)msk; =20 - ret =3D mptcp_pm_parse_entry(attr, info, false, &loc); - if (ret < 0) - goto set_flags_err; - - if (attr_rem) { - ret =3D mptcp_pm_parse_addr(attr_rem, info, &rem); - if (ret < 0) - goto set_flags_err; - } - - if (loc.addr.family =3D=3D AF_UNSPEC || - rem.family =3D=3D AF_UNSPEC) { + if (loc->addr.family =3D=3D AF_UNSPEC || + rem->family =3D=3D AF_UNSPEC) { GENL_SET_ERR_MSG(info, "invalid address families"); ret =3D -EINVAL; goto set_flags_err; } =20 - if (loc.flags & MPTCP_PM_ADDR_FLAG_BACKUP) + if (loc->flags & MPTCP_PM_ADDR_FLAG_BACKUP) bkup =3D 1; =20 lock_sock(sk); - ret =3D mptcp_pm_nl_mp_prio_send_ack(msk, &loc.addr, &rem, bkup); + ret =3D mptcp_pm_nl_mp_prio_send_ack(msk, &loc->addr, rem, bkup); release_sock(sk); =20 set_flags_err: diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index d8870ba24d02..742a35d41cdd 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1033,7 +1033,9 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk, struct mptcp_pm_add_entry * mptcp_lookup_anno_list_by_saddr(const struct mptcp_sock *msk, const struct mptcp_addr_info *addr); -int mptcp_userspace_pm_set_flags(struct genl_info *info); +int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *loc, + struct mptcp_addr_info *rem, + struct genl_info *info); int mptcp_pm_announce_addr(struct mptcp_sock *msk, const struct mptcp_addr_info *addr, bool echo); --=20 2.43.0 From nobody Sat Nov 23 10:34:17 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C9B7C178372 for ; Thu, 10 Oct 2024 05:48:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539303; cv=none; b=MjKDUlQdYb72Y66BFZSw/bD8JaI+SQ92ZtTHCgwAN9CsY3lcUp1FcoM2gFb2bpozEzQkKXOiv8VwktjUvbyFjbsqrL1ceHlbgR2CLKSYBGLrybrhC0KP9V/9UGHa/gFT5nXgGDTI80OPbFIfePwVbyR0nDtkyLes9L3smRYiGeU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539303; c=relaxed/simple; bh=cGLX3jY4KBrI+++SKyxHmbhuZiJJEVgem0RqbjscISE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gKWe4wCKSC3p4wsUeEjkK9F32z+vunIhgDW9OpbxPr4ncsW9NI7FF6RLo/xwSmFZlNPG4Vjunnd4oS9doSaCBSek5Nfr8alp1x+PFVn/pqU9iQULrQfXRYZ2hqgWzfwOkEHtVYZbs8+zs8Px4RgOwimHiQkPqBJgJZE1FLsX4z4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cZ7lOK7E; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cZ7lOK7E" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75139C4CEC6; Thu, 10 Oct 2024 05:48:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728539303; bh=cGLX3jY4KBrI+++SKyxHmbhuZiJJEVgem0RqbjscISE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cZ7lOK7EhGkuuUyc56ACTzO5rcHYOKh6UGq5/7ccKyE0rukY9JT14FIIVhtre+HF/ NnyNW6whFKvoxTM4XCoEfAdq9FEaLQWs57gBKgIy8U7ZQyrRqqfSmdYEvWC8Ag70vh yviSMg7xtRXkmf9ksFVq8xnBYeDoJOycDCKG1b4H0M/7qoYzAzCrxWt8tPBaAoG5Or KP31oldd3e2oMwxcjKOxg7xfrgtOnf3WWhPZ+Rlr7YNlIMzwC5aC7OH6wqI/p3JAhw 1uuDxL3D9phcFd+iqmou5ho5uBi/0zQLgEly4eg4VS9dDTsoX+cBeanUM9apnrpaw8 TojErDoV6FO0w== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 09/15] mptcp: update address type of get_local_id Date: Thu, 10 Oct 2024 13:47:54 +0800 Message-ID: <6d5df01f8db9857078c89197135cb385e5adb1f1.1728538976.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang The following code in mptcp_userspace_pm_get_local_id() that assigns "skc" to "new_entry" is not allowed in BPF if we use the same code to implement the get_local_id() interface of a BFP path manager: memset(&new_entry, 0, sizeof(struct mptcp_pm_addr_entry)); new_entry.addr =3D *skc; new_entry.addr.id =3D 0; new_entry.flags =3D MPTCP_PM_ADDR_FLAG_IMPLICIT; To solve the issue, this patch moves this assignment to "new_entry" forward to mptcp_pm_get_local_id(), and then passing "new_entry" as a parameter to both mptcp_pm_nl_get_local_id() and mptcp_userspace_pm_get_local_id(). Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 10 ++++++++-- net/mptcp/pm_netlink.c | 11 +++-------- net/mptcp/pm_userspace.c | 17 ++++++----------- net/mptcp/protocol.h | 4 ++-- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index c051c1ec4de4..4046e6727cb6 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -404,6 +404,7 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struc= t sock_common *skc) { struct mptcp_addr_info skc_local; struct mptcp_addr_info msk_local; + struct mptcp_pm_addr_entry local; =20 if (WARN_ON_ONCE(!msk)) return -1; @@ -416,9 +417,14 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, stru= ct sock_common *skc) if (mptcp_addresses_equal(&msk_local, &skc_local, false)) return 0; =20 + memset(&local, 0, sizeof(struct mptcp_pm_addr_entry)); + local.addr =3D skc_local; + local.addr.id =3D 0; + local.flags =3D MPTCP_PM_ADDR_FLAG_IMPLICIT; + if (mptcp_pm_is_userspace(msk)) - return mptcp_userspace_pm_get_local_id(msk, &skc_local); - return mptcp_pm_nl_get_local_id(msk, &skc_local); + return mptcp_userspace_pm_get_local_id(msk, &local); + return mptcp_pm_nl_get_local_id(msk, &local); } =20 bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 96d7ccb355ae..f42bc6bb19fa 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1137,7 +1137,7 @@ static int mptcp_pm_nl_create_listen_socket(struct so= ck *sk, return err; } =20 -int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_inf= o *skc) +int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr_= entry *local) { struct mptcp_pm_addr_entry *entry; struct pm_nl_pernet *pernet; @@ -1146,7 +1146,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, = struct mptcp_addr_info *skc pernet =3D pm_nl_get_pernet_from_msk(msk); =20 rcu_read_lock(); - entry =3D __lookup_addr(pernet, skc); + entry =3D __lookup_addr(pernet, &local->addr); if (entry) ret =3D entry->addr.id; rcu_read_unlock(); @@ -1158,12 +1158,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk,= struct mptcp_addr_info *skc if (!entry) return -ENOMEM; =20 - entry->addr =3D *skc; - entry->addr.id =3D 0; - entry->addr.port =3D 0; - entry->ifindex =3D 0; - entry->flags =3D MPTCP_PM_ADDR_FLAG_IMPLICIT; - entry->lsk =3D NULL; + *entry =3D *local; ret =3D mptcp_pm_nl_append_new_local_addr(pernet, entry, true); if (ret < 0) kfree(entry); diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 5175c30bcd64..6685c76fe151 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -131,27 +131,22 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_soc= k *msk, unsigned int id) } =20 int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, - struct mptcp_addr_info *skc) + struct mptcp_pm_addr_entry *local) { - struct mptcp_pm_addr_entry *entry =3D NULL, new_entry; + struct mptcp_pm_addr_entry *entry =3D NULL; __be16 msk_sport =3D ((struct inet_sock *) inet_sk((struct sock *)msk))->inet_sport; =20 spin_lock_bh(&msk->pm.lock); - entry =3D mptcp_userspace_pm_lookup_addr(msk, skc); + entry =3D mptcp_userspace_pm_lookup_addr(msk, &local->addr); spin_unlock_bh(&msk->pm.lock); if (entry) return entry->addr.id; =20 - memset(&new_entry, 0, sizeof(struct mptcp_pm_addr_entry)); - new_entry.addr =3D *skc; - new_entry.addr.id =3D 0; - new_entry.flags =3D MPTCP_PM_ADDR_FLAG_IMPLICIT; - - if (new_entry.addr.port =3D=3D msk_sport) - new_entry.addr.port =3D 0; + if (local->addr.port =3D=3D msk_sport) + local->addr.port =3D 0; =20 - return mptcp_userspace_pm_append_new_local_addr(msk, &new_entry, true); + return mptcp_userspace_pm_append_new_local_addr(msk, local, true); } =20 bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 742a35d41cdd..767da3cb43cb 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1120,8 +1120,8 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk,= const struct sk_buff *skb, bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remainin= g, struct mptcp_rm_list *rm_list); int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc); -int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_inf= o *skc); -int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_a= ddr_info *skc); +int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr_= entry *local); +int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_p= m_addr_entry *local); bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc); bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info = *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_add= r_info *skc); --=20 2.43.0 From nobody Sat Nov 23 10:34:17 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 336A418C03D for ; Thu, 10 Oct 2024 05:48:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539305; cv=none; b=YzB7V0f7c6LaBGtWQJ75vfXJ2nbIrXDa1vWMB3V3Eph3CAxBhCIBbaaNgafJydH32P6JyRJeqB2aEUArre5s4X6jGMfpv00Rnw6n5lKXt7ET8FbvIUF9/4+58u48AWpr3SaooZHS4cSehSnIzoQhMkjaoc+65z3RjuTJEPIIZhE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539305; c=relaxed/simple; bh=rlqY/0Zv4hvalp6tJ7Ebi9dCAPy875VloLxigP6tC+k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cu6Pr5lsxq1XEatTc/c7xoRGnu7KA6DjkbwW15T9Xa8agfWqqD25stg94yosBy7awgcqJGygKUe18IXofnVMdG2vRD09agi2pvfRp9jG0M/WQWDdYkxMrgbSP0m4dL7gDixuW3WdRMUKGPv4n2mNJrxr1DeMEgTitDsFt0n40KQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sMvtM5Jc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sMvtM5Jc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBA11C4CEC5; Thu, 10 Oct 2024 05:48:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728539305; bh=rlqY/0Zv4hvalp6tJ7Ebi9dCAPy875VloLxigP6tC+k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sMvtM5JcTqwtcxNBVhdq0JNEsqAh/9oWQxZZgZ8IWXNikVLt221nkbZ/ey1X7cUXN MPKDnOcFcOzk1UL7/9rFqZE2a/KkpyON7flOYyWMowYvKIOjPFrVoUkYscsg7lw33o 2qp/CqSE+rWDnS/dQMm+/oIvWvc9Hi4Pgvg0vMd4IHUCKxb2UKKWMXMQD21/f5S+e9 Awph+mYmAgyku3fvHd48B/zXJCwzmc+FSGZrHwGXXCYAlmYPWH7aDnfauAUeLBnUWp PtP3MQJZz+RlOem8t9k5DFzPFbFc3f711MA+Vuhe/UACkdgkdCVbFoa0KrPUv84luv 01OdTPA516lag== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 10/15] mptcp: change is_backup interfaces as get_flags Date: Thu, 10 Oct 2024 13:47:55 +0800 Message-ID: <33f7ebb53d3195278d42c7b43f5d286e9ea40b4c.1728538976.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang The is_backup() interface of path manager is not very common. A more common approach is to add a get_flags() interface to obtain the flags value of a given address. Then is_backup() can be implemented through get_flags() by test whether backup flag is set in the flags value. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 7 +++++-- net/mptcp/pm_netlink.c | 8 ++++---- net/mptcp/pm_userspace.c | 10 +++++----- net/mptcp/protocol.h | 4 ++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 4046e6727cb6..d2ddf467dcce 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -430,13 +430,16 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, str= uct sock_common *skc) bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc) { struct mptcp_addr_info skc_local; + u8 flags; =20 mptcp_local_address((struct sock_common *)skc, &skc_local); =20 if (mptcp_pm_is_userspace(msk)) - return mptcp_userspace_pm_is_backup(msk, &skc_local); + flags =3D mptcp_userspace_pm_get_flags(msk, &skc_local); + else + flags =3D mptcp_pm_nl_get_flags(msk, &skc_local); =20 - return mptcp_pm_nl_is_backup(msk, &skc_local); + return !!(flags & MPTCP_PM_ADDR_FLAG_BACKUP); } =20 void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock = *ssk) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index f42bc6bb19fa..38168eb6d4a0 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1166,19 +1166,19 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk= , struct mptcp_pm_addr_entry return ret; } =20 -bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info = *skc) +u8 mptcp_pm_nl_get_flags(struct mptcp_sock *msk, struct mptcp_addr_info *s= kc) { struct pm_nl_pernet *pernet =3D pm_nl_get_pernet_from_msk(msk); struct mptcp_pm_addr_entry *entry; - bool backup =3D false; + u8 flags =3D 0; =20 rcu_read_lock(); entry =3D __lookup_addr(pernet, skc); if (entry) - backup =3D !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); + flags =3D entry->flags; rcu_read_unlock(); =20 - return backup; + return flags; } =20 #define MPTCP_PM_CMD_GRP_OFFSET 0 diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 6685c76fe151..50b1aea7a719 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -149,19 +149,19 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock= *msk, return mptcp_userspace_pm_append_new_local_addr(msk, local, true); } =20 -bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, - struct mptcp_addr_info *skc) +u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk, + struct mptcp_addr_info *skc) { struct mptcp_pm_addr_entry *entry; - bool backup =3D false; + u8 flags =3D 0; =20 spin_lock_bh(&msk->pm.lock); entry =3D mptcp_userspace_pm_lookup_addr(msk, skc); if (entry) - backup =3D !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); + flags =3D entry->flags; spin_unlock_bh(&msk->pm.lock); =20 - return backup; + return flags; } =20 static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_in= fo *info) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 767da3cb43cb..20ed572472aa 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1123,8 +1123,8 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, str= uct sock_common *skc); int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr_= entry *local); int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_p= m_addr_entry *local); bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc); -bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info = *skc); -bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_add= r_info *skc); +u8 mptcp_pm_nl_get_flags(struct mptcp_sock *msk, struct mptcp_addr_info *s= kc); +u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk, struct mptcp_addr_= info *skc); int mptcp_userspace_pm_dump_addr(struct mptcp_id_bitmap *bitmap, const struct genl_info *info); int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, --=20 2.43.0 From nobody Sat Nov 23 10:34:17 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 39DE3178372 for ; Thu, 10 Oct 2024 05:48:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539308; cv=none; b=fh2T5VVVyLqDtLV5cwUlr5rohzTlZI7BAoS1hSRH21crOuzX050OSMNL1XAVy5bNG/c30Rt1K8qlWC40+tPdqj42xO9tFiZoLJY5GbdACm+IY75v4Y805w6gb9Fr/t3VcfEeUmyS55T7czwCmhMuglLHN/1oniM/DHTT/DnclCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539308; c=relaxed/simple; bh=Vgmg8a6K8iVpjllsRYvZXr5hm6ZiY+oZFMBddg6YNeo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rnXv0FUyuz5e7DzCN+WVgXhp2fLfycTHatirTEibm5UyFkSOyO6cjmcs3FLXEFUxvYoyuWFMRSCPWi5DYh1sdWvFK5xOi8LIettlMszKT9lWDYoUQcLGSUWCixG2Dvn0HhoZ54Uf3Ea0773j55SGA7U+xr3OviKO13Ddec+kKfE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UhKXkpKe; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UhKXkpKe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7FB8C4CEC5; Thu, 10 Oct 2024 05:48:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728539306; bh=Vgmg8a6K8iVpjllsRYvZXr5hm6ZiY+oZFMBddg6YNeo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UhKXkpKeGee/WnuY3ehN0ObVgGVBVl2sH2lmJkQbsbXoVEqhbqYo0ZshtJlXOHvhJ Um++u/zrg5iPkE4ysJ5BVMNJc604GjzZ/N8ONhBN04GdFw7UUz7bM/9d2ZMZcGLKsQ O3RLnxjneHlwCKkgtTrcLIvJy/E/lviilBc5MDCxPu7U6FzBT6Pmvn1PxWraI8nM5H Ps+1tCmkrrWjDY0e9OJ19eMMdzutXrNl7H8n+9xZ9Xs+DBjiZ4ZSUAUv4MZOKIgieL X6SLfS4uLwf2x8m9I/Cd1Nuvxl+pvrKoCQcLLFfg0nYNdAVsdndOnvo0xZtL1vKZeY 8tztw8mLHjefQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 11/15] mptcp: hold pm lock when deleting entry Date: Thu, 10 Oct 2024 13:47:56 +0800 Message-ID: <1de80bc1c399d9ff66cd66dd7e490772e8f4ebfc.1728538976.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang When traversing userspace_pm_local_addr_list and deleting an entry from it in mptcp_pm_nl_remove_doit(), msk->pm.lock should be held. Fixes: d9a4594edabf ("mptcp: netlink: Add MPTCP_PM_CMD_REMOVE") Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 50b1aea7a719..05ad0d17ea81 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -310,14 +310,17 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, stru= ct genl_info *info) =20 lock_sock(sk); =20 + spin_lock_bh(&msk->pm.lock); match =3D mptcp_userspace_pm_lookup_addr_by_id(msk, id_val); if (!match) { GENL_SET_ERR_MSG(info, "address with specified id not found"); + spin_unlock_bh(&msk->pm.lock); release_sock(sk); goto out; } =20 list_move(&match->list, &free_list); + spin_unlock_bh(&msk->pm.lock); =20 mptcp_pm_remove_addrs(msk, &free_list); =20 --=20 2.43.0 From nobody Sat Nov 23 10:34:17 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C01BD178372 for ; Thu, 10 Oct 2024 05:48:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539308; cv=none; b=HG2m1iS3u8F5wlpozWwvptGu2tbx1JuQua/8IgAuef0ny4RzGVhTksXIitRQv5ckDc8/j5qd8MPZnZnKOZ7gEIoFTU5zj00e7DztWLjoQ3G4HjwDXHjvwmagSVKy+i9acB4+3BzLWXCnVS6yM8zJaOovaXHzhAJMEp5UbnlTSoY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539308; c=relaxed/simple; bh=E5CvVASfaVU1hIk2R50aKjxHTmAtX6JmVYKO9gtaUAA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Oq4PJzzcLR7RKIJwAaUqKgvgLtUM7Z71AoWBH3+/kqRZIJBq0ZQ5iSdMvdsw3+o0H/vFeg+k1DYDEuszCzcQ/iAGeM3Zn20QSY0kYIg/eNDEvMOWuT8FRw2C2q0zp79ljlHys3blgCeSIH88sKvPJrMV0IJxlEJIhMBFE122W1k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kgFS464R; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kgFS464R" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7830CC4CEC6; Thu, 10 Oct 2024 05:48:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728539308; bh=E5CvVASfaVU1hIk2R50aKjxHTmAtX6JmVYKO9gtaUAA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kgFS464RiXWR38yiBlQknU7WmndCMgDpvkVruhVKyvgyShkdDOBNek4bNUMhkUlaW m3DrZS63ObZ3UmX/k5UVzo0cs/Y07r4P0OOfHroUe7ueJhFea40tCdVWsiEPhWgooo kz353/9GYbY/CL6ksMCuCo2sBcia9VKlyHZ4zTzW9pY9c+4o7bC7QQKpS7NaNcM/Fz y6lBnWro/oftRyICjsovmNuFijTUDYCWMGNSi4eXUeAXakY0yFEpsxB7//X2mdXI2G GJNjgAs3+Mc1nstWfPSjGRpKX0zUm5FM9UpiQweFvWo+6jNfD+kSCLZDyRZi+Wsb26 FWZ8sG8uX0OHQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 12/15] mptcp: rename mptcp_pm_remove_addrs Date: Thu, 10 Oct 2024 13:47:57 +0800 Message-ID: <90414a91e0248adb5a7e4ab46ef12f9a1ab475a9.1728538976.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang mptcp_pm_remove_addrs() actually only deletes one address, which does not match its name. This patch renames it to mptcp_pm_remove_addr_entry() and changes the parameter "rm_list" to "entry". Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 24 ++++++++++-------------- net/mptcp/pm_userspace.c | 2 +- net/mptcp/protocol.h | 3 ++- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 38168eb6d4a0..47dda03e4ee2 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1629,26 +1629,22 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, = struct genl_info *info) } =20 /* Called from the userspace PM only */ -void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_li= st) +void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *entry) { struct mptcp_rm_list alist =3D { .nr =3D 0 }; - struct mptcp_pm_addr_entry *entry; int anno_nr =3D 0; =20 - list_for_each_entry(entry, rm_list, list) { - if (alist.nr >=3D MPTCP_RM_IDS_MAX) - break; - - /* only delete if either announced or matching a subflow */ - if (remove_anno_list_by_saddr(msk, &entry->addr)) - anno_nr++; - else if (!lookup_subflow_by_saddr(&msk->conn_list, - &entry->addr)) - continue; + /* only delete if either announced or matching a subflow */ + if (remove_anno_list_by_saddr(msk, &entry->addr)) + anno_nr++; + else if (!lookup_subflow_by_saddr(&msk->conn_list, + &entry->addr)) + goto out; =20 - alist.ids[alist.nr++] =3D entry->addr.id; - } + alist.ids[alist.nr++] =3D entry->addr.id; =20 +out: if (alist.nr) { spin_lock_bh(&msk->pm.lock); msk->pm.add_addr_signaled -=3D anno_nr; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 05ad0d17ea81..9477c36d3284 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -322,7 +322,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct= genl_info *info) list_move(&match->list, &free_list); spin_unlock_bh(&msk->pm.lock); =20 - mptcp_pm_remove_addrs(msk, &free_list); + mptcp_pm_remove_addr_entry(msk, match); =20 release_sock(sk); =20 diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 20ed572472aa..168f144b86a4 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1040,7 +1040,8 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk, const struct mptcp_addr_info *addr, bool echo); int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_lis= t *rm_list); -void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_li= st); +void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *entry); =20 void mptcp_free_local_addr_list(struct mptcp_sock *msk); =20 --=20 2.43.0 From nobody Sat Nov 23 10:34:17 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 ED1F9178372 for ; Thu, 10 Oct 2024 05:48:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539311; cv=none; b=Kj0SermptLAss7Yhlkj8DHH2Cant2cjTDTYqMgIe/kGTH9yVjHcsJ1lCfEfLXnJ88YM6ZY0rBsaOLdx4XLWaHq/8UzJRqYI/jh2zzCqWUMZ1bBiizSk4nutXRGTRdWiDIm0lTUjjFFTtFbcfUebUWScLpmb4WCq5jkOoB+pYG+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539311; c=relaxed/simple; bh=zRrDYSrsKOnxGUDLUv6SHHsyzHqehx5WeHxuztEZX9k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IrceZPAF/hZzCueGSX+bJq/18mZw9uFP39evhGjzAVBzMcdg2yaXQL5N7/Z50/WETpN2TW3fFuQkcuU9n1tKulglrSCmicjr4n2IO7EpX2q1e+fPwF5uwRpTP/op6wvYJW2UcwlJjhOng4yK9QoT6oG3RL5BIYJmZGHjAAwDifs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aXLaPpdM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aXLaPpdM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5333BC4CEC6; Thu, 10 Oct 2024 05:48:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728539310; bh=zRrDYSrsKOnxGUDLUv6SHHsyzHqehx5WeHxuztEZX9k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aXLaPpdMlmRaJ1SVE7BG2xhoeBvHFPfDsyjKIVDdT168PGQk+UaPazcamx+eyIu/P ytk8291UyuIY+99ZMO55Zxe/qsdHa4y8FhVyho92C08JoF3wbLA4Lxc4ekBzG11l0Y qAIG0dNXCG8IWiTJO7Lxx20kkuCXGPsPNmvxKpHdy6PwsM0PRPZmEjmM4pX2zmTQ+P KHcQJvXPTLbUBwmBkFhAPWg5DvraPoHv9/QsreuN/lS9gZSbreWquEPz5da8o9z7uq inAB8l+p0YMdIEf7CE4KJxwV2rKnbD7ddeQa04/hvhgalBtXIG4K4JgldESFCUOKs/ p24NzZtzFJwLg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 13/15] mptcp: drop free_list for deleting entries Date: Thu, 10 Oct 2024 13:47:58 +0800 Message-ID: <65f5108cce91f79a93915d84047ec03c10655623.1728538976.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang With the help of mptcp_pm_remove_addr_entry(), it's no longer necessary to move the entry to be deleted to free_list and then traverse the list to delete the entry, which is not allowed in BPF. The entry can be directly deleted through list_del_rcu() and sock_kfree_s() now. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 9477c36d3284..4b2c3d0f685e 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -283,9 +283,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct= genl_info *info) { struct nlattr *id =3D info->attrs[MPTCP_PM_ATTR_LOC_ID]; struct mptcp_pm_addr_entry *match; - struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; - LIST_HEAD(free_list); int err =3D -EINVAL; struct sock *sk; u8 id_val; @@ -312,23 +310,21 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, stru= ct genl_info *info) =20 spin_lock_bh(&msk->pm.lock); match =3D mptcp_userspace_pm_lookup_addr_by_id(msk, id_val); + spin_unlock_bh(&msk->pm.lock); if (!match) { GENL_SET_ERR_MSG(info, "address with specified id not found"); - spin_unlock_bh(&msk->pm.lock); release_sock(sk); goto out; } =20 - list_move(&match->list, &free_list); - spin_unlock_bh(&msk->pm.lock); - mptcp_pm_remove_addr_entry(msk, match); =20 release_sock(sk); =20 - list_for_each_entry_safe(match, entry, &free_list, list) { - sock_kfree_s(sk, match, sizeof(*match)); - } + spin_lock_bh(&msk->pm.lock); + list_del_rcu(&match->list); + sock_kfree_s(sk, match, sizeof(*match)); + spin_unlock_bh(&msk->pm.lock); =20 err =3D 0; out: --=20 2.43.0 From nobody Sat Nov 23 10:34:17 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C5BB2178372 for ; Thu, 10 Oct 2024 05:48:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539312; cv=none; b=JG+OSiD6x5KXtu8IAhejdq2bTKci/HDnjFvDBmRkWX/4Y9lfvbvsXjIxB5avNDUooG+hqh65hiXk7tPz18bWTaJsDq8EXR6l3dYDI7h0hnGOlvHNFvYeNhZFSHDIA4vR7akWXxhXGrMUrBySKlcq6YI60x7NfNU21rvfCVdCeFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539312; c=relaxed/simple; bh=BeacQk9SNJKDALTc97IELSpe5HWfKDrbBtJDX/4EDjk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hYeNyE0sU3KJVT2jCPy9vvwj2wfsjZvBnOs9lEr29Tkd2ah9ohFk/C3yN4sQ72Tdsc0r+tedyH8A083MGUn/VyGbd+TJQvzUIR/fXIUgHdSfAm2Ng4dsxAca7q78rrtx9Ygzz9ZHOSvsfUzf0P7nS7E0WKsQPDFRRROjfMp9b38= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RGD2/5hx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RGD2/5hx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BAA4C4CEC5; Thu, 10 Oct 2024 05:48:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728539312; bh=BeacQk9SNJKDALTc97IELSpe5HWfKDrbBtJDX/4EDjk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RGD2/5hxKvlywJCwC6CTma0kaO+XZU0lh2lwA8Mps5wHOan67XMPuTvil5nVLWu85 yfamLS+zJPRp3ZH/UjvOYK81l9IHcjmieQdl91cinKJOtprwZuaTnijByY0yz6sKAB ZfZTfdOZvrb7B4XJ+WvztgxktnHIfVzocJ5qrbUymuZRUbe41OIC+lOrzuTVPKpwkb cF5QveZ0GZwHSYmvkOZ7MVXvbOITSSlXd5Eee9JhS8HrwOljUctEFqTy3ZDs0/obQI ZKa60A1DexKF7b4FIZPaGarToB+CdlFsUsJtmjNubZ88M37fIM1MCXxq+MCQ9ocByu heYcweWwkNwIw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 14/15] mptcp: drop struct mptcp_pm_local Date: Thu, 10 Oct 2024 13:47:59 +0800 Message-ID: <13e159c0bc49c99a692c71d3ed83634119b8a3bf.1728538976.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang The following code in mptcp_pm_nl_subflow_create_doit() that assigns struct mptcp_pm_addr_entry "entry" to the local struct mptcp_pm_local variable "local" is not allowed in BPF if we use the same code to implement the subflow_create() interface of a BFP path manager: struct mptcp_pm_local local; local.addr =3D entry.addr; local.flags =3D entry.flags; local.ifindex =3D entry.ifindex; We should avoid this type of assignment from struct mptcp_pm_addr_entry to struct mptcp_pm_local. In fact, there is no need to add a dedicated address entry type for local address entry. All its fields are the same as struct mptcp_pm_addr_entry, except that it lacks a "lsk" for the listening socket. So we can use struct mptcp_pm_addr_entry directly. This makes the path manager code simpler. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 22 ++++++++-------------- net/mptcp/pm_userspace.c | 7 +------ net/mptcp/protocol.h | 8 +------- net/mptcp/subflow.c | 2 +- 4 files changed, 11 insertions(+), 28 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 47dda03e4ee2..03f3b02d4542 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -149,7 +149,7 @@ static bool lookup_subflow_by_daddr(const struct list_h= ead *list, static bool select_local_address(const struct pm_nl_pernet *pernet, const struct mptcp_sock *msk, - struct mptcp_pm_local *new_local) + struct mptcp_pm_addr_entry *new_local) { struct mptcp_pm_addr_entry *entry; bool found =3D false; @@ -164,9 +164,7 @@ select_local_address(const struct pm_nl_pernet *pernet, if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap.map)) continue; =20 - new_local->addr =3D entry->addr; - new_local->flags =3D entry->flags; - new_local->ifindex =3D entry->ifindex; + *new_local =3D *entry; found =3D true; break; } @@ -177,7 +175,7 @@ select_local_address(const struct pm_nl_pernet *pernet, =20 static bool select_signal_address(struct pm_nl_pernet *pernet, const struct mptcp_sock= *msk, - struct mptcp_pm_local *new_local) + struct mptcp_pm_addr_entry *new_local) { struct mptcp_pm_addr_entry *entry; bool found =3D false; @@ -195,9 +193,7 @@ select_signal_address(struct pm_nl_pernet *pernet, cons= t struct mptcp_sock *msk, if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) continue; =20 - new_local->addr =3D entry->addr; - new_local->flags =3D entry->flags; - new_local->ifindex =3D entry->ifindex; + *new_local =3D *entry; found =3D true; break; } @@ -534,11 +530,11 @@ __lookup_addr(struct pm_nl_pernet *pernet, const stru= ct mptcp_addr_info *info) static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) { struct sock *sk =3D (struct sock *)msk; + struct mptcp_pm_addr_entry local; unsigned int add_addr_signal_max; bool signal_and_subflow =3D false; unsigned int local_addr_max; struct pm_nl_pernet *pernet; - struct mptcp_pm_local local; unsigned int subflows_max; =20 pernet =3D pm_nl_get_pernet(sock_net(sk)); @@ -660,7 +656,7 @@ static void mptcp_pm_nl_subflow_established(struct mptc= p_sock *msk) */ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, struct mptcp_addr_info *remote, - struct mptcp_pm_local *locals) + struct mptcp_pm_addr_entry *locals) { struct sock *sk =3D (struct sock *)msk; struct mptcp_pm_addr_entry *entry; @@ -683,9 +679,7 @@ static unsigned int fill_local_addresses_vec(struct mpt= cp_sock *msk, continue; =20 if (msk->pm.subflows < subflows_max) { - locals[i].addr =3D entry->addr; - locals[i].flags =3D entry->flags; - locals[i].ifindex =3D entry->ifindex; + locals[i] =3D *entry; =20 /* Special case for ID0: set the correct ID */ if (mptcp_addresses_equal(&locals[i].addr, &mpc_addr, locals[i].addr.po= rt)) @@ -721,7 +715,7 @@ static unsigned int fill_local_addresses_vec(struct mpt= cp_sock *msk, =20 static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk) { - struct mptcp_pm_local locals[MPTCP_PM_ADDR_MAX]; + struct mptcp_pm_addr_entry locals[MPTCP_PM_ADDR_MAX]; struct sock *sk =3D (struct sock *)msk; unsigned int add_addr_accept_max; struct mptcp_addr_info remote; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 4b2c3d0f685e..fc2f2bf6a69d 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -338,7 +338,6 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb= , struct genl_info *info) struct nlattr *laddr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_pm_addr_entry entry =3D { 0 }; struct mptcp_addr_info addr_r; - struct mptcp_pm_local local; struct mptcp_sock *msk; int err =3D -EINVAL; struct sock *sk; @@ -385,12 +384,8 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *sk= b, struct genl_info *info) goto create_err; } =20 - local.addr =3D entry.addr; - local.flags =3D entry.flags; - local.ifindex =3D entry.ifindex; - lock_sock(sk); - err =3D __mptcp_subflow_connect(sk, &local, &addr_r); + err =3D __mptcp_subflow_connect(sk, &entry, &addr_r); release_sock(sk); =20 spin_lock_bh(&msk->pm.lock); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 168f144b86a4..c4842fe5d3ff 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -240,12 +240,6 @@ struct mptcp_pm_data { struct mptcp_rm_list rm_list_rx; }; =20 -struct mptcp_pm_local { - struct mptcp_addr_info addr; - u8 flags; - int ifindex; -}; - struct mptcp_pm_addr_entry { struct list_head list; struct mptcp_addr_info addr; @@ -738,7 +732,7 @@ bool mptcp_addresses_equal(const struct mptcp_addr_info= *a, void mptcp_local_address(const struct sock_common *skc, struct mptcp_addr_= info *addr); =20 /* called with sk socket lock held */ -int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_pm_local *= local, +int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_pm_addr_en= try *local, const struct mptcp_addr_info *remote); int mptcp_subflow_create_socket(struct sock *sk, unsigned short family, struct socket **new_sock); diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 860903e06422..b54324d106f1 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -1582,7 +1582,7 @@ void mptcp_info2sockaddr(const struct mptcp_addr_info= *info, #endif } =20 -int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_pm_local *= local, +int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_pm_addr_en= try *local, const struct mptcp_addr_info *remote) { struct mptcp_sock *msk =3D mptcp_sk(sk); --=20 2.43.0 From nobody Sat Nov 23 10:34:17 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 686CC178372 for ; Thu, 10 Oct 2024 05:48:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539314; cv=none; b=mnLajDYdVs9UsjtavXB2birZiVxIt1KVe6c01Lbstm4TxERy7rAFHSTP5kGAxTWKUi392c8EBsnBwOrJjrtBS3ztfGFU+hMMPTsadk0AXt6YfGTJdrDN9P7brQplLBezZmuZGvX3K2z3eCj1AYZ8VrZ6SugY1FFv/OATVvyscwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728539314; c=relaxed/simple; bh=nGXPYD9JAuT50yyFZ38LOYzMJS0R297pVdOZ5QLH+0I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fPErrMhjQon0g7KGZAZOUAVohMv+0SYNj2KspSZiG2+X0q5pV5d3Wuy3Y936NiFaqV1W5q59Urz+PbG+wxSlCDvXp0oNtVVGYB4z9aqfHQSQPuqN34bY9dDjNcuIsnuyV3uyLQlYB9uw80uIA8HyxUeSu5dN+CcOFuw90JNwmNA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k4d5WimT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="k4d5WimT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E4C8C4CEC6; Thu, 10 Oct 2024 05:48:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728539314; bh=nGXPYD9JAuT50yyFZ38LOYzMJS0R297pVdOZ5QLH+0I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k4d5WimTdVPyQpz3uqXMC963a4I2Uof2FIe6cLuosFM2RzqxFNT8JU17hda7PCoz/ NaURqNLzh34gVFZ/OYFL6ZNCrva1A4VgXicqOvIcto8KYJ65uP6SuUKAKMEsG3gS50 vc5hP2mq+X4DtbSU/Z7m5LWt7eOAuiY2ZodltflnVl7kEyKCXEqeBfNIq9M8TMyQVJ kSQ6KHo05VizUa23uTMIwu7iYkQwSIbmzQM/7ZMCU4bLErFDMT3N6zi0ZYtvpuCd0u lV7ZM1+3vw0STap2tvSvlmfnng90rDdmMKi7Carmx1s6lEArJdUfD3FYbhQrKOZM2s 3wqi2jToohzaA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 15/15] mptcp: drop struct mptcp_pm_add_entry Date: Thu, 10 Oct 2024 13:48:00 +0800 Message-ID: <4c6c8196fe0c36ae3ce4fc8b8b28d0e37f581ea3.1728538976.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang There is no need to add a dedicated address entry type "mptcp_pm_add_entry" to represent ADD_ADDR addresses. Additional fileds for ADD_ADDR addresses can be added into struct mptcp_pm_addr_entry directly. This makes the path manager code simpler. Here "union" can be used to merge struct mptcp_pm_addr_entry and struct mptcp_pm_add_entry into one. Then all mptcp_pm_add_entry can be replaced by mptcp_pm_addr_entry. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 26 +++++++++----------------- net/mptcp/protocol.h | 20 +++++++++++++++----- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 03f3b02d4542..83f2d9638bbc 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -18,14 +18,6 @@ =20 static int pm_nl_pernet_id; =20 -struct mptcp_pm_add_entry { - struct list_head list; - struct mptcp_addr_info addr; - u8 retrans_times; - struct timer_list add_timer; - struct mptcp_sock *sock; -}; - struct pm_nl_pernet { /* protects pernet updates */ spinlock_t lock; @@ -247,11 +239,11 @@ bool mptcp_pm_nl_check_work_pending(struct mptcp_sock= *msk) return true; } =20 -struct mptcp_pm_add_entry * +struct mptcp_pm_addr_entry * mptcp_lookup_anno_list_by_saddr(const struct mptcp_sock *msk, const struct mptcp_addr_info *addr) { - struct mptcp_pm_add_entry *entry; + struct mptcp_pm_addr_entry *entry; =20 lockdep_assert_held(&msk->pm.lock); =20 @@ -265,7 +257,7 @@ mptcp_lookup_anno_list_by_saddr(const struct mptcp_sock= *msk, =20 bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, const struct sock= *sk) { - struct mptcp_pm_add_entry *entry; + struct mptcp_pm_addr_entry *entry; struct mptcp_addr_info saddr; bool ret =3D false; =20 @@ -286,7 +278,7 @@ bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk= , const struct sock *sk) =20 static void mptcp_pm_add_timer(struct timer_list *timer) { - struct mptcp_pm_add_entry *entry =3D from_timer(entry, timer, add_timer); + struct mptcp_pm_addr_entry *entry =3D from_timer(entry, timer, add_timer); struct mptcp_sock *msk =3D entry->sock; struct sock *sk =3D (struct sock *)msk; =20 @@ -328,11 +320,11 @@ static void mptcp_pm_add_timer(struct timer_list *tim= er) __sock_put(sk); } =20 -struct mptcp_pm_add_entry * +struct mptcp_pm_addr_entry * mptcp_pm_del_add_timer(struct mptcp_sock *msk, const struct mptcp_addr_info *addr, bool check_id) { - struct mptcp_pm_add_entry *entry; + struct mptcp_pm_addr_entry *entry; struct sock *sk =3D (struct sock *)msk; struct timer_list *add_timer =3D NULL; =20 @@ -356,7 +348,7 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk, bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk, const struct mptcp_addr_info *addr) { - struct mptcp_pm_add_entry *add_entry =3D NULL; + struct mptcp_pm_addr_entry *add_entry =3D NULL; struct sock *sk =3D (struct sock *)msk; struct net *net =3D sock_net(sk); =20 @@ -392,7 +384,7 @@ bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk, =20 void mptcp_pm_free_anno_list(struct mptcp_sock *msk) { - struct mptcp_pm_add_entry *entry, *tmp; + struct mptcp_pm_addr_entry *entry, *tmp; struct sock *sk =3D (struct sock *)msk; LIST_HEAD(free_list); =20 @@ -1439,7 +1431,7 @@ int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, st= ruct genl_info *info) static bool remove_anno_list_by_saddr(struct mptcp_sock *msk, const struct mptcp_addr_info *addr) { - struct mptcp_pm_add_entry *entry; + struct mptcp_pm_addr_entry *entry; =20 entry =3D mptcp_pm_del_add_timer(msk, addr, false); if (entry) { diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index c4842fe5d3ff..a3c59eee6db4 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -243,9 +243,19 @@ struct mptcp_pm_data { struct mptcp_pm_addr_entry { struct list_head list; struct mptcp_addr_info addr; - u8 flags; - int ifindex; - struct socket *lsk; + union { + struct { + u8 flags; + int ifindex; + struct socket *lsk; + }; + /* mptcp_pm_add_entry */ + struct { + u8 retrans_times; + struct timer_list add_timer; + struct mptcp_sock *sock; + }; + }; }; =20 struct mptcp_data_frag { @@ -1021,10 +1031,10 @@ bool mptcp_pm_alloc_anno_list(struct mptcp_sock *ms= k, const struct mptcp_addr_info *addr); void mptcp_pm_free_anno_list(struct mptcp_sock *msk); bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, const struct sock= *sk); -struct mptcp_pm_add_entry * +struct mptcp_pm_addr_entry * mptcp_pm_del_add_timer(struct mptcp_sock *msk, const struct mptcp_addr_info *addr, bool check_id); -struct mptcp_pm_add_entry * +struct mptcp_pm_addr_entry * mptcp_lookup_anno_list_by_saddr(const struct mptcp_sock *msk, const struct mptcp_addr_info *addr); int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *loc, --=20 2.43.0