diff mbox series

[mptcp-next,v3,6/9] mptcp: use mptcp_pm_local in pm_netlink only

Message ID b101754b454313dadde8c89634982f9052e0cfc7.1730961810.git.tanggeliang@kylinos.cn (mailing list archive)
State Rejected, archived
Headers show
Series BPF path manager, part 1 | expand

Checks

Context Check Description
matttbe/checkpatch warning total: 0 errors, 2 warnings, 0 checks, 93 lines checked
matttbe/shellcheck success MPTCP selftests files have not been modified
matttbe/build success Build and static analysis OK
matttbe/KVM_Validation__normal warning Unstable: 1 failed test(s): selftest_mptcp_connect
matttbe/KVM_Validation__debug success Success! ✅
matttbe/KVM_Validation__btf-normal__only_bpftest_all_ success Success! ✅
matttbe/KVM_Validation__btf-debug__only_bpftest_all_ warning Unstable: 1 failed test(s): bpftest_test_progs-cpuv4_mptcp

Commit Message

Geliang Tang Nov. 7, 2024, 6:45 a.m. UTC
From: Geliang Tang <tanggeliang@kylinos.cn>

struct mptcp_pm_local is used in pm_netlink to reduce memory usage, but
it has less effect in pm_userspace because userspace pm doesn't use an
array of struct mptcp_pm_addr_entry type.

So this patch moves struct mptcp_pm_local to pm_netlink and restores the
use of mptcp_pm_addr_entry type parameters in __mptcp_subflow_connect().
In this case, only one "struct mptcp_pm_addr_entry" is needed, that's not
reserving too much memory.

This patch makes the path manager code simpler, and easier to implement
the BPF path manager.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 net/mptcp/pm_netlink.c   | 26 ++++++++++++++++++++++----
 net/mptcp/pm_userspace.c |  7 +------
 net/mptcp/protocol.h     |  8 +-------
 net/mptcp/subflow.c      |  2 +-
 4 files changed, 25 insertions(+), 18 deletions(-)

Comments

Geliang Tang Nov. 10, 2024, 4:40 a.m. UTC | #1
As I mentioned in [1], I decided to deprecate this patch and keep the
code for struct mptcp_pm_local as it is.

I changed this patch as "Rejected" in patchwork. Other patches in this
set are still valid.

Thanks,
-Geliang

[1]
https://patchwork.kernel.org/project/mptcp/patch/5b8a8e318c9d661f495b6d0be2b7a776de7da7a1.1729588019.git.tanggeliang@kylinos.cn/

On Thu, 2024-11-07 at 14:45 +0800, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> struct mptcp_pm_local is used in pm_netlink to reduce memory usage,
> but
> it has less effect in pm_userspace because userspace pm doesn't use
> an
> array of struct mptcp_pm_addr_entry type.
> 
> So this patch moves struct mptcp_pm_local to pm_netlink and restores
> the
> use of mptcp_pm_addr_entry type parameters in
> __mptcp_subflow_connect().
> In this case, only one "struct mptcp_pm_addr_entry" is needed, that's
> not
> reserving too much memory.
> 
> This patch makes the path manager code simpler, and easier to
> implement
> the BPF path manager.
> 
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
>  net/mptcp/pm_netlink.c   | 26 ++++++++++++++++++++++----
>  net/mptcp/pm_userspace.c |  7 +------
>  net/mptcp/protocol.h     |  8 +-------
>  net/mptcp/subflow.c      |  2 +-
>  4 files changed, 25 insertions(+), 18 deletions(-)
> 
> diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
> index 8aba7670345d..00911fae5d88 100644
> --- a/net/mptcp/pm_netlink.c
> +++ b/net/mptcp/pm_netlink.c
> @@ -40,6 +40,12 @@ struct pm_nl_pernet {
>  	DECLARE_BITMAP(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
>  };
>  
> +struct mptcp_pm_local {
> +	struct mptcp_addr_info	addr;
> +	u8			flags;
> +	int			ifindex;
> +};
> +
>  #define MPTCP_PM_ADDR_MAX	8
>  #define ADD_ADDR_RETRANS_MAX	3
>  
> @@ -638,8 +644,14 @@ static void
> mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
>  			continue;
>  
>  		spin_unlock_bh(&msk->pm.lock);
> -		for (i = 0; i < nr; i++)
> -			__mptcp_subflow_connect(sk, &local,
> &addrs[i]);
> +		for (i = 0; i < nr; i++) {
> +			struct mptcp_pm_addr_entry entry = { 0 };
> +
> +			entry.addr = local.addr;
> +			entry.flags = local.flags;
> +			entry.ifindex = local.ifindex;
> +			__mptcp_subflow_connect(sk, &entry,
> &addrs[i]);
> +		}
>  		spin_lock_bh(&msk->pm.lock);
>  	}
>  	mptcp_pm_nl_check_work_pending(msk);
> @@ -755,9 +767,15 @@ static void mptcp_pm_nl_add_addr_received(struct
> mptcp_sock *msk)
>  		return;
>  
>  	spin_unlock_bh(&msk->pm.lock);
> -	for (i = 0; i < nr; i++)
> -		if (__mptcp_subflow_connect(sk, &locals[i], &remote)
> == 0)
> +	for (i = 0; i < nr; i++) {
> +		struct mptcp_pm_addr_entry entry = { 0 };
> +
> +		entry.addr = locals[i].addr;
> +		entry.flags = locals[i].flags;
> +		entry.ifindex = locals[i].ifindex;
> +		if (__mptcp_subflow_connect(sk, &entry, &remote) ==
> 0)
>  			sf_created = true;
> +	}
>  	spin_lock_bh(&msk->pm.lock);
>  
>  	if (sf_created) {
> diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
> index a98da9a44bfa..db09350b5022 100644
> --- a/net/mptcp/pm_userspace.c
> +++ b/net/mptcp/pm_userspace.c
> @@ -368,7 +368,6 @@ int mptcp_pm_nl_subflow_create_doit(struct
> sk_buff *skb, struct genl_info *info)
>  	struct nlattr *laddr = info->attrs[MPTCP_PM_ATTR_ADDR];
>  	struct mptcp_pm_addr_entry entry = { 0 };
>  	struct mptcp_addr_info addr_r;
> -	struct mptcp_pm_local local;
>  	struct mptcp_sock *msk;
>  	int err = -EINVAL;
>  	struct sock *sk;
> @@ -415,12 +414,8 @@ int mptcp_pm_nl_subflow_create_doit(struct
> sk_buff *skb, struct genl_info *info)
>  		goto create_err;
>  	}
>  
> -	local.addr = entry.addr;
> -	local.flags = entry.flags;
> -	local.ifindex = entry.ifindex;
> -
>  	lock_sock(sk);
> -	err = __mptcp_subflow_connect(sk, &local, &addr_r);
> +	err = __mptcp_subflow_connect(sk, &entry, &addr_r);
>  	release_sock(sk);
>  
>  	spin_lock_bh(&msk->pm.lock);
> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> index 19a811220621..775ac2fd6854 100644
> --- a/net/mptcp/protocol.h
> +++ b/net/mptcp/protocol.h
> @@ -236,12 +236,6 @@ struct mptcp_pm_data {
>  	struct mptcp_rm_list rm_list_rx;
>  };
>  
> -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;
> @@ -736,7 +730,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);
>  
>  /* 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_entry *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 07352b15f145..2ae8f467abc1 100644
> --- a/net/mptcp/subflow.c
> +++ b/net/mptcp/subflow.c
> @@ -1586,7 +1586,7 @@ void mptcp_info2sockaddr(const struct
> mptcp_addr_info *info,
>  #endif
>  }
>  
> -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_entry *local,
>  			    const struct mptcp_addr_info *remote)
>  {
>  	struct mptcp_sock *msk = mptcp_sk(sk);
diff mbox series

Patch

diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 8aba7670345d..00911fae5d88 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -40,6 +40,12 @@  struct pm_nl_pernet {
 	DECLARE_BITMAP(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
 };
 
+struct mptcp_pm_local {
+	struct mptcp_addr_info	addr;
+	u8			flags;
+	int			ifindex;
+};
+
 #define MPTCP_PM_ADDR_MAX	8
 #define ADD_ADDR_RETRANS_MAX	3
 
@@ -638,8 +644,14 @@  static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 			continue;
 
 		spin_unlock_bh(&msk->pm.lock);
-		for (i = 0; i < nr; i++)
-			__mptcp_subflow_connect(sk, &local, &addrs[i]);
+		for (i = 0; i < nr; i++) {
+			struct mptcp_pm_addr_entry entry = { 0 };
+
+			entry.addr = local.addr;
+			entry.flags = local.flags;
+			entry.ifindex = local.ifindex;
+			__mptcp_subflow_connect(sk, &entry, &addrs[i]);
+		}
 		spin_lock_bh(&msk->pm.lock);
 	}
 	mptcp_pm_nl_check_work_pending(msk);
@@ -755,9 +767,15 @@  static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)
 		return;
 
 	spin_unlock_bh(&msk->pm.lock);
-	for (i = 0; i < nr; i++)
-		if (__mptcp_subflow_connect(sk, &locals[i], &remote) == 0)
+	for (i = 0; i < nr; i++) {
+		struct mptcp_pm_addr_entry entry = { 0 };
+
+		entry.addr = locals[i].addr;
+		entry.flags = locals[i].flags;
+		entry.ifindex = locals[i].ifindex;
+		if (__mptcp_subflow_connect(sk, &entry, &remote) == 0)
 			sf_created = true;
+	}
 	spin_lock_bh(&msk->pm.lock);
 
 	if (sf_created) {
diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index a98da9a44bfa..db09350b5022 100644
--- a/net/mptcp/pm_userspace.c
+++ b/net/mptcp/pm_userspace.c
@@ -368,7 +368,6 @@  int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
 	struct nlattr *laddr = info->attrs[MPTCP_PM_ATTR_ADDR];
 	struct mptcp_pm_addr_entry entry = { 0 };
 	struct mptcp_addr_info addr_r;
-	struct mptcp_pm_local local;
 	struct mptcp_sock *msk;
 	int err = -EINVAL;
 	struct sock *sk;
@@ -415,12 +414,8 @@  int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
 		goto create_err;
 	}
 
-	local.addr = entry.addr;
-	local.flags = entry.flags;
-	local.ifindex = entry.ifindex;
-
 	lock_sock(sk);
-	err = __mptcp_subflow_connect(sk, &local, &addr_r);
+	err = __mptcp_subflow_connect(sk, &entry, &addr_r);
 	release_sock(sk);
 
 	spin_lock_bh(&msk->pm.lock);
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 19a811220621..775ac2fd6854 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -236,12 +236,6 @@  struct mptcp_pm_data {
 	struct mptcp_rm_list rm_list_rx;
 };
 
-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;
@@ -736,7 +730,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);
 
 /* 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_entry *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 07352b15f145..2ae8f467abc1 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -1586,7 +1586,7 @@  void mptcp_info2sockaddr(const struct mptcp_addr_info *info,
 #endif
 }
 
-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_entry *local,
 			    const struct mptcp_addr_info *remote)
 {
 	struct mptcp_sock *msk = mptcp_sk(sk);