* [PATCH mptcp-next v10] mptcp: count the DATA_FIN in mptcp_inq_hint
@ 2026-12-06 4:42 Geliang Tang
2026-12-06 4:56 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Geliang Tang @ 2026-12-06 4:42 UTC (permalink / raw)
To: mptcp
From: Geliang Tang <tanggeliang@kylinos.cn>
Since mptcp_inq_hint() uses mptcp_data_avail(), it no longer counts the
DATA_FIN while data are still queued. With TCP, the FIN is counted in
the TCP_CM_INQ hint until it is read.
Add the FIN byte (+1) when SOCK_DONE is set, or when the new helper
mptcp_pending_eof() reports a pending EOF, using mptcp_check_fin_eof()
shared with mptcp_check_data_fin(): on fallback, the FIN is counted only
once tcp_fin() set SOCK_DONE on the first subflow, so a RST-induced
emulated DATA_FIN is not counted.
The RX path may leave the DATA_FIN for the worker to process. If the
receive queue is drained before the worker runs, the hint would advertise
the EOF byte while a non-blocking recvmsg() returns -EAGAIN. Treat a
pending EOF as a loop exit condition in mptcp_recvmsg(), like a FIN at
the queue tail, so the read returns the data or EOF without waiting for
mptcp_worker().
Keep the 'seq' parameter of mptcp_pending_eof(), although the callers
currently pass NULL, since it will be used in subsequent patches.
This has been reproduced with new Packetdrill tests, checking TCP_CM_INQ
while data are queued with a DATA_FIN, or with a FIN after a fallback to
TCP:
mptcp_inq_hint.pkt:37: runtime error in recvmsg call: Bad data in cmsg 0: expected=51 actual=50
fallback_fin.pkt:19: runtime error in recvmsg call: Bad data in cmsg 0: expected=51 actual=50
Co-developed-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v10:
- check mptcp_pending_eof() instead of rcv_data_fin in mptcp_recvmsg.
v9:
- Process the pending DATA_FIN synchronously in mptcp_recvmsg()
- Mention in the commit log why the 'seq' parameter of mptcp_pending_eof()
is kept: it will be used in subsequent patches.
- https://patchwork.kernel.org/project/mptcp/patch/30e3f1d6eabedf2cc62dbb742d48983187c90ffd.1796518897.git.tanggeliang@kylinos.cn/
v8:
- https://patchwork.kernel.org/project/mptcp/patch/29b6798cd39edaab5dcd58f10148067edecb4f1e.1796509287.git.tanggeliang@kylinos.cn/
v7:
- https://patchwork.kernel.org/project/mptcp/patch/20261203-mptcp-fixes-for-siocinq-v7-6-e6d589de9cf8@kernel.org/
---
net/mptcp/protocol.c | 43 ++++++++++++++++++++++++++-----------------
1 file changed, 26 insertions(+), 17 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 14fca55d4619..7527d1757260 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -566,9 +566,9 @@ static void mptcp_check_data_fin_ack(struct sock *sk)
}
/* can be called with no lock acquired */
-static bool mptcp_pending_data_fin(struct sock *sk, u64 *seq)
+static bool mptcp_pending_data_fin(const struct sock *sk, u64 *seq)
{
- struct mptcp_sock *msk = mptcp_sk(sk);
+ const struct mptcp_sock *msk = mptcp_sk(sk);
if (READ_ONCE(msk->rcv_data_fin) &&
((1 << inet_sk_state_load(sk)) &
@@ -588,6 +588,18 @@ static bool mptcp_pending_data_fin(struct sock *sk, u64 *seq)
return false;
}
+static bool mptcp_check_fin_eof(const struct mptcp_sock *msk)
+{
+ return !__mptcp_check_fallback(msk) ||
+ (msk->first && sock_flag(msk->first, SOCK_DONE));
+}
+
+static bool mptcp_pending_eof(const struct sock *sk, u64 *seq)
+{
+ return mptcp_pending_data_fin(sk, seq) &&
+ mptcp_check_fin_eof(mptcp_sk(sk));
+}
+
static void mptcp_set_datafin_timeout(struct sock *sk)
{
struct inet_connection_sock *icsk = inet_csk(sk);
@@ -717,8 +729,7 @@ static void mptcp_check_data_fin(struct sock *sk)
WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | RCV_SHUTDOWN);
/* on fallback, also emulated after a reset: check for a FIN */
- if (!__mptcp_check_fallback(msk) ||
- (msk->first && sock_flag(msk->first, SOCK_DONE)))
+ if (mptcp_check_fin_eof(msk))
sock_set_flag(sk, SOCK_DONE);
smp_mb__before_atomic(); /* SHUTDOWN must be visible first */
@@ -2480,22 +2491,16 @@ static bool mptcp_move_skbs(struct sock *sk)
static unsigned int mptcp_inq_hint(const struct sock *sk)
{
const struct mptcp_sock *msk = mptcp_sk(sk);
- const struct sk_buff *skb;
+ u64 hint_val = mptcp_data_avail(msk);
- skb = skb_peek(&sk->sk_receive_queue);
- if (skb) {
- u64 hint_val = mptcp_data_avail(msk);
-
- if (hint_val >= INT_MAX)
- return INT_MAX;
-
- return (unsigned int)hint_val;
- }
+ if (hint_val >= INT_MAX)
+ return INT_MAX;
- if (sock_flag(sk, SOCK_DONE))
- return 1;
+ /* Like TCP, keep the hint non-zero when only EOF is left. */
+ if (sock_flag(sk, SOCK_DONE) || mptcp_pending_eof(sk, NULL))
+ hint_val += 1;
- return 0;
+ return (unsigned int)hint_val;
}
static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
@@ -2544,6 +2549,10 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
if (!list_empty(&msk->backlog_list) && mptcp_move_skbs(sk))
continue;
+ /* A pending EOF acts like a FIN at the queue tail. */
+ if (mptcp_pending_eof(sk, NULL))
+ break;
+
/* only the MPTCP socket status is relevant here. The exit
* conditions mirror closely tcp_recvmsg()
*/
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH mptcp-next v10] mptcp: count the DATA_FIN in mptcp_inq_hint
2026-12-06 4:42 [PATCH mptcp-next v10] mptcp: count the DATA_FIN in mptcp_inq_hint Geliang Tang
@ 2026-12-06 4:56 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-06 4:56 UTC (permalink / raw)
To: Geliang Tang, mptcp
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] mptcp: mptcp_splice_read() misses mptcp_pending_eof() check
--
commit 682dbfa2512e69f321d0fd1137d83a62ffdf44a7
Author: Geliang Tang <geliang@kernel.org>
mptcp: count the DATA_FIN in mptcp_inq_hint
This commit counts a pending DATA_FIN in mptcp_inq_hint() using a new
mptcp_pending_eof() helper and adds mptcp_pending_eof() as an exit
condition in mptcp_recvmsg().
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 14fca55d46199..7527d17572606 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
[ ... ]
> @@ -2544,6 +2549,10 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
> if (!list_empty(&msk->backlog_list) && mptcp_move_skbs(sk))
> continue;
>
> + /* A pending EOF acts like a FIN at the queue tail. */
> + if (mptcp_pending_eof(sk, NULL))
> + break;
> +
> /* only the MPTCP socket status is relevant here. The exit
> * conditions mirror closely tcp_recvmsg()
> */
[Severity: Low]
Does mptcp_splice_read() need the same mptcp_pending_eof() check?
When data and an in-sequence DATA_FIN arrive while the socket is not
owned by userspace, mptcp_check_data_fin() is deferred to mptcp_worker()
with backlog_list empty. After recvmsg() drains the queue and reports
TCP_CM_INQ = 1, SOCK_DONE and RCV_SHUTDOWN remain unset.
If userspace then calls non-blocking splice() before mptcp_worker()
runs, mptcp_recv_skb() skips mptcp_move_skbs() because backlog_list is
empty, and mptcp_splice_read() only checks SOCK_DONE and RCV_SHUTDOWN,
so it returns -EAGAIN instead of 0.
--
Sashiko AI review · https://sashiko.dev/#/patchset/41d066cd5e7a602c2e909acd83c43672f213795e.1796531907.git.tanggeliang@kylinos.cn?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-06 4:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06 4:42 [PATCH mptcp-next v10] mptcp: count the DATA_FIN in mptcp_inq_hint Geliang Tang
2026-12-06 4:56 ` sashiko-bot
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.