All of lore.kernel.org
 help / color / mirror / Atom feed
* [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

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.