From: Gang Yan <gang.yan@linux.dev>
To: mptcp@lists.linux.dev
Subject: [PATCH mptcp-next v2 5/5] Squash to "bpf: Add mptcp packet scheduler struct_ops"
Date: Tue, 18 Aug 2026 17:48:25 +0800 [thread overview]
Message-ID: <20260818094825.48446-6-gang.yan@linux.dev> (raw)
In-Reply-To: <20260818094825.48446-1-gang.yan@linux.dev>
From: Gang Yan <yangang@kylinos.cn>
The pernet sysctl patches in this series swap the scheduler pointer
with xchg() without taking any module reference: this is fine while
ops can only be registered from built-in code.
This commit is what makes BPF schedulers registerable, i.e. the first
one whose ops can be unloaded while a pernet still stores them. Take
the reference accordingly:
- mptcp_pernet_set_defaults() pins &mptcp_sched_default, mirroring
tcp_sk_init() pinning &tcp_reno;
- mptcp_set_scheduler() takes a reference on the new ops and
releases the one held on the ops it replaces, mirroring
tcp_set_default_congestion_control();
- mptcp_net_exit() releases the last reference, mirroring
tcp_sk_exit().
Assisted-by: Claude:GLM5.2
Co-developed-by: Tao Cui <cuitao@kylinos.cn>
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
Signed-off-by: Gang Yan <yangang@kylinos.cn>
---
net/mptcp/ctrl.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/net/mptcp/ctrl.c b/net/mptcp/ctrl.c
index 32268aa26097..309bbb2a4eb0 100644
--- a/net/mptcp/ctrl.c
+++ b/net/mptcp/ctrl.c
@@ -123,7 +123,8 @@ static void mptcp_pernet_set_defaults(struct mptcp_pernet *pernet)
pernet->stale_loss_cnt = 4;
pernet->pm_type = MPTCP_PM_TYPE_KERNEL;
- RCU_INIT_POINTER(pernet->scheduler, &mptcp_sched_default);
+ if (bpf_try_module_get(&mptcp_sched_default, mptcp_sched_default.owner))
+ RCU_INIT_POINTER(pernet->scheduler, &mptcp_sched_default);
if (bpf_try_module_get(&mptcp_pm_kernel, mptcp_pm_kernel.owner))
RCU_INIT_POINTER(pernet->path_manager, &mptcp_pm_kernel);
@@ -134,15 +135,22 @@ static void mptcp_pernet_set_defaults(struct mptcp_pernet *pernet)
#ifdef CONFIG_SYSCTL
static int mptcp_set_scheduler(struct mptcp_pernet *pernet, const char *name)
{
- struct mptcp_sched_ops *sched;
+ struct mptcp_sched_ops *sched, *prev;
int ret = 0;
rcu_read_lock();
sched = mptcp_sched_find(name);
- if (sched)
- xchg(&pernet->scheduler, sched);
- else
+ if (sched) {
+ if (bpf_try_module_get(sched, sched->owner)) {
+ prev = xchg(&pernet->scheduler, sched);
+ if (prev)
+ bpf_module_put(prev, prev->owner);
+ } else {
+ ret = -EBUSY;
+ }
+ } else {
ret = -ENOENT;
+ }
rcu_read_unlock();
return ret;
@@ -603,10 +611,15 @@ static int __net_init mptcp_net_init(struct net *net)
static void __net_exit mptcp_net_exit(struct net *net)
{
struct mptcp_pernet *pernet = mptcp_get_pernet(net);
+ struct mptcp_sched_ops *sched;
struct mptcp_pm_ops *pm;
mptcp_pernet_del_table(pernet);
+ sched = rcu_dereference_protected(pernet->scheduler, true);
+ if (sched)
+ bpf_module_put(sched, sched->owner);
+
pm = rcu_dereference_protected(pernet->path_manager, true);
if (pm)
bpf_module_put(pm, pm->owner);
--
2.43.0
next prev parent reply other threads:[~2026-08-18 9:48 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 9:48 [PATCH mptcp-next v2 0/5] mptcp: avoid data-races around the sysctls Gang Yan
2026-08-18 9:48 ` [PATCH mptcp-next v2 1/5] mptcp: sched: change scheduler sysctl atomically Gang Yan
2026-08-18 9:59 ` sashiko-bot
2026-08-18 12:56 ` gang.yan
2026-08-18 15:50 ` Matthieu Baerts
2026-08-18 9:48 ` [PATCH mptcp-next v2 2/5] mptcp: pm: change path_manager " Gang Yan
2026-08-18 10:00 ` sashiko-bot
2026-08-18 12:57 ` gang.yan
2026-08-18 15:52 ` Matthieu Baerts
2026-08-18 9:48 ` [PATCH mptcp-next v2 3/5] mptcp: use READ_ONCE() over sysctls Gang Yan
2026-08-18 10:01 ` sashiko-bot
2026-08-18 13:02 ` gang.yan
2026-08-18 15:57 ` Matthieu Baerts
2026-08-18 9:48 ` [PATCH mptcp-next v2 4/5] Squash to "mptcp: pm: init and release mptcp_pm_ops" Gang Yan
2026-08-18 10:03 ` sashiko-bot
2026-08-18 13:06 ` gang.yan
2026-08-18 9:48 ` Gang Yan [this message]
2026-08-18 11:13 ` [PATCH mptcp-next v2 0/5] mptcp: avoid data-races around the sysctls MPTCP CI
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260818094825.48446-6-gang.yan@linux.dev \
--to=gang.yan@linux.dev \
--cc=mptcp@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.