* [PATCH mptcp-next v8] mptcp: count the DATA_FIN in mptcp_inq_hint
@ 2026-12-05 22:26 Geliang Tang
2026-12-05 22:40 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Geliang Tang @ 2026-12-05 22:26 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().
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>
---
net/mptcp/protocol.c | 42 +++++++++++++++++++++++++-----------------
1 file changed, 25 insertions(+), 17 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 0ee7e632484b..509f48b9525e 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 */
@@ -2543,22 +2558,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,
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH mptcp-next v8] mptcp: count the DATA_FIN in mptcp_inq_hint
2026-12-05 22:26 [PATCH mptcp-next v8] mptcp: count the DATA_FIN in mptcp_inq_hint Geliang Tang
@ 2026-12-05 22:40 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-05 22:40 UTC (permalink / raw)
To: Geliang Tang, mptcp
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] mptcp: mptcp_inq_hint() reports INQ=1 before SOCK_DONE
causing recvmsg EAGAIN
- [Low] mptcp: unused u64 *seq parameter in static helper
mptcp_pending_eof()
--
commit 2e71023ce38283df6ab91e55af965d48b4b59289
Author: Geliang Tang <geliang@kernel.org>
mptcp: count the DATA_FIN in mptcp_inq_hint
This commit updates mptcp_inq_hint() to count a pending DATA_FIN in
TCP_CM_INQ even while payload is still queued, introducing
mptcp_check_fin_eof() and mptcp_pending_eof().
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 14fca55d46199..09380154ee55b 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
[ ... ]
> @@ -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);
> +}
[Severity: Low]
Is the seq parameter of mptcp_pending_eof() needed?
The only caller is mptcp_inq_hint(), which passes NULL. Passing seq to
mptcp_pending_data_fin() before mptcp_check_fin_eof() would also write
*seq even when mptcp_pending_eof() returns false.
Dropping the parameter and calling mptcp_pending_data_fin(sk, NULL)
directly avoids this.
[ ... ]
> @@ -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: Medium]
Can mptcp_inq_hint() now advertise TCP_CM_INQ = 1 on an empty receive
queue before SOCK_DONE or RCV_SHUTDOWN is set, causing a non-blocking
recvmsg() to return -EAGAIN instead of EOF?
When payload and a DATA_FIN arrive in softirq while the socket is not
owned by userspace, move_skbs_to_msk() queues the payload directly on
sk_receive_queue and defers mptcp_check_data_fin() to mptcp_worker().
If userspace drains the queue before the worker runs, msk->backlog_list
is empty so mptcp_recvmsg() skips mptcp_move_skbs():
<softirq> userspace
mptcp_data_ready()
move_skbs_to_msk()
enqueue on sk_receive_queue
mptcp_schedule_work(sk)
mptcp_recvmsg()
drains sk_receive_queue (avail == 0)
backlog_list empty, skips move_skbs
mptcp_inq_hint() -> returns 1
recvmsg(MSG_DONTWAIT)
SOCK_DONE & RCV_SHUTDOWN still unset
returns -EAGAIN <-- expected 0 (EOF)
Because TCP_CM_INQ = 1 tells a TCP_INQ reader to issue another read for
EOF without polling, this causes a spurious -EAGAIN until mptcp_worker()
runs. Calling mptcp_check_data_fin(sk) under lock_sock(sk) in
mptcp_recvmsg() would set SOCK_DONE and RCV_SHUTDOWN synchronously.
--
Sashiko AI review · https://sashiko.dev/#/patchset/29b6798cd39edaab5dcd58f10148067edecb4f1e.1796509287.git.tanggeliang@kylinos.cn?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-05 22:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 22:26 [PATCH mptcp-next v8] mptcp: count the DATA_FIN in mptcp_inq_hint Geliang Tang
2026-12-05 22:40 ` 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.