From: Tao Cui <cui.tao@linux.dev>
To: mptcp@lists.linux.dev, matttbe@kernel.org, quanyeyang@proton.me
Cc: geliang@kernel.org, cuitao@kylinos.cn, cui.tao@linux.dev
Subject: [PATCH mptcp-next v3 2/3] mptcp: pm: skip extra_subflows accounting on disconnected msk
Date: Fri, 4 Sep 2026 13:11:49 +0800 [thread overview]
Message-ID: <20260904051150.1196427-3-cui.tao@linux.dev> (raw)
In-Reply-To: <20260904051150.1196427-1-cui.tao@linux.dev>
From: Tao Cui <cuitao@kylinos.cn>
The WARN_ON_ONCE() guards added to the extra_subflows decrement sites
turn out to be reachable:
mptcp_pm_data_reset() zeroes the counter with only the msk socket lock
held, while an MP_JOIN subflow can still sit in msk->join_list, its
reference already accounted by mptcp_pm_allow_new_subflow() under
pm->lock. If the socket gets disconnected(AF_UNSPEC) in that window,
mptcp_pm_data_reset() zeroes the counter, and the join list is flushed
later at release_sock() time: the leftover subflow then reaches
mptcp_pm_subflow_check_next() (or __mptcp_pm_close_subflow() for
kernel PM sockets) with the counter already at 0, firing the warning.
On panic_on_warn kernels this is a remotely triggerable panic, which
is worse than the silent wrap the guards replaced.
Skip the PM accounting when the msk is already in TCP_CLOSE: in the
scenario above the state is set before the counters are cleared, and
once the msk is closed the accounting is not relevant anymore. Keep a
clamp and a rate-limited pr_warn() on the decrement sites instead,
to leave a trace of any imbalance we would still not know about.
Fixes: e99c1ca89071 ("mptcp: pm: add WARN_ON_ONCE guards on extra_subflows underflow")
Link: https://github.com/multipath-tcp/mptcp_net-next/issues/629
Suggested-by: Matthieu Baerts <matttbe@kernel.org>
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
net/mptcp/pm.c | 11 ++++++++++-
net/mptcp/protocol.h | 14 ++++++++++++--
2 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index 07cdcdb54b15..cccf5319cce0 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -671,9 +671,18 @@ void mptcp_pm_subflow_check_next(struct mptcp_sock *msk,
update_subflows = subflow->request_join || subflow->mp_join;
if (mptcp_pm_is_userspace(msk)) {
if (update_subflows) {
+ /* The PM counters have already been cleared if the
+ * msk got disconnected while this subflow was still
+ * queued in the join list
+ */
+ if (inet_sk_state_load(sk) == TCP_CLOSE)
+ return;
spin_lock_bh(&pm->lock);
- if (!WARN_ON_ONCE(pm->extra_subflows == 0))
+ if (likely(pm->extra_subflows))
pm->extra_subflows--;
+ else
+ pr_warn_ratelimited("extra_subflows underflow, msk=%p\n",
+ msk);
spin_unlock_bh(&pm->lock);
}
return;
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 87ccb84e9927..07821551499c 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -1252,8 +1252,18 @@ u8 mptcp_pm_get_limit_extra_subflows(const struct mptcp_sock *msk);
/* called under PM lock */
static inline void __mptcp_pm_close_subflow(struct mptcp_sock *msk)
{
- if (!WARN_ON_ONCE(msk->pm.extra_subflows == 0) &&
- --msk->pm.extra_subflows < mptcp_pm_get_limit_extra_subflows(msk))
+ /* The PM counters have already been cleared if the msk got
+ * disconnected while this subflow was still queued in the
+ * join list
+ */
+ if (inet_sk_state_load((struct sock *)msk) == TCP_CLOSE)
+ return;
+
+ if (unlikely(msk->pm.extra_subflows == 0)) {
+ pr_warn_ratelimited("extra_subflows underflow, msk=%p\n", msk);
+ return;
+ }
+ if (--msk->pm.extra_subflows < mptcp_pm_get_limit_extra_subflows(msk))
WRITE_ONCE(msk->pm.accept_subflow, true);
}
--
2.43.0
next prev parent reply other threads:[~2026-09-04 5:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 5:11 [PATCH mptcp-next v3 0/3] mptcp: pm: fix reachable extra_subflows guards Tao Cui
2026-09-04 5:11 ` [PATCH mptcp-next v3 1/3] mptcp: pm: bound extra_subflows admission on userspace PM Tao Cui
2026-09-04 5:11 ` Tao Cui [this message]
2026-09-04 5:28 ` [PATCH mptcp-next v3 2/3] mptcp: pm: skip extra_subflows accounting on disconnected msk sashiko-bot
2026-09-04 5:11 ` [PATCH mptcp-next v3 3/3] mptcp: pm: userspace: cap extra_subflows on Netlink subflow creation Tao Cui
2026-09-04 6:29 ` [PATCH mptcp-next v3 0/3] mptcp: pm: fix reachable extra_subflows guards 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=20260904051150.1196427-3-cui.tao@linux.dev \
--to=cui.tao@linux.dev \
--cc=cuitao@kylinos.cn \
--cc=geliang@kernel.org \
--cc=matttbe@kernel.org \
--cc=mptcp@lists.linux.dev \
--cc=quanyeyang@proton.me \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox