BPF path manager, part 6
Subsystems (2)
Geliang Tang
reviewerv5 cover BPF path manager, part 6
From: Geliang Tang <[email protected]>
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 (7):
Squash to "mptcp: pm: add get_local_id() interface"
mptcp: pm: add accept_new_subflow() interface
mptcp: pm: use accept_new_subflow in allow_new_subflow
mptcp: pm: update pm lock order in mptcp_pm_worker
mptcp: pm: add established() interface
mptcp: pm: add subflow_established() interface
mptcp: pm: drop is_userspace in subflow_check_next
include/net/mptcp.h | 7 +++- net/mptcp/pm.c | 88 ++++++++++++++++++++-------------------- net/mptcp/pm_kernel.c | 52 ++++++++++++++++++------ net/mptcp/pm_userspace.c | 7 ++++ net/mptcp/protocol.h | 1 + net/mptcp/subflow.c | 6 +-- 6 files changed, 99 insertions(+), 62 deletions(-)
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v5 1/7 Squash to "mptcp: pm: add get_local_id() interface"
From: Geliang Tang <[email protected]>
Update the comment for get_local_id and get_priority.
--- include/net/mptcp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/mptcp.h +1 -1
@@ -118,7 +118,7 @@ struct mptcp_sched_ops {#define MPTCP_PM_BUF_MAX (MPTCP_PM_NAME_MAX * MPTCP_PM_MAX)struct mptcp_pm_ops { -/* required */ +/* required, call from the subflow context */ int (*get_local_id)(struct mptcp_sock *msk,struct mptcp_pm_addr_entry *skc); bool (*get_priority)(struct mptcp_sock *msk,
Signature · 1 line
2.43.0
Matthieu Baerts
maintainerRe: [PATCH mptcp-next v5 1/7] Squash to "mptcp: pm: add get_local_id() interface"
Hi Geliang,
Quoted 3 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Update the comment for
get_local_idandget_priority.
Thank you, I just applied this patch 1/7:
New patches for t/upstream:
- 00b6c34b9ea1: "squashed" patch 1/7 in "mptcp: pm: add get_local_id() interface"
- Results: 4e2b25079a95..8bfbd2e1bf59 (export)
Tests are now in progress:
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerPATCH v5 2/7 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().
--- include/net/mptcp.h | 1 + net/mptcp/pm.c | 8 +++++++- net/mptcp/pm_kernel.c | 15 +++++++++++++++ net/mptcp/pm_userspace.c | 7 +++++++ net/mptcp/protocol.h | 1 + net/mptcp/subflow.c | 6 ++---- 6 files changed, 33 insertions(+), 5 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 +7 -1
@@ -453,6 +453,11 @@ 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;
@@ -1050,7 +1055,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 +15 -0
@@ -1399,6 +1399,20 @@ 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) +{ +struct mptcp_pm_data *pm = &msk->pm; +bool ret = false; + +if (READ_ONCE (pm->accept_subflow)) { +if (allow) +return true; + } + +return ret; +} +static void mptcp_pm_kernel_init (struct mptcp_sock *msk) {bool subflows_allowed = !!mptcp_pm_get_subflows_max (msk);
@@ -1422,6 +1436,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 +1 -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);
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
Matthieu Baerts
maintainerRe: [PATCH mptcp-next v5 2/7] mptcp: pm: add accept_new_subflow() interface
Hi Geliang,
Quoted 70 lines · Geliang Tang
From: Geliang Tang <[email protected]>
The helper
mptcp_pm_is_userspace()is used to distinguish userspace PM operations from in-kernel PM inmptcp_can_accept_new_subflow(). It seems reasonable to add a mandatory .accept_new_subflow interface for structmptcp_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 inpm.cto ensure thatpm->opsis only used inpm.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 ofmptcp_userspace_pm_active().Signed-off-by Geliang Tang <[email protected]>--- include/net/mptcp.h | 1 + net/mptcp/pm.c | 8 +++++++- net/mptcp/pm_kernel.c | 15 +++++++++++++++ net/mptcp/pm_userspace.c | 7 +++++++ net/mptcp/protocol.h | 1 + net/mptcp/subflow.c | 6 ++---- 6 files changed, 33 insertions(+), 5 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 +7
-1@@ -453,6 +453,11 @@ 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;@@ -1050,7 +1055,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 +0
-0
net/mptcp/pm_kernel.c static struct pernet_operations mptcp_pm_pernet_ops = { · line 1403
Quoted 5 lines
net/mptcp/pm_kernel.c +2
-0@@ -1399,6 +1399,20 @@ 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)
"allow" is always true.
net/mptcp/pm_kernel.c static struct pernet_operations mptcp_pm_pernet_ops = { · line 1413
Quoted 10 lines
net/mptcp/pm_kernel.c +10
-0+{ +struct mptcp_pm_data *pm = &msk->pm; +bool ret = false; + +if (READ_ONCE (pm->accept_subflow)) { +if (allow) +return true; + } + +return ret;
Mmh, what about:
return READ_ONCE(msk->pm.accept_subflow) && allow;
EDIT: OK, I just noticed the next patch. I suggest squashing this patch with the next one, or you remove 'allow' and simplify this code here, but I think it is easier to squash.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerPATCH v5 3/7 mptcp: pm: use accept_new_subflow in allow_new_subflow
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch reduces 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().
--- net/mptcp/pm.c | 27 ++++----------------------- net/mptcp/pm_kernel.c | 10 ++++++++++ 2 files changed, 14 insertions(+), 23 deletions(-)
net/mptcp/pm.c +4 -23
@@ -461,34 +461,15 @@ bool mptcp_pm_accept_new_subflow(struct mptcp_sock *msk, bool 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) + pm->subflows++;spin_unlock_bh (&pm->lock);return ret;
net/mptcp/pm_kernel.c +10 -0
@@ -1403,11 +1403,21 @@ static bool mptcp_pm_kernel_accept_new_subflow(struct mptcp_sock *msk, bool allow) {struct mptcp_pm_data *pm = &msk->pm; +unsigned int subflows_max;bool ret = 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)); +if (READ_ONCE (pm->accept_subflow)) {if (allow)return true; + + ret = pm->subflows < subflows_max; +if (ret && pm->subflows == subflows_max -1 ) +WRITE_ONCE (pm->accept_subflow, false); }return ret;
Signature · 1 line
2.43.0
Matthieu Baerts
maintainerRe: [PATCH mptcp-next v5 3/7] mptcp: pm: use accept_new_subflow in allow_new_subflow
Hi Geliang,
Quoted 40 lines · Geliang Tang
From: Geliang Tang <[email protected]>
This patch reduces the dependency on
mptcp_pm_is_userspace()to identify userspace PM from in-kernel PM by usingmptcp_pm_accept_new_subflow()helper inmptcp_pm_allow_new_subflow().Signed-off-by Geliang Tang <[email protected]>--- net/mptcp/pm.c | 27 ++++----------------------- net/mptcp/pm_kernel.c | 10 ++++++++++ 2 files changed, 14 insertions(+), 23 deletions(-)net/mptcp/pm.c +0
-18@@ -461,34 +461,15 @@ bool mptcp_pm_accept_new_subflow(struct mptcp_sock *msk, bool 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))
net/mptcp/pm.c bool mptcp_pm_accept_new_subflow(struct mptcp_sock *msk, bool allow) · line 470
Quoted 10 lines
net/mptcp/pm.c +2
-5+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);
I think it would make more sense **not** to call pm->ops callback under the PM lock.
I think a BPF PM should not modify this structure directly. If something needs to be changed, it should be done via a kfunc that will automatically take the PM spin lock if needed, and release it at the end. Only the "PM core" (pm.c) should modify it and the in-kernel and userspace PM because they require a way to store data. A BPF PM can store data in a map elsewhere.
Quoted 10 lines
net/mptcp/pm.c +2
-0+if (ret) + pm->subflows++;spin_unlock_bh (&pm->lock);return ret;net/mptcp/pm_kernel.c +0
-0
net/mptcp/pm_kernel.c static bool mptcp_pm_kernel_accept_new_subflow(struct mptcp_sock *msk, · line 1409
Quoted 7 lines
net/mptcp/pm_kernel.c +2
-0@@ -1403,11 +1403,21 @@ static bool mptcp_pm_kernel_accept_new_subflow(struct mptcp_sock *msk, bool allow) {struct mptcp_pm_data *pm = &msk->pm; +unsigned int subflows_max;bool ret = false; + subflows_max =mptcp_pm_get_subflows_max (msk);
this variable is only needed for pm->accept_subflow && !allow, maybe we should declare it there, and assign it only when needed?
net/mptcp/pm_kernel.c static bool mptcp_pm_kernel_accept_new_subflow(struct mptcp_sock *msk, · line 1412
Quoted 2 lines
net/mptcp/pm_kernel.c +2
-0+pr_debug ("msk=%p subflows=%d max=%d allow=%d\n" , msk, pm->subflows, + subflows_max,READ_ONCE (pm->accept_subflow));
Perhaps we can drop this pr_debug, or remove subflows_max: easy to get the info from userspace.
net/mptcp/pm_kernel.c static bool mptcp_pm_kernel_accept_new_subflow(struct mptcp_sock *msk, · line 1419
Quoted 7 lines
net/mptcp/pm_kernel.c +4
-0+if (READ_ONCE (pm->accept_subflow)) {if (allow)return true; + + ret = pm->subflows < subflows_max; +if (ret && pm->subflows == subflows_max -1 )
detail, I think it makes more sense to use "+ 1":
if (ret && (pm->subflows + 1) == subflows_max)
net/mptcp/pm_kernel.c static bool mptcp_pm_kernel_accept_new_subflow(struct mptcp_sock *msk, · line 1423
Quoted 4 lines
net/mptcp/pm_kernel.c +1
-0+WRITE_ONCE (pm->accept_subflow, false); }return ret;
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerPATCH v5 4/7 mptcp: pm: update pm lock order in mptcp_pm_worker
In reply to Geliang TangFrom: 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 while holding the mptcp pm lock, then read the copy after releasing the lock.
For each PM status flag, hold the lock, clear this flag of pm->status, and then call each handling function before or after releasing the lock as needed.
Finally, hold the lock before calling __mptcp_pm_kernel_worker() and release it afterwards.
--- net/mptcp/pm.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
net/mptcp/pm.c +13 -6
@@ -932,26 +932,33 @@ void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)void mptcp_pm_worker (struct mptcp_sock *msk) {struct mptcp_pm_data *pm = &msk->pm; +u8 status;msk_owned_by_me (msk);if (!(pm->status &MPTCP_PM_WORK_MASK ))return ; -spin_lock_bh (&msk->pm.lock); +spin_lock_bh (&pm->lock); + status =READ_ONCE (pm->status); +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 )) { +pr_debug ("msk=%p status=%x\n" , msk, status); +if (status &BIT (MPTCP_PM_ADD_ADDR_SEND_ACK )) { +spin_lock_bh (&pm->lock); pm->status &= ~BIT (MPTCP_PM_ADD_ADDR_SEND_ACK );mptcp_pm_addr_send_ack (msk); +spin_unlock_bh (&pm->lock); } -if (pm->status &BIT (MPTCP_PM_RM_ADDR_RECEIVED )) { +if (status &BIT (MPTCP_PM_RM_ADDR_RECEIVED )) { +spin_lock_bh (&pm->lock); pm->status &= ~BIT (MPTCP_PM_RM_ADDR_RECEIVED );mptcp_pm_rm_addr_recv (msk); +spin_unlock_bh (&pm->lock); } +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,
Signature · 1 line
2.43.0
Matthieu Baerts
maintainerRe: [PATCH mptcp-next v5 4/7] mptcp: pm: update pm lock order in mptcp_pm_worker
Hi Geliang,
Quoted 29 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->statuswhile holding the mptcp pm lock, then read the copy after releasing the lock.For each PM status flag, hold the lock, clear this flag of
pm->status, and then call each handling function before or after releasing the lock as needed.Finally, hold the lock before calling
__mptcp_pm_kernel_worker()and release it afterwards.Signed-off-by Geliang Tang <[email protected]>--- net/mptcp/pm.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)net/mptcp/pm.c +0
-0@@ -932,26 +932,33 @@ void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)void mptcp_pm_worker (struct mptcp_sock *msk) {struct mptcp_pm_data *pm = &msk->pm;
net/mptcp/pm.c void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) · line 943
Quoted 10 lines
net/mptcp/pm.c +3
-1+u8 status;msk_owned_by_me (msk);if (!(pm->status &MPTCP_PM_WORK_MASK ))return ; -spin_lock_bh (&msk->pm.lock); +spin_lock_bh (&pm->lock); + status =READ_ONCE (pm->status);
Do you think it would be OK to clear all the bits that are going to be checked here (or once at the end), using MPTCP_PM_WORK_MASK? Before the PM lock was released temporally in some sections, I guess it should be fine.
Also you don't need READ_ONCE() here as pm->status is protected only by the pm lock.
net/mptcp/pm.c void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) · line 948
Quoted 7 lines
net/mptcp/pm.c +4
-2+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 )) { +pr_debug ("msk=%p status=%x\n" , msk, status); +if (status &BIT (MPTCP_PM_ADD_ADDR_SEND_ACK )) { +spin_lock_bh (&pm->lock);
I *think* we should change the way the PM lock is currently handled. For the moment, we lock very big sections, and not only when it is needed. That is probably easier somehow, but it might not be clear when it is locked or not, and required unlock/lock in some other cases.
Changing the lock might have a cost in some cases, but probably a gain in others. Concretely, here, we should not lock now, and let the callee the responsibility to do so only when required.
By doing that, all PM callbacks will not be called with the PM locks, which would make easier to deal with kfunc with BPF.
If you are not comfortable doing such modifications, do not hesitate to tell us to get some helps. I can try to look when I have a bit of time if you prefer.
net/mptcp/pm.c void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) · line 949
Quoted 1 line
net/mptcp/pm.c +0
-0pm->status &= ~BIT (MPTCP_PM_ADD_ADDR_SEND_ACK );
(so this should be done before/after)
net/mptcp/pm.c void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) · line 954
Quoted 6 lines
net/mptcp/pm.c +3
-1mptcp_pm_addr_send_ack (msk); +spin_unlock_bh (&pm->lock); } -if (pm->status &BIT (MPTCP_PM_RM_ADDR_RECEIVED )) { +if (status &BIT (MPTCP_PM_RM_ADDR_RECEIVED )) { +spin_lock_bh (&pm->lock);
(same here)
net/mptcp/pm.c void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) · line 955
Quoted 1 line
net/mptcp/pm.c +0
-0pm->status &= ~BIT (MPTCP_PM_RM_ADDR_RECEIVED );
(same here)
net/mptcp/pm.c void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) · line 959
Quoted 4 lines
net/mptcp/pm.c +2
-0mptcp_pm_rm_addr_recv (msk); +spin_unlock_bh (&pm->lock); } +spin_lock_bh (&pm->lock);
(same here and in the next patches)
net/mptcp/pm.c void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) · line 964
Quoted 7 lines
net/mptcp/pm.c +1
-2__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,
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerPATCH v5 5/7 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 | 9 ++++++++- net/mptcp/pm_kernel.c | 22 +++++++++++++--------- 3 files changed, 24 insertions(+), 10 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 +8 -1
@@ -505,7 +505,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 )
@@ -956,6 +957,12 @@ void mptcp_pm_worker(struct mptcp_sock *msk)mptcp_pm_rm_addr_recv (msk);spin_unlock_bh (&pm->lock); } +if (status &BIT (MPTCP_PM_ESTABLISHED )) { +spin_lock_bh (&pm->lock); + pm->status &= ~BIT (MPTCP_PM_ESTABLISHED ); +spin_unlock_bh (&pm->lock); + 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);
@@ -1447,6 +1450,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 v5 6/7 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 | 13 ++++++++++--- net/mptcp/pm_kernel.c | 9 +++------ 3 files changed, 14 insertions(+), 9 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 +10 -3
@@ -533,7 +533,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);
@@ -560,7 +560,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);
@@ -618,7 +619,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);
@@ -963,6 +964,12 @@ void mptcp_pm_worker(struct mptcp_sock *msk)spin_unlock_bh (&pm->lock); pm->ops->established (msk); } +if (status &BIT (MPTCP_PM_SUBFLOW_ESTABLISHED )) { +spin_lock_bh (&pm->lock); + pm->status &= ~BIT (MPTCP_PM_SUBFLOW_ESTABLISHED ); +spin_unlock_bh (&pm->lock); + 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)
@@ -1451,6 +1447,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 v5 7/7 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
@@ -551,22 +551,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!
But sadly, our CI spotted some issues with it when trying to build it.
You can find more details there:
https://github.com/multipath-tcp/mptcp_net-next/actions/runs/14100178407
Status: failure
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/55c1c9f50291
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=947653
Feel free to reply to this email if you cannot access logs, if you need some support to fix the error, if this doesn't seem to be caused by your modifications or if the error is a false positive one.
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
Matthieu Baerts
maintainerHi Geliang,
Quoted 9 lines · MPTCP CI
Hi Geliang,
Thank you for your modifications, that's great!
But sadly, our CI spotted some issues with it when trying to build it.
You can find more details there:
https://github.com/multipath-tcp/mptcp_net-next/actions/runs/14100178407
It looks like it is a false positive because one function has been renamed, we can ignore it for the moment.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
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/14100178411
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/55c1c9f50291
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=947653
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 12 lines · Geliang Tang
From: Geliang Tang <[email protected]>
v5:
- add comment "call from the subflow/msk context" formptcp_sched_ops.
- add new helpermptcp_pm_accept_new_subflow.
- add "bool allow" parameter formptcp_pm_accept_new_subflow, and drop .allow_new_subflow interface.
- use a copy ofpm->statusinmptcp_pm_worker.
- renamemptcp_pm_create_subflow_or_signal_addrwith "__" prefix.
- drop "!update_subflows" inmptcp_pm_subflow_check_next.
- add_addr_received/rm_addr_received interfaces will be added in the next series.
Thank you for the update. I think more changes are needed around the PM lock. Please see my individual comments.
Do not hesitate to tell me if you see what I mean with the modifications around the PM lock, or if you prefer I (or someone else) take over this part.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.