BPF path manager, part 6
Subsystems (2)
Geliang Tang
reviewerv6 cover BPF path manager, part 6
From: Geliang Tang <[email protected]>
v6:
- squash accept_new_subflow patches into one.
- change "pm->subflows == subflows_max - 1" to
pm->subflows + 1 == subflows_max.
- not to call accept_new_subflow under the PM lock.
- add mptcp_pm_accept_subflow helpers.
- drop READ_ONCE in mptcp_pm_worker.
- clear all the pm status flags once in mptcp_pm_worker.
v5:
- add comment "call from the subflow/msk context" for mptcp_sched_ops.
- add new helper mptcp_pm_accept_new_subflow.
- add "bool allow" parameter for mptcp_pm_accept_new_subflow, and drop .allow_new_subflow interface.
- use a copy of pm->status in mptcp_pm_worker.
- rename mptcp_pm_create_subflow_or_signal_addr with "__" prefix.
- drop "!update_subflows" in mptcp_pm_subflow_check_next.
- add_addr_received/rm_addr_received interfaces will be added in the next series.
v4:
- address Matt's comments in v3.
- update pm locks in mptcp_pm_worker.
- move the lock inside mptcp_pm_create_subflow_or_signal_addr.
- move the lock inside mptcp_pm_nl_add_addr_received.
- invoke add_addr_received interface from mptcp_pm_worker.
- invoke rm_addr_received interface from mptcp_pm_rm_addr_or_subflow.
- simply call mptcp_pm_close_subflow() in mptcp_pm_subflow_check_next.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v3:
- merge 'bugfixes for "BPF path manager, part 6, v2"' into this set.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v2:
- address Matt's comments in v1.
- add add_addr_received and rm_addr_received interfaces.
- drop subflow_check_next interface.
- add a "required" or "optional" comment for a group of interfaces in struct mptcp_pm_ops.
v1:
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
New interfaces for struct mptcp_pm_ops.
Geliang Tang (5):
mptcp: pm: call pm worker handler without pm lock
mptcp: pm: add accept_new_subflow() interface
mptcp: pm: add established() interface
mptcp: pm: add subflow_established() interface
mptcp: pm: drop is_userspace in subflow_check_next
include/net/mptcp.h | 5 ++ net/mptcp/pm.c | 100 +++++++++++++++++++-------------------- net/mptcp/pm_kernel.c | 47 ++++++++++++------ net/mptcp/pm_userspace.c | 9 +++- net/mptcp/protocol.h | 27 ++++++++++- net/mptcp/subflow.c | 6 +-- 6 files changed, 122 insertions(+), 72 deletions(-)
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v6 1/5 mptcp: pm: call pm worker handler without pm lock
From: Geliang Tang <[email protected]>
Later functions that cannot hold the mptcp pm lock will be called from the PM worker, so this patch modifies the order of holding the lock at the beginning of this function and releasing the lock at the end.
The new order is to obtain a copy of pm->status and clear the flags of pm->status while holding the mptcp pm lock, then read the copy after releasing the lock.
For each PM status flag, call each handling function without locks.
Finally, hold the lock before calling __mptcp_pm_kernel_worker() and release it afterwards.
Rename mptcp_pm_addr_send_ack() with "__" prefix to indicate that the mptcp pm lock is not held.
Hold the mptcp pm lock inside mptcp_pm_rm_addr_recv().
--- net/mptcp/pm.c | 34 ++++++++++++++++++++++------------ net/mptcp/pm_kernel.c | 4 ++-- net/mptcp/pm_userspace.c | 2 +- net/mptcp/protocol.h | 2 +- 4 files changed, 26 insertions(+), 16 deletions(-)
net/mptcp/pm.c +22 -12
@@ -211,7 +211,7 @@ void mptcp_pm_send_ack(struct mptcp_sock *msk,spin_lock_bh (&msk->pm.lock); } -void mptcp_pm_addr_send_ack (struct mptcp_sock *msk) +void __mptcp_pm_addr_send_ack (struct mptcp_sock *msk) {struct mptcp_subflow_context *subflow, *alt =NULL ;
@@ -238,6 +238,13 @@ void mptcp_pm_addr_send_ack(struct mptcp_sock *msk)mptcp_pm_send_ack (msk, alt, false, false); } +static void mptcp_pm_addr_send_ack (struct mptcp_sock *msk) +{ +spin_lock_bh (&msk->pm.lock); +__mptcp_pm_addr_send_ack (msk); +spin_unlock_bh (&msk->pm.lock); +} + int mptcp_pm_mp_prio_send_ack(struct mptcp_sock *msk, struct mptcp_addr_info *addr, struct mptcp_addr_info *rem,
@@ -437,7 +444,7 @@ int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_ msk->pm.rm_list_tx = *rm_list; rm_addr |=BIT (MPTCP_RM_ADDR_SIGNAL );WRITE_ONCE (msk->pm.addr_signal, rm_addr); -mptcp_pm_addr_send_ack (msk); +__mptcp_pm_addr_send_ack (msk);return 0 ; }
@@ -715,7 +722,9 @@ static void mptcp_pm_rm_addr_or_subflow(struct mptcp_sock *msk,static void mptcp_pm_rm_addr_recv (struct mptcp_sock *msk) { +spin_lock_bh (&msk->pm.lock);mptcp_pm_rm_addr_or_subflow (msk, &msk->pm.rm_list_rx,MPTCP_MIB_RMADDR ); +spin_unlock_bh (&msk->pm.lock); } void mptcp_pm_rm_subflow(struct mptcp_sock *msk,
@@ -945,6 +954,8 @@ void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)void mptcp_pm_worker (struct mptcp_sock *msk) { +u8 status, mask =BIT (MPTCP_PM_ADD_ADDR_SEND_ACK ) | +BIT (MPTCP_PM_RM_ADDR_RECEIVED );struct mptcp_pm_data *pm = &msk->pm;msk_owned_by_me (msk);
@@ -952,20 +963,19 @@ void mptcp_pm_worker(struct mptcp_sock *msk)if (!(pm->status &MPTCP_PM_WORK_MASK ))return ; -spin_lock_bh (&msk->pm.lock); +spin_lock_bh (&pm->lock); + status = pm->status; + pm->status &= ~mask; +spin_unlock_bh (&pm->lock); -pr_debug ("msk=%p status=%x\n" , msk, pm->status); -if (pm->status &BIT (MPTCP_PM_ADD_ADDR_SEND_ACK )) { - pm->status &= ~BIT (MPTCP_PM_ADD_ADDR_SEND_ACK ); +pr_debug ("msk=%p status=%x\n" , msk, status); +if (status &BIT (MPTCP_PM_ADD_ADDR_SEND_ACK ))mptcp_pm_addr_send_ack (msk); - } -if (pm->status &BIT (MPTCP_PM_RM_ADDR_RECEIVED )) { - pm->status &= ~BIT (MPTCP_PM_RM_ADDR_RECEIVED ); +if (status &BIT (MPTCP_PM_RM_ADDR_RECEIVED ))mptcp_pm_rm_addr_recv (msk); - } +spin_lock_bh (&pm->lock);__mptcp_pm_kernel_worker (msk); - -spin_unlock_bh (&msk->pm.lock); +spin_unlock_bh (&pm->lock); } static void mptcp_pm_ops_init(struct mptcp_sock *msk,
net/mptcp/pm_kernel.c +2 -2
@@ -326,7 +326,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) local.addr.id =0 ;mptcp_pm_announce_addr (msk, &local.addr, false); -mptcp_pm_addr_send_ack (msk); +__mptcp_pm_addr_send_ack (msk);if (local.flags &MPTCP_PM_ADDR_FLAG_SUBFLOW ) signal_and_subflow = true;
@@ -460,7 +460,7 @@ static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk) remote = msk->pm.remote;mptcp_pm_announce_addr (msk, &remote, true); -mptcp_pm_addr_send_ack (msk); +__mptcp_pm_addr_send_ack (msk);if (lookup_subflow_by_daddr (&msk->conn_list, &remote))return ;
net/mptcp/pm_userspace.c +1 -1
@@ -231,7 +231,7 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)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_addr_send_ack (msk); +__mptcp_pm_addr_send_ack (msk); }spin_unlock_bh (&msk->pm.lock);
net/mptcp/protocol.h +1 -1
@@ -1022,7 +1022,7 @@ void mptcp_pm_add_addr_send_ack(struct mptcp_sock *msk);void mptcp_pm_send_ack (struct mptcp_sock *msk,struct mptcp_subflow_context *subflow,bool prio,bool backup); -void mptcp_pm_addr_send_ack (struct mptcp_sock *msk); +void __mptcp_pm_addr_send_ack (struct mptcp_sock *msk);void mptcp_pm_nl_rm_addr (struct mptcp_sock *msk,u8 rm_id);void mptcp_pm_rm_subflow (struct mptcp_sock *msk,const struct mptcp_rm_list *rm_list);
Signature · 1 line
2.43.0
Geliang Tang
reviewerRe: [PATCH mptcp-next v6 1/5] mptcp: pm: call pm worker handler without pm lock
Hi Matt,
Quoted 94 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Later functions that cannot hold the mptcp pm lock will be called from
the PM worker, so this patch modifies the order of holding the lock at the beginning of this function and releasing the lock at the end.The new order is to obtain a copy of
pm->statusand clear the flags ofpm->statuswhile holding the mptcp pm lock, then read the copy after releasing the lock.For each PM status flag, call each handling function without locks.
Finally, hold the lock before calling
__mptcp_pm_kernel_worker()and release it afterwards.Rename
mptcp_pm_addr_send_ack()with "__" prefix to indicate that the mptcp pm lock is not held.Hold the mptcp pm lock inside
mptcp_pm_rm_addr_recv().Signed-off-by Geliang Tang <[email protected]>---
net/mptcp/pm.c | 34 ++++++++++++++++++++++------------ net/mptcp/pm_kernel.c | 4 ++--net/mptcp/pm_userspace.c| 2 +-
net/mptcp/protocol.h | 2 +-4 files changed, 26 insertions(+), 16 deletions(-)net/mptcp/pm.c +0
-0@@ -211,7 +211,7 @@ void mptcp_pm_send_ack(struct mptcp_sock *msk, spin_lock_bh(&msk->pm.lock); }net/mptcp/pm.c +1
-1-void mptcp_pm_addr_send_ack (struct mptcp_sock *msk) +void __mptcp_pm_addr_send_ack (struct mptcp_sock *msk){
structmptcp_subflow_context*subflow, *alt = NULL;net/mptcp/pm.c +0
-0@@ -238,6 +238,13 @@ void mptcp_pm_addr_send_ack(struct mptcp_sock *msk) mptcp_pm_send_ack(msk, alt, false, false); }net/mptcp/pm.c +7
-0+static void mptcp_pm_addr_send_ack (struct mptcp_sock *msk) +{ +spin_lock_bh (&msk->pm.lock); +__mptcp_pm_addr_send_ack (msk); +spin_unlock_bh (&msk->pm.lock); +} +int mptcp_pm_mp_prio_send_ack(struct
mptcp_sock*msk, structmptcp_addr_info*addr, structmptcp_addr_info*rem,net/mptcp/pm.c +0
-0@@ -437,7 +444,7 @@ int mptcp_pm_remove_addr(struct mptcp_sock *msk,const struct
mptcp_rm_list*rm_
msk->pm.rm_list_tx=*rm_list;
rm_addr|=BIT(MPTCP_RM_ADDR_SIGNAL);
WRITE_ONCE(msk->pm.addr_signal, rm_addr);net/mptcp/pm.c +1
-1-mptcp_pm_addr_send_ack (msk); +__mptcp_pm_addr_send_ack (msk);return 0;
}net/mptcp/pm.c +0
-0@@ -715,7 +722,9 @@ static void mptcp_pm_rm_addr_or_subflow(struct mptcp_sock *msk,
static voidmptcp_pm_rm_addr_recv(struct mptcp_sock *msk){net/mptcp/pm.c +1
-0+spin_lock_bh (&msk->pm.lock);
mptcp_pm_rm_addr_or_subflow(msk, &msk->pm.rm_list_rx, MPTCP_MIB_RMADDR);net/mptcp/pm.c +1
-0+spin_unlock_bh (&msk->pm.lock);}
void mptcp_pm_rm_subflow(structmptcp_sock*msk,net/mptcp/pm.c +0
-0@@ -945,6 +954,8 @@ void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)
voidmptcp_pm_worker(struct mptcp_sock *msk)
{net/mptcp/pm.c +2
-0+u8 status, mask =BIT (MPTCP_PM_ADD_ADDR_SEND_ACK ) | + BIT(MPTCP_PM_RM_ADDR_RECEIVED);struct
mptcp_pm_data*pm =&msk->pm;
msk_owned_by_me(msk);net/mptcp/pm.c +0
-0@@ -952,20 +963,19 @@ void mptcp_pm_worker(struct mptcp_sock *msk) if (!(pm->status & MPTCP_PM_WORK_MASK)) return;
net/mptcp/pm.c void mptcp_pm_worker(struct mptcp_sock *msk) · line 968
Quoted 4 lines
net/mptcp/pm.c +3
-1-spin_lock_bh (&msk->pm.lock); +spin_lock_bh (&pm->lock); + status = pm->status; + pm->status &= ~mask;
I found that there is no need to define a 'mask' variable, we can directly use MPTCP_PM_WORK_MASK here, I will update this in v7.
Thanks,
-Geliang
Quoted 74 lines
net/mptcp/pm.c +1
-0+spin_unlock_bh (&pm->lock);net/mptcp/pm.c +2
-3-pr_debug ("msk=%p status=%x\n" , msk, pm->status); -if (pm->status &BIT (MPTCP_PM_ADD_ADDR_SEND_ACK )) { - pm->status &= ~BIT (MPTCP_PM_ADD_ADDR_SEND_ACK ); +pr_debug ("msk=%p status=%x\n" , msk, status); +if (status &BIT (MPTCP_PM_ADD_ADDR_SEND_ACK ))
mptcp_pm_addr_send_ack(msk);net/mptcp/pm.c +1
-3- } -if (pm->status &BIT (MPTCP_PM_RM_ADDR_RECEIVED )) { - pm->status &= ~BIT (MPTCP_PM_RM_ADDR_RECEIVED ); +if (status &BIT (MPTCP_PM_RM_ADDR_RECEIVED ))
mptcp_pm_rm_addr_recv(msk);net/mptcp/pm.c +1
-1- } +spin_lock_bh (&pm->lock);
__mptcp_pm_kernel_worker(msk);net/mptcp/pm.c +1
-2- -spin_unlock_bh (&msk->pm.lock); +spin_unlock_bh (&pm->lock);}
static void mptcp_pm_ops_init(structmptcp_sock*msk,net/mptcp/pm_kernel.c +0
-0@@ -326,7 +326,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) local.addr.id = 0;
mptcp_pm_announce_addr(msk, &local.addr, false);net/mptcp/pm_kernel.c +1
-1-mptcp_pm_addr_send_ack (msk); +__mptcp_pm_addr_send_ack (msk);
if (local.flags &MPTCP_PM_ADDR_FLAG_SUBFLOW)signal_and_subflow= true;net/mptcp/pm_kernel.c +0
-0@@ -460,7 +460,7 @@ static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)
remote =msk->pm.remote;mptcp_pm_announce_addr(msk, &remote, true);net/mptcp/pm_kernel.c +1
-1-mptcp_pm_addr_send_ack (msk); +__mptcp_pm_addr_send_ack (msk);
if (lookup_subflow_by_daddr(&msk->conn_list, &remote)) return;net/mptcp/pm_userspace.c +1
-1@@ -231,7 +231,7 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) 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_addr_send_ack (msk); +__mptcp_pm_addr_send_ack (msk); }
spin_unlock_bh(&msk->pm.lock);net/mptcp/protocol.h +1
-1@@ -1022,7 +1022,7 @@ void mptcp_pm_add_addr_send_ack(struct mptcp_sock *msk); void mptcp_pm_send_ack(struct mptcp_sock *msk, struct mptcp_subflow_context *subflow, bool prio, bool backup); -void mptcp_pm_addr_send_ack (struct mptcp_sock *msk); +void __mptcp_pm_addr_send_ack (struct mptcp_sock *msk); void mptcp_pm_nl_rm_addr(struct mptcp_sock *msk, u8 rm_id); void mptcp_pm_rm_subflow(struct mptcp_sock *msk,const struct
mptcp_rm_list*rm_list);
Geliang Tang
reviewerPATCH v6 2/5 mptcp: pm: add accept_new_subflow() interface
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
The helper mptcp_pm_is_userspace() is used to distinguish userspace PM operations from in-kernel PM in mptcp_can_accept_new_subflow(). It seems reasonable to add a mandatory .accept_new_subflow interface for struct mptcp_pm_ops.
The boolean type 'allow' parameter is used to control whether to allow new subflow unconditionally.
A new helper mptcp_pm_accept_new_subflow() is added in pm.c to ensure that pm->ops is only used in pm.c.
This interface of the in-kernel PM is implemented as a wrapper of READ_ONCE(pm->accept_subflow), and this interface of the userspace PM is implemented as a wrapper of mptcp_userspace_pm_active().
To reduce the dependency on mptcp_pm_is_userspace() to identify userspace PM from in-kernel PM by using mptcp_pm_accept_new_subflow() helper in mptcp_pm_allow_new_subflow().
--- include/net/mptcp.h | 1 + net/mptcp/pm.c | 38 +++++++++++++------------------------- net/mptcp/pm_kernel.c | 16 ++++++++++++++++ net/mptcp/pm_userspace.c | 7 +++++++ net/mptcp/protocol.h | 25 +++++++++++++++++++++++++ net/mptcp/subflow.c | 6 ++---- 6 files changed, 64 insertions(+), 29 deletions(-)
include/net/mptcp.h +1 -0
@@ -123,6 +123,7 @@ struct mptcp_pm_ops { struct mptcp_pm_addr_entry *skc);bool (*get_priority)(struct mptcp_sock *msk,struct mptcp_addr_info *skc); +bool (*accept_new_subflow)(struct mptcp_sock *msk,bool allow);char name[MPTCP_PM_NAME_MAX ];struct module *owner;
net/mptcp/pm.c +13 -25
@@ -460,38 +460,25 @@ void mptcp_pm_new_connection(struct mptcp_sock *msk, const struct sock *ssk, intmptcp_event (MPTCP_EVENT_CREATED , msk, ssk,GFP_ATOMIC ); } +bool mptcp_pm_accept_new_subflow (struct mptcp_sock *msk,bool allow) +{ +return msk->pm.ops->accept_new_subflow (msk, allow); +} +bool mptcp_pm_allow_new_subflow (struct mptcp_sock *msk) {struct mptcp_pm_data *pm = &msk->pm; -unsigned int subflows_max;int ret =0 ; -if (mptcp_pm_is_userspace (msk)) { -if (mptcp_userspace_pm_active (msk)) { -spin_lock_bh (&pm->lock); - pm->subflows++; -spin_unlock_bh (&pm->lock); -return true; - } -return false; - } - - subflows_max =mptcp_pm_get_subflows_max (msk); - -pr_debug ("msk=%p subflows=%d max=%d allow=%d\n" , msk, pm->subflows, - subflows_max,READ_ONCE (pm->accept_subflow)); - -/* try to avoid acquiring the lock below */ -if (!READ_ONCE (pm->accept_subflow)) +if (!mptcp_pm_accept_new_subflow (msk, true))return false; -spin_lock_bh (&pm->lock); -if (READ_ONCE (pm->accept_subflow)) { - ret = pm->subflows < subflows_max; -if (ret && ++pm->subflows == subflows_max) -WRITE_ONCE (pm->accept_subflow, false); + ret =mptcp_pm_accept_new_subflow (msk, false); +if (ret) { +spin_lock_bh (&pm->lock); + pm->subflows++; +spin_unlock_bh (&pm->lock); } -spin_unlock_bh (&pm->lock);return ret; }
@@ -1060,7 +1047,8 @@ struct mptcp_pm_ops *mptcp_pm_find(const char *name)int mptcp_pm_validate (struct mptcp_pm_ops *pm_ops) { -if (!pm_ops->get_local_id || !pm_ops->get_priority) { +if (!pm_ops->get_local_id || !pm_ops->get_priority || + !pm_ops->accept_new_subflow) {pr_err ("%s does not implement required ops\n" , pm_ops->name);return -EINVAL ; }
net/mptcp/pm_kernel.c +16 -0
@@ -1399,6 +1399,21 @@ static struct pernet_operations mptcp_pm_pernet_ops = { .size = sizeof(struct pm_nl_pernet), }; +static bool mptcp_pm_kernel_accept_new_subflow (struct mptcp_sock *msk, +bool allow) +{ +bool ret = false; + +if (READ_ONCE (msk->pm.accept_subflow)) { +if (allow) +return true; + + ret =mptcp_pm_accept_subflow (msk); + } + +return ret; +} +static void mptcp_pm_kernel_init (struct mptcp_sock *msk) {bool subflows_allowed = !!mptcp_pm_get_subflows_max (msk);
@@ -1422,6 +1437,7 @@ static void mptcp_pm_kernel_init(struct mptcp_sock *msk)struct mptcp_pm_ops mptcp_pm_kernel = { .get_local_id = mptcp_pm_kernel_get_local_id, .get_priority = mptcp_pm_kernel_get_priority, + .accept_new_subflow = mptcp_pm_kernel_accept_new_subflow, .init = mptcp_pm_kernel_init, .name ="kernel" , .owner =THIS_MODULE ,
net/mptcp/pm_userspace.c +7 -0
@@ -683,6 +683,12 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,return ret; } +static bool mptcp_pm_userspace_accept_new_subflow (struct mptcp_sock *msk, +bool allow) +{ +return mptcp_userspace_pm_active (msk); +} +static void mptcp_pm_userspace_release (struct mptcp_sock *msk) {mptcp_userspace_pm_free_local_addr_list (msk);
@@ -691,6 +697,7 @@ static void mptcp_pm_userspace_release(struct mptcp_sock *msk)static struct mptcp_pm_ops mptcp_pm_userspace = { .get_local_id = mptcp_pm_userspace_get_local_id, .get_priority = mptcp_pm_userspace_get_priority, + .accept_new_subflow = mptcp_pm_userspace_accept_new_subflow, .release = mptcp_pm_userspace_release, .name ="userspace" , .owner =THIS_MODULE ,
net/mptcp/protocol.h +25 -0
@@ -1008,6 +1008,7 @@ bool mptcp_pm_addr_families_match(const struct sock *sk,void mptcp_pm_subflow_chk_stale (const struct mptcp_sock *msk,struct sock *ssk);void mptcp_pm_new_connection (struct mptcp_sock *msk,const struct sock *ssk,int server_side);void mptcp_pm_fully_established (struct mptcp_sock *msk,const struct sock *ssk); +bool mptcp_pm_accept_new_subflow (struct mptcp_sock *msk,bool allow);bool mptcp_pm_allow_new_subflow (struct mptcp_sock *msk);void mptcp_pm_connection_closed (struct mptcp_sock *msk);void mptcp_pm_subflow_established (struct mptcp_sock *msk);
@@ -1184,6 +1185,30 @@ static inline void mptcp_pm_close_subflow(struct mptcp_sock *msk)spin_unlock_bh (&msk->pm.lock); } +static inline bool __mptcp_pm_accept_subflow (struct mptcp_sock *msk) +{ +unsigned int subflows_max =mptcp_pm_get_subflows_max (msk); +struct mptcp_pm_data *pm = &msk->pm; +bool ret; + + ret = pm->subflows < subflows_max; +if (ret && pm->subflows +1 == subflows_max) +WRITE_ONCE (pm->accept_subflow, false); + +return ret; +} + +static inline bool mptcp_pm_accept_subflow (struct mptcp_sock *msk) +{ +bool ret; + +spin_lock_bh (&msk->pm.lock); + ret =__mptcp_pm_accept_subflow (msk); +spin_unlock_bh (&msk->pm.lock); + +return ret; +} +void mptcp_sockopt_sync_locked (struct mptcp_sock *msk,struct sock *ssk);static inline struct mptcp_ext *mptcp_get_ext (const struct sk_buff *skb)
net/mptcp/subflow.c +2 -4
@@ -58,12 +58,10 @@ static void subflow_generate_hmac(u64 key1, u64 key2, u32 nonce1, u32 nonce2,mptcp_crypto_hmac_sha (key1, key2, msg,8 , hmac); } -static bool mptcp_can_accept_new_subflow (const struct mptcp_sock *msk) +static bool mptcp_can_accept_new_subflow (struct mptcp_sock *msk) {return mptcp_is_fully_established ((void *)msk) && - ((mptcp_pm_is_userspace (msk) && -mptcp_userspace_pm_active (msk)) || -READ_ONCE (msk->pm.accept_subflow)); +mptcp_pm_accept_new_subflow (msk, true); }/* validate received token and create truncated hmac and nonce for SYN-ACK */
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v6 3/5 mptcp: pm: add established() interface
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch adds a .established interface for struct mptcp_pm_ops, and calls pm->ops->established in from mptcp_pm_worker(). Then get rid of the corresponding code from __mptcp_pm_kernel_worker().
Since mptcp_pm_addr_send_ack() is a sleepable kfunc, which is invoked by mptcp_pm_create_subflow_or_signal_addr(), .established() interface of BPF PM should be invoked by __bpf_prog_enter_sleepable(), which can't be invoked under a lock. This patch unlocks the pm lock before invoking this interface in mptcp_pm_worker(), while holding this lock in mptcp_pm_kernel_established().
Add a helper to call mptcp_pm_create_subflow_or_signal_addr() while holding mptcp pm lock, and rename the original one with "__" prefix.
--- include/net/mptcp.h | 3 +++ net/mptcp/pm.c | 8 ++++++-- net/mptcp/pm_kernel.c | 22 +++++++++++++--------- 3 files changed, 22 insertions(+), 11 deletions(-)
include/net/mptcp.h +3 -0
@@ -125,6 +125,9 @@ struct mptcp_pm_ops { struct mptcp_addr_info *skc);bool (*accept_new_subflow)(struct mptcp_sock *msk,bool allow); +/* optional, call from the msk context */ +void (*established)(struct mptcp_sock *msk); +char name[MPTCP_PM_NAME_MAX ];struct module *owner;struct list_head list;
net/mptcp/pm.c +6 -2
@@ -513,7 +513,8 @@ void mptcp_pm_fully_established(struct mptcp_sock *msk, const struct sock *ssk)* be sure to serve this event only once. */ if (READ_ONCE (pm->work_pending) && - !(pm->status &BIT (MPTCP_PM_ALREADY_ESTABLISHED ))) + !(pm->status &BIT (MPTCP_PM_ALREADY_ESTABLISHED )) && + pm->ops->established)mptcp_pm_schedule_work (msk,MPTCP_PM_ESTABLISHED );if ((pm->status &BIT (MPTCP_PM_ALREADY_ESTABLISHED )) ==0 )
@@ -942,7 +943,8 @@ void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)void mptcp_pm_worker (struct mptcp_sock *msk) {u8 status, mask =BIT (MPTCP_PM_ADD_ADDR_SEND_ACK ) | -BIT (MPTCP_PM_RM_ADDR_RECEIVED ); +BIT (MPTCP_PM_RM_ADDR_RECEIVED ) | +BIT (MPTCP_PM_ESTABLISHED );struct mptcp_pm_data *pm = &msk->pm;msk_owned_by_me (msk);
@@ -960,6 +962,8 @@ void mptcp_pm_worker(struct mptcp_sock *msk)mptcp_pm_addr_send_ack (msk);if (status &BIT (MPTCP_PM_RM_ADDR_RECEIVED ))mptcp_pm_rm_addr_recv (msk); +if (status &BIT (MPTCP_PM_ESTABLISHED )) + pm->ops->established (msk);spin_lock_bh (&pm->lock);__mptcp_pm_kernel_worker (msk);spin_unlock_bh (&pm->lock);
net/mptcp/pm_kernel.c +13 -9
@@ -253,7 +253,7 @@ __lookup_addr(struct pm_nl_pernet *pernet, const struct mptcp_addr_info *info)return NULL ; } -static void mptcp_pm_create_subflow_or_signal_addr (struct mptcp_sock *msk) +static void __mptcp_pm_create_subflow_or_signal_addr (struct mptcp_sock *msk) {struct sock *sk = (struct sock *)msk;unsigned int add_addr_signal_max;
@@ -367,14 +367,21 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)mptcp_pm_nl_check_work_pending (msk); } -static void mptcp_pm_nl_fully_established (struct mptcp_sock *msk) +static void mptcp_pm_create_subflow_or_signal_addr (struct mptcp_sock *msk) +{ +spin_lock_bh (&msk->pm.lock); +__mptcp_pm_create_subflow_or_signal_addr (msk); +spin_unlock_bh (&msk->pm.lock); +} + +static void mptcp_pm_kernel_established (struct mptcp_sock *msk) {mptcp_pm_create_subflow_or_signal_addr (msk); }static void mptcp_pm_nl_subflow_established (struct mptcp_sock *msk) { -mptcp_pm_create_subflow_or_signal_addr (msk); +__mptcp_pm_create_subflow_or_signal_addr (msk); }/* Fill all the local addresses into the array addrs[],
@@ -758,7 +765,7 @@ static int mptcp_nl_add_subflow_or_signal_addr(struct net *net,spin_lock_bh (&msk->pm.lock);if (mptcp_addresses_equal (addr, &mpc_addr, addr->port)) msk->mpc_endpoint_id = addr->id; -mptcp_pm_create_subflow_or_signal_addr (msk); +__mptcp_pm_create_subflow_or_signal_addr (msk);spin_unlock_bh (&msk->pm.lock);release_sock (sk);
@@ -1243,7 +1250,7 @@ static void mptcp_pm_nl_fullmesh(struct mptcp_sock *msk,spin_lock_bh (&msk->pm.lock);mptcp_pm_rm_subflow (msk, &list);__mark_subflow_endp_available (msk, list.ids[0 ]); -mptcp_pm_create_subflow_or_signal_addr (msk); +__mptcp_pm_create_subflow_or_signal_addr (msk);spin_unlock_bh (&msk->pm.lock); }
@@ -1348,10 +1355,6 @@ void __mptcp_pm_kernel_worker(struct mptcp_sock *msk) pm->status &= ~BIT (MPTCP_PM_ADD_ADDR_RECEIVED );mptcp_pm_nl_add_addr_received (msk); } -if (pm->status &BIT (MPTCP_PM_ESTABLISHED )) { - pm->status &= ~BIT (MPTCP_PM_ESTABLISHED ); -mptcp_pm_nl_fully_established (msk); - }if (pm->status &BIT (MPTCP_PM_SUBFLOW_ESTABLISHED )) { pm->status &= ~BIT (MPTCP_PM_SUBFLOW_ESTABLISHED );mptcp_pm_nl_subflow_established (msk);
@@ -1438,6 +1441,7 @@ struct mptcp_pm_ops mptcp_pm_kernel = { .get_local_id = mptcp_pm_kernel_get_local_id, .get_priority = mptcp_pm_kernel_get_priority, .accept_new_subflow = mptcp_pm_kernel_accept_new_subflow, + .established = mptcp_pm_kernel_established, .init = mptcp_pm_kernel_init, .name = "kernel", .owner = THIS_MODULE,
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v6 4/5 mptcp: pm: add subflow_established() interface
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch adds a .subflow_established interface for struct mptcp_pm_ops, and calls pm->ops->subflow_established in from mptcp_pm_worker(). Then get rid of the corresponding code from __mptcp_pm_kernel_worker().
Since mptcp_pm_addr_send_ack() is a sleepable kfunc, which is invoked by mptcp_pm_create_subflow_or_signal_addr(), .subflow_established() interface of BPF PM should be invoked by __bpf_prog_enter_sleepable(), which can't be invoked under a lock. This patch unlocks the pm lock before invoking this interface in mptcp_pm_worker(), while holding this lock in mptcp_pm_kernel_subflow_established().
--- include/net/mptcp.h | 1 + net/mptcp/pm.c | 12 ++++++++---- net/mptcp/pm_kernel.c | 9 +++------ 3 files changed, 12 insertions(+), 10 deletions(-)
include/net/mptcp.h +1 -0
@@ -127,6 +127,7 @@ struct mptcp_pm_ops {/* optional, call from the msk context */ void (*established)(struct mptcp_sock *msk); +void (*subflow_established)(struct mptcp_sock *msk);char name[MPTCP_PM_NAME_MAX ];struct module *owner;
net/mptcp/pm.c +8 -4
@@ -541,7 +541,7 @@ void mptcp_pm_subflow_established(struct mptcp_sock *msk)pr_debug ("msk=%p\n" , msk); -if (!READ_ONCE (pm->work_pending)) +if (!READ_ONCE (pm->work_pending) || !pm->ops->subflow_established)return ;spin_lock_bh (&pm->lock);
@@ -568,7 +568,8 @@ void mptcp_pm_subflow_check_next(struct mptcp_sock *msk,return ; } -if (!READ_ONCE (pm->work_pending) && !update_subflows) +if (!pm->ops->subflow_established || + (!READ_ONCE (pm->work_pending) && !update_subflows))return ;spin_lock_bh (&pm->lock);
@@ -626,7 +627,7 @@ void mptcp_pm_add_addr_echoed(struct mptcp_sock *msk,pr_debug ("msk=%p\n" , msk); -if (!READ_ONCE (pm->work_pending)) +if (!READ_ONCE (pm->work_pending) || !pm->ops->subflow_established)return ;spin_lock_bh (&pm->lock);
@@ -944,7 +945,8 @@ void mptcp_pm_worker(struct mptcp_sock *msk) {u8 status, mask =BIT (MPTCP_PM_ADD_ADDR_SEND_ACK ) |BIT (MPTCP_PM_RM_ADDR_RECEIVED ) | -BIT (MPTCP_PM_ESTABLISHED ); +BIT (MPTCP_PM_ESTABLISHED ) | +BIT (MPTCP_PM_SUBFLOW_ESTABLISHED );struct mptcp_pm_data *pm = &msk->pm;msk_owned_by_me (msk);
@@ -964,6 +966,8 @@ void mptcp_pm_worker(struct mptcp_sock *msk)mptcp_pm_rm_addr_recv (msk);if (status &BIT (MPTCP_PM_ESTABLISHED )) pm->ops->established (msk); +if (status &BIT (MPTCP_PM_SUBFLOW_ESTABLISHED )) + pm->ops->subflow_established (msk);spin_lock_bh (&pm->lock);__mptcp_pm_kernel_worker (msk);spin_unlock_bh (&pm->lock);
net/mptcp/pm_kernel.c +3 -6
@@ -379,9 +379,9 @@ static void mptcp_pm_kernel_established(struct mptcp_sock *msk)mptcp_pm_create_subflow_or_signal_addr (msk); } -static void mptcp_pm_nl_subflow_established (struct mptcp_sock *msk) +static void mptcp_pm_kernel_subflow_established (struct mptcp_sock *msk) { -__mptcp_pm_create_subflow_or_signal_addr (msk); +mptcp_pm_create_subflow_or_signal_addr (msk); }/* Fill all the local addresses into the array addrs[],
@@ -1355,10 +1355,6 @@ void __mptcp_pm_kernel_worker(struct mptcp_sock *msk) pm->status &= ~BIT (MPTCP_PM_ADD_ADDR_RECEIVED );mptcp_pm_nl_add_addr_received (msk); } -if (pm->status &BIT (MPTCP_PM_SUBFLOW_ESTABLISHED )) { - pm->status &= ~BIT (MPTCP_PM_SUBFLOW_ESTABLISHED ); -mptcp_pm_nl_subflow_established (msk); - } }static int __net_init pm_nl_init_net (struct net *net)
@@ -1442,6 +1438,7 @@ struct mptcp_pm_ops mptcp_pm_kernel = { .get_priority = mptcp_pm_kernel_get_priority, .accept_new_subflow = mptcp_pm_kernel_accept_new_subflow, .established = mptcp_pm_kernel_established, + .subflow_established = mptcp_pm_kernel_subflow_established, .init = mptcp_pm_kernel_init, .name = "kernel", .owner = THIS_MODULE,
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v6 5/5 mptcp: pm: drop is_userspace in subflow_check_next
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch moves mptcp_pm_close_subflow() forward to let it be used by both the userspace PM and the in-kernel PM in mptcp_pm_subflow_check_next(). Then mptcp_pm_is_userspace() here can be dropped.
--- net/mptcp/pm.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
net/mptcp/pm.c +3 -11
@@ -559,22 +559,14 @@ void mptcp_pm_subflow_check_next(struct mptcp_sock *msk,bool update_subflows; update_subflows = subflow->request_join || subflow->mp_join; -if (mptcp_pm_is_userspace (msk)) { -if (update_subflows) { -spin_lock_bh (&pm->lock); - pm->subflows--; -spin_unlock_bh (&pm->lock); - } -return ; - } +if (update_subflows) +mptcp_pm_close_subflow (msk);if (!pm->ops->subflow_established || - (!READ_ONCE (pm->work_pending) && !update_subflows)) + !READ_ONCE (pm->work_pending))return ;spin_lock_bh (&pm->lock); -if (update_subflows) -__mptcp_pm_close_subflow (msk);/* Even if this subflow is not really established, tell the PM to try * to pick the next ones, if possible.
Signature · 1 line
2.43.0
Hi Geliang,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/14121889205
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/c19b176f03f3
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=947940
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normalFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
Matthieu Baerts
maintainerHi Geliang,
Quoted 10 lines · Geliang Tang
From: Geliang Tang <[email protected]>
v6:
- squashaccept_new_subflowpatches into one.
- change "pm->subflows==subflows_max- 1" topm->subflows + 1 == subflows_max.- not to call
accept_new_subflowunder the PM lock.
- addmptcp_pm_accept_subflowhelpers.
- dropREAD_ONCEinmptcp_pm_worker.
- clear all the pm status flags once inmptcp_pm_worker.
Thank you for the new version.
FYI, I'm still thinking about how to handle PM lock should be handled. I will come back to you later. I might suggest a new version with some modifications if that's OK, that might be easier.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerHi Matt,
Quoted 14 lines · Matthieu Baerts
Hi Geliang,
Quoted 10 lines · Geliang Tang
From: Geliang Tang <[email protected]>
v6:
- squashaccept_new_subflowpatches into one.
- change "pm->subflows==subflows_max- 1" topm->subflows + 1 == subflows_max.- not to call
accept_new_subflowunder the PM lock.
- addmptcp_pm_accept_subflowhelpers.
- dropREAD_ONCEinmptcp_pm_worker.
- clear all the pm status flags once inmptcp_pm_worker.
Quoted 6 lines
Thank you for the new version.
FYI, I'm still thinking about how to handle PM lock should be handled. I
will come back to you later. I might suggest a new version with some modifications if that's OK, that might be easier.
Thanks for helping me think about this part around the PM lock. Look forward to your feedback.
-Geliang
Quoted 3 lines
Cheers,
Matt
Geliang Tang
reviewerHi Matt,
Quoted 19 lines · Geliang Tang
Hi Matt,
Quoted 16 lines · Matthieu Baerts
Hi Geliang,
Quoted 10 lines · Geliang Tang
From: Geliang Tang <[email protected]>
v6:
- squashaccept_new_subflowpatches into one.
- change "pm->subflows==subflows_max- 1" topm->subflows + 1 == subflows_max.- not to call
accept_new_subflowunder the PM lock.
- addmptcp_pm_accept_subflowhelpers.
- dropREAD_ONCEinmptcp_pm_worker.
- clear all the pm status flags once inmptcp_pm_worker.Thank you for the new version.
Quoted 8 lines
Quoted 5 lines
FYI, I'm still thinking about how to handle PM lock should be handled. I
will come back to you later. I might suggest a new version with some
modifications if that's OK, that might be easier.Thanks for helping me think about this part around the PM lock. Look forward to your feedback.
If you have time to take over this part around the PM lock, that would be even better and I would be very grateful.
Thanks,
-Geliang
Quoted 8 lines
-Geliang
Quoted 3 lines
Cheers,
Matt
Matthieu Baerts
maintainerHi Geliang,
Quoted 28 lines · Geliang Tang
Hi Matt,
Quoted 25 lines · Geliang Tang
Hi Matt,
Quoted 21 lines · Matthieu Baerts
Hi Geliang,
Quoted 10 lines · Geliang Tang
From: Geliang Tang <[email protected]>
v6:
- squashaccept_new_subflowpatches into one.
- change "pm->subflows==subflows_max- 1" topm->subflows + 1 == subflows_max.- not to call
accept_new_subflowunder the PM lock.
- addmptcp_pm_accept_subflowhelpers.
- dropREAD_ONCEinmptcp_pm_worker.
- clear all the pm status flags once inmptcp_pm_worker.Thank you for the new version.
FYI, I'm still thinking about how to handle PM lock should be handled. I
will come back to you later. I might suggest a new version with some
modifications if that's OK, that might be easier.
Quoted 5 lines
Quoted 2 lines
Thanks for helping me think about this part around the PM lock. Look forward to your feedback.
If you have time to take over this part around the PM lock, that would be even better and I would be very grateful.
Sure, no problem, I will have a look. But sadly, for the moment, it is hard for me to dedicate a long time on some tasks. It might take a bit of time for me to look at it, but I think that's fine, we are not in a rush.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.