Skip to contentSkip to conversation

prepare interfaces for kTLS and sockmap support

PATCH In review Geliang Tang 3 participants 15 messages Nov 16 – Nov 18

Subsystems (3)
lore
Share & tools
lore

Geliang Tang

author reviewer
#0 lore raw

v8 cover prepare interfaces for kTLS and sockmap support

v8:
- patch 1: change mptcp_inq_hint() to maintain TCP semantics by adding 1 to hint_val when RCV_SHUTDOWN is set or sk_state is TCP_CLOSE, matching TCP behavior where FIN consumes a sequence number.
- patch 2: update the test.
- patches 3-7: no changes.

v7:
- patch 1: add 1 to hint_val when RCV_SHUTDOWN is set to include the FIN
byte, matching the previous ack_seq - map_seq behavior. Simplify the
EOF condition accordingly.
- patch 2: replace poll()-based check with a wait_for_remote_key() helper
that polls MPTCP_INFO until MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED is set, ensuring the third ACK has been processed before checking SIOCINQ. Add SOL_MPTCP fallback definition and handle ENOPROTOOPT/EOPNOTSUPP for
TCP or fallback sockets.
- patches 3-7: no changes.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/

v6:
- patch 2: add Fixes tag, and use '-net' prefix.
- patch 3: remove poll() call, check SIOCINQ directly after accept().
- patch 6: add READ_ONCE() for msk->flags and msk->cb_flags reads in mptcp_rate_check_app_limited() to annotate intentionally racy accesses.
- update commit logs.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/

v5:
- patch 2: new patch - rewrite mptcp_inq_hint() to use mptcp_data_avail() instead of ack_seq - map_seq, completely avoiding TFO overflow issues.
- patch 3: new patch - add TFO SIOCINQ overflow detection in
mptcp_connect test to catch INT_MAX returns on TFO connections.
- patch 4: mptcp_inq() now returns INT_MAX instead of 0 when avail >=
INT_MAX. Removed mptcp_inq_hint() changes (moved to patch 2).
- patch 6: replace mptcp_rtx_head() check with MPTCP_WORK_RTX and MPTCP_RETRANSMIT flag checks in mptcp_rate_check_app_limited() to
properly detect pending retransmissions without data race issues.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/

v4:
- patch 2: fix mptcp_inq_hint() to return 0 instead of INT_MAX on
passive TFO overflow (ack_seq - map_seq >= INT_MAX).
- patch 4: add mptcp_rtx_head(sk) to the early-return check in mptcp_rate_check_app_limited() so pending retransmissions also
prevent false app-limited marking.
- patch 5: update comment message.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/

v3:
- patch 2: drop DATA_FIN subtraction in mptcp_inq(), remove the
intermediate 'answ' variable and return (unsigned int)avail
directly. Update commit message accordingly.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/

v2:
- drop the patch "prevent dummy DATA_FIN on RST in fallback mode".
- keep mptcp_inq_hint in mptcp_ioctl unchanged.
- use mptcp_data_avail in mptcp_inq.
- add msk_owned_by_me check in mptcp_sendmsg_locked.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/

v1:
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/

This series was previously posted as part of "Reduce the differences between TCP and MPTCP for TLS usage" v15. It creates the mptcp_inq() and mptcp_sendmsg_locked() interfaces that are required for the upcoming MPTCP kTLS and MPTCP sockmap implementations.

The series has been rebased and no longer depends on Paolo's CB layout refactoring patches (mptcp: drop the mptcp_ooo_try_coalesce() helper,
mptcp: drop the cant_coalesce CB field, mptcp: remove CB offset field,
mptcp: sync mptcp skb cb layout with tcp one, mptcp: defer read_sock cleanup to mptcp_worker). Those patches are more complex and will be sent in a separate series.

Patch overview:

1. mptcp: update mptcp_check_readable
- Align with TCP's sock_is_readable for better TLS compatibility

2. mptcp: prevent dummy DATA_FIN on RST in fallback mode
- Fix semantic issue where RST on fallback connections would create dummy DATA_FIN, causing unnecessary state transitions
- Add sk_err check to subflow_is_done() to distinguish abortive closes (RST) from clean closes (FIN)

3. mptcp: implement peek_len for proto_ops
- Add mptcp_inq() to report readable bytes at MPTCP level
- Wire into .peek_len proto_ops for both IPv4 and IPv6
- Handle 32-bit torn reads by returning 0 instead of INT_MAX
- Prepare for TLS strparser integration

4. mptcp: add sendmsg_locked to proto_ops
- Split mptcp_sendmsg() into locked/unlocked variants
- Expose .sendmsg_locked in proto_ops for TLS send path

5. mptcp: track app-limited state in mptcp_sendmsg
- Add mptcp_rate_check_app_limited() to mark subflows as app-limited
- Bail out when MPTCP has unsent data (write_seq != snd_nxt or mptcp_send_head() != NULL) to avoid false app-limited marking
- Enable accurate delivery rate estimation for BBR

6. selftests: mptcp: sockopt: check app_limited
- Add regression test for app-limited accounting
- Verify tcpi_delivery_rate_app_limited == 1 after small transfers

Gang Yan (1):
mptcp: update mptcp_check_readable

Geliang Tang (6):
mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
selftests: mptcp: connect: check TFO SIOCINQ overflow
mptcp: implement peek_len for proto_ops
mptcp: add sendmsg_locked to proto_ops
mptcp: track app-limited state in mptcp_sendmsg
selftests: mptcp: sockopt: check app_limited

 net/mptcp/protocol.c                          | 95 +++++++++++++++----
 .../selftests/net/mptcp/mptcp_connect.c       | 64 +++++++++++++
 .../selftests/net/mptcp/mptcp_sockopt.c       |  5 +
 3 files changed, 145 insertions(+), 19 deletions(-)
Signature · 1 line
2.55.0
author reviewer
#1 lore raw

PATCH v8 1/7 mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint

From: Geliang Tang <[email protected]>

Fix mptcp_inq_hint() to compute available bytes using mptcp_data_avail() (bytes_received - bytes_consumed) instead of ack_seq minus the head skb's map_seq.

On passive TFO connections, the TFO skb has map_seq set to -skb->len, causing mptcp_inq_hint() to compute "ack_seq - map_seq = iasn + len", which overflows to INT_MAX. This breaks SIOCINQ/FIONREAD, TCP_CM_INQ, and receive buffer autotuning.

Using mptcp_data_avail() avoids this overflow. To maintain TCP semantics, the hint includes the FIN byte (adds 1) when DATA_FIN is pending (RCV_SHUTDOWN set) or the connection is closed (TCP_CLOSE state). This ensures SIOCINQ reports N+1 when N bytes are unread with DATA_FIN pending, matching TCP behavior where FIN consumes a sequence number.

Fixes f03afb3aeb9d ("mptcp: drop __mptcp_fastopen_gen_msk_ackseq()")
---
 net/mptcp/protocol.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
net/mptcp/protocol.c +5 -12
index 50de5cedfd0f..574eba9989a8 100644
@@ -2404,22 +2404,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;
+	u64 hint_val = mptcp_data_avail(msk);
 
-	skb = skb_peek(&sk->sk_receive_queue);
-	if (skb) {
-		u64 hint_val = READ_ONCE(msk->ack_seq) - MPTCP_SKB_CB(skb)->map_seq;
-
-		if (hint_val >= INT_MAX)
-			return INT_MAX;
-
-		return (unsigned int)hint_val;
-	}
+	if (hint_val >= INT_MAX)
+		return INT_MAX;
 
 	if (sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN))
-		return 1;
+		hint_val += 1;
 
-	return 0;
+	return (unsigned int)hint_val;
 }
 
 static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
Signature · 1 line
2.55.0
author reviewer
#3 lore raw

PATCH v8 2/7 selftests: mptcp: connect: check TFO SIOCINQ overflow

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Add a SIOCINQ check in mptcp_connect's server mode when MPTFO is enabled to detect TFO SIOCINQ overflow regressions.

Wait for MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED using poll() bounded by poll_timeout, then check if SIOCINQ returns INT_MAX. Use poll() instead of usleep() to detect dead connections via POLLHUP/POLLERR. Add SOL_MPTCP fallback definition and handle ENOPROTOOPT/EOPNOTSUPP errors to skip the wait for TCP or fallback sockets. Skip SIOCINQ check on timeout rather than failing the test.

---
 .../selftests/net/mptcp/mptcp_connect.c       | 64 +++++++++++++++++++
 1 file changed, 64 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_connect.c +64 -0
index 178d98d91fea..143d8177b5a3 100644
@@ -34,6 +34,7 @@
 #include <linux/time_types.h>
 #include <linux/sockios.h>
 #include <linux/compiler.h>
+#include <linux/mptcp.h>
 
 extern int optind;
 
@@ -43,6 +44,9 @@ extern int optind;
 #ifndef TCP_ULP
 #define TCP_ULP 31
 #endif
+#ifndef SOL_MPTCP
+#define SOL_MPTCP 284
+#endif
 
 static int  poll_timeout = 10 * 1000;
 static bool listen_mode;
@@ -1176,6 +1180,48 @@ static void maybe_close(int fd)
 		close(fd);
 }
 
+static int wait_for_remote_key(int fd)
+{
+	struct mptcp_info info;
+	int timeout_ms = 10;
+	struct pollfd pfd;
+	int elapsed = 0;
+	socklen_t olen;
+	int ret;
+
+	pfd.fd = fd;
+	pfd.events = 0;
+
+	while (elapsed < poll_timeout || poll_timeout < 0) {
+		ret = poll(&pfd, 1, timeout_ms);
+		if (ret < 0) {
+			perror("TFO: poll");
+			return -1;
+		}
+
+		if (pfd.revents & (POLLHUP | POLLERR)) {
+			fprintf(stderr, "TFO: connection closed or reset\n");
+			return -1;
+		}
+
+		olen = sizeof(info);
+		if (getsockopt(fd, SOL_MPTCP, MPTCP_INFO, &info, &olen) < 0) {
+			/* Not an MPTCP socket (TCP or fallback), skip wait */
+			if (errno == ENOPROTOOPT || errno == EOPNOTSUPP)
+				return 0;
+			perror("TFO: getsockopt(MPTCP_INFO)");
+			return -1;
+		}
+		if (info.mptcpi_flags & MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED)
+			return 0;
+
+		elapsed += timeout_ms;
+	}
+	fprintf(stderr,
+		"TFO: timeout waiting for remote key, skip SIOCINQ check\n");
+	return 1;
+}
+
 int main_loop_s(int listensock)
 {
 	struct sockaddr_storage ss;
@@ -1207,6 +1253,24 @@ int main_loop_s(int listensock)
 		check_sockaddr(pf, &ss, salen);
 		check_getpeername(remotesock, &ss, salen);
 
+		if (cfg_sockopt_types.mptfo) {
+			int ret, avail;
+
+			ret = wait_for_remote_key(remotesock);
+			if (ret < 0) {
+				close(remotesock);
+				return 1;
+			}
+
+			if (ret == 0 &&
+			    ioctl(remotesock, SIOCINQ, &avail) == 0 &&
+			    avail == INT_MAX) {
+				fprintf(stderr, "TFO SIOCINQ overflow\n");
+				close(remotesock);
+				return 1;
+			}
+		}
+
 		if (cfg_input) {
 			fd = open(cfg_input, O_RDONLY);
 			if (fd < 0)
Signature · 1 line
2.55.0
author reviewer
#5 lore raw

PATCH v8 3/7 mptcp: implement peek_len for proto_ops

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

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.

Wire mptcp_inq() into mptcp_peek_len() and assign .peek_len in both mptcp_stream_ops and mptcp_v6_stream_ops.

Unlike mptcp_inq_hint() (used by SIOCINQ), mptcp_inq() does not include the EOF hint (returning 1 when socket is closed with no data) because peek_len is used by strparser to check whether the whole message is already queued, not to report connection state to userspace. It also does not drain the backlog before reading counters; the caller mptcp_ioctl() handles that for SIOCINQ, while strparser only needs a heuristic value.

This prepares for upcoming kTLS and sockmap support.

---
 net/mptcp/protocol.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
net/mptcp/protocol.c +22 -0
index 574eba9989a8..a0ad28f5a385 100644
@@ -4789,6 +4789,26 @@ static ssize_t mptcp_splice_read(struct socket *sock, loff_t *ppos,
 	return ret;
 }
 
+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_peek_len(struct socket *sock)
+{
+	return mptcp_inq(sock->sk);
+}
+
 static const struct proto_ops mptcp_stream_ops = {
 	.family		   = PF_INET,
 	.owner		   = THIS_MODULE,
@@ -4811,6 +4831,7 @@ static const struct proto_ops mptcp_stream_ops = {
 	.set_rcvlowat	   = mptcp_set_rcvlowat,
 	.read_sock	   = mptcp_read_sock,
 	.splice_read	   = mptcp_splice_read,
+	.peek_len	   = mptcp_peek_len,
 };
 
 static struct inet_protosw mptcp_protosw = {
@@ -4923,6 +4944,7 @@ static const struct proto_ops mptcp_v6_stream_ops = {
 	.set_rcvlowat	   = mptcp_set_rcvlowat,
 	.read_sock	   = mptcp_read_sock,
 	.splice_read	   = mptcp_splice_read,
+	.peek_len	   = mptcp_peek_len,
 };
 
 static struct proto mptcp_v6_prot;
Signature · 1 line
2.55.0
author reviewer
#7 lore raw

PATCH v8 4/7 mptcp: add sendmsg_locked to proto_ops

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

MPTCP currently provides a standard sendmsg() implementation which acquires and releases the socket lock internally. However, certain upper layers need to call the sendmsg method while the socket lock is already held.

Split the existing mptcp_sendmsg() into mptcp_sendmsg_locked() which assumes the caller holds the socket lock, and a tiny wrapper mptcp_sendmsg() that acquires the lock and calls the locked version. Add msk_owned_by_me() assertion to enforce the locking requirement. Expose .sendmsg_locked in both mptcp_stream_ops and mptcp_v6_stream_ops.

Unlike tcp_sendmsg_locked(), mptcp_sendmsg_locked() drops the MSG_SPLICE_PAGES flag from the mask. Future kTLS and sockmap support will require additional changes to call through proto_ops->sendmsg_locked instead of tcp_sendmsg_locked() directly.

---
 net/mptcp/protocol.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
net/mptcp/protocol.c +16 -4
index a0ad28f5a385..83abdf39c4e5 100644
@@ -2039,7 +2039,7 @@ static void mptcp_rps_record_subflows(const struct mptcp_sock *msk)
 	}
 }
 
-static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
+static int mptcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t len)
 {
 	struct mptcp_sock *msk = mptcp_sk(sk);
 	struct page_frag *pfrag;
@@ -2047,12 +2047,12 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	int ret = 0;
 	long timeo;
 
+	msk_owned_by_me(msk);
+
 	/* silently ignore everything else */
 	msg->msg_flags &= MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL |
 			  MSG_FASTOPEN | MSG_EOR;
 
-	lock_sock(sk);
-
 	mptcp_rps_record_subflows(msk);
 
 	if (unlikely(inet_test_bit(DEFER_CONNECT, sk) ||
@@ -2168,7 +2168,6 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	}
 
 out:
-	release_sock(sk);
 	return copied;
 
 do_error:
@@ -2181,6 +2180,17 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	goto out;
 }
 
+static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
+{
+	int ret;
+
+	lock_sock(sk);
+	ret = mptcp_sendmsg_locked(sk, msg, len);
+	release_sock(sk);
+
+	return ret;
+}
+
 static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied);
 
 static void mptcp_eat_recv_skb(struct sock *sk, struct sk_buff *skb)
@@ -4832,6 +4842,7 @@ static const struct proto_ops mptcp_stream_ops = {
 	.read_sock	   = mptcp_read_sock,
 	.splice_read	   = mptcp_splice_read,
 	.peek_len	   = mptcp_peek_len,
+	.sendmsg_locked	   = mptcp_sendmsg_locked,
 };
 
 static struct inet_protosw mptcp_protosw = {
@@ -4945,6 +4956,7 @@ static const struct proto_ops mptcp_v6_stream_ops = {
 	.read_sock	   = mptcp_read_sock,
 	.splice_read	   = mptcp_splice_read,
 	.peek_len	   = mptcp_peek_len,
+	.sendmsg_locked	   = mptcp_sendmsg_locked,
 };
 
 static struct proto mptcp_v6_prot;
Signature · 1 line
2.55.0
author reviewer
#9 lore raw

PATCH v8 5/7 mptcp: track app-limited state in mptcp_sendmsg

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Add mptcp_rate_check_app_limited() that walks every subflow and runs tcp_rate_check_app_limited() under each subflow's socket lock. The helper bails out early when MPTCP still has data to send: unsent data (write_seq != snd_nxt), pending dfrags (mptcp_send_head), or pending retransmission (MPTCP_WORK_RTX or MPTCP_RETRANSMIT flags). In these cases marking subflows app-limited would mislead congestion controllers.

Invoke from mptcp_sendmsg_locked() after send-side setup so BBR and similar controllers can ignore rate samples taken while the connection is genuinely application-limited. The per-subflow locking only occurs when the MPTCP send queue is empty, which is the correct scenario to mark the connection as application-limited.

---
 net/mptcp/protocol.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
net/mptcp/protocol.c +27 -0
index 83abdf39c4e5..b9d080121f78 100644
@@ -2039,6 +2039,30 @@ static void mptcp_rps_record_subflows(const struct mptcp_sock *msk)
 	}
 }
 
+static void mptcp_rate_check_app_limited(struct sock *sk)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct mptcp_subflow_context *subflow;
+	unsigned long flags, cb_flags;
+
+	flags = READ_ONCE(msk->flags);
+	cb_flags = READ_ONCE(msk->cb_flags);
+
+	if (msk->write_seq != msk->snd_nxt || mptcp_send_head(sk) ||
+	    test_bit(MPTCP_WORK_RTX, &flags) ||
+	    test_bit(MPTCP_RETRANSMIT, &cb_flags))
+		return;
+
+	mptcp_for_each_subflow(msk, subflow) {
+		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+		bool slow;
+
+		slow = lock_sock_fast_nested(ssk);
+		tcp_rate_check_app_limited(ssk);
+		unlock_sock_fast(ssk, slow);
+	}
+}
+
 static int mptcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t len)
 {
 	struct mptcp_sock *msk = mptcp_sk(sk);
@@ -2069,6 +2093,9 @@ static int mptcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t len)
 
 	timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
 
+	/* is sending application-limited? */
+	mptcp_rate_check_app_limited(sk);
+
 	if ((1 << sk->sk_state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) {
 		ret = sk_stream_wait_connect(sk, &timeo);
 		if (ret)
Signature · 1 line
2.55.0
author reviewer
#11 lore raw

PATCH v8 6/7 selftests: mptcp: sockopt: check app_limited

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

After a small data exchange, assert tcpi_delivery_rate_app_limited == 1 when expect_all_features() is enabled.

rate_app_limited starts at 1 (tcp_init_sock) and is cleared only by non-app-limited rate samples. The preceding commit makes mptcp_rate_check_app_limited() set tp->app_limited on subflows when MPTCP has no pending data, marking outgoing skbs as app-limited so rate samples don't clear rate_app_limited.

This guards against regressions where subflows are never marked app-limited. The test covers the empty-queue path only; the early return in mptcp_rate_check_app_limited() (when MPTCP has pending data or retransmissions) is not exercised by this test.

---
 tools/testing/selftests/net/mptcp/mptcp_sockopt.c | 5 +++++
 1 file changed, 5 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +5 -0
index b8158a1198eb..9517c530ba21 100644
@@ -635,6 +635,11 @@ static void connect_one_server(int fd, int pipefd)
 	do_getsockopts(&s, fd, total, total);
 
 	assert(s.mptcpi_rcv_delta == (uint64_t)total);
+
+	/* app-limited accounting only checked under EXPECT_ALL_FEATURES */
+	if (expect_all_features())
+		assert(s.tcp_info.tcpi_delivery_rate_app_limited == 1);
+
 	close(fd);
 }
 
Signature · 1 line
2.55.0
author reviewer
#13 lore raw

PATCH v8 7/7 mptcp: update mptcp_check_readable

In reply to Geliang Tang

From: Gang Yan <[email protected]>

This patch makes mptcp_check_readable() aligned with TCP, and renames it to mptcp_stream_is_readable(). It will be used in the case of KTLS, because 'prot' will be modified, tls_sw_sock_is_readable() is expected to be called from prot->sock_is_readable().

---
 net/mptcp/protocol.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
net/mptcp/protocol.c +6 -3
index b9d080121f78..c81300db1db3 100644
@@ -3508,9 +3508,11 @@ void __mptcp_unaccepted_force_close(struct sock *sk)
 	__mptcp_destroy_sock(sk);
 }
 
-static __poll_t mptcp_check_readable(struct sock *sk)
+static bool mptcp_stream_is_readable(struct sock *sk)
 {
-	return mptcp_epollin_ready(sk) ? EPOLLIN | EPOLLRDNORM : 0;
+	if (mptcp_epollin_ready(sk))
+		return true;
+	return sk_is_readable(sk);
 }
 
 static void mptcp_check_listen_stop(struct sock *sk)
@@ -4612,7 +4614,8 @@ static __poll_t mptcp_poll(struct file *file, struct socket *sock,
 		mask |= EPOLLIN | EPOLLRDNORM | EPOLLRDHUP;
 
 	if (state != TCP_SYN_SENT && state != TCP_SYN_RECV) {
-		mask |= mptcp_check_readable(sk);
+		if (mptcp_stream_is_readable(sk))
+			mask |= EPOLLIN | EPOLLRDNORM;
 		if (shutdown & SEND_SHUTDOWN)
 			mask |= EPOLLOUT | EPOLLWRNORM;
 		else
Signature · 1 line
2.55.0
#14 lore raw
In reply to Geliang Tang

Hi Gang,

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: Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/43862767956

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/ea5be39da628
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1212621

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)

#2 lore raw

Re: [PATCH mptcp-net v8 1/7] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint

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

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

Critical: 0 · High: 0 · Medium: 2 · Low: 0

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] This is a regression the patch introduces in net/mptcp/protocol.c:mptcp_inq_hint().
- [Medium] The commit message says the new code "ensures SIOCINQ reports N+1 when N bytes are unread with DATA_FIN pending, matching TCP…

--

mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint

This commit changes mptcp_inq_hint() to take the readable byte count from mptcp_data_avail() instead of ack_seq minus the map_seq of the head skb. The old calculation overflowed to INT_MAX on passive TFO connections. The commit also adds one byte to the hint when RCV_SHUTDOWN is set or the socket is in TCP_CLOSE.

Quoted 16 lines
net/mptcp/protocol.c +1 -6
index 50de5cedfd0fb..574eba9989a8d 100644
@@ -2404,22 +2404,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;
+	u64 hint_val = mptcp_data_avail(msk);
 
-	skb = skb_peek(&sk->sk_receive_queue);
-	if (skb) {
-		u64 hint_val = READ_ONCE(msk->ack_seq) - MPTCP_SKB_CB(skb)->map_seq;
-
-		if (hint_val >= INT_MAX)

net/mptcp/protocol.c static bool mptcp_move_skbs(struct sock *sk) · line 2413

Quoted 10 lines
net/mptcp/protocol.c +3 -5
-			return INT_MAX;
-
-		return (unsigned int)hint_val;
-	}
+	if (hint_val >= INT_MAX)
+		return INT_MAX;
 
 	if (sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN))
-		return 1;
+		hint_val += 1;

[Severity: Medium]
Does RCV_SHUTDOWN here always mean that a DATA_FIN is pending? The commit message treats the two as the same thing. However, the +1 is now added on top of a non-zero mptcp_data_avail() whenever RCV_SHUTDOWN or TCP_CLOSE is set, even if no DATA_FIN ever used up a sequence number.

Before this patch, with a non-empty receive queue the hint was ack_seq - head->map_seq. That is exactly the N unread bytes, because __mptcp_recvmsg_mskq() advances map_seq on partial reads:

    MPTCP_SKB_CB(skb)->map_seq += count;

The value only became N+1 after mptcp_check_data_fin() accounted for a real DATA_FIN:

    WRITE_ONCE(msk->ack_seq, msk->ack_seq + 1);

The old "return 1" only ran when the queue was empty.

There seem to be two cases where the new code reports N+1 and the old code reported N.

The first is a local shutdown(fd, SHUT_RD). inet_shutdown() sets RCV_SHUTDOWN, but mptcp_shutdown() only handles SEND_SHUTDOWN, so no DATA_FIN exists.

The second is an MP_FASTCLOSE from the peer, handled in mptcp_check_fastclose():

    mptcp_set_state(sk, TCP_CLOSE);
    WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);

This path does not touch ack_seq and does not purge sk_receive_queue.

The inflated value then reaches userspace through mptcp_ioctl(SIOCINQ) and through the TCP_CM_INQ cmsg in mptcp_recvmsg(). It also feeds the "copied -= mptcp_inq_hint(sk)" step in mptcp_rcv_space_adjust().

For comparison, tcp_inq() and tcp_inq_hint() only count a FIN that was actually received (SOCK_DONE is set by tcp_fin()). tcp_inq_hint() also only forces 1 when inq is 0.

Could the FIN byte be added only when a DATA_FIN was actually accounted for, or only when mptcp_data_avail() returns 0? As far as I can tell, mptcp_inq_hint() stays unchanged through the end of the series.

[Severity: Medium]
The commit message says:

This ensures SIOCINQ reports N+1 when N bytes are unread with DATA_FIN pending, matching TCP behavior where FIN consumes a sequence number.

Is that right for SIOCINQ? On TCP, SIOCINQ goes through tcp_ioctl()->tcp_inq(), which subtracts the FIN byte:

		answ = tp->rcv_nxt - tp->copied_seq;

		/* Subtract 1, if FIN was received */
		if (answ && sock_flag(sk, SOCK_DONE))
			answ--;

So TCP reports N while a FIN is pending and 0 at EOF. Only TCP_CM_INQ, via tcp_inq_hint(), counts the FIN.

mptcp_ioctl(SIOCINQ) returns mptcp_inq_hint(), the same helper that TCP_CM_INQ uses. As a result, FIONREAD on an MPTCP socket returns N+1 after a DATA_FIN and 1 after EOF, where TCP returns N and 0.

The old ack_seq based calculation already produced N+1, and 1 at EOF. This patch, though, rewrites the helper and makes the +1 explicit based on the TCP parity claim above.

A later patch in the series ("mptcp: implement peek_len for proto_ops") adds mptcp_inq(), which returns mptcp_data_avail() without the FIN. However, SIOCINQ still calls mptcp_inq_hint() at the end of the series.

Should mptcp_ioctl() use a helper that leaves out the FIN, as tcp_inq() does for TCP?

The FIONREAD check in process_one_client() in tools/testing/selftests/net/mptcp/mptcp_inq.c only runs before the peer sends its DATA_FIN, so this case does not seem to be covered by the selftest.

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794826541.git.geliang%40kernel.org
#4 lore raw

Re: [PATCH mptcp-next v8 2/7] selftests: mptcp: connect: check TFO SIOCINQ overflow

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

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] The commit message says that when waiting for the remote key times out, the test skips the SIOCINQ check instead of failing.
- [Low] The commit message for "selftests: mptcp: connect: check TFO SIOCINQ overflow" does not mention the kernel fix this test checks for.

--

selftests: mptcp: connect: check TFO SIOCINQ overflow

This commit adds a SIOCINQ check to mptcp_connect's server mode when MPTFO is enabled. The server polls until MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED is set, with a limit of poll_timeout. It then fails the test if SIOCINQ returns INT_MAX.

Quoted 8 lines

Wait for MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED using poll() bounded by poll_timeout, then check if SIOCINQ returns INT_MAX. Use poll() instead of usleep() to detect dead connections via POLLHUP/POLLERR. Add SOL_MPTCP fallback definition and handle ENOPROTOOPT/EOPNOTSUPP errors to skip the wait for TCP or fallback sockets. Skip SIOCINQ check on timeout rather than failing the test.

[Severity: Low]
Should this commit refer to the kernel fix it tests? The previous patch in the series, "mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint", has:

Fixes f03afb3aeb9d ("mptcp: drop __mptcp_fastopen_gen_msk_ackseq()")

This patch has no Fixes: tag and does not mention that fix.

The new check in main_loop_s() will report "TFO SIOCINQ overflow" on any kernel that has f03afb3aeb9d but not the fix. Stable maintainers would need to know that the two patches go together.

Also, the sentence "Use poll() instead of usleep() to detect dead connections via POLLHUP/POLLERR" reads like a changelog from an earlier version. This patch does not replace any usleep() based wait. Should that text go below the --- line?

Quoted 4 lines
tools/testing/selftests/net/mptcp/mptcp_connect.c +0 -0
index 178d98d91fea2..143d8177b5a33 100644

[ ... ]

Quoted 18 lines
tools/testing/selftests/net/mptcp/mptcp_connect.c +14 -0
@@ -1176,6 +1180,48 @@ static void maybe_close(int fd)
 		close(fd);
 }
 
+static int wait_for_remote_key(int fd)
+{
+	struct mptcp_info info;
+	int timeout_ms = 10;
+	struct pollfd pfd;
+	int elapsed = 0;
+	socklen_t olen;
+	int ret;
+
+	pfd.fd = fd;
+	pfd.events = 0;
+
+	while (elapsed < poll_timeout || poll_timeout < 0) {
+		ret = poll(&pfd, 1, timeout_ms);

[ ... ]

tools/testing/selftests/net/mptcp/mptcp_connect.c static void maybe_close(int fd) · line 1223

Quoted 9 lines
tools/testing/selftests/net/mptcp/mptcp_connect.c +9 -0
+		if (info.mptcpi_flags & MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED)
+			return 0;
+
+		elapsed += timeout_ms;
+	}
+	fprintf(stderr,
+		"TFO: timeout waiting for remote key, skip SIOCINQ check\n");
+	return 1;
+}

[Severity: Medium]
Can this timeout path really skip the SIOCINQ check, as the commit message says?

The loop in wait_for_remote_key() is limited by the global poll_timeout. The client uses the same idle timeout in copyfd_io_poll():

tools/testing/selftests/net/mptcp/mptcp_connect.c:copyfd_io_poll() {
    ...
		switch (poll(&fds, 1, poll_timeout)) {
		...
		case 0:
			fprintf(stderr, "%s: poll timed out (events: "
				"POLLIN %u, POLLOUT %u)\n", __func__,
				fds.events & POLLIN, fds.events & POLLOUT);
			return 2;
		}
    ...
}

main_loop_s() calls wait_for_remote_key() after accept() and before copyfd_io(). The server does not read or write while it waits. mptcp_connect.sh starts both sides with -t ${timeout_poll}, which is 30 seconds.

Each iteration counts 10 ms in elapsed, but the poll() and getsockopt() calls take at least that long. The real wait is therefore longer than poll_timeout.

Suppose a non-fallback MPTCP socket never gets the remote key. By then the client has filled the socket buffers or called shut_wr(), and it sees no more poll events. Won't the client hit its own poll timeout at about the same time, usually first, and exit with 2? do_transfer() would then report a failure with "client exit code 2".

That turns the skip into a 30 second stall followed by a client failure that depends on timing. Would a separate, much shorter limit for the remote key wait give the intended behavior?

With -t 0 (poll_timeout == -1) this loop never ends. That matches what -t 0 does for the other polls in the tool.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794826541.git.geliang%40kernel.org
#6 lore raw

Re: [PATCH mptcp-next v8 3/7] mptcp: implement peek_len for proto_ops

In reply to Geliang Tang
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The new mptcp_peek_len() (net/mptcp/protocol.c), wired into mptcp_stream_ops and mptcp_v6_stream_ops, has no caller that can reach…

--

mptcp: implement peek_len for proto_ops

This adds mptcp_inq(), which uses mptcp_data_avail() to report how many bytes can be read at the MPTCP level. It also wires mptcp_inq() into a new mptcp_peek_len() callback. That callback is set as .peek_len in both mptcp_stream_ops and mptcp_v6_stream_ops, to prepare for kTLS and sockmap support.

Quoted 10 lines
net/mptcp/protocol.c +2 -0
index 574eba9989a8d..a0ad28f5a3851 100644
@@ -4789,6 +4789,26 @@ static ssize_t mptcp_splice_read(struct socket *sock, loff_t *ppos,
 	return ret;
 }
 
+static int mptcp_inq(struct sock *sk)
+{

[ ... ]

net/mptcp/protocol.c static ssize_t mptcp_splice_read(struct socket *sock, loff_t *ppos, · line 4810

Quoted 6 lines
net/mptcp/protocol.c +6 -0
+}
+
+static int mptcp_peek_len(struct socket *sock)
+{
+	return mptcp_inq(sock->sk);
+}

[Severity: Low]
Can anything call mptcp_peek_len() on an MPTCP socket, either at this commit or later in the series?

I can only find two users of ->peek_len. One is strp_peek_len() in net/strparser/strparser.c, called from strp_recv() and strp_data_ready(). The other is drivers/vhost/net.c, and vhost-net only accepts AF_PACKET or tap sockets through get_raw_socket() and get_tap_socket().

The strparser users don't seem to accept MPTCP sockets. sock_map_link() only sets up the strparser for TCP:

net/core/sock_map.c:sock_map_link() {
    ...
	if (stream_parser && stream_verdict && !psock->saved_data_ready) {
		if (sk_is_tcp(sk))
			ret = sk_psock_init_strp(sk, psock);
		else
			ret = -EOPNOTSUPP;
    ...
}

sk_is_tcp() requires sk_protocol == IPPROTO_TCP. kcm_attach() also rejects any csk->sk_protocol other than IPPROTO_TCP.

The commit message says:

This prepares for upcoming kTLS and sockmap support.

Is the kTLS part accurate? kTLS receive doesn't use net/strparser. It has its own parser in net/tls/tls_strp.c, which calls tcp_inq(), tcp_sk() and tcp_read_sock() directly on strp->sk and never calls sock->ops->peek_len:

net/tls/tls_strp.c:tls_strp_read_sock() {
    ...
	inq = tcp_inq(strp->sk);
	if (inq < 1)
		return 0;
    ...
}

The commit message also uses a consumer that isn't in this series to justify some specific choices: no EOF hint, no backlog drain, and returning 0 in TCP_SYN_SENT/TCP_SYN_RECV.

None of the later patches in the series seem to add a caller either. That covers "mptcp: add sendmsg_locked to proto_ops", "mptcp: track app-limited state in mptcp_sendmsg", "mptcp: update mptcp_check_readable" and the selftests.

Could this patch be merged together with its first user? Those choices could then be checked against how the callback is actually used.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794826541.git.geliang%40kernel.org
#8 lore raw

Re: [PATCH mptcp-next v8 4/7] mptcp: add sendmsg_locked to proto_ops

In reply to Geliang Tang
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The patch adds .sendmsg_locked = mptcp_sendmsg_locked to mptcp_stream_ops and mptcp_v6_stream_ops, but no in-tree caller…
- [Low] The commit author is 'Geliang Tang <[email protected]>', but the only Signed-off-by is 'Geliang Tang <[email protected]>'.

--

mptcp: add sendmsg_locked to proto_ops

This commit splits mptcp_sendmsg() into mptcp_sendmsg_locked(), which expects the caller to hold the msk socket lock, and a small mptcp_sendmsg() wrapper that takes the lock. It also sets mptcp_sendmsg_locked() as the .sendmsg_locked hook in both mptcp_stream_ops and mptcp_v6_stream_ops.

Quoted 1 line

[Severity: Low]
This isn't a bug, but the author is Geliang Tang <[email protected]>, while the only sign-off uses [email protected]. checkpatch.pl reports this as FROM_SIGN_OFF_MISMATCH.

Could a Signed-off-by for the author address be added, or the author address be changed to match?

Quoted 4 lines
net/mptcp/protocol.c +0 -0
index a0ad28f5a3851..83abdf39c4e54 100644

[ ... ]

net/mptcp/protocol.c static const struct proto_ops mptcp_stream_ops = { · line 4846

Quoted 6 lines
net/mptcp/protocol.c +1 -0
@@ -4832,6 +4842,7 @@ static const struct proto_ops mptcp_stream_ops = {
 	.read_sock	   = mptcp_read_sock,
 	.splice_read	   = mptcp_splice_read,
 	.peek_len	   = mptcp_peek_len,
+	.sendmsg_locked	   = mptcp_sendmsg_locked,
 };

[Severity: Low]
Is there an in-tree caller that can reach this hook for an MPTCP socket?

The only generic caller of proto_ops->sendmsg_locked seems to be sendmsg_locked() in net/core/skbuff.c. It is reached only through __skb_send_sock(), from skb_send_sock_locked() and skb_send_sock_locked_with_flags(). Only espintcp and ovpn call those helpers.

ovpn_socket_attach() in drivers/net/ovpn/socket.c rejects any protocol other than UDP and TCP:

	if (sock->sk->sk_protocol == IPPROTO_UDP)
		return ovpn_udp_socket_attach(ovpn_sock, sock, peer->ovpn);
	else if (sock->sk->sk_protocol == IPPROTO_TCP)
		return ovpn_tcp_socket_attach(ovpn_sock, peer);

	return -EOPNOTSUPP;

espintcp needs the TCP ULP, and mptcp_setsockopt_sol_tcp() in net/mptcp/sockopt.c refuses it:

	case TCP_ULP:
		return -EOPNOTSUPP;

As the commit message itself says, kTLS and sockmap still call tcp_sendmsg_locked() directly.

The commit message also says:

However, certain upper layers need to call the sendmsg method while the socket lock is already held.

Which upper layer does this refer to? I could not find anything in this patch or in the rest of the series (app-limited tracking, the mptcp_check_readable update, selftests) that calls .sendmsg_locked on an msk. So the new entry here, and the matching one in mptcp_v6_stream_ops, look unused.

Could the commit message name the intended consumer? Alternatively, could this patch be merged together with the series that adds that consumer?

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794826541.git.geliang%40kernel.org
#10 lore raw

Re: [PATCH mptcp-next v8 5/7] mptcp: track app-limited state in mptcp_sendmsg

In reply to Geliang Tang
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] mptcp_rate_check_app_limited() (net/mptcp/protocol.c:2042-2064) runs unconditionally from mptcp_sendmsg_locked() (line 2097).

--

mptcp: track app-limited state in mptcp_sendmsg

This commit adds mptcp_rate_check_app_limited(). It walks every subflow and calls tcp_rate_check_app_limited() under each subflow's socket lock, unless the MPTCP level still has unsent data or a retransmission pending. It is called from mptcp_sendmsg_locked() so that BBR and similar congestion controllers can ignore rate samples taken while the connection is application-limited.

Quoted 21 lines
net/mptcp/protocol.c +13 -0
index 83abdf39c4e54..b9d080121f782 100644
@@ -2039,6 +2039,30 @@ static void mptcp_rps_record_subflows(const struct mptcp_sock *msk)
 	}
 }
 
+static void mptcp_rate_check_app_limited(struct sock *sk)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct mptcp_subflow_context *subflow;
+	unsigned long flags, cb_flags;
+
+	flags = READ_ONCE(msk->flags);
+	cb_flags = READ_ONCE(msk->cb_flags);
+
+	if (msk->write_seq != msk->snd_nxt || mptcp_send_head(sk) ||
+	    test_bit(MPTCP_WORK_RTX, &flags) ||
+	    test_bit(MPTCP_RETRANSMIT, &cb_flags))
+		return;

net/mptcp/protocol.c static void mptcp_rps_record_subflows(const struct mptcp_sock *msk) · line 2064

Quoted 10 lines
net/mptcp/protocol.c +10 -0
+
+	mptcp_for_each_subflow(msk, subflow) {
+		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+		bool slow;
+
+		slow = lock_sock_fast_nested(ssk);
+		tcp_rate_check_app_limited(ssk);
+		unlock_sock_fast(ssk, slow);
+	}
+}

[Severity: Low]
Is this loop acceptable on the sendmsg() fast path?

The early return only happens while MPTCP-level data is still pending. For request/response, interactive or paced senders, __mptcp_push_pending() has usually pushed out the previous write by the time the next one arrives. So write_seq equals snd_nxt, first_pending is NULL and no RTX flag is set. In that steady state the walk runs on every call.

Each sendmsg() then takes the socket lock of every subflow on conn_list. That includes backup, stale or idle subflows the scheduler will not use. This comes on top of the subflow locking that __mptcp_push_pending() already does for the subflows it schedules.

The other subflow walk on the same path is gated, so it costs nothing when it is not needed:

net/mptcp/protocol.c:mptcp_rps_record_subflows() {
	if (!rfs_is_needed())
		return;
    ...
}

The new call in mptcp_sendmsg_locked() has no gate:

	/* is sending application-limited? */
	mptcp_rate_check_app_limited(sk);

Could this be gated in a similar way? Other options would be to do the check in the push path, where the subflow lock is already held, or to skip subflows that cannot send.

The commit message says:

The per-subflow locking only occurs
when the MPTCP send queue is empty, which is the correct scenario to mark the connection as application-limited.

For the workloads this patch targets, an empty send queue is the normal state. Are there any measurements of the added overhead, or of the BBR benefit?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794826541.git.geliang%40kernel.org
#12 lore raw

Re: [PATCH mptcp-next v8 6/7] selftests: mptcp: sockopt: check app_limited

In reply to Geliang Tang
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit 'selftests: mptcp: sockopt: check app_limited' is authored by Geliang Tang <[email protected]>, but its only Signed-…
- [Low] In connect_one_server() (tools/testing/selftests/net/mptcp/mptcp_sockopt.c:640-641), the new…

--

selftests: mptcp: sockopt: check app_limited

This commit adds a check to connect_one_server() in mptcp_sockopt.c. After a small data exchange, it asserts that tcpi_delivery_rate_app_limited is 1 when expect_all_features() is enabled. The goal is to catch regressions where MPTCP subflows are never marked app-limited.

Quoted 3 lines

Author: Geliang Tang <[email protected]>
...

[Severity: Low]
This isn't a bug, but the author address and the only Signed-off-by address are different. checkpatch.pl reports this as FROM_SIGN_OFF_MISMATCH.

Most of the series has the same mismatch:

"mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint" "selftests: mptcp: connect: check TFO SIOCINQ overflow" "mptcp: implement peek_len for proto_ops" "mptcp: add sendmsg_locked to proto_ops" "mptcp: track app-limited state in mptcp_sendmsg"

"mptcp: update mptcp_check_readable", however, signs off with the kernel.org address.

Could an in-body From: line with the kylinos.cn address be added, or the sign-off switched to the kernel.org address, so the series is consistent?

tools/testing/selftests/net/mptcp/mptcp_sockopt.c static void connect_one_server(int fd, int pipefd) · line 641

Quoted 12 lines
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +4 -0
index b8158a1198eba..9517c530ba214 100644
@@ -635,6 +635,11 @@ static void connect_one_server(int fd, int pipefd)
 	do_getsockopts(&s, fd, total, total);
 
 	assert(s.mptcpi_rcv_delta == (uint64_t)total);
+
+	/* app-limited accounting only checked under EXPECT_ALL_FEATURES */
+	if (expect_all_features())
+		assert(s.tcp_info.tcpi_delivery_rate_app_limited == 1);

[Severity: Low]
Can this assertion pass even when no rate sample was accepted for the client's data?

The expected value is the same one tcp_init_sock() sets at the start:

net/ipv4/tcp.c:tcp_init_sock() {
    ...
	tp->app_limited = ~0U;
	tp->rate_app_limited = 1;
    ...
}

tcp_rate_gen() only updates tp->rate_app_limited when the sample gets past its early returns, including this one:

net/ipv4/tcp_input.c:tcp_rate_gen() {
    ...
	if (unlikely(rs->interval_us < tcp_min_rtt(tp))) {
		...
		rs->interval_us = -1;
		return;
	}
    ...
}

Also, tcp_update_rtt_min() replaces a 0 us RTT with one jiffy:

net/ipv4/tcp_input.c:tcp_update_rtt_min() {
    ...
	minmax_running_min(&tp->rtt_min, wlen, tcp_jiffies32,
			   rtt_us ? : jiffies_to_usecs(1));
}

Suppose the clocksource is coarse and the data skb's RTT measures as 0 us. Then ack_us is below min_rtt and the sample is dropped. rate_app_limited keeps its initial value of 1, so the assert would still pass if mptcp_rate_check_app_limited() were broken or removed.

On loopback with a fine-grained clock a sample is normally accepted, so the check works in the usual case.

Would it make sense to also require s.tcp_info.tcpi_delivery_rate != 0, or to compare tcpi_delivered before and after the exchange? Either would confirm that a sample was actually measured.

Quoted 3 lines
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +1 -0
+
 	close(fd);
 }
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794826541.git.geliang%40kernel.org