From patchwork Wed Jan 15 09:59:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13940188 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 F31281EEA31 for ; Wed, 15 Jan 2025 09:59:43 +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=1736935184; cv=none; b=V28OJf2dsrweTtrQuaSAI9odcNj9BPL1Gd4+NwSRofapDpbDs2Npm8cSyw3aascWthqfI3sBB/9FzOvjf6hkIcDzRCz7uF2O9cjveR7wujbXp+1k0+ZpFIsVlwyryjWKmZKf85OKBch5hADJafhKV7DZu1AoUg2m6oEPMhUryIU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736935184; c=relaxed/simple; bh=mReufQBMfhEAFgVxSJjYHyXTepa6JXN6QhJtShKUhQ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g9O9tkOkYEVLo7pdelAYyRSvxAy4tYbTk5OKe/PyFym7U8xdJYOjSUquUvMUJRMDQG/e4TKft9GgCQJjyCPWXA6jpP/eOEfxVoG0q70Gc49i00ls6yotOy7nwj+NHzfT07nqTHnKZFgnVXjpCxl5JWot0zX5Gw/D/PoLJFi1LkM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aTTiJn4S; 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="aTTiJn4S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2AE6C4AF09; Wed, 15 Jan 2025 09:59:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736935183; bh=mReufQBMfhEAFgVxSJjYHyXTepa6JXN6QhJtShKUhQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aTTiJn4S/N16+1QG/As+HwZNnXwVKAe9F7yay6TWarGy/wt+MS/fvMLHi60r9sMc8 ujRZbEXt32wFQF5dijy/3GMAF3vdoAf6m5HlS28dxYKPzMUDdAvNgjdvMam2RdcFE8 +6A33o8hSM4ztflkDEKE/VwgxHsP9q/Ur9ZHG6rWom0JBcmb4QNBaNp034RBm//Iqs Koq13LQBP4sXD6utMmOhLv9Anb806Z6RcKPC8JwWYMgfILferQWbG1d3MM+oUgVk/y 1XCFn51RSAlYab57CsM+2TYY/4NUB5QYw/SM3T5fru6oeNm9jVjPdwOUeN4ZgxP3F4 bjcpZxzM2WutQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 1/6] mptcp: add mptcp_pm_genl_fill_addr helper Date: Wed, 15 Jan 2025 17:59:27 +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 From: Geliang Tang To save some redundant code in dump_addr() interfaces of both the netlink PM and userspace PM, the code that calls netlink message helpers (genlmsg_put/cancel/end) and mptcp_nl_fill_addr() is wrapped into a new helper mptcp_pm_genl_fill_addr(). This helper will also be used in BPF path managers. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 21 +++++++++++++++++++++ net/mptcp/pm_netlink.c | 12 +----------- net/mptcp/pm_userspace.c | 12 +----------- net/mptcp/protocol.h | 3 +++ 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index b1f36dc1a091..16cacce6c10f 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -489,6 +489,27 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) return ret; } +int mptcp_pm_genl_fill_addr(struct sk_buff *msg, + struct netlink_callback *cb, + struct mptcp_pm_addr_entry *entry) +{ + void *hdr; + + hdr = 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) + return -EINVAL; + + if (mptcp_nl_fill_addr(msg, entry) < 0) { + genlmsg_cancel(msg, hdr); + return -EINVAL; + } + + genlmsg_end(msg, hdr); + return 0; +} + static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) { const struct genl_info *info = genl_info_dump(cb); diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index fef01692eaed..afd517ff260c 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1798,7 +1798,6 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg, struct mptcp_pm_addr_entry *entry; struct pm_nl_pernet *pernet; int id = cb->args[0]; - void *hdr; int i; pernet = pm_nl_get_pernet(net); @@ -1813,19 +1812,10 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg, if (entry->addr.id <= id) continue; - hdr = 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) + if (mptcp_pm_genl_fill_addr(msg, cb, entry)) break; - if (mptcp_nl_fill_addr(msg, entry) < 0) { - genlmsg_cancel(msg, hdr); - break; - } - id = entry->addr.id; - genlmsg_end(msg, hdr); } } rcu_read_unlock(); diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 277cf092a870..b50462b527bd 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -641,7 +641,6 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct mptcp_sock *msk; int ret = -EINVAL; struct sock *sk; - void *hdr; bitmap = (struct id_bitmap *)cb->ctx; @@ -657,19 +656,10 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, if (test_bit(entry->addr.id, bitmap->map)) continue; - hdr = 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) + if (mptcp_pm_genl_fill_addr(msg, cb, entry)) break; - if (mptcp_nl_fill_addr(msg, entry) < 0) { - genlmsg_cancel(msg, hdr); - break; - } - __set_bit(entry->addr.id, bitmap->map); - genlmsg_end(msg, hdr); } spin_unlock_bh(&msk->pm.lock); release_sock(sk); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 6fb536de9981..20941405a1ea 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1060,6 +1060,9 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subf struct request_sock *req); int mptcp_nl_fill_addr(struct sk_buff *skb, struct mptcp_pm_addr_entry *entry); +int mptcp_pm_genl_fill_addr(struct sk_buff *msg, + struct netlink_callback *cb, + struct mptcp_pm_addr_entry *entry); static inline bool mptcp_pm_should_add_signal(struct mptcp_sock *msk) { From patchwork Wed Jan 15 09:59:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13940189 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 E879D1DB14D for ; Wed, 15 Jan 2025 09:59:45 +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=1736935186; cv=none; b=IX+EPCP7d6kcD6p7wdobOrkChIHAUur4BaOM2kjzmt42xwAIW/Nf9nYg6cvsEqhs8FIIN67mvuq5xF/RkHcVGnH0E8GWtvWrcHwk3WKWWGXAhvbSgFt0FfyCfNnEwv8POCSsPTezoNheRvQynPFFZlCRA91fsMnRTzdxaruQjbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736935186; c=relaxed/simple; bh=VQTbXInIocsUug3Gaqad5FUcamm3egJMgNUOEl9m6Tg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oxPxGsH6c8aY1aqNZ/j9l4whCK06TSuruO//Hsnw9yc3mpen91JOEGiQCISOAIGBNMeO2/PqcLi1sFEB+rRwhkHzc45N1k+3tfoiHz49U3V63qqJ/op4ZL/8bya41qn4OdbxzG81EDThzJToKArjUkpmm9LD/A8Us1K6S7jQmMU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ava02Ius; 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="ava02Ius" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7359FC4CEE1; Wed, 15 Jan 2025 09:59:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736935185; bh=VQTbXInIocsUug3Gaqad5FUcamm3egJMgNUOEl9m6Tg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ava02IusewSXyJnzOrbAJdr/h0EWkaFRsTwI49RvO1tLir6ijLhIMx6qH/nyDVTrR 3A1TcARnbr+GPUpUgbsVQ0sIv+cH1sXtv+Xt4k8HD6x/XL9RMJ9J8N2+MQ7uCtiEkM qNGvJ71wbWaSHH2B3R60UtHa+q3LSEyh6L7e2S/n3WGBwicbk2/qPcUUK6TyzdTWmC HNIb/Se/w878iLRugdyw4YlSHO3ka4zm4LQshIttfX1zYFflu5CUxJ6hGj+yY5D6sN TA2QemleUTG4Cw2gtfPvY5WjvApBgwdHXMS5wfXDLzTEAlsLf4vIK/9x2a/T3bNGmG 4iGjVGjrdY3lg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 2/6] mptcp: add struct mptcp_pm_addr_id_bitmap Date: Wed, 15 Jan 2025 17:59:28 +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 From: Geliang Tang To simplify the use of bitmap in BPF, a new type for MPTCP userspace pm id bitmap, struct mptcp_pm_addr_id_bitmap is defined. Because there's no way to use DECLARE_BITMAP macro in BPF program, and it's not easy to reimplement it in BPF. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 14 ++++++-------- net/mptcp/protocol.h | 4 ++++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index b50462b527bd..e53426a5fc52 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -47,7 +47,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *entry, bool needs_id) { - DECLARE_BITMAP(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); + struct mptcp_pm_addr_id_bitmap id_bitmap; struct mptcp_pm_addr_entry *match = NULL; struct sock *sk = (struct sock *)msk; struct mptcp_pm_addr_entry *e; @@ -55,7 +55,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, bool id_match = false; int ret = -EINVAL; - bitmap_zero(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); + bitmap_zero(id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); spin_lock_bh(&msk->pm.lock); mptcp_for_each_userspace_pm_addr(msk, e) { @@ -69,7 +69,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, } else if (addr_match || id_match) { break; } - __set_bit(e->addr.id, id_bitmap); + __set_bit(e->addr.id, id_bitmap.map); } if (!match && !addr_match && !id_match) { @@ -84,7 +84,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, *e = *entry; if (!e->addr.id && needs_id) - e->addr.id = find_next_zero_bit(id_bitmap, + e->addr.id = find_next_zero_bit(id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1, 1); list_add_tail_rcu(&e->list, &msk->pm.userspace_pm_local_addr_list); @@ -633,16 +633,14 @@ int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *local, int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) { - struct id_bitmap { - DECLARE_BITMAP(map, MPTCP_PM_MAX_ADDR_ID + 1); - } *bitmap; const struct genl_info *info = genl_info_dump(cb); + struct mptcp_pm_addr_id_bitmap *bitmap; struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; int ret = -EINVAL; struct sock *sk; - bitmap = (struct id_bitmap *)cb->ctx; + bitmap = (struct mptcp_pm_addr_id_bitmap *)cb->ctx; msk = mptcp_userspace_pm_get_sock(info); if (!msk) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 20941405a1ea..aca3de2baf81 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -212,6 +212,10 @@ enum mptcp_addr_signal_status { /* max value of mptcp_addr_info.id */ #define MPTCP_PM_MAX_ADDR_ID U8_MAX +struct mptcp_pm_addr_id_bitmap { + DECLARE_BITMAP(map, MPTCP_PM_MAX_ADDR_ID + 1); +}; + struct mptcp_pm_data { struct mptcp_addr_info local; struct mptcp_addr_info remote; From patchwork Wed Jan 15 09:59:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13940190 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 7D68E1DB14D for ; Wed, 15 Jan 2025 09:59:47 +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=1736935187; cv=none; b=qyRAvTsgyGVpC4xvxTFyfImMExeE5tmWskE2097FdIexdaeENcGKXNLtSZRWN5NhlfEOR0VfYVyVQCW5PHfdA2jzgo4UmN9CdEVi9TV7UjZaHIllWOoWpK0i4+uckA0F0I2DM1p6eG5z7fpl0fbO3iztuD62zC3FMzOsMxsD2Lo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736935187; c=relaxed/simple; bh=wgDmtBTPbeJRMEXqfy9UulGSZmSZ3VD6Zw43FACGutQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H4/f/RG0eVgaWiYygx0+ywdGYqJI7uGOVVmcq3PnI0IYkb7i9wKSt8mOITzk2VZO0deSJ8cE1DOY2vZtgTQfQkfQuIrKGoTwSBs5NsGtGSRANm/bqKKjh3xI2xMhlsDuxp9ZP5CDajD3mjxK3huse3wdLztPm6xhnci3oHx0spg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pgY8kMWT; 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="pgY8kMWT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33B8BC4CEDF; Wed, 15 Jan 2025 09:59:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736935187; bh=wgDmtBTPbeJRMEXqfy9UulGSZmSZ3VD6Zw43FACGutQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pgY8kMWTgfzq5WcKGn89FbVvwmYc2TNCCtVcbFcR/Hq2fV03+ffVmYM760rgvdus9 m+h6MbJv8nlHq89By1CsD3hQ5s9YsZq6mSX5p0FUyyRHkt+vWXk/qKsmd4xC4iquD8 Q7Ft6fAmVL/A33ENjjkX6l1UdC17efS+0ihAN9AVdJuYqPA8dhaZRkx3gofqqg6mY9 ue83ww1Z8GDGDmrGSMUMi/6O+p9CFA7k1N2cj64mqo43uFU8pOlOzBQCKpMbr4NduU 2/7oBVa77bQiEAs1IlSLfNzmDB6RiRrSg4IYWfDiOCi0dQP+Sowz2mFz0Vk+er939P 2pR9Ts7J+98QA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 3/6] mptcp: drop inet6_sk in mptcp_nl_find_ssk Date: Wed, 15 Jan 2025 17:59:29 +0800 Message-ID: <27f1c41a7a532e09596979e895af8dcbaca9313a.1736935086.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 From: Geliang Tang In mptcp_nl_find_ssk(), 'issk' has already been got through inet_sk(). No need to use inet6_sk() to get 'pinfo' again, just use issk->pinet6 instead. This patch also drops this 'pinfo' variable. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index e53426a5fc52..de17b18b78fe 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -465,9 +465,7 @@ static struct sock *mptcp_nl_find_ssk(struct mptcp_sock *msk, break; #if IS_ENABLED(CONFIG_MPTCP_IPV6) case AF_INET6: { - const struct ipv6_pinfo *pinfo = inet6_sk(ssk); - - if (!ipv6_addr_equal(&local->addr6, &pinfo->saddr) || + if (!ipv6_addr_equal(&local->addr6, &issk->pinet6->saddr) || !ipv6_addr_equal(&remote->addr6, &ssk->sk_v6_daddr)) continue; break; From patchwork Wed Jan 15 09:59:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13940191 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 EC0291DB14D for ; Wed, 15 Jan 2025 09:59:48 +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=1736935189; cv=none; b=d+hOxT+cof4wOerRrzC+PXq7M5iEvZYJ8tbfE3v07KXGitDhfOTLYb3a7hO36gXE4iik6XOphspvB+k2FCkzh9XX/0s+z8qFje+zcpnV72q1XzIWUllo5CtyTcWzZ9R0YptzwBGkREMvaEwpTu1DaKrhpNYevIPB2AslClrV/ac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736935189; c=relaxed/simple; bh=Xw3wlccCqpdwPt88Y4SCvZLPmSfjOGk3ELg4WNOmO6A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aE22VurDPIh2WoFQl5anpSKXs26U1pgVCCs3eJzOKbEvIHDuGtkkdh5z0zkIzqgjCUpW0945jI+sAfoCejPpADTgyHkh07wO/4XgaVvdvnFB6IEP0xeIys7VtWV2W/SYJzFBZM1l05uxyxFDr9tB80zgKBEGtAbAVLS4s87HsJQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=H38y3MaE; 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="H38y3MaE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0676C4CEDF; Wed, 15 Jan 2025 09:59:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736935188; bh=Xw3wlccCqpdwPt88Y4SCvZLPmSfjOGk3ELg4WNOmO6A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H38y3MaE/4wI2A5STwdupVKZV3tLVENWxb20PKFd+ycM3atU6KoFiAAmOuobfOs3i 8xFL0nkCmi9XqqizdECqoo/SZ9qxBB05tehdhR1CvL10YFiJRvUsN+1LU+dKRy1lVw mFm/YrKgJj7I9/L/5KT3fK74YawpH09pRy9kQswjTEQhmb5Pzwe1ALsmpLf1sMB1P5 xL3ucpXTNbBYHV7P+5y6BX5+L2eCPAbQx/6bSS6uMGLzy9pDN7LlxHIUOjfiUkw0bb KB9XIcC25jQgDR5ejWBoCnZfqrilCPkYARaBh+Y4xV7ZGlnbrApEOCFOKmqOU5DpRP f+jfjea305UVA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 4/6] mptcp: drop match in userspace_pm_append_new_local_addr Date: Wed, 15 Jan 2025 17:59:30 +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 From: Geliang Tang The variable 'match' in mptcp_userspace_pm_append_new_local_addr() is a redundant one, and this patch drops it. No need to define 'match' as 'struct mptcp_pm_addr_entry *' type. In this function, it's only used to check whether it's NULL. It can be defined as a Boolean one. Also other variables 'addr_match' and 'id_match' make 'match' a redundant one, which can be replaced by directly checking 'addr_match && id_match'. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index de17b18b78fe..7075c7f7229f 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -48,7 +48,6 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, bool needs_id) { struct mptcp_pm_addr_id_bitmap id_bitmap; - struct mptcp_pm_addr_entry *match = NULL; struct sock *sk = (struct sock *)msk; struct mptcp_pm_addr_entry *e; bool addr_match = false; @@ -63,16 +62,12 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, if (addr_match && entry->addr.id == 0 && needs_id) entry->addr.id = e->addr.id; id_match = (e->addr.id == entry->addr.id); - if (addr_match && id_match) { - match = e; + if (addr_match || id_match) break; - } else if (addr_match || id_match) { - break; - } __set_bit(e->addr.id, id_bitmap.map); } - if (!match && !addr_match && !id_match) { + if (!addr_match && !id_match) { /* Memory for the entry is allocated from the * sock option buffer. */ @@ -90,7 +85,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, list_add_tail_rcu(&e->list, &msk->pm.userspace_pm_local_addr_list); msk->pm.local_addr_used++; ret = e->addr.id; - } else if (match) { + } else if (addr_match && id_match) { ret = entry->addr.id; } From patchwork Wed Jan 15 09:59:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13940192 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 F174E1DB14D for ; Wed, 15 Jan 2025 09:59:49 +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=1736935190; cv=none; b=VqMt/Lb/1B2DDIJsX8BHek24KPNummNGZmHOU/fHNqgRQ9zjq+N/JCMMGrrnyMrvzssiJWvVqxMWv1st6dMknKrgrcvqDZLvGpu8nthFSI6v+SIt47BEgXBDtmyuZSW43kjnrxL3jdBtoQ2p0MQ6g1TWDzjYLCxsRKpDF4zOi80= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736935190; c=relaxed/simple; bh=rXH8FpolB35Qn7+rHdrsYKPOEuRbjgNNE0VlMv4qb6o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bP85Bo6AINfkO6HMimfbDV2qY3rSIJbHh+S3VrNSyc1F2QopE8zjSNRddRGX0e57/mEcdaCn06fUVrCJKs4WJ3RxA6bdOVbmt+OHpUNFnpvp/lGBDqr2gbZOAapWsAMO24azvwKy1OElnGJofUumzMnOJ08yKSaC8hYhqKp2xZQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q2wHd+9a; 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="q2wHd+9a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13067C4CEE1; Wed, 15 Jan 2025 09:59:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736935189; bh=rXH8FpolB35Qn7+rHdrsYKPOEuRbjgNNE0VlMv4qb6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q2wHd+9aWzfV8qTwv3zbNWxhPT7+4jtyPu6ZCmqh2qtxgxi2QLgAwOBvRcbMotTeo KmUPjX+UYbJFFDRHCtLhVSuroll9tqq8jI2bcEAm6ZWUtxl8lZUaO6XtPMS1NJ2fL4 fejcMhDtU5kM8fAL8oiv7OCK8lp2XppU19VNtp/evdDi50l61b/VzDu3sHIgmVRw9j AsJ1xCyGAQLnNZggXQvHVKadFmCSz105qSGaiko9BlwcYe6GSOXMtZTrfQwq6BGdtr FfaF1vJ2t3CYXhZ34hrhiWWTEMBDjueLxukR46U+Jrao0/9ybOZKEy53B2pQ2NPv5S zlWtXq+ehpWdA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 5/6] mptcp: hold msk lock before removing id 0 address Date: Wed, 15 Jan 2025 17:59:31 +0800 Message-ID: <9eb68e270d56b0bd7cc92e6d84c735465cc39bd3.1736935086.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 From: Geliang Tang In mptcp_pm_nl_remove_doit(), move 'lock_sock(sk)' before invoking the function mptcp_userspace_pm_remove_id_zero_address(). Then no need to hold and release this lock in this function. And 'sk' and 'err' variables and 'remove_err' label in it can be dropped. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 7075c7f7229f..eda4277bfff4 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -256,11 +256,8 @@ static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk) { struct mptcp_rm_list list = { .nr = 0 }; struct mptcp_subflow_context *subflow; - struct sock *sk = (struct sock *)msk; bool has_id_0 = false; - int err = -EINVAL; - lock_sock(sk); mptcp_for_each_subflow(msk, subflow) { if (READ_ONCE(subflow->local_id) == 0) { has_id_0 = true; @@ -268,7 +265,7 @@ static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk) } } if (!has_id_0) - goto remove_err; + return -EINVAL; list.ids[list.nr++] = 0; @@ -276,11 +273,7 @@ static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk) mptcp_pm_remove_addr(msk, &list); spin_unlock_bh(&msk->pm.lock); - err = 0; - -remove_err: - release_sock(sk); - return err; + return 0; } void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk, @@ -324,13 +317,14 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) sk = (struct sock *)msk; + lock_sock(sk); + if (id_val == 0) { err = mptcp_userspace_pm_remove_id_zero_address(msk); + release_sock(sk); goto out; } - lock_sock(sk); - spin_lock_bh(&msk->pm.lock); match = mptcp_userspace_pm_lookup_addr_by_id(msk, id_val); if (!match) { From patchwork Wed Jan 15 09:59:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13940193 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 4B26B1DB14D for ; Wed, 15 Jan 2025 09:59:51 +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=1736935191; cv=none; b=iayrkRJCv7BTdD6L6EByLesWaTwQN4IIzmi1vnGqr52IIHoetSKszVHkidI7USADkKs1h5L4u5fnyB91sCsIr76TuwjwLDPmjSr1UTOA25t4PllAAdFNTY3IjIgLIdv5rujvNOeSkrdVANWbMkuiLu5WPDBbxOIut0qJZxEDgRo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736935191; c=relaxed/simple; bh=7mkYii45NYgmQcvp6vpUD1R88k+FO4BEjXgso8lwUgw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gdP913GTyx8oOeVqzi1j6ww4XBMX4yOKlajnSqGhjpE9Me6NLNMqCr3gSu9zuu2W9Lme4SxrjBArSybgIdQ58LA3DTWm68e3kRJneR4d+6Jn1syRj9lUs1kRAGIkdnT2wixd54LIkOTVtsBq6dpgUal8+TfXhXUzp6+CozXCNu0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hHPMVT0b; 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="hHPMVT0b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56E44C4CEE2; Wed, 15 Jan 2025 09:59:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736935191; bh=7mkYii45NYgmQcvp6vpUD1R88k+FO4BEjXgso8lwUgw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hHPMVT0bjCmr9AWgUzYNByQ5HfiCnGPggtk+oHXKgyZR9WYCuF+CYLCAXsn8qWBmM 1GgqQpWa+CVXKAvcvMduiJfReR61aM9KlqHwJ+7cqlUkJjZs98A4Zpbu+qloS8rv/I b2CadwSKF4tpYMTBDVAU536ZBT8WVnNNc6QMlWMN3iydZr8ahQX8mDVtGtuEzm2bFO Z0ixc+D7tUVABTNb0jJ+xwLUJKpz2BzTsuRwGFN3RlCFkkbTl9+TwJmwMKUFRRgBaT jEhiM8e6YzjWzdlkHNcZzIDOBTUdvvzm/m0snwE8gci7eaNzBiicyY73GePF/1YCSQ R8wiOxz+//SxA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 6/6] mptcp: change is_backup interfaces as get_flags Date: Wed, 15 Jan 2025 17:59:32 +0800 Message-ID: <2c8cc97535d697aadc62d222f3af85f865efec30.1736935086.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 From: Geliang Tang is_backup() interface of the path managers 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 | 9 +++++---- net/mptcp/pm_userspace.c | 10 +++++----- net/mptcp/protocol.h | 6 ++++-- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 16cacce6c10f..e275be73b963 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -425,13 +425,16 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc) { struct mptcp_addr_info skc_local; + u8 flags; mptcp_local_address((struct sock_common *)skc, &skc_local); if (mptcp_pm_is_userspace(msk)) - return mptcp_userspace_pm_is_backup(msk, &skc_local); + flags = mptcp_userspace_pm_get_flags(msk, &skc_local); + else + flags = mptcp_pm_nl_get_flags(msk, &skc_local); - return mptcp_pm_nl_is_backup(msk, &skc_local); + return !!(flags & MPTCP_PM_ADDR_FLAG_BACKUP); } static int mptcp_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index afd517ff260c..e7febe3f00ae 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1172,18 +1172,19 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc return ret; } -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 *skc) { struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk); struct mptcp_pm_addr_entry *entry; - bool backup; + u8 flags; rcu_read_lock(); entry = __lookup_addr(pernet, skc); - backup = entry && !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); + flags = entry ? entry->flags : 0; rcu_read_unlock(); - return backup; + return flags; } #define MPTCP_PM_CMD_GRP_OFFSET 0 diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index eda4277bfff4..1713e9bb6945 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -154,18 +154,18 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, return mptcp_userspace_pm_append_new_local_addr(msk, &new_entry, true); } -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; + u8 flags; spin_lock_bh(&msk->pm.lock); entry = mptcp_userspace_pm_lookup_addr(msk, skc); - backup = entry && !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); + flags = entry ? entry->flags : 0; spin_unlock_bh(&msk->pm.lock); - return backup; + return flags; } static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *info) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index aca3de2baf81..e8d8236a40e1 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1132,8 +1132,10 @@ 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_info *skc); int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc); 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_addr_info *skc); +u8 mptcp_pm_nl_get_flags(struct mptcp_sock *msk, + struct mptcp_addr_info *skc); +u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk, + struct mptcp_addr_info *skc); int mptcp_pm_nl_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,