* [PATCH mptcp-next v9] mptcp: count the DATA_FIN in mptcp_inq_hint
@ 2026-12-06 1:07 Geliang Tang
2026-12-06 1:28 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Geliang Tang @ 2026-12-06 1:07 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: an in-sequence DATA_FIN checked
by mptcp_pending_data_fin(), accepted on non-fallback connections, or on
fallback ones once tcp_fin() set SOCK_DONE on the first subflow, using
mptcp_check_fin_eof() shared with mptcp_check_data_fin().
The RX path may queue the data directly on the msk receive queue and
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 SOCK_DONE is not set yet, and a non-blocking recvmsg() would
return -EAGAIN instead of 0. Process the pending DATA_FIN synchronously
in mptcp_recvmsg() to close this window.
Keep the 'seq' parameter of mptcp_pending_eof(), although the only caller
currently passes NULL, since it will be used in subsequent patches.
This way the fallback FIN is counted without waiting for mptcp_worker(),
while a RST-induced emulated DATA_FIN and a stale rcv_data_fin on
TCP_CLOSE are not counted.
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>
---
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.
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 | 48 ++++++++++++++++++++++++++++----------------
1 file changed, 31 insertions(+), 17 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 14fca55d4619..7ae33bfd2d44 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,22 @@ 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)
+{
+ const struct mptcp_sock *msk = mptcp_sk(sk);
+
+ if (!mptcp_pending_data_fin(sk, seq))
+ return false;
+
+ return mptcp_check_fin_eof(msk);
+}
+
static void mptcp_set_datafin_timeout(struct sock *sk)
{
struct inet_connection_sock *icsk = inet_csk(sk);
@@ -717,8 +733,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 +2495,15 @@ 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;
-
- skb = skb_peek(&sk->sk_receive_queue);
- if (skb) {
- u64 hint_val = mptcp_data_avail(msk);
+ 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;
+ 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 +2552,12 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
if (!list_empty(&msk->backlog_list) && mptcp_move_skbs(sk))
continue;
+ /* The RX path may have queued the data directly and left
+ * the DATA_FIN for the worker to process.
+ */
+ if (unlikely(READ_ONCE(msk->rcv_data_fin)))
+ mptcp_check_data_fin(sk);
+
/* 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 v9] mptcp: count the DATA_FIN in mptcp_inq_hint
2026-12-06 1:07 [PATCH mptcp-next v9] mptcp: count the DATA_FIN in mptcp_inq_hint Geliang Tang
@ 2026-12-06 1:28 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-06 1:28 UTC (permalink / raw)
To: Geliang Tang, mptcp
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] mptcp: mptcp_recvmsg() can return EOF instead of ECONNRESET
on fallback RST
- [Low] mptcp: mptcp_splice_read() skips pending DATA_FIN processing
--
commit 2c5b77605c15fa6fb81035b488f9f109e3948643
Author: Geliang Tang <geliang@kernel.org>
mptcp: count the DATA_FIN in mptcp_inq_hint
This commit adds the DATA_FIN byte to mptcp_inq_hint() when SOCK_DONE is
set or a pending EOF is detected, and processes pending DATA_FINs
synchronously in mptcp_recvmsg().
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 14fca55d46199..7ae33bfd2d448 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
[ ... ]
> @@ -2480,22 +2495,15 @@ 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;
> -
> - skb = skb_peek(&sk->sk_receive_queue);
> - if (skb) {
> - u64 hint_val = mptcp_data_avail(msk);
> + 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;
> + if (sock_flag(sk, SOCK_DONE) || mptcp_pending_eof(sk, NULL))
> + hint_val += 1;
>
> - return 0;
> + return (unsigned int)hint_val;
> }
[Severity: Low]
Does mptcp_splice_read() also need to process a pending DATA_FIN
synchronously?
A zero-length recvmsg() with TCP_INQ skips the receive loop in
mptcp_recvmsg() without calling mptcp_check_data_fin(), yet
mptcp_inq_hint() still advertises the pending EOF byte via
mptcp_pending_eof().
If userspace then calls non-blocking splice() before mptcp_worker() runs
while msk->backlog_list is empty, mptcp_recv_skb() skips
mptcp_move_skbs(), so SOCK_DONE and RCV_SHUTDOWN remain unset and
mptcp_splice_read() returns -EAGAIN instead of 0. Processing a pending
DATA_FIN synchronously in mptcp_splice_read() would close this window.
> @@ -2544,6 +2552,12 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
> if (!list_empty(&msk->backlog_list) && mptcp_move_skbs(sk))
> continue;
>
> + /* The RX path may have queued the data directly and left
> + * the DATA_FIN for the worker to process.
> + */
> + if (unlikely(READ_ONCE(msk->rcv_data_fin)))
> + mptcp_check_data_fin(sk);
> +
> /* only the MPTCP socket status is relevant here. The exit
> * conditions mirror closely tcp_recvmsg()
> */
[Severity: Medium]
Can calling mptcp_check_data_fin() unconditionally here cause
mptcp_recvmsg() to return 0 instead of -ECONNRESET on a fallback socket
reset?
CPU0 CPU1 (<softirq>)
mptcp_recvmsg()
lock_sock(sk)
tcp_reset(ssk)
tcp_done_with_error(ssk, ECONNRESET)
subflow_state_change(ssk)
subflow_sched_work_if_closed()
msk->rcv_data_fin = 1
subflow_error_report(ssk)
set MPTCP_ERROR_REPORT in cb_flags
mptcp_check_data_fin(sk)
sk->sk_shutdown |= RCV_SHUTDOWN
sock_error(sk) == 0
if (sk->sk_shutdown & RCV_SHUTDOWN)
break; <-- returns 0 (EOF)
release_sock(sk)
__mptcp_error_report(sk)
On a fallback connection with an empty receive queue, a concurrent RST
sets msk->rcv_data_fin via subflow_sched_work_if_closed() without setting
SOCK_DONE on msk->first. Because lock_sock(sk) is held,
subflow_error_report() defers sk->sk_err until release_sock(sk).
mptcp_check_data_fin() still sets RCV_SHUTDOWN when mptcp_check_fin_eof()
is false, so mptcp_recvmsg() sees sock_error(sk) == 0 and returns 0
instead of -ECONNRESET. Gating this call on mptcp_pending_eof(sk, NULL)
would avoid consuming a RST-emulated DATA_FIN before error propagation.
--
Sashiko AI review · https://sashiko.dev/#/patchset/30e3f1d6eabedf2cc62dbb742d48983187c90ffd.1796518897.git.tanggeliang@kylinos.cn?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-06 1:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06 1:07 [PATCH mptcp-next v9] mptcp: count the DATA_FIN in mptcp_inq_hint Geliang Tang
2026-12-06 1:28 ` 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.