From nobody Wed Jan 22 01:25:56 2025 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 4B41C22E406 for ; Wed, 15 Jan 2025 07:08: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=1736924923; cv=none; b=FXAVFLUgGj6mqxCBuqd8L3WGmYjNl0RS2DUPpTduN4/d5AEQllwmN/x54UAGlBUAme9tz/vjY3ws/FKoM7P1VPsPoQuYdLgDBQ8W8IzWjBSkElcofojbjlFV1yIla1WGrUgEyza0+7Z58cRyBGKzLK9/sj8ey/kYJVNQR07jVqE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736924923; c=relaxed/simple; bh=6JtPSofMynJwdChakfUTX9LL11rZmMBkN1FRhZl3pVw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AltzRKkuosGVtpJjZv/YeR6275vrU4X7/YLM/tPrWEyKMaItShHMLuaKFVEKdSIfAp9qG97Z1vw86MClzZyIzD8UlXhpe3txBrEqXQ0ZThSJeH69EsP+wKRI5JQrmrXrdNuDTSu6IZvcCpbRlzMMolN+Cc4uAXJs2tT7Gl4FMxg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eXmr+SsO; 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="eXmr+SsO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AAC4EC4CEE1; Wed, 15 Jan 2025 07:08:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736924922; bh=6JtPSofMynJwdChakfUTX9LL11rZmMBkN1FRhZl3pVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eXmr+SsOu8q7WJd2nOEAotP5TNgCWGwP4RLCJw9wflQxdL12dOvyTkU1fcogp7g5S 9uY92+8VNPQm+VvANg7usFM0ftX/edwvh7vdLc7Ga0Gqr1DyDCYbe+Dhi3W2D2xCao j4d9PKK0HhQpvLo2rhBl2IUXqn+dqVHklsIixxRkhekURYdLlDk5x3VCC4pxZFiUrN GhngCpEK1H23IFaPkNcvSvHcSA3rGV8FFJbDL7QJelmySS1U3RrRvvNlOjFNiplrsj 1YX8RYHgtz56CMydk3GGs2z+Bn6JGMi9xVBdI9PE2UlNwyMd/ZzXmLbI6T2U300uJd L2aHjeWm0Kg9A== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 1/3] mptcp: define struct mptcp_pm_ops Date: Wed, 15 Jan 2025 15:08:32 +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 In order to allow users to develop their own BPF-based path manager, this patch defines a struct ops "mptcp_pm_ops" for a userspace path manager, which contains a set of interfaces. Add a set of functions to register, unregister, find and validate a given struct ops. Signed-off-by: Geliang Tang --- include/net/mptcp.h | 27 +++++++++++++++++++ net/mptcp/pm_userspace.c | 57 ++++++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 5 ++++ 3 files changed, 89 insertions(+) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 94d5976f7b8d..0918b91a29ab 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -14,6 +14,7 @@ =20 struct mptcp_info; struct mptcp_sock; +struct mptcp_pm_addr_entry; struct seq_file; =20 /* MPTCP sk_buff extension data */ @@ -120,6 +121,32 @@ struct mptcp_sched_ops { void (*release)(struct mptcp_sock *msk); } ____cacheline_aligned_in_smp; =20 +struct mptcp_pm_ops { + int (*address_announce)(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local); + int (*address_remove)(struct mptcp_sock *msk, u8 id); + int (*subflow_create)(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local, + struct mptcp_addr_info *remote); + int (*subflow_destroy)(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local, + struct mptcp_addr_info *remote); + int (*get_local_id)(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local); + u8 (*get_flags)(struct mptcp_sock *msk, + struct mptcp_addr_info *skc); + int (*set_flags)(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local, + struct mptcp_addr_info *remote); + + u8 type; + struct module *owner; + struct list_head list; + + void (*init)(struct mptcp_sock *msk); + void (*release)(struct mptcp_sock *msk); +} ____cacheline_aligned_in_smp; + #ifdef CONFIG_MPTCP void mptcp_init(void); =20 diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index a7b836309d2b..1530b0c9d0b4 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -4,6 +4,8 @@ * Copyright (c) 2022, Intel Corporation. */ =20 +#include +#include #include "protocol.h" #include "mib.h" #include "mptcp_pm_gen.h" @@ -12,6 +14,9 @@ list_for_each_entry(__entry, \ &((__msk)->pm.userspace_pm_local_addr_list), list) =20 +static DEFINE_SPINLOCK(mptcp_pm_list_lock); +static LIST_HEAD(mptcp_pm_list); + void mptcp_free_local_addr_list(struct mptcp_sock *msk) { struct mptcp_pm_addr_entry *entry, *tmp; @@ -676,3 +681,55 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm= _addr_entry *addr, sock_put(sk); return ret; } + +/* Must be called with rcu read lock held */ +struct mptcp_pm_ops *mptcp_pm_find(enum mptcp_pm_type type) +{ + struct mptcp_pm_ops *pm; + + list_for_each_entry_rcu(pm, &mptcp_pm_list, list) { + if (pm->type =3D=3D type) + return pm; + } + + return NULL; +} + +int mptcp_validate_path_manager(struct mptcp_pm_ops *pm) +{ + if (!pm->address_announce && !pm->address_remove && + !pm->subflow_create && !pm->subflow_destroy && + !pm->get_local_id && !pm->get_flags && !pm->set_flags) { + pr_err("%u does not implement required ops\n", pm->type); + return -EINVAL; + } + + return 0; +} + +int mptcp_register_path_manager(struct mptcp_pm_ops *pm) +{ + int ret; + + ret =3D mptcp_validate_path_manager(pm); + if (ret) + return ret; + + spin_lock(&mptcp_pm_list_lock); + if (mptcp_pm_find(pm->type)) { + spin_unlock(&mptcp_pm_list_lock); + return -EEXIST; + } + list_add_tail_rcu(&pm->list, &mptcp_pm_list); + spin_unlock(&mptcp_pm_list_lock); + + pr_debug("userspace_pm type %u registered\n", pm->type); + return 0; +} + +void mptcp_unregister_path_manager(struct mptcp_pm_ops *pm) +{ + spin_lock(&mptcp_pm_list_lock); + list_del_rcu(&pm->list); + spin_unlock(&mptcp_pm_list_lock); +} diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 80a18877e47d..10aa4820c5b2 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1048,6 +1048,11 @@ int mptcp_pm_remove_addr(struct mptcp_sock *msk, con= st struct mptcp_rm_list *rm_ void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *entry); =20 +struct mptcp_pm_ops *mptcp_pm_find(enum mptcp_pm_type type); +int mptcp_validate_path_manager(struct mptcp_pm_ops *pm); +int mptcp_register_path_manager(struct mptcp_pm_ops *pm); +void mptcp_unregister_path_manager(struct mptcp_pm_ops *pm); + void mptcp_free_local_addr_list(struct mptcp_sock *msk); =20 void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk, --=20 2.43.0 From nobody Wed Jan 22 01:25:56 2025 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 AB9A422E406 for ; Wed, 15 Jan 2025 07:08: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=1736924925; cv=none; b=m/uij9l/G537h5/VxAAKUQ3CrB/pA+8BcV4+0EBqOe39giItBZgpu45pNp6LftgdKcVXg0eWQNQtvFRWoGg9hgWjiQW8a0wRtjZDD6k+tS/VZs8wYeAYUr9DLsDpe/z+GljMuXxq98Z9nFO7VMoITVE2zMKnX0SlDKb+IyRkt1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736924925; c=relaxed/simple; bh=LAV138qnnnVbF8SX3IChfKjVFZQyntkD5BpPKmnwrFc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gy0jU7fEFyH83LWdBjXeIdfYiulKOl6smvkN+kz77r7HQc52bizYgexM/MgJ2z/SiJ/1Mf8vSWQnEWkNG5UfXxvhYpXgUPmEV0DMgzX3qDJaUyTb3DnSL50dI7aHApgLYjjIRmATYlHe2LRxtHXYC6p5va3rIIbAz0RobedzXA0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=u8k08WB/; 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="u8k08WB/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D770C4CEE1; Wed, 15 Jan 2025 07:08:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736924925; bh=LAV138qnnnVbF8SX3IChfKjVFZQyntkD5BpPKmnwrFc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u8k08WB/hNaK1ZNujfzaxOpU6wlpmO0fYwlryaIr9QQ4LwZ3tmJgy/idQEjWRs1hq D3zv/E2AvbF8LrAlHHnqGcbivoqHDVLHlUAL8TV4/mbpHJu0LzuoqYhflz/k0LS/33 WqSmhpcNpzKtXWXD93fN6xtvw3y6XA7jMa1wl720pQwdNHzTZb8xnGOFnB8FyVmJa1 oNi6pl7ZEIoMCEdL7GZXAW+82ykXnrM87pU7RpQcvcBPtBNnx9C/gl5durLn83+Vzo L++VGSIEI7TyU5iQ+MIDv62bn1ZDFHQL/Yw9KMh9GBRoIxigIUt29knTr50dkcyd6m Xe7zcyaIkLWTg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 2/3] mptcp: register default userspace pm Date: Wed, 15 Jan 2025 15:08:33 +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 This patch defines the original userspace pm as the default path manager, named mptcp_userspace_pm, and register it in mptcp_pm_data_init(). Extract address_announce() interface of the userspace PM from the handler of netlink commond MPTCP_PM_CMD_ANNOUNCE mptcp_pm_nl_announce_doit(), only leave the code for obtaining msk through "info" and parsing address entry in the handler. Extract address_remove() interface of the userspace PM from the handler of netlink commond MPTCP_PM_CMD_REMOVE mptcp_pm_nl_remove_doit(), only leave the code for parsing address id and obtaining msk through "info" in the handler. Extract subflow_create() interface of the userspace PM from the handler of netlink commond MPTCP_PM_CMD_SUBFLOW_CREATE mptcp_pm_nl_subflow_create_doit(), only leave the code for obtaining msk through "info", parsing local address entry and parsing remote address info in the handler. Extract subflow_destroy() interface of the userspace PM from the handler of netlink commond MPTCP_PM_CMD_SUBFLOW_DESTROY mptcp_pm_nl_subflow_destroy_doit(), only leave the code for obtaining msk through "info", parsing local address entry and parsing remote address info in the handler. Extract set_flags() interface of the userspace PM from function mptcp_userspace_pm_set_flags(), only leave the code for obtaining msk through "info" in this function. All fives interfaces are invoked under holding the msk socket lock. Other interfaces get_local_id() and get_flags() are only defined as wrappers. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 1 + net/mptcp/pm_userspace.c | 261 ++++++++++++++++++++++++--------------- net/mptcp/protocol.h | 1 + 3 files changed, 165 insertions(+), 98 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index a0f4d06692cc..aa0fee7c1b77 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -650,4 +650,5 @@ void mptcp_pm_data_init(struct mptcp_sock *msk) void __init mptcp_pm_init(void) { mptcp_pm_nl_init(); + mptcp_userspace_pm_init(); } diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 1530b0c9d0b4..ac4ccda43ce8 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -135,8 +135,8 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_sock = *msk, unsigned int id) return NULL; } =20 -int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, - struct mptcp_pm_addr_entry *local) +static int userspace_pm_get_local_id(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local) { __be16 msk_sport =3D ((struct inet_sock *) inet_sk((struct sock *)msk))->inet_sport; @@ -154,8 +154,14 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock = *msk, return mptcp_userspace_pm_append_new_local_addr(msk, local, true); } =20 -u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk, - struct mptcp_addr_info *skc) +int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local) +{ + return userspace_pm_get_local_id(msk, local); +} + +static u8 userspace_pm_get_flags(struct mptcp_sock *msk, + struct mptcp_addr_info *skc) { struct mptcp_pm_addr_entry *entry; u8 flags; @@ -168,6 +174,12 @@ u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk, return flags; } =20 +u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk, + struct mptcp_addr_info *skc) +{ + return userspace_pm_get_flags(msk, skc); +} + static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_in= fo *info) { struct mptcp_sock *msk; @@ -193,6 +205,28 @@ static struct mptcp_sock *mptcp_userspace_pm_get_sock(= const struct genl_info *in return msk; } =20 +static int userspace_pm_address_announce(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local) +{ + int err; + + err =3D mptcp_userspace_pm_append_new_local_addr(msk, local, false); + if (err < 0) + return err; + + spin_lock_bh(&msk->pm.lock); + + if (mptcp_pm_alloc_anno_list(msk, &local->addr)) { + msk->pm.add_addr_signaled++; + mptcp_pm_announce_addr(msk, &local->addr, false); + mptcp_pm_nl_addr_send_ack(msk); + } + + spin_unlock_bh(&msk->pm.lock); + + return 0; +} + int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) { struct mptcp_pm_addr_entry addr_val; @@ -227,26 +261,13 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, st= ruct genl_info *info) goto announce_err; } =20 - err =3D mptcp_userspace_pm_append_new_local_addr(msk, &addr_val, false); - if (err < 0) { - NL_SET_ERR_MSG_ATTR(info->extack, addr, - "did not match address and id"); - goto announce_err; - } - lock_sock(sk); - spin_lock_bh(&msk->pm.lock); - - if (mptcp_pm_alloc_anno_list(msk, &addr_val.addr)) { - msk->pm.add_addr_signaled++; - mptcp_pm_announce_addr(msk, &addr_val.addr, false); - mptcp_pm_nl_addr_send_ack(msk); - } - - spin_unlock_bh(&msk->pm.lock); + err =3D userspace_pm_address_announce(msk, &addr_val); release_sock(sk); + if (err) + NL_SET_ERR_MSG_ATTR(info->extack, addr, + "did not match address and id"); =20 - err =3D 0; announce_err: sock_put(sk); return err; @@ -296,9 +317,32 @@ void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk, spin_unlock_bh(&msk->pm.lock); } =20 +static int userspace_pm_address_remove(struct mptcp_sock *msk, u8 id) +{ + struct mptcp_pm_addr_entry *entry; + + if (id =3D=3D 0) + return mptcp_userspace_pm_remove_id_zero_address(msk); + + spin_lock_bh(&msk->pm.lock); + entry =3D mptcp_userspace_pm_lookup_addr_by_id(msk, id); + if (!entry) { + spin_unlock_bh(&msk->pm.lock); + return -EINVAL; + } + + list_del_rcu(&entry->list); + spin_unlock_bh(&msk->pm.lock); + + mptcp_pm_remove_addr_entry(msk, entry); + + sock_kfree_s((struct sock *)msk, entry, sizeof(*entry)); + + return 0; +} + int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) { - struct mptcp_pm_addr_entry *match; struct mptcp_sock *msk; struct nlattr *id; int err =3D -EINVAL; @@ -318,32 +362,8 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struc= t genl_info *info) sk =3D (struct sock *)msk; =20 lock_sock(sk); - - if (id_val =3D=3D 0) { - err =3D mptcp_userspace_pm_remove_id_zero_address(msk); - release_sock(sk); - goto out; - } - - spin_lock_bh(&msk->pm.lock); - match =3D mptcp_userspace_pm_lookup_addr_by_id(msk, id_val); - if (!match) { - spin_unlock_bh(&msk->pm.lock); - release_sock(sk); - goto out; - } - - list_del_rcu(&match->list); - spin_unlock_bh(&msk->pm.lock); - - mptcp_pm_remove_addr_entry(msk, match); - + err =3D userspace_pm_address_remove(msk, id_val); release_sock(sk); - - sock_kfree_s(sk, match, sizeof(*match)); - - err =3D 0; -out: if (err) NL_SET_ERR_MSG_ATTR_FMT(info->extack, id, "address with id %u not found", @@ -353,12 +373,38 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, stru= ct genl_info *info) return err; } =20 +static int userspace_pm_subflow_create(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *entry, + struct mptcp_addr_info *remote) +{ + struct sock *sk =3D (struct sock *)msk; + struct mptcp_pm_local local; + int err; + + err =3D mptcp_userspace_pm_append_new_local_addr(msk, entry, false); + if (err < 0) + return err; + + local.addr =3D entry->addr; + local.flags =3D entry->flags; + local.ifindex =3D entry->ifindex; + + err =3D __mptcp_subflow_connect(sk, &local, remote); + spin_lock_bh(&msk->pm.lock); + if (err) + mptcp_userspace_pm_delete_local_addr(msk, entry); + else + msk->pm.subflows++; + spin_unlock_bh(&msk->pm.lock); + + return 0; +} + int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info = *info) { struct mptcp_pm_addr_entry entry =3D { 0 }; struct mptcp_addr_info addr_r; struct nlattr *raddr, *laddr; - struct mptcp_pm_local local; struct mptcp_sock *msk; int err =3D -EINVAL; struct sock *sk; @@ -396,31 +442,13 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *s= kb, struct genl_info *info) goto create_err; } =20 - err =3D mptcp_userspace_pm_append_new_local_addr(msk, &entry, false); - if (err < 0) { - NL_SET_ERR_MSG_ATTR(info->extack, laddr, - "did not match address and id"); - goto create_err; - } - - 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 userspace_pm_subflow_create(msk, &entry, &addr_r); release_sock(sk); =20 if (err) GENL_SET_ERR_MSG_FMT(info, "connect error: %d", err); =20 - spin_lock_bh(&msk->pm.lock); - if (err) - mptcp_userspace_pm_delete_local_addr(msk, &entry); - else - msk->pm.subflows++; - spin_unlock_bh(&msk->pm.lock); - create_err: sock_put(sk); return err; @@ -472,14 +500,34 @@ static struct sock *mptcp_nl_find_ssk(struct mptcp_so= ck *msk, return NULL; } =20 +static int userspace_pm_subflow_destroy(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local, + struct mptcp_addr_info *remote) +{ + struct sock *ssk, *sk =3D (struct sock *)msk; + + ssk =3D mptcp_nl_find_ssk(msk, &local->addr, remote); + if (!ssk) + return -ESRCH; + + spin_lock_bh(&msk->pm.lock); + mptcp_userspace_pm_delete_local_addr(msk, local); + spin_unlock_bh(&msk->pm.lock); + mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN); + mptcp_close_ssk(sk, ssk, mptcp_subflow_ctx(ssk)); + MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMSUBFLOW); + + return 0; +} + int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info= *info) { struct mptcp_pm_addr_entry addr_l; struct mptcp_addr_info addr_r; struct nlattr *raddr, *laddr; struct mptcp_sock *msk; - struct sock *sk, *ssk; int err =3D -EINVAL; + struct sock *sk; =20 if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR) || GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR_REMOTE)) @@ -530,37 +578,47 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *= skb, struct genl_info *info } =20 lock_sock(sk); - ssk =3D mptcp_nl_find_ssk(msk, &addr_l.addr, &addr_r); - if (!ssk) { - GENL_SET_ERR_MSG(info, "subflow not found"); - err =3D -ESRCH; - goto release_sock; - } - - spin_lock_bh(&msk->pm.lock); - mptcp_userspace_pm_delete_local_addr(msk, &addr_l); - spin_unlock_bh(&msk->pm.lock); - mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN); - mptcp_close_ssk(sk, ssk, mptcp_subflow_ctx(ssk)); - MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMSUBFLOW); -release_sock: + err =3D userspace_pm_subflow_destroy(msk, &addr_l, &addr_r); release_sock(sk); + if (err) + GENL_SET_ERR_MSG(info, "subflow not found"); =20 destroy_err: sock_put(sk); return err; } =20 +static int userspace_pm_set_flags(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local, + struct mptcp_addr_info *remote) +{ + struct mptcp_pm_addr_entry *entry; + u8 bkup =3D 0; + + if (local->flags & MPTCP_PM_ADDR_FLAG_BACKUP) + bkup =3D 1; + + spin_lock_bh(&msk->pm.lock); + entry =3D mptcp_userspace_pm_lookup_addr(msk, &local->addr); + if (entry) { + if (bkup) + entry->flags |=3D MPTCP_PM_ADDR_FLAG_BACKUP; + else + entry->flags &=3D ~MPTCP_PM_ADDR_FLAG_BACKUP; + } + spin_unlock_bh(&msk->pm.lock); + + return mptcp_pm_nl_mp_prio_send_ack(msk, &local->addr, remote, bkup); +} + int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *local, struct genl_info *info) { struct mptcp_addr_info rem =3D { .family =3D AF_UNSPEC, }; - struct mptcp_pm_addr_entry *entry; struct nlattr *attr, *attr_rem; struct mptcp_sock *msk; int ret =3D -EINVAL; struct sock *sk; - u8 bkup =3D 0; =20 if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR_REMOTE)) return ret; @@ -591,21 +649,8 @@ int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_= entry *local, goto set_flags_err; } =20 - if (local->flags & MPTCP_PM_ADDR_FLAG_BACKUP) - bkup =3D 1; - - spin_lock_bh(&msk->pm.lock); - entry =3D mptcp_userspace_pm_lookup_addr(msk, &local->addr); - if (entry) { - if (bkup) - entry->flags |=3D MPTCP_PM_ADDR_FLAG_BACKUP; - else - entry->flags &=3D ~MPTCP_PM_ADDR_FLAG_BACKUP; - } - spin_unlock_bh(&msk->pm.lock); - lock_sock(sk); - ret =3D mptcp_pm_nl_mp_prio_send_ack(msk, &local->addr, &rem, bkup); + ret =3D userspace_pm_set_flags(msk, local, &rem); release_sock(sk); =20 /* mptcp_pm_nl_mp_prio_send_ack() only fails in one case */ @@ -682,6 +727,18 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm= _addr_entry *addr, return ret; } =20 +static struct mptcp_pm_ops mptcp_userspace_pm =3D { + .address_announce =3D userspace_pm_address_announce, + .address_remove =3D userspace_pm_address_remove, + .subflow_create =3D userspace_pm_subflow_create, + .subflow_destroy =3D userspace_pm_subflow_destroy, + .get_local_id =3D userspace_pm_get_local_id, + .get_flags =3D userspace_pm_get_flags, + .set_flags =3D userspace_pm_set_flags, + .type =3D MPTCP_PM_TYPE_USERSPACE, + .owner =3D THIS_MODULE, +}; + /* Must be called with rcu read lock held */ struct mptcp_pm_ops *mptcp_pm_find(enum mptcp_pm_type type) { @@ -729,7 +786,15 @@ int mptcp_register_path_manager(struct mptcp_pm_ops *p= m) =20 void mptcp_unregister_path_manager(struct mptcp_pm_ops *pm) { + if (pm =3D=3D &mptcp_userspace_pm) + return; + spin_lock(&mptcp_pm_list_lock); list_del_rcu(&pm->list); spin_unlock(&mptcp_pm_list_lock); } + +void __init mptcp_userspace_pm_init(void) +{ + mptcp_register_path_manager(&mptcp_userspace_pm); +} diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 10aa4820c5b2..762873d9fa8c 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1162,6 +1162,7 @@ static inline u8 subflow_get_local_id(const struct mp= tcp_subflow_context *subflo } =20 void __init mptcp_pm_nl_init(void); +void __init mptcp_userspace_pm_init(void); void mptcp_pm_nl_work(struct mptcp_sock *msk); unsigned int mptcp_pm_get_add_addr_signal_max(const struct mptcp_sock *msk= ); unsigned int mptcp_pm_get_add_addr_accept_max(const struct mptcp_sock *msk= ); --=20 2.43.0 From nobody Wed Jan 22 01:25:56 2025 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 7D53F1BEF9E for ; Wed, 15 Jan 2025 07:08: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=1736924927; cv=none; b=BM+dixiZSzIJvV2EIzsR3F4ABJDjL52QDx5Hek7TX2hzvzSXWvOAg6sPZ83tSjJsBk6VtFEseTf92s3ft+nfE+u2mfcNfBXtOxMxPtn6wh7lgaZoSjGF0BMiNX9YZHZlNR4KaLjL8oQplMdzAiZ8F7+r3jkmlZsseFEQFEAkHv8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736924927; c=relaxed/simple; bh=5BQj75zP2sQAJFSNQDRX18yN9P8vflEFlVP/UqSEsS0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JoRRj214N0n30CyffKOKtXzrPOkoykcYhkTCxXidOwp/M4Zxx5ZaezPPi78cAqDNrUWfD/Ruz7feIQ8UCjVy8NIYZYpintgfoxj+GvHHfStzCjybyGkMV6KKol+2KlbGqWwBh2FB/kO8GpV7FcEDac+Em0tGagAkDCDy4E2DnM4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Xlg/i6BL; 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="Xlg/i6BL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBF84C4CEDF; Wed, 15 Jan 2025 07:08:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736924927; bh=5BQj75zP2sQAJFSNQDRX18yN9P8vflEFlVP/UqSEsS0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xlg/i6BL1i5xt5QFC7s0A87c5yfkwq0td8PMjtlIlX5nToUDrXXCRBm0gQ5OoAcZI IXz92+fDdHOncAP8wapBM0BFCPik/ZKFhttGVyyJ6efYCazC83vvoPIkvCp2+w9lrC 0uOr1rKTaG2D7eSJprvoUZtx0/sV30SW7C7a/l9nEWjhOb4t+qiwY1y8LUTHX0J+46 G+DEeHB0GFnAhC2q2JMzKaIn9Oz8u9NBCcuQ3fnZTSsf4TtDo1v0o6cDNfm94OOW0D WwpTZoK8jB8s6riKSzzrQPFn5cDovsUeYIqpKGfBeCNQ9gpeZGZt8WrsqAef9NpCnr eFSp4qu710XsQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 3/3] mptcp: init and release mptcp_pm_ops Date: Wed, 15 Jan 2025 15:08:34 +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 Add a struct mptcp_pm_ops pointer "ops" in struct mptcp_pm_data, and two functions mptcp_init_pm() and mptcp_release_pm(), to set and release this pointer. mptcp_init_pm() is invoked in mptcp_pm_data_reset(), while mptcp_release_pm() is invoked in __mptcp_destroy_sock(). In this way, different userspace path managers can be initialized through the pm_type sysctl, and then called into their respective interfaces through "ops" of "msk->pm". Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 7 +++++ net/mptcp/pm_userspace.c | 58 +++++++++++++++++++++++++++++++++++----- net/mptcp/protocol.c | 1 + net/mptcp/protocol.h | 3 +++ 4 files changed, 62 insertions(+), 7 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index aa0fee7c1b77..8352d44ab9b3 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -604,6 +604,7 @@ void mptcp_pm_data_reset(struct mptcp_sock *msk) { u8 pm_type =3D mptcp_get_pm_type(sock_net((struct sock *)msk)); struct mptcp_pm_data *pm =3D &msk->pm; + int ret; =20 pm->add_addr_signaled =3D 0; pm->add_addr_accepted =3D 0; @@ -631,6 +632,12 @@ void mptcp_pm_data_reset(struct mptcp_sock *msk) WRITE_ONCE(pm->work_pending, 0); WRITE_ONCE(pm->accept_addr, 0); WRITE_ONCE(pm->accept_subflow, 0); + + rcu_read_lock(); + ret =3D mptcp_init_pm(msk, mptcp_pm_find(pm_type)); + rcu_read_unlock(); + if (ret) + return; } =20 WRITE_ONCE(pm->addr_signal, 0); diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index ac4ccda43ce8..e19374a057c5 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -157,7 +157,9 @@ static int userspace_pm_get_local_id(struct mptcp_sock = *msk, int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *local) { - return userspace_pm_get_local_id(msk, local); + return msk->pm.ops->get_local_id ? + msk->pm.ops->get_local_id(msk, local) : + userspace_pm_get_local_id(msk, local); } =20 static u8 userspace_pm_get_flags(struct mptcp_sock *msk, @@ -177,7 +179,9 @@ static u8 userspace_pm_get_flags(struct mptcp_sock *msk, u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk, struct mptcp_addr_info *skc) { - return userspace_pm_get_flags(msk, skc); + return msk->pm.ops->get_flags ? + msk->pm.ops->get_flags(msk, skc) : + userspace_pm_get_flags(msk, skc); } =20 static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_in= fo *info) @@ -262,7 +266,9 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, stru= ct genl_info *info) } =20 lock_sock(sk); - err =3D userspace_pm_address_announce(msk, &addr_val); + err =3D msk->pm.ops->address_announce ? + msk->pm.ops->address_announce(msk, &addr_val) : + userspace_pm_address_announce(msk, &addr_val); release_sock(sk); if (err) NL_SET_ERR_MSG_ATTR(info->extack, addr, @@ -362,7 +368,9 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct= genl_info *info) sk =3D (struct sock *)msk; =20 lock_sock(sk); - err =3D userspace_pm_address_remove(msk, id_val); + err =3D msk->pm.ops->address_remove ? + msk->pm.ops->address_remove(msk, id_val) : + userspace_pm_address_remove(msk, id_val); release_sock(sk); if (err) NL_SET_ERR_MSG_ATTR_FMT(info->extack, id, @@ -443,7 +451,9 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb= , struct genl_info *info) } =20 lock_sock(sk); - err =3D userspace_pm_subflow_create(msk, &entry, &addr_r); + err =3D msk->pm.ops->subflow_create ? + msk->pm.ops->subflow_create(msk, &entry, &addr_r) : + userspace_pm_subflow_create(msk, &entry, &addr_r); release_sock(sk); =20 if (err) @@ -578,7 +588,9 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *sk= b, struct genl_info *info } =20 lock_sock(sk); - err =3D userspace_pm_subflow_destroy(msk, &addr_l, &addr_r); + err =3D msk->pm.ops->subflow_destroy ? + msk->pm.ops->subflow_destroy(msk, &addr_l, &addr_r) : + userspace_pm_subflow_destroy(msk, &addr_l, &addr_r); release_sock(sk); if (err) GENL_SET_ERR_MSG(info, "subflow not found"); @@ -650,7 +662,9 @@ int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_e= ntry *local, } =20 lock_sock(sk); - ret =3D userspace_pm_set_flags(msk, local, &rem); + ret =3D msk->pm.ops->set_flags ? + msk->pm.ops->set_flags(msk, local, &rem) : + userspace_pm_set_flags(msk, local, &rem); release_sock(sk); =20 /* mptcp_pm_nl_mp_prio_send_ack() only fails in one case */ @@ -794,6 +808,36 @@ void mptcp_unregister_path_manager(struct mptcp_pm_ops= *pm) spin_unlock(&mptcp_pm_list_lock); } =20 +int mptcp_init_pm(struct mptcp_sock *msk, struct mptcp_pm_ops *pm) +{ + if (!pm) + pm =3D &mptcp_userspace_pm; + + if (!bpf_try_module_get(pm, pm->owner)) + return -EBUSY; + + msk->pm.ops =3D pm; + if (msk->pm.ops->init) + msk->pm.ops->init(msk); + + pr_debug("userspace_pm type %u initialized\n", msk->pm.ops->type); + return 0; +} + +void mptcp_release_pm(struct mptcp_sock *msk) +{ + struct mptcp_pm_ops *pm =3D msk->pm.ops; + + if (!pm) + return; + + msk->pm.ops =3D NULL; + if (pm->release) + pm->release(msk); + + bpf_module_put(pm, pm->owner); +} + void __init mptcp_userspace_pm_init(void) { mptcp_register_path_manager(&mptcp_userspace_pm); diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 5cda189d29f2..bba22c3f7279 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -2940,6 +2940,7 @@ static void __mptcp_destroy_sock(struct sock *sk) sk_stop_timer(sk, &sk->sk_timer); msk->pm.status =3D 0; mptcp_release_sched(msk); + mptcp_release_pm(msk); =20 sk->sk_prot->destroy(sk); =20 diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 762873d9fa8c..a64125e8ad80 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -221,6 +221,7 @@ struct mptcp_pm_data { struct mptcp_addr_info remote; struct list_head anno_list; struct list_head userspace_pm_local_addr_list; + struct mptcp_pm_ops *ops; =20 spinlock_t lock; /*protects the whole PM data */ =20 @@ -1052,6 +1053,8 @@ struct mptcp_pm_ops *mptcp_pm_find(enum mptcp_pm_type= type); int mptcp_validate_path_manager(struct mptcp_pm_ops *pm); int mptcp_register_path_manager(struct mptcp_pm_ops *pm); void mptcp_unregister_path_manager(struct mptcp_pm_ops *pm); +int mptcp_init_pm(struct mptcp_sock *msk, struct mptcp_pm_ops *pm); +void mptcp_release_pm(struct mptcp_sock *msk); =20 void mptcp_free_local_addr_list(struct mptcp_sock *msk); =20 --=20 2.43.0