All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH mptcp-net v7 0/6] mptcp: fixes for SIOCINQ
@ 2026-12-03 16:48 Matthieu Baerts (NGI0)
  2026-12-03 16:48 ` [PATCH mptcp-net v7 1/6] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint Matthieu Baerts (NGI0)
                   ` (6 more replies)
  0 siblings, 7 replies; 15+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-12-03 16:48 UTC (permalink / raw)
  To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0), Zqiang, Paolo Abeni, Geliang Tang

The goal of this series is to make MPTCP's SIOCINQ fully consistent with
TCP's: both report the number of readable data bytes, excluding the FIN
byte.

Patch 1 fixes mptcp_inq_hint() INT_MAX overflow on passive TFO by using
mptcp_data_avail() instead of ack_seq minus map_seq. A fix for v6.2.

The next patches are for mptcp-next, as they are not urgent:

- Patch 2 adds missing smp_wmb/smp_rmb barriers for rcv_data_fin_seq on
  weakly-ordered architectures. A fix for v5.9.

- Patch 3 extracts the DATA_FIN check of mptcp_pending_data_fin() into a
  helper, for patch 6.

- Patch 4 adds mptcp_inq() that excludes the FIN byte, matching TCP's
  tcp_inq() behavior, and switches SIOCINQ to it. A fix for v5.17.

- Patch 5 uses SOCK_DONE in mptcp_inq_hint(), as tcp_inq_hint() does.

- Patch 6 counts the DATA_FIN in mptcp_inq_hint(), as TCP does with the
  FIN in TCP_CM_INQ.

Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
Changes in v7:
- Patch 1: new, the TFO fix of v6's patch 4 alone, for -net, with the
  Fixes tag of v6.2, where the issue is also visible. The other patches
  are now for mptcp-next. Note: I re-used Geliang's commit message from
  the previous version of patch 6, and kept him as author. I hope that's
  OK. (I removed Paolo's suggested-by because it is no longer something
  he suggested.) After the new fix, patch 6 title had to be modified.
- Patch 3: helper renamed to mptcp_rcv_data_fin_in_seq().
- Patch 4: moved before the mptcp_inq_hint() changes, not to count the
  FIN byte in SIOCINQ again after patch 1.
- Patch 6: the DATA_FIN changes of v6's patch 4.
- Patches 4-6: commit msg: the Packetdrill tests reproducing the issues.
- Link to v6: https://patch.msgid.link/cover.1796101973.git.tanggeliang@kylinos.cn

Changes in v6:
- add patch 2: factor mptcp_data_fin() out of mptcp_pending_data_fin() as
  a standalone preparation.
- patch 4: move the mptcp_data_fin() introduction to patch 2, and drop the
  rcv_data_fin_seq reset in mptcp_disconnect().
- Link to v5: https://patch.msgid.link/cover.1796008859.git.tanggeliang@kylinos.cn

Changes in v5:
- patch 3: check fallback in mptcp_inq_hint
- Link to v4: https://patch.msgid.link/cover.1795863454.git.tanggeliang@kylinos.cn

Changes in v4:
- drop patch 1 "handle ack_seq advancing past rcv_data_fin_seq": revert
  '!before64()' back to '==' in mptcp_pending_data_fin(), the OFO queue
  edge case is not a real issue
- add patch 2 "use SOCK_DONE in mptcp_inq_hint": replace the
  TCP_CLOSE/RCV_SHUTDOWN check with sock_flag(sk, SOCK_DONE), aligning
  with tcp_inq_hint()
- patch 3: use sock_flag(sk, SOCK_DONE) to add FIN byte instead of
  checking TCP_CLOSE/RCV_SHUTDOWN and rcv_fastclose, simplifying the
  condition.
- Link to v3: https://patch.msgid.link/cover.1795396910.git.tanggeliang@kylinos.cn

Changes in v3:
- patch 3: fix Sashiko AI review comment
  avoid comparing ack_seq with unset rcv_data_fin_seq (0)
  check TCP_CLOSE/RCV_SHUTDOWN directly, only call mptcp_data_fin() when
  rcv_data_fin is true, exclude MP_FASTCLOSE from +1
- Link to v2: https://patch.msgid.link/cover.1795348666.git.tanggeliang@kylinos.cn

Changes in v2:
- patch 3: drop mptcp_data_fin_seq(), reuse mptcp_data_fin()
  - u64 return couldn't distinguish "no DATA_FIN" from "DATA_FIN at seq 0"
  - mptcp_inq_hint() checks rcv_data_fin/TCP_CLOSE/RCV_SHUTDOWN first
- Link to v1: https://patch.msgid.link/cover.1795318567.git.tanggeliang@kylinos.cn

---
Geliang Tang (6):
      mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
      [mptcp-next] mptcp: add missing memory barriers for rcv_data_fin_seq
      [mptcp-next] mptcp: extract mptcp_rcv_data_fin_in_seq helper
      [mptcp-next] mptcp: add mptcp_inq() for SIOCINQ
      [mptcp-next] mptcp: use SOCK_DONE in mptcp_inq_hint
      [mptcp-next] mptcp: count the DATA_FIN in mptcp_inq_hint

 net/mptcp/options.c  |  1 +
 net/mptcp/protocol.c | 61 ++++++++++++++++++++++++++++++++++------------------
 2 files changed, 41 insertions(+), 21 deletions(-)
---
base-commit: a65588052e99335b9659dff59586854ba0215c81
change-id: 20261203-mptcp-fixes-for-siocinq-d84237074756

Best regards,
--  
Matthieu Baerts (NGI0) <matttbe@kernel.org>


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH mptcp-net v7 1/6] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
  2026-12-03 16:48 [PATCH mptcp-net v7 0/6] mptcp: fixes for SIOCINQ Matthieu Baerts (NGI0)
@ 2026-12-03 16:48 ` Matthieu Baerts (NGI0)
  2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 2/6] mptcp: add missing memory barriers for rcv_data_fin_seq Matthieu Baerts (NGI0)
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 15+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-12-03 16:48 UTC (permalink / raw)
  To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0), Geliang Tang

From: Geliang Tang <tanggeliang@kylinos.cn>

On passive TFO, the map_seq of the skb carrying the data from the SYN is
set to -skb->len, computed on 32 bits, then shifted by ack_seq at the
3rd ACK until commit f03afb3aeb9d ("mptcp: drop
__mptcp_fastopen_gen_msk_ackseq()"). Either way, "ack_seq - map_seq" in
mptcp_inq_hint() is above INT_MAX while this skb is queued, and
SIOCINQ/FIONREAD/TCP_CM_INQ report INT_MAX. Since commit 7272d8131a9d
("mptcp: add receive queue awareness in tcp_rcv_space_adjust()"), this
also affects the receive buffer autotuning, in mptcp_rcv_space_adjust().

This has been reproduced with a new Packetdrill test, checking SIOCINQ
after the 3rd ACK, while the data received in the SYN are still queued:

  server-tfo-inq.pkt:17: runtime error in ioctl call: Bad ioctl optval: expected: 500 actual: 2147483647

Use mptcp_data_avail() (bytes_received - bytes_consumed) instead. With
it, the DATA_FIN is no longer counted while data are queued: SIOCINQ
then reports the number of bytes to read, as TCP does. TCP_CM_INQ, using
the same helper, no longer counts it either in this case, unlike TCP.

Counting the DATA_FIN in TCP_CM_INQ requires more modifications, which
will be done in net-next. Omitting it for the moment is fine: the hint
is only one byte lower than with TCP while data are queued, and it still
reports 1 once only the DATA_FIN is left, as TCP does to tell userspace
to continue reading until the EOF.

Note for the backports: a conflict is expected in v6.6, because commit
9426ce476a70 ("mptcp: annotate lockless access for RX path fields") is
not in this version. It can be resolved by using mptcp_data_avail() the
same way: this helper and the accounting of the TFO data are available
there too.

Fixes: 36b122baf6a8 ("mptcp: add subflow_v(4,6)_send_synack()")
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Co-developed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v7: only the TFO fix of v6's patch 4, for -net, with an older Fixes tag
---
 net/mptcp/protocol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index b9c6e5a615c8..72be0a8f9d87 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2482,7 +2482,7 @@ static unsigned int mptcp_inq_hint(const struct sock *sk)
 
 	skb = skb_peek(&sk->sk_receive_queue);
 	if (skb) {
-		u64 hint_val = READ_ONCE(msk->ack_seq) - MPTCP_SKB_CB(skb)->map_seq;
+		u64 hint_val = mptcp_data_avail(msk);
 
 		if (hint_val >= INT_MAX)
 			return INT_MAX;

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH mptcp-next mptcp-net v7 2/6] mptcp: add missing memory barriers for rcv_data_fin_seq
  2026-12-03 16:48 [PATCH mptcp-net v7 0/6] mptcp: fixes for SIOCINQ Matthieu Baerts (NGI0)
  2026-12-03 16:48 ` [PATCH mptcp-net v7 1/6] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint Matthieu Baerts (NGI0)
@ 2026-12-03 16:48 ` Matthieu Baerts (NGI0)
  2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 3/6] mptcp: extract mptcp_rcv_data_fin_in_seq helper Matthieu Baerts (NGI0)
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 15+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-12-03 16:48 UTC (permalink / raw)
  To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0), Geliang Tang

From: Geliang Tang <tanggeliang@kylinos.cn>

mptcp_update_rcv_data_fin() writes rcv_data_fin_seq before setting
rcv_data_fin, but there is no write barrier to ensure the ordering
is visible to concurrent readers.

mptcp_pending_data_fin() checks rcv_data_fin and then reads
rcv_data_fin_seq, but has no read barrier. On weakly-ordered
architectures, the reader could observe rcv_data_fin == 1 with a
stale rcv_data_fin_seq. Since the workqueue guarantees ordering
between mptcp_update_rcv_data_fin() and the worker that calls
mptcp_check_data_fin(), the worst case for opportunistic readers
is a short delay until the worker runs.

Add smp_wmb() in mptcp_update_rcv_data_fin() between the two writes
and a matching smp_rmb() in mptcp_pending_data_fin() between the
two reads.

Fixes: 3721b9b64676 ("mptcp: Track received DATA_FIN sequence number and add related helpers")
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v7: for mptcp-next: not urgent
---
 net/mptcp/options.c  | 1 +
 net/mptcp/protocol.c | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 05b9c66aaed6..7c5e748105ea 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -1204,6 +1204,7 @@ bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq, bool us
 
 	WRITE_ONCE(msk->rcv_data_fin_seq,
 		   mptcp_expand_seq(READ_ONCE(msk->ack_seq), data_fin_seq, use_64bit));
+	smp_wmb(); /* ensure rcv_data_fin_seq is visible before rcv_data_fin */
 	WRITE_ONCE(msk->rcv_data_fin, 1);
 
 	return true;
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 72be0a8f9d87..45d0276a242f 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -573,8 +573,10 @@ static bool mptcp_pending_data_fin(struct sock *sk, u64 *seq)
 	if (READ_ONCE(msk->rcv_data_fin) &&
 	    ((1 << inet_sk_state_load(sk)) &
 	     (TCPF_ESTABLISHED | TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2))) {
-		u64 rcv_data_fin_seq = READ_ONCE(msk->rcv_data_fin_seq);
+		u64 rcv_data_fin_seq;
 
+		smp_rmb(); /* pair with smp_wmb in mptcp_update_rcv_data_fin */
+		rcv_data_fin_seq = READ_ONCE(msk->rcv_data_fin_seq);
 		if (READ_ONCE(msk->ack_seq) == rcv_data_fin_seq) {
 			if (seq)
 				*seq = rcv_data_fin_seq;

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH mptcp-next mptcp-net v7 3/6] mptcp: extract mptcp_rcv_data_fin_in_seq helper
  2026-12-03 16:48 [PATCH mptcp-net v7 0/6] mptcp: fixes for SIOCINQ Matthieu Baerts (NGI0)
  2026-12-03 16:48 ` [PATCH mptcp-net v7 1/6] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint Matthieu Baerts (NGI0)
  2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 2/6] mptcp: add missing memory barriers for rcv_data_fin_seq Matthieu Baerts (NGI0)
@ 2026-12-03 16:48 ` Matthieu Baerts (NGI0)
  2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 4/6] mptcp: add mptcp_inq() for SIOCINQ Matthieu Baerts (NGI0)
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 15+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-12-03 16:48 UTC (permalink / raw)
  To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0), Geliang Tang

From: Geliang Tang <tanggeliang@kylinos.cn>

Factor the rcv_data_fin and ack_seq == rcv_data_fin_seq check out of
mptcp_pending_data_fin() into mptcp_rcv_data_fin_in_seq(), without the
socket state restriction. mptcp_pending_data_fin() keeps the state check
and calls the helper, so the DATA_FIN condition can also be tested
regardless of the socket state, e.g. in mptcp_inq_hint().

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v7: helper renamed, for mptcp-next: not urgent
---
 net/mptcp/protocol.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 45d0276a242f..56f06b2fb452 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -565,14 +565,11 @@ 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_rcv_data_fin_in_seq(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)) &
-	     (TCPF_ESTABLISHED | TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2))) {
+	if (READ_ONCE(msk->rcv_data_fin)) {
 		u64 rcv_data_fin_seq;
 
 		smp_rmb(); /* pair with smp_wmb in mptcp_update_rcv_data_fin */
@@ -588,6 +585,16 @@ static bool mptcp_pending_data_fin(struct sock *sk, u64 *seq)
 	return false;
 }
 
+/* can be called with no lock acquired */
+static bool mptcp_pending_data_fin(struct sock *sk, u64 *seq)
+{
+	if ((1 << inet_sk_state_load(sk)) &
+	    (TCPF_ESTABLISHED | TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2))
+		return mptcp_rcv_data_fin_in_seq(sk, seq);
+
+	return false;
+}
+
 static void mptcp_set_datafin_timeout(struct sock *sk)
 {
 	struct inet_connection_sock *icsk = inet_csk(sk);

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH mptcp-next mptcp-net v7 4/6] mptcp: add mptcp_inq() for SIOCINQ
  2026-12-03 16:48 [PATCH mptcp-net v7 0/6] mptcp: fixes for SIOCINQ Matthieu Baerts (NGI0)
                   ` (2 preceding siblings ...)
  2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 3/6] mptcp: extract mptcp_rcv_data_fin_in_seq helper Matthieu Baerts (NGI0)
@ 2026-12-03 16:48 ` Matthieu Baerts (NGI0)
  2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 5/6] mptcp: use SOCK_DONE in mptcp_inq_hint Matthieu Baerts (NGI0)
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 15+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-12-03 16:48 UTC (permalink / raw)
  To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0), Zqiang, Geliang Tang

From: Geliang Tang <tanggeliang@kylinos.cn>

Add mptcp_inq() to compute readable bytes at the MPTCP level using
mptcp_data_avail() (bytes_received - bytes_consumed). It returns 0 during
handshake (TCPF_SYN_SENT/TCPF_SYN_RECV), INT_MAX when avail >= INT_MAX,
otherwise the actual byte count.

Unlike mptcp_inq_hint(), mptcp_inq() does not include the FIN byte.
Switch SIOCINQ from mptcp_inq_hint() to mptcp_inq() so that FIONREAD
reports 0 (not 1) when there is nothing left to read, e.g. after a
DATA_FIN, matching TCP's tcp_ioctl() which subtracts the FIN byte.

This has been reproduced with a new Packetdrill test, checking SIOCINQ
once all the data has been read, after the reception of a DATA_FIN:

  mptcp_inq.pkt:29: runtime error in ioctl call: Bad ioctl optval: expected: 0 actual: 1

Fixes: 644807e3e462 ("mptcp: add SIOCINQ, OUTQ and OUTQNSD ioctls")
Co-developed-by: Zqiang <qiang.zhang@linux.dev>
Signed-off-by: Zqiang <qiang.zhang@linux.dev>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v7: moved before the inq_hint changes, for mptcp-next: not urgent, and
    commit msg: Packetdrill reproducer
---
 net/mptcp/protocol.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 56f06b2fb452..c706468d4709 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -4425,6 +4425,21 @@ static int mptcp_ioctl_outq(const struct mptcp_sock *msk, u64 v)
 	return (int)delta;
 }
 
+static int mptcp_inq(struct sock *sk)
+{
+	const struct mptcp_sock *msk = mptcp_sk(sk);
+	u64 avail;
+
+	if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV))
+		return 0;
+
+	avail = mptcp_data_avail(msk);
+	if (avail >= INT_MAX)
+		return INT_MAX;
+
+	return (unsigned int)avail;
+}
+
 static int mptcp_ioctl(struct sock *sk, int cmd, int *karg)
 {
 	struct mptcp_sock *msk = mptcp_sk(sk);
@@ -4438,7 +4453,7 @@ static int mptcp_ioctl(struct sock *sk, int cmd, int *karg)
 		lock_sock(sk);
 		if (mptcp_move_skbs(sk))
 			mptcp_cleanup_rbuf(msk, 0);
-		*karg = mptcp_inq_hint(sk);
+		*karg = mptcp_inq(sk);
 		release_sock(sk);
 		break;
 	case SIOCOUTQ:

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH mptcp-next mptcp-net v7 5/6] mptcp: use SOCK_DONE in mptcp_inq_hint
  2026-12-03 16:48 [PATCH mptcp-net v7 0/6] mptcp: fixes for SIOCINQ Matthieu Baerts (NGI0)
                   ` (3 preceding siblings ...)
  2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 4/6] mptcp: add mptcp_inq() for SIOCINQ Matthieu Baerts (NGI0)
@ 2026-12-03 16:48 ` Matthieu Baerts (NGI0)
  2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 6/6] mptcp: count the DATA_FIN " Matthieu Baerts (NGI0)
  2026-12-03 18:33 ` [PATCH mptcp-net v7 0/6] mptcp: fixes for SIOCINQ MPTCP CI
  6 siblings, 0 replies; 15+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-12-03 16:48 UTC (permalink / raw)
  To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0), Geliang Tang

From: Geliang Tang <tanggeliang@kylinos.cn>

mptcp_inq_hint() checks sk_state == TCP_CLOSE and RCV_SHUTDOWN to
decide whether to return a non-zero hint when the receive queue is
empty. Switch to sock_flag(sk, SOCK_DONE) to align with tcp_inq_hint().

SOCK_DONE is set when a peer DATA_FIN or fallback FIN is received, in
mptcp_check_data_fin() and __mptcp_subflow_error_report(). It is not
set by __mptcp_close() or local shutdown(SHUT_RD), so on an empty
receive queue after a local shutdown, on a closed or unconnected socket,
or after an abortive close without a prior DATA_FIN, mptcp_inq_hint()
now returns 0 instead of 1.

This has been reproduced with a new Packetdrill test, checking
TCP_CM_INQ when reading the last data, after a fallback to TCP, and a
reset:

  fallback_rst.pkt:26: runtime error in recvmsg call: Bad data in cmsg 0: expected=0 actual=1

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v7: for mptcp-next: not urgent, and commit msg: Packetdrill reproducer
---
 net/mptcp/protocol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index c706468d4709..1d330c5d09f4 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2499,7 +2499,7 @@ static unsigned int mptcp_inq_hint(const struct sock *sk)
 		return (unsigned int)hint_val;
 	}
 
-	if (sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN))
+	if (sock_flag(sk, SOCK_DONE))
 		return 1;
 
 	return 0;

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH mptcp-next mptcp-net v7 6/6] mptcp: count the DATA_FIN in mptcp_inq_hint
  2026-12-03 16:48 [PATCH mptcp-net v7 0/6] mptcp: fixes for SIOCINQ Matthieu Baerts (NGI0)
                   ` (4 preceding siblings ...)
  2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 5/6] mptcp: use SOCK_DONE in mptcp_inq_hint Matthieu Baerts (NGI0)
@ 2026-12-03 16:48 ` Matthieu Baerts (NGI0)
  2026-12-03 18:50   ` sashiko-bot
  2026-12-05  6:21   ` netdev-bot+sashiko
  2026-12-03 18:33 ` [PATCH mptcp-net v7 0/6] mptcp: fixes for SIOCINQ MPTCP CI
  6 siblings, 2 replies; 15+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-12-03 16:48 UTC (permalink / raw)
  To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0), Paolo Abeni, Geliang Tang

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 not in fallback and
mptcp_rcv_data_fin_in_seq() reports ack_seq caught up; the fallback path
is excluded since subflow_sched_work_if_closed() sets rcv_data_fin on
any subflow close (including RST), which would count a spurious FIN
byte.

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>
---
v7: without the TFO fix, now a separate patch for -net, and commit msg:
    Packetdrill reproducers
---
 net/mptcp/protocol.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 1d330c5d09f4..e0e6266e11c8 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2487,22 +2487,17 @@ 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;
 
-		if (hint_val >= INT_MAX)
-			return INT_MAX;
+	if (sock_flag(sk, SOCK_DONE) ||
+	    (!__mptcp_check_fallback(msk) &&
+	     mptcp_rcv_data_fin_in_seq(sk, NULL)))
+		hint_val += 1;
 
-		return (unsigned int)hint_val;
-	}
-
-	if (sock_flag(sk, SOCK_DONE))
-		return 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] 15+ messages in thread

* Re: [PATCH mptcp-net v7 0/6] mptcp: fixes for SIOCINQ
  2026-12-03 16:48 [PATCH mptcp-net v7 0/6] mptcp: fixes for SIOCINQ Matthieu Baerts (NGI0)
                   ` (5 preceding siblings ...)
  2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 6/6] mptcp: count the DATA_FIN " Matthieu Baerts (NGI0)
@ 2026-12-03 18:33 ` MPTCP CI
  6 siblings, 0 replies; 15+ messages in thread
From: MPTCP CI @ 2026-12-03 18:33 UTC (permalink / raw)
  To: Geliang Tang; +Cc: mptcp

Hi Geliang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal (except selftest_mptcp_join): Success! ✅
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Success! ✅
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Perf: Unstable: regression:sched-bbr regression:sched-mem-pressure(3) validation:sched-loss ⚠️  (5 improvements, 69 new outliers to review)
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/47165126248

Initiator: Matthieu Baerts (NGI0)
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/8034805f333d
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1230871


If there are some issues, you can reproduce them using the same environment as
the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

    https://github.com/multipath-tcp/mptcp-upstream-virtme-docker


Please note that despite all the efforts that have been already done to have a
stable tests suite when executed on a public CI like here, it is possible some
reported issues are not due to your modifications. Still, do not hesitate to
help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH mptcp-next mptcp-net v7 6/6] mptcp: count the DATA_FIN in mptcp_inq_hint
  2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 6/6] mptcp: count the DATA_FIN " Matthieu Baerts (NGI0)
@ 2026-12-03 18:50   ` sashiko-bot
  2026-12-04 10:55     ` Geliang Tang
  2026-12-05  6:21   ` netdev-bot+sashiko
  1 sibling, 1 reply; 15+ messages in thread
From: sashiko-bot @ 2026-12-03 18:50 UTC (permalink / raw)
  To: Matthieu Baerts (NGI0), MPTCP Linux

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] mptcp: mptcp_inq_hint() omits pending FIN byte on fallback
  sockets
- [Medium] mptcp: race in mptcp_inq_hint() counts spurious FIN on
  fallback RST
- [Low] mptcp: mptcp_inq_hint() omits TCP_CLOSE check for rcv_data_fin
--

commit 3d490bb2690ae1fefdf4a528196f8efa6be2b028
Author: Geliang Tang <geliang@kernel.org>

mptcp: count the DATA_FIN in mptcp_inq_hint

This commit updates mptcp_inq_hint() to add the FIN byte to the available
data count when SOCK_DONE is set or when a non-fallback connection has an
in-sequence DATA_FIN pending.

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 1d330c5d09f42..e0e6266e11c85 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -2487,22 +2487,17 @@ 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;
> +	if (sock_flag(sk, SOCK_DONE) ||
> +	    (!__mptcp_check_fallback(msk) &&
> +	     mptcp_rcv_data_fin_in_seq(sk, NULL)))
> +		hint_val += 1;

[Severity: Medium]
Can excluding __mptcp_check_fallback(msk) here omit the pending FIN byte
on fallback sockets before mptcp_worker() sets SOCK_DONE on sk?

When a fallen-back socket receives data and a TCP FIN in softirq,
tcp_fin() sets SOCK_DONE on msk->first, move_skbs_to_msk() queues the
data directly on sk->sk_receive_queue, and mptcp_data_ready() wakes
userspace while SOCK_DONE propagation waits on mptcp_worker():

CPU0 (softirq / kworker)          CPU1 (userspace)
tcp_fin()
  sock_set_flag(ssk, SOCK_DONE)
mptcp_data_ready()
  move_skbs_to_msk()
  sk->sk_data_ready(sk)
subflow_sched_work_if_closed()
  mptcp_update_rcv_data_fin()
  mptcp_schedule_work(sk)
                                  mptcp_recvmsg()
                                    lock_sock(sk)
                                    ... (backlog_list empty)
mptcp_worker()
  lock_sock(sk)  (blocks)
                                    mptcp_inq_hint()  <-- omits +1

With msk->backlog_list empty, mptcp_recvmsg() skips mptcp_move_skbs()
and mptcp_check_data_fin(), so TCP_CM_INQ under-reports by 1 byte (or
returns 0 instead of 1 after draining the last data bytes).

Since callers of mptcp_inq_hint() hold lock_sock(sk), this could mirror
mptcp_check_data_fin() and check (!__mptcp_check_fallback(msk) ||
(msk->first && sock_flag(msk->first, SOCK_DONE))) to count fallback FINs
while still excluding fallback RSTs.

[Severity: Medium]
Does testing !__mptcp_check_fallback(msk) before
mptcp_rcv_data_fin_in_seq(sk, NULL) race with a concurrent fallback and
TCP RST and count a spurious FIN byte?

mptcp_inq_hint() runs under lock_sock(sk) without msk->fallback_lock or
the subflow lock.  Concurrently in softirq, a non-MP_CAPABLE RST before
fully_established (or a fallback followed by RST) sets
MPTCP_FALLBACK_DONE before smp_wmb() and msk->rcv_data_fin = 1:

CPU0 (userspace)                  CPU1 (softirq)
mptcp_inq_hint()
  !__mptcp_check_fallback(msk)
    (true)
                                  tcp_reset()
                                    __mptcp_try_fallback()
                                      set_bit(MPTCP_FALLBACK_DONE, ...)
                                    subflow_sched_work_if_closed()
                                      mptcp_update_rcv_data_fin()
                                        smp_wmb()
                                        msk->rcv_data_fin = 1
  mptcp_rcv_data_fin_in_seq()
    (true -> hint_val += 1)  <-- spurious FIN

Because the reader checks MPTCP_FALLBACK_DONE before msk->rcv_data_fin
with no barrier in between, it can observe the emulated DATA_FIN from
the RST and report an unread FIN byte on a reset connection.

Calling mptcp_rcv_data_fin_in_seq(sk, NULL) first, which executes the
pairing smp_rmb() after reading msk->rcv_data_fin, and checking
__mptcp_check_fallback(msk) afterward closes both the race window and
load reordering.

[Severity: Low]
Should this check the socket state (like mptcp_pending_data_fin() does)
so a stale rcv_data_fin on a TCP_CLOSE socket is not counted?

In mptcp_check_fastclose(), mptcp_check_data_fin(sk) runs before locking
and closing the subflows.  A zero-length in-sequence DATA_FIN arriving on
an open subflow in that window sets msk->rcv_data_fin = 1 just before sk
transitions to TCP_CLOSE with ECONNRESET and SOCK_DONE unset:

CPU0 (kworker)                    CPU1 (softirq)
mptcp_check_fastclose()
  mptcp_check_data_fin(sk)
                                  mptcp_incoming_options()
                                    mptcp_update_rcv_data_fin()
                                      msk->rcv_data_fin = 1
  sk->sk_err = ECONNRESET
  mptcp_set_state(sk, TCP_CLOSE)  <-- rcv_data_fin left stale

Once sk is in TCP_CLOSE, mptcp_pending_data_fin() returns false and
mptcp_worker() exits early, leaving msk->rcv_data_fin permanently set
without SOCK_DONE.  When userspace drains queued data, mptcp_inq_hint()
still adds +1 to TCP_CM_INQ even though the next recvmsg() will return
-ECONNRESET rather than EOF.

Using mptcp_pending_data_fin() (or excluding TCP_CLOSE) avoids counting
an unprocessable DATA_FIN.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-mptcp-fixes-for-siocinq-v7-0-e6d589de9cf8@kernel.org?part=6

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH mptcp-next mptcp-net v7 6/6] mptcp: count the DATA_FIN in mptcp_inq_hint
  2026-12-03 18:50   ` sashiko-bot
@ 2026-12-04 10:55     ` Geliang Tang
  2026-12-04 12:12       ` Matthieu Baerts
  0 siblings, 1 reply; 15+ messages in thread
From: Geliang Tang @ 2026-12-04 10:55 UTC (permalink / raw)
  To: sashiko-reviews, Matthieu Baerts (NGI0), MPTCP Linux

Hi Matt,

Thank you very much for helping me send this v7.

On Thu, 2026-12-03 at 18:50 +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 3 potential
> issues to consider:
> - [Medium] mptcp: mptcp_inq_hint() omits pending FIN byte on fallback
>   sockets
> - [Medium] mptcp: race in mptcp_inq_hint() counts spurious FIN on
>   fallback RST
> - [Low] mptcp: mptcp_inq_hint() omits TCP_CLOSE check for rcv_data_fin
> --

I plan to address all three points by replacing the open-coded check in
mptcp_inq_hint() with a new helper:

        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_fallback(msk) ||
                       (msk->first && sock_flag(msk->first, SOCK_DONE));
        }

and calling it from mptcp_inq_hint():

        if (sock_flag(sk, SOCK_DONE) || mptcp_pending_eof(sk, NULL))
                hint_val += 1;

Also, the mptcp_rcv_data_fin_in_seq helper can be deleted.

> 
> commit 3d490bb2690ae1fefdf4a528196f8efa6be2b028
> Author: Geliang Tang <geliang@kernel.org>
> 
> mptcp: count the DATA_FIN in mptcp_inq_hint
> 
> This commit updates mptcp_inq_hint() to add the FIN byte to the available
> data count when SOCK_DONE is set or when a non-fallback connection has an
> in-sequence DATA_FIN pending.
> 
> > diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> > index 1d330c5d09f42..e0e6266e11c85 100644
> > --- a/net/mptcp/protocol.c
> > +++ b/net/mptcp/protocol.c
> > @@ -2487,22 +2487,17 @@ 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;
> > +	if (sock_flag(sk, SOCK_DONE) ||
> > +	    (!__mptcp_check_fallback(msk) &&
> > +	     mptcp_rcv_data_fin_in_seq(sk, NULL)))
> > +		hint_val += 1;
> 
> [Severity: Medium]
> Can excluding __mptcp_check_fallback(msk) here omit the pending FIN byte
> on fallback sockets before mptcp_worker() sets SOCK_DONE on sk?
> 
> When a fallen-back socket receives data and a TCP FIN in softirq,
> tcp_fin() sets SOCK_DONE on msk->first, move_skbs_to_msk() queues the
> data directly on sk->sk_receive_queue, and mptcp_data_ready() wakes
> userspace while SOCK_DONE propagation waits on mptcp_worker():
> 
> CPU0 (softirq / kworker)          CPU1 (userspace)
> tcp_fin()
>   sock_set_flag(ssk, SOCK_DONE)
> mptcp_data_ready()
>   move_skbs_to_msk()
>   sk->sk_data_ready(sk)
> subflow_sched_work_if_closed()
>   mptcp_update_rcv_data_fin()
>   mptcp_schedule_work(sk)
>                                   mptcp_recvmsg()
>                                     lock_sock(sk)
>                                     ... (backlog_list empty)
> mptcp_worker()
>   lock_sock(sk)  (blocks)
>                                     mptcp_inq_hint()  <-- omits +1
> 
> With msk->backlog_list empty, mptcp_recvmsg() skips mptcp_move_skbs()
> and mptcp_check_data_fin(), so TCP_CM_INQ under-reports by 1 byte (or
> returns 0 instead of 1 after draining the last data bytes).
> 
> Since callers of mptcp_inq_hint() hold lock_sock(sk), this could mirror
> mptcp_check_data_fin() and check (!__mptcp_check_fallback(msk) ||
> (msk->first && sock_flag(msk->first, SOCK_DONE))) to count fallback FINs
> while still excluding fallback RSTs.

The helper counts the fallback FIN once msk->first has SOCK_DONE set,
as in mptcp_check_data_fin(), without waiting for mptcp_worker().

> 
> [Severity: Medium]
> Does testing !__mptcp_check_fallback(msk) before
> mptcp_rcv_data_fin_in_seq(sk, NULL) race with a concurrent fallback and
> TCP RST and count a spurious FIN byte?
> 
> mptcp_inq_hint() runs under lock_sock(sk) without msk->fallback_lock or
> the subflow lock.  Concurrently in softirq, a non-MP_CAPABLE RST before
> fully_established (or a fallback followed by RST) sets
> MPTCP_FALLBACK_DONE before smp_wmb() and msk->rcv_data_fin = 1:
> 
> CPU0 (userspace)                  CPU1 (softirq)
> mptcp_inq_hint()
>   !__mptcp_check_fallback(msk)
>     (true)
>                                   tcp_reset()
>                                     __mptcp_try_fallback()
>                                       set_bit(MPTCP_FALLBACK_DONE, ...)
>                                     subflow_sched_work_if_closed()
>                                       mptcp_update_rcv_data_fin()
>                                         smp_wmb()
>                                         msk->rcv_data_fin = 1
>   mptcp_rcv_data_fin_in_seq()
>     (true -> hint_val += 1)  <-- spurious FIN
> 
> Because the reader checks MPTCP_FALLBACK_DONE before msk->rcv_data_fin
> with no barrier in between, it can observe the emulated DATA_FIN from
> the RST and report an unread FIN byte on a reset connection.
> 
> Calling mptcp_rcv_data_fin_in_seq(sk, NULL) first, which executes the
> pairing smp_rmb() after reading msk->rcv_data_fin, and checking
> __mptcp_check_fallback(msk) afterward closes both the race window and
> load reordering.

The pending DATA_FIN is observed before the fallback flag; the
smp_rmb() in mptcp_pending_data_fin() pairs with the smp_wmb() in
mptcp_update_rcv_data_fin(), so a RST-induced DATA_FIN is excluded.

> 
> [Severity: Low]
> Should this check the socket state (like mptcp_pending_data_fin() does)
> so a stale rcv_data_fin on a TCP_CLOSE socket is not counted?
> 
> In mptcp_check_fastclose(), mptcp_check_data_fin(sk) runs before locking
> and closing the subflows.  A zero-length in-sequence DATA_FIN arriving on
> an open subflow in that window sets msk->rcv_data_fin = 1 just before sk
> transitions to TCP_CLOSE with ECONNRESET and SOCK_DONE unset:
> 
> CPU0 (kworker)                    CPU1 (softirq)
> mptcp_check_fastclose()
>   mptcp_check_data_fin(sk)
>                                   mptcp_incoming_options()
>                                     mptcp_update_rcv_data_fin()
>                                       msk->rcv_data_fin = 1
>   sk->sk_err = ECONNRESET
>   mptcp_set_state(sk, TCP_CLOSE)  <-- rcv_data_fin left stale
> 
> Once sk is in TCP_CLOSE, mptcp_pending_data_fin() returns false and
> mptcp_worker() exits early, leaving msk->rcv_data_fin permanently set
> without SOCK_DONE.  When userspace drains queued data, mptcp_inq_hint()
> still adds +1 to TCP_CM_INQ even though the next recvmsg() will return
> -ECONNRESET rather than EOF.
> 
> Using mptcp_pending_data_fin() (or excluding TCP_CLOSE) avoids counting
> an unprocessable DATA_FIN.

The ESTABLISHED/FIN_WAIT1/FIN_WAIT2 state check in
mptcp_pending_data_fin() keeps a stale rcv_data_fin on TCP_CLOSE from
being counted.

If you think this is okay, I'll send a v8.

Thanks,
-Geliang

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH mptcp-next mptcp-net v7 6/6] mptcp: count the DATA_FIN in mptcp_inq_hint
  2026-12-04 10:55     ` Geliang Tang
@ 2026-12-04 12:12       ` Matthieu Baerts
  2026-12-04 12:14         ` Matthieu Baerts
  2026-12-04 23:06         ` Geliang Tang
  0 siblings, 2 replies; 15+ messages in thread
From: Matthieu Baerts @ 2026-12-04 12:12 UTC (permalink / raw)
  To: Geliang Tang; +Cc: sashiko-reviews, MPTCP Linux

Hi Geliang,

On 04/12/2026 11:55, Geliang Tang wrote:

> Thank you very much for helping me send this v7.

You're welcome!

> On Thu, 2026-12-03 at 18:50 +0000, sashiko-bot@kernel.org wrote:
>> Thank you for your contribution! Sashiko AI review found 3 potential
>> issues to consider:
>> - [Medium] mptcp: mptcp_inq_hint() omits pending FIN byte on fallback
>>   sockets
>> - [Medium] mptcp: race in mptcp_inq_hint() counts spurious FIN on
>>   fallback RST
>> - [Low] mptcp: mptcp_inq_hint() omits TCP_CLOSE check for rcv_data_fin
>> --
> 
> I plan to address all three points by replacing the open-coded check in
> mptcp_inq_hint() with a new helper:
> 
>         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_fallback(msk) ||
>                        (msk->first && sock_flag(msk->first, SOCK_DONE));
>         }
> 
> and calling it from mptcp_inq_hint():
> 
>         if (sock_flag(sk, SOCK_DONE) || mptcp_pending_eof(sk, NULL))
>                 hint_val += 1;
> 
> Also, the mptcp_rcv_data_fin_in_seq helper can be deleted.

Good idea, thank you: the DATA_FIN is then counted in the conditions
where mptcp_check_data_fin() will set SOCK_DONE. That fixes the three
points, and the series gets shorter!

Some small details:

- mptcp_pending_data_fin() takes a non-const 'sk': it needs to be
  constified, with its 'msk', otherwise the compiler will complain.

- The 'seq' parameter can be dropped: it is always NULL, no?

- (Optional) The fallback condition duplicates the one from
  mptcp_check_data_fin(): a small helper used by both would keep them in
  sync? (I didn't check in details)

Also, it might be good to add a short note in the commit (under '---')
for the 3 notes from Clashiko (or improving the commit message?)

> If you think this is okay, I'll send a v8.

Yes please, but I think it is always best to wait for Clashiko review
before sending a new version:

https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203-mptcp-fixes-for-siocinq-v7-0-e6d589de9cf8@kernel.org

Also, if there are no complain about the 2 first patches, I could
already apply them. (But if you are ready before I applied then, feel
free to send them in a v8)

One last point, if you want to easily take over, you can launch these
commands:

  $ git switch t/upstream && git pull     # or export or for-review
  $ b4 prep -n mptcp-fixes-for-SIOCINQ \
       -F 20261203-mptcp-fixes-for-siocinq-v7-0-e6d589de9cf8@kernel.org

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH mptcp-next mptcp-net v7 6/6] mptcp: count the DATA_FIN in mptcp_inq_hint
  2026-12-04 12:12       ` Matthieu Baerts
@ 2026-12-04 12:14         ` Matthieu Baerts
  2026-12-04 23:06         ` Geliang Tang
  1 sibling, 0 replies; 15+ messages in thread
From: Matthieu Baerts @ 2026-12-04 12:14 UTC (permalink / raw)
  To: Geliang Tang; +Cc: sashiko-reviews, MPTCP Linux

On 04/12/2026 13:12, Matthieu Baerts wrote:
> - (Optional) The fallback condition duplicates the one from
>   mptcp_check_data_fin(): a small helper used by both would keep them in
>   sync? (I didn't check in details)

(but no need to have a dedicated commit for such small new helper: only
create a new commit when it is a bigger move or when you need to modify
the new helper compared to the original code → not the case here)

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH mptcp-next mptcp-net v7 6/6] mptcp: count the DATA_FIN in mptcp_inq_hint
  2026-12-04 12:12       ` Matthieu Baerts
  2026-12-04 12:14         ` Matthieu Baerts
@ 2026-12-04 23:06         ` Geliang Tang
  2026-12-05 14:28           ` Matthieu Baerts
  1 sibling, 1 reply; 15+ messages in thread
From: Geliang Tang @ 2026-12-04 23:06 UTC (permalink / raw)
  To: Matthieu Baerts; +Cc: sashiko-reviews, MPTCP Linux

Hi Matt,

On Fri, 2026-12-04 at 13:12 +0100, Matthieu Baerts wrote:
> Hi Geliang,
> 
> On 04/12/2026 11:55, Geliang Tang wrote:
> 
> > Thank you very much for helping me send this v7.
> 
> You're welcome!
> 
> > On Thu, 2026-12-03 at 18:50 +0000, sashiko-bot@kernel.org wrote:
> > > Thank you for your contribution! Sashiko AI review found 3 potential
> > > issues to consider:
> > > - [Medium] mptcp: mptcp_inq_hint() omits pending FIN byte on fallback
> > >   sockets
> > > - [Medium] mptcp: race in mptcp_inq_hint() counts spurious FIN on
> > >   fallback RST
> > > - [Low] mptcp: mptcp_inq_hint() omits TCP_CLOSE check for rcv_data_fin
> > > --
> > 
> > I plan to address all three points by replacing the open-coded check in
> > mptcp_inq_hint() with a new helper:
> > 
> >         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_fallback(msk) ||
> >                        (msk->first && sock_flag(msk->first, SOCK_DONE));
> >         }
> > 
> > and calling it from mptcp_inq_hint():
> > 
> >         if (sock_flag(sk, SOCK_DONE) || mptcp_pending_eof(sk, NULL))
> >                 hint_val += 1;
> > 
> > Also, the mptcp_rcv_data_fin_in_seq helper can be deleted.
> 
> Good idea, thank you: the DATA_FIN is then counted in the conditions
> where mptcp_check_data_fin() will set SOCK_DONE. That fixes the three
> points, and the series gets shorter!
> 
> Some small details:
> 
> - mptcp_pending_data_fin() takes a non-const 'sk': it needs to be
>   constified, with its 'msk', otherwise the compiler will complain.
> 
> - The 'seq' parameter can be dropped: it is always NULL, no?

I'll keep this 'seq' parameter since it will be used in subsequent patches.

> 
> - (Optional) The fallback condition duplicates the one from
>   mptcp_check_data_fin(): a small helper used by both would keep them in
>   sync? (I didn't check in details)
> 
> Also, it might be good to add a short note in the commit (under '---')
> for the 3 notes from Clashiko (or improving the commit message?)
> 
> > If you think this is okay, I'll send a v8.
> 
> Yes please, but I think it is always best to wait for Clashiko review
> before sending a new version:
> 
> https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203-mptcp-fixes-for-siocinq-v7-0-e6d589de9cf8@kernel.org
> 
> Also, if there are no complain about the 2 first patches, I could
> already apply them. (But if you are ready before I applied then, feel

There have been no complaints about the first 5 patches for Clashiko. So patches
1, 2, 4, and 5 can all be applied if you want.

> free to send them in a v8)

I'll wait until they are applied before sending a v8.

Thanks,
-Geliang

> 
> One last point, if you want to easily take over, you can launch these
> commands:
> 
>   $ git switch t/upstream && git pull     # or export or for-review
>   $ b4 prep -n mptcp-fixes-for-SIOCINQ \
>        -F 20261203-mptcp-fixes-for-siocinq-v7-0-e6d589de9cf8@kernel.org
> 
> Cheers,
> Matt

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH mptcp-next mptcp-net v7 6/6] mptcp: count the DATA_FIN in mptcp_inq_hint
  2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 6/6] mptcp: count the DATA_FIN " Matthieu Baerts (NGI0)
  2026-12-03 18:50   ` sashiko-bot
@ 2026-12-05  6:21   ` netdev-bot+sashiko
  1 sibling, 0 replies; 15+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05  6:21 UTC (permalink / raw)
  To: matttbe; +Cc: mptcp, pabeni, geliang, kuba

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] In fallback mode, mptcp_inq_hint() counts the FIN only through
  the msk SOCK_DONE flag.
- [Low] mptcp_inq_hint() reads the MPTCP_FALLBACK_DONE bit
  (__mptcp_check_fallback()) before it reads msk->rcv_data_fin,…

--

mptcp: count the DATA_FIN in mptcp_inq_hint

This commit changes mptcp_inq_hint() to always start from
mptcp_data_avail(). It then adds one byte for the DATA_FIN when SOCK_DONE
is set, or when not in fallback and mptcp_rcv_data_fin_in_seq() reports
the DATA_FIN in sequence. The aim is to match TCP, where the FIN is
counted in TCP_CM_INQ until it is read.

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 1d330c5d09f42..e0e6266e11c85 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -2487,22 +2487,17 @@ 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);

[ ... ]

> -	if (sock_flag(sk, SOCK_DONE))
> -		return 1;
> +	if (sock_flag(sk, SOCK_DONE) ||
> +	    (!__mptcp_check_fallback(msk) &&
> +	     mptcp_rcv_data_fin_in_seq(sk, NULL)))
> +		hint_val += 1;

[Severity: Medium]
In fallback mode, can this still miss the FIN in the case the
fallback_fin.pkt reproducer covers?

With fallback, the FIN is counted only through the msk SOCK_DONE flag.
For a fallback FIN, that flag is set only by mptcp_check_data_fin(),
which runs from the worker:

net/mptcp/subflow.c:subflow_sched_work_if_closed() {
    ...
	if (__mptcp_check_fallback(msk) && subflow_is_done(ssk) &&
	    msk->first == ssk &&
	    mptcp_update_rcv_data_fin(msk, subflow->map_seq +
				      subflow->map_data_len, true))
		mptcp_schedule_work(sk);
}

If the reader is blocked in sk_wait_data(), the msk is not owned, so
__mptcp_data_ready() moves the data straight into the msk queue:

net/mptcp/protocol.c:__mptcp_data_ready() {
    ...
	if (!sock_owned_by_user(sk)) {
		/* Wake-up the reader only for in-sequence data */
		if (move_skbs_to_msk(msk, ssk) && mptcp_epollin_ready(sk))
			sk->sk_data_ready(sk);
    ...
}

The woken reader then takes the msk lock and copies the data. The
backlog is empty, so mptcp_move_skbs() and mptcp_check_data_fin() never
run in the recvmsg path. The worker can't run in time either, because
the reader holds the msk lock.

At that point mptcp_inq_hint() sees SOCK_DONE clear. The second term is
skipped because __mptcp_check_fallback(msk) is true.

Wouldn't TCP_CM_INQ then report N (or 0 once everything is read), where
TCP would report N+1 (or 1)? It looks like the reproducer passes only
when the worker runs before recvmsg().

mptcp_check_data_fin() already tells a FIN apart from an RST in
fallback:

net/mptcp/protocol.c:mptcp_check_data_fin() {
    ...
		if (!__mptcp_check_fallback(msk) ||
		    (msk->first && sock_flag(msk->first, SOCK_DONE)))
			sock_set_flag(sk, SOCK_DONE);
    ...
}

Could the hint combine that msk->first SOCK_DONE test with
mptcp_rcv_data_fin_in_seq(), instead of excluding every fallback case?
mptcp_inq_hint() always runs under the msk socket lock, so msk->first
can be read there.

[Severity: Low]
Is there an ordering issue between the fallback check and the loads in
mptcp_rcv_data_fin_in_seq()?

The MPTCP_FALLBACK_DONE bit is tested before rcv_data_fin,
rcv_data_fin_seq and ack_seq are read. No lock or barrier ties the two
checks together, and the reader holds only the msk socket lock.

Both values are written from softirq:

- __mptcp_try_fallback() sets the fallback bit under msk->fallback_lock,
  for example from check_fully_established() or
  subflow_check_data_avail().
- subflow_sched_work_if_closed()->mptcp_update_rcv_data_fin() publishes
  the dummy DATA_FIN.

A possible interleaving:

CPU0 (msk lock owner)         CPU1 (softirq)
mptcp_inq_hint()
  __mptcp_check_fallback()
    returns false
                              __mptcp_try_fallback()
                                set MPTCP_FALLBACK_DONE
                              subflow RST
                              subflow_sched_work_if_closed()
                                mptcp_update_rcv_data_fin()
                                  rcv_data_fin_seq = map_seq + map_data_len
                                  rcv_data_fin = 1
  mptcp_rcv_data_fin_in_seq()
    rcv_data_fin == 1
    ack_seq == rcv_data_fin_seq
  hint_val += 1

Take an active-side msk that has received no data since the fallback.
There, map_seq + map_data_len equals ack_seq, because
mptcp_finish_connect() initialises subflow->map_seq to ack_seq.

Wouldn't this count the spurious FIN byte on RST that the commit message
says excluding fallback avoids? On weakly ordered CPUs the two loads
could also be reordered.

Would reading rcv_data_fin first (with smp_rmb()) and checking the
fallback bit afterwards close most of this window?

>  
> -	return 0;
> +	return (unsigned int)hint_val;
>  }

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203-mptcp-fixes-for-siocinq-v7-0-e6d589de9cf8%40kernel.org

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH mptcp-next mptcp-net v7 6/6] mptcp: count the DATA_FIN in mptcp_inq_hint
  2026-12-04 23:06         ` Geliang Tang
@ 2026-12-05 14:28           ` Matthieu Baerts
  0 siblings, 0 replies; 15+ messages in thread
From: Matthieu Baerts @ 2026-12-05 14:28 UTC (permalink / raw)
  To: Geliang Tang; +Cc: sashiko-reviews, MPTCP Linux

Hi Geliang,

On 05/12/2026 00:06, Geliang Tang wrote:
> Hi Matt,
> 
> On Fri, 2026-12-04 at 13:12 +0100, Matthieu Baerts wrote:
>> Hi Geliang,
>>
>> On 04/12/2026 11:55, Geliang Tang wrote:
>>
>>> Thank you very much for helping me send this v7.
>>
>> You're welcome!
>>
>>> On Thu, 2026-12-03 at 18:50 +0000, sashiko-bot@kernel.org wrote:
>>>> Thank you for your contribution! Sashiko AI review found 3 potential
>>>> issues to consider:
>>>> - [Medium] mptcp: mptcp_inq_hint() omits pending FIN byte on fallback
>>>>   sockets
>>>> - [Medium] mptcp: race in mptcp_inq_hint() counts spurious FIN on
>>>>   fallback RST
>>>> - [Low] mptcp: mptcp_inq_hint() omits TCP_CLOSE check for rcv_data_fin
>>>> --
>>>
>>> I plan to address all three points by replacing the open-coded check in
>>> mptcp_inq_hint() with a new helper:
>>>
>>>         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_fallback(msk) ||
>>>                        (msk->first && sock_flag(msk->first, SOCK_DONE));
>>>         }
>>>
>>> and calling it from mptcp_inq_hint():
>>>
>>>         if (sock_flag(sk, SOCK_DONE) || mptcp_pending_eof(sk, NULL))
>>>                 hint_val += 1;
>>>
>>> Also, the mptcp_rcv_data_fin_in_seq helper can be deleted.
>>
>> Good idea, thank you: the DATA_FIN is then counted in the conditions
>> where mptcp_check_data_fin() will set SOCK_DONE. That fixes the three
>> points, and the series gets shorter!
>>
>> Some small details:
>>
>> - mptcp_pending_data_fin() takes a non-const 'sk': it needs to be
>>   constified, with its 'msk', otherwise the compiler will complain.
>>
>> - The 'seq' parameter can be dropped: it is always NULL, no?
> 
> I'll keep this 'seq' parameter since it will be used in subsequent patches.

OK.

>> - (Optional) The fallback condition duplicates the one from
>>   mptcp_check_data_fin(): a small helper used by both would keep them in
>>   sync? (I didn't check in details)
>>
>> Also, it might be good to add a short note in the commit (under '---')
>> for the 3 notes from Clashiko (or improving the commit message?)
>>
>>> If you think this is okay, I'll send a v8.
>>
>> Yes please, but I think it is always best to wait for Clashiko review
>> before sending a new version:
>>
>> https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203-mptcp-fixes-for-siocinq-v7-0-e6d589de9cf8@kernel.org
>>
>> Also, if there are no complain about the 2 first patches, I could
>> already apply them. (But if you are ready before I applied then, feel
> 
> There have been no complaints about the first 5 patches for Clashiko. So patches
> 1, 2, 4, and 5 can all be applied if you want.

OK, just did:

New patches for t/upstream-net and t/upstream:
- ab71be681642: mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
- Results: 903a6acff8e8..1f6385e4dff8 (export-net)
- Results: e6c75140c403..a621efb40408 (export)

Tests are now in progress:

- export-net:
https://github.com/multipath-tcp/mptcp_net-next/commit/1cc2e638db9260152dda2ce873c12ea355d6ed9d/checks
- export:
https://github.com/multipath-tcp/mptcp_net-next/commit/120a97fb4e42106b4cee8abd799e1950d6ce3d7a/checks

New patches for t/upstream:
- 658f503e4251: mptcp: add missing memory barriers for rcv_data_fin_seq
- 0e7ab0b26630: mptcp: add mptcp_inq() for SIOCINQ
- 522bc659cdd1: mptcp: use SOCK_DONE in mptcp_inq_hint
- Results: a621efb40408..c74d97230c59 (export)

Tests are now in progress:

- export:
https://github.com/multipath-tcp/mptcp_net-next/commit/4cf6479e48d41dc7dbffc5984e0ae2b63960a856/checks
Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2026-12-05 14:28 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 16:48 [PATCH mptcp-net v7 0/6] mptcp: fixes for SIOCINQ Matthieu Baerts (NGI0)
2026-12-03 16:48 ` [PATCH mptcp-net v7 1/6] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint Matthieu Baerts (NGI0)
2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 2/6] mptcp: add missing memory barriers for rcv_data_fin_seq Matthieu Baerts (NGI0)
2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 3/6] mptcp: extract mptcp_rcv_data_fin_in_seq helper Matthieu Baerts (NGI0)
2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 4/6] mptcp: add mptcp_inq() for SIOCINQ Matthieu Baerts (NGI0)
2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 5/6] mptcp: use SOCK_DONE in mptcp_inq_hint Matthieu Baerts (NGI0)
2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 6/6] mptcp: count the DATA_FIN " Matthieu Baerts (NGI0)
2026-12-03 18:50   ` sashiko-bot
2026-12-04 10:55     ` Geliang Tang
2026-12-04 12:12       ` Matthieu Baerts
2026-12-04 12:14         ` Matthieu Baerts
2026-12-04 23:06         ` Geliang Tang
2026-12-05 14:28           ` Matthieu Baerts
2026-12-05  6:21   ` netdev-bot+sashiko
2026-12-03 18:33 ` [PATCH mptcp-net v7 0/6] mptcp: fixes for SIOCINQ MPTCP CI

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.