Skip to contentSkip to conversation

prepare interfaces for kTLS and sockmap support

PATCH Superseded Geliang Tang 4 participants 12 messages Nov 2 – Nov 3

Subsystems (3)

v4 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

Geliang Tang

author reviewer
#0 lore raw

v4 cover prepare interfaces for kTLS and sockmap support

From: Geliang Tang <[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.

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 (4):
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                          | 75 +++++++++++++++++--
 .../selftests/net/mptcp/mptcp_sockopt.c       |  5 ++
 2 files changed, 72 insertions(+), 8 deletions(-)
Signature · 1 line
2.55.0
author reviewer
#1 lore raw

PATCH v4 1/5 mptcp: update mptcp_check_readable

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 02a4f479d9d8..0caa31525b90 100644
@@ -3476,9 +3476,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)
@@ -4580,7 +4582,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
author reviewer
#2 lore raw

PATCH v4 2/5 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) to avoid TFO overflow issues. Returns 0 during handshake or when avail >= INT_MAX.

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

Also fix mptcp_inq_hint() to return 0 instead of INT_MAX when ack_seq minus the head skb's map_seq overflows. On passive TFO the head skb has map_seq = -skb->len while ack_seq is later set to iasn, so the subtraction overflows INT_MAX. Returning 0 prevents SIOCINQ from reporting 2GB and stops mptcp_rcv_space_adjust() from skipping autotuning.

---
 net/mptcp/protocol.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +23 -1
index 0caa31525b90..c6d354900e7d 100644
@@ -2409,7 +2409,7 @@ static unsigned int mptcp_inq_hint(const struct sock *sk)
 		u64 hint_val = READ_ONCE(msk->ack_seq) - MPTCP_SKB_CB(skb)->map_seq;
 
 		if (hint_val >= INT_MAX)
-			return INT_MAX;
+			return 0;
 
 		return (unsigned int)hint_val;
 	}
@@ -4797,6 +4797,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 0;
+
+	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,
@@ -4819,6 +4839,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 = {
@@ -4931,6 +4952,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
#3 lore raw

Re: [PATCH mptcp-next v4 2/5] mptcp: implement peek_len for proto_ops

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] mptcp: incorrect readable byte count in mptcp_inq_hint() on passive TFO --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] mptcp: incorrect readable byte count in mptcp_inq_hint() on passive TFO --

commit c2b974abec7822444a7f621944b513eb168889a9
Author: Geliang Tang <[email protected]>

mptcp: implement peek_len for proto_ops

This commit implements the peek_len callback for mptcp_stream_ops and mptcp_v6_stream_ops using mptcp_data_avail(). It also changes mptcp_inq_hint() to return 0 instead of INT_MAX when msk->ack_seq minus the head skb's map_seq is at least INT_MAX.

net/mptcp/protocol.c static unsigned int mptcp_inq_hint(const struct sock *sk) · line 2415

Quoted 13 lines
net/mptcp/protocol.c +1 -1
index 0caa31525b907..c6d354900e7d2 100644
@@ -2409,7 +2409,7 @@ static unsigned int mptcp_inq_hint(const struct sock *sk)
 		u64 hint_val = READ_ONCE(msk->ack_seq) - MPTCP_SKB_CB(skb)->map_seq;
 
 		if (hint_val >= INT_MAX)
-			return INT_MAX;
+			return 0;
 
 		return (unsigned int)hint_val;
 	}

[Severity: Medium]
On passive TFO connections, won't returning 0 here cause mptcp_inq_hint() to report 0 readable bytes (or a bogus subflow->iasn-derived value when hint_val wraps below INT_MAX) even when unread data is queued in sk->sk_receive_queue?

During passive TFO, mptcp_fastopen_subflow_synack_set_params() queues the SYN payload skb onto sk->sk_receive_queue with map_seq = -skb->len and increments msk->bytes_received by skb->len while msk->ack_seq is 0:

net/mptcp/fastopen.c:mptcp_fastopen_subflow_synack_set_params() {
	...
	/* Only the sequence delta is relevant */
	MPTCP_SKB_CB(skb)->map_seq = -skb->len;
	MPTCP_SKB_CB(skb)->end_seq = 0;
	MPTCP_SKB_CB(skb)->offset = 0;
	...
}

When the third ACK carrying MP_CAPABLE_ACK arrives, __mptcp_subflow_fully_established() -> subflow_set_remote_key() sets msk->ack_seq to subflow->iasn without rebasing the TFO head skb's map_seq:

net/mptcp/subflow.c:subflow_set_remote_key() {
	...
	WRITE_ONCE(msk->remote_key, subflow->remote_key);
	WRITE_ONCE(msk->ack_seq, subflow->iasn);
	...
}

While any unconsumed bytes of the TFO skb remain at the head of sk->sk_receive_queue (before the first read, during MSG_PEEK, or after a partial read), mptcp_inq_hint() computes:

	hint_val = READ_ONCE(msk->ack_seq) - MPTCP_SKB_CB(skb)->map_seq;

which evaluates to subflow->iasn + mptcp_data_avail(msk) (mod 2^64).

When hint_val >= INT_MAX, mptcp_inq_hint() returns 0 despite unread data sitting in sk->sk_receive_queue, and when the 64-bit sum wraps below INT_MAX, it returns a bogus byte count up to INT_MAX - 1. This causes SIOCINQ in mptcp_ioctl() and the TCP_CM_INQ cmsg in mptcp_recvmsg() to report an incorrect readable byte count to userspace, and causes mptcp_rcv_space_adjust() to subtract 0 (or a bogus iasn offset) instead of the unread receive queue occupancy.

Should mptcp_inq_hint() compute the available bytes using mptcp_data_avail(msk) like mptcp_inq() does?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#4 lore raw

Re: [PATCH mptcp-next v4 2/5] mptcp: implement peek_len for proto_ops

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

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

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

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).

- [High] The patch changes how mptcp_inq_hint() (net/mptcp/protocol.c:2402-2420) handles the passive-TFO overflow: it…
- [Low] A fix for a user-visible bug in released kernels is folded into a feature patch titled "mptcp: implement peek_len for proto_ops", with…
- [Low] The new mptcp_peek_len() (net/mptcp/protocol.c:4815-4818), installed as .peek_len in mptcp_stream_ops and mptcp_v6_stream_ops,…

--

mptcp: implement peek_len for proto_ops

This adds mptcp_inq() and mptcp_peek_len(), which use mptcp_data_avail() to compute the readable bytes at the MPTCP level. It sets .peek_len in both mptcp_stream_ops and mptcp_v6_stream_ops. It also changes mptcp_inq_hint() to return 0 instead of INT_MAX when ack_seq minus the head skb's map_seq overflows on passive TFO.

net/mptcp/protocol.c static unsigned int mptcp_inq_hint(const struct sock *sk) · line 2412

Quoted 10 lines
net/mptcp/protocol.c +1 -1
index 0caa31525b907..c6d354900e7d2 100644
@@ -2409,7 +2409,7 @@ static unsigned int mptcp_inq_hint(const struct sock *sk)
 		u64 hint_val = READ_ONCE(msk->ack_seq) - MPTCP_SKB_CB(skb)->map_seq;
 
 		if (hint_val >= INT_MAX)
-			return INT_MAX;
+			return 0;

[Severity: High]
Doesn't this still report a wrong value, just a different one? On passive TFO there is readable data at the head of sk_receive_queue, so returning 0 tells userspace that nothing is queued when data is.

The TFO skb is queued with a synthetic map_seq, while bytes_received is updated with the real length:

net/mptcp/fastopen.c:mptcp_fastopen_subflow_synack_set_params() {
    ...
	MPTCP_SKB_CB(skb)->map_seq = -skb->len;
    ...
	mptcp_sk(sk)->bytes_received += skb->len;
    ...
}

At the third ACK, ack_seq moves into the key-derived sequence space. Nothing rebases the map_seq of the queued skb:

net/mptcp/subflow.c:subflow_set_remote_key() {
    ...
	WRITE_ONCE(msk->ack_seq, subflow->iasn);
    ...
}

While the TFO skb is still at the head of the queue, hint_val works out to iasn + remaining_len. The skb may be unread, or only partly read, since recvmsg only advances map_seq by the copied count. Because iasn is effectively random, this is almost always >= INT_MAX.

With this change, SIOCINQ/FIONREAD in mptcp_ioctl() returns 0 to userspace:

	*karg = mptcp_inq_hint(sk);

The TCP_CM_INQ cmsg in mptcp_recvmsg() also reports 0, including after a partial read of the TFO payload. Poll still reports EPOLLIN through mptcp_data_avail(). mptcp_rcv_space_adjust() now subtracts nothing for the queued data.

Could an application that treats "readable but 0 bytes queued" as EOF, or that stops draining on a zero INQ hint, misbehave here?

In the rare case where iasn + len is below INT_MAX, wouldn't a garbage value still be returned?

The new mptcp_inq() below already gets the right count from mptcp_data_avail(). The commit message also describes this as the way to avoid the TFO overflow. On the same socket, .peek_len would return the correct count while SIOCINQ and TCP_CM_INQ return 0.

Would it be better to compute mptcp_inq_hint() from mptcp_data_avail(), keeping the return 1 at EOF behaviour? Rebasing map_seq for the TFO skb would also work. Either seems better than clamping the overflow to 0.

[Severity: Low]
This isn't a bug, but this hunk fixes a user-visible problem in released kernels. It is bundled into a patch whose subject only mentions peek_len, and there is no Fixes: tag.

The return INT_MAX branch came from commit 2c9e77659a0c8d ("mptcp: add TCP_INQ cmsg support").

The overflow became reachable after commit f03afb3aeb9d81 ("mptcp: drop __mptcp_fastopen_gen_msk_ackseq()"). That commit stopped rebasing the map_seq of the queued TFO skb at third ACK time.

Could this be split out as a separate patch for net with:

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

That way stable could pick up the fix without the unrelated .peek_len feature. The approach would still need the change described above.

[ ... ]

Quoted 6 lines
net/mptcp/protocol.c +2 -0
@@ -4797,6 +4797,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 4818

Quoted 11 lines
net/mptcp/protocol.c +11 -0
+	avail = mptcp_data_avail(msk);
+	if (avail >= INT_MAX)
+		return 0;
+
+	return (unsigned int)avail;
+}
+
+static int mptcp_peek_len(struct socket *sock)
+{
+	return mptcp_inq(sock->sk);
+}

[Severity: Low]
Can any in-tree caller reach this callback? The only sock->ops->peek_len users appear to be the following.

drivers/vhost/net.c:sock_has_rx_data(). Its backend is limited to tun/tap and AF_PACKET sockets.

net/strparser/strparser.c:strp_peek_len(), used by KCM and sockmap. kcm_attach() rejects anything that isn't IPPROTO_TCP:

	    csk->sk_protocol != IPPROTO_TCP) {

For sockmap, MPTCP sets psock_update_sk_prot = NULL, so an MPTCP socket cannot join a sockmap.

Without a consumer it is hard to check the semantics. For example, mptcp_peek_len() does not count data still on msk->backlog_list, while the SIOCINQ path calls mptcp_move_skbs() first.

Could the commit message name the intended consumer (perhaps upcoming sockmap support)? Alternatively, could this callback be added together with that user?

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1793588257.git.tanggeliang%40kylinos.cn
author reviewer
#5 lore raw

PATCH v4 3/5 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.

This prepares for upcoming kTLS and sockmap support.

---
 net/mptcp/protocol.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
net/mptcp/protocol.c +16 -4
index c6d354900e7d..7ccb1c7506a3 100644
@@ -2038,7 +2038,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;
@@ -2046,12 +2046,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) ||
@@ -2167,7 +2167,6 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	}
 
 out:
-	release_sock(sk);
 	return copied;
 
 do_error:
@@ -2180,6 +2179,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)
@@ -4840,6 +4850,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 = {
@@ -4953,6 +4964,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
#6 lore raw

Re: [PATCH mptcp-next v4 3/5] mptcp: add sendmsg_locked to proto_ops

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's author identity (Geliang Tang <[email protected]>) does not match its only Signed-off-by (Geliang Tang…

--

mptcp: add sendmsg_locked to proto_ops

This commit splits mptcp_sendmsg() into mptcp_sendmsg_locked(), which expects the caller to already hold the msk socket lock, and a small wrapper that takes the lock around it. It also adds an msk_owned_by_me() assertion and sets .sendmsg_locked in both mptcp_stream_ops and mptcp_v6_stream_ops, as groundwork for kTLS and sockmap support.

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. The author is [email protected] and the sign-off uses [email protected].

checkpatch reports this as FROM_SIGN_OFF_MISMATCH.

The first patch in the series, "mptcp: update mptcp_check_readable", signs off with the [email protected] address, so the addresses also differ across the series.

Could a Signed-off-by with the author address be added, or the From:
line changed to match the sign-off?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1793588257.git.tanggeliang%40kylinos.cn
author reviewer
#7 lore raw

PATCH v4 4/5 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), skbs on the send queue (mptcp_send_head), or data awaiting retransmission (mptcp_rtx_head). 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.

---
 net/mptcp/protocol.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
net/mptcp/protocol.c +22 -0
index 7ccb1c7506a3..ab7de11a448c 100644
@@ -2038,6 +2038,25 @@ 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;
+
+	if (msk->write_seq != msk->snd_nxt ||
+	    mptcp_send_head(sk) || mptcp_rtx_head(sk))
+		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);
@@ -2068,6 +2087,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
#8 lore raw

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

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] mptcp: mptcp_rate_check_app_limited() bails out when data is in flight - [Medium] mptcp…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] mptcp: mptcp_rate_check_app_limited() bails out when data is in flight
- [Medium] mptcp: unlocked msk->snd_una read in mptcp_rate_check_app_limited() --

commit 6075a59b5fc2bd09596bbf554a3f811da115a224
Author: Geliang Tang <[email protected]>

mptcp: track app-limited state in mptcp_sendmsg

This commit adds mptcp_rate_check_app_limited() to run tcp_rate_check_app_limited() across all subflows from mptcp_sendmsg_locked() when no unsent data is queued at the MPTCP level.

Quoted 6 lines
net/mptcp/protocol.c +0 -0
index 7ccb1c7506a37..ab7de11a448ce 100644
@@ -2038,6 +2038,25 @@ static void mptcp_rps_record_subflows(const struct mptcp_sock *msk)
 	}

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

Quoted 10 lines
net/mptcp/protocol.c +8 -0
 }
 
+static void mptcp_rate_check_app_limited(struct sock *sk)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct mptcp_subflow_context *subflow;
+
+	if (msk->write_seq != msk->snd_nxt ||
+	    mptcp_send_head(sk) || mptcp_rtx_head(sk))
+		return;

[Severity: Medium]
Does checking mptcp_rtx_head(sk) here prevent subflows from being marked application-limited whenever any sent data is still in flight?

Every sent mptcp_data_frag stays on msk->rtx_queue until a DATA_ACK advances msk->snd_una past it and __mptcp_clean_una() removes it, so mptcp_rtx_head() returns non-NULL whenever msk->snd_una != msk->snd_nxt:

net/mptcp/protocol.h:mptcp_rtx_head() {
	struct mptcp_sock *msk = mptcp_sk(sk);

	if (msk->snd_una == msk->snd_nxt)
		return NULL;

	return list_first_entry_or_null(&msk->rtx_queue, struct mptcp_data_frag, list);
}

In contrast, tcp_rate_check_app_limited() is designed to run while packets are in flight below cwnd (tcp_packets_in_flight(tp) < tcp_snd_cwnd(tp)) and already checks tp->lost_out <= tp->retrans_out on each subflow, while MPTCP-level reinjection in __mptcp_retransmit_pending_data() resets msk->first_pending (which is covered by mptcp_send_head(sk)). With the mptcp_rtx_head(sk) check in place, won't mptcp_rate_check_app_limited() bail out whenever any unacknowledged data is in flight on the connection?

[Severity: Medium]
Additionally, is it safe to call mptcp_rtx_head(sk) from mptcp_sendmsg_locked() -> mptcp_rate_check_app_limited() without holding mptcp_data_lock(sk)?

mptcp_rtx_head() performs a plain 64-bit read of msk->snd_una, whereas incoming DATA_ACK processing in softirq context updates msk->snd_una under mptcp_data_lock(sk) even while the user owns the msk socket lock:

mptcp_incoming_options()
ack_update_msk()

    mptcp_data_lock(sk)
    __mptcp_snd_una_update()
      WRITE_ONCE(msk->snd_una, new_snd_una);

Other callers of mptcp_rtx_head() (__mptcp_clean_una(), __mptcp_retransmit_pending_data(), and __mptcp_retrans()) hold mptcp_data_lock(sk), and helpers that read msk->snd_una under only the msk socket lock use READ_ONCE(msk->snd_una). Can this cause a data race or 64-bit load tearing on 32-bit architectures?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#9 lore raw

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

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

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

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

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] mptcp_rate_check_app_limited() (net/mptcp/protocol.c:2041-2058) returns early when mptcp_rtx_head(sk)…
- [Low] The commit 'mptcp: track app-limited state in mptcp_sendmsg' lists 'Geliang Tang <[email protected]>' as Author, but its only…
- [Low] mptcp_rate_check_app_limited() calls mptcp_rtx_head(sk) while holding only the msk's owner lock (lock_sock in mptcp_sendmsg), not…

--

mptcp: track app-limited state in mptcp_sendmsg

This patch adds mptcp_rate_check_app_limited(), which runs tcp_rate_check_app_limited() on every subflow under the subflow socket lock. It returns early when MPTCP still has unsent, queued or retransmittable data. The helper is called from mptcp_sendmsg_locked() so that BBR and similar controllers can ignore app-limited rate samples.

Quoted 1 line

[Severity: Low]
This isn't a bug, but the Author line is Geliang Tang <[email protected]>, and the only Signed-off-by is <[email protected]>. No sign-off matches the From: identity, so checkpatch reports "From:/Signed-off-by: email address mismatch".

The other Geliang-authored patches in the series have the same mismatch:
"mptcp: implement peek_len for proto_ops", "mptcp: add sendmsg_locked to proto_ops" and "selftests: mptcp: sockopt: check app_limited".

Quoted 6 lines
net/mptcp/protocol.c +0 -0
index 7ccb1c7506a37..ab7de11a448ce 100644
@@ -2038,6 +2038,25 @@ static void mptcp_rps_record_subflows(const struct mptcp_sock *msk)
 	}

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

Quoted 10 lines
net/mptcp/protocol.c +8 -0
 }
 
+static void mptcp_rate_check_app_limited(struct sock *sk)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct mptcp_subflow_context *subflow;
+
+	if (msk->write_seq != msk->snd_nxt ||
+	    mptcp_send_head(sk) || mptcp_rtx_head(sk))
+		return;

[Severity: Medium]
Does the mptcp_rtx_head() check do what the commit message says? The commit message describes it as:

data awaiting retransmission (mptcp_rtx_head)

However, mptcp_rtx_head() returns non-NULL whenever any data is still unacked at the DATA level:

net/mptcp/protocol.h:mptcp_rtx_head() {
	...
	if (msk->snd_una == msk->snd_nxt)
		return NULL;

	return list_first_entry_or_null(&msk->rtx_queue, struct mptcp_data_frag, list);
}

rtx_queue holds every sent dfrag until __mptcp_clean_una() sees snd_una move past its end. So this guard returns early whenever any MPTCP-level data is in flight. Subflows only get marked when the connection is fully idle, with write_seq == snd_nxt == snd_una.

The TCP call site in tcp_sendmsg_locked() has no such gate. The wrapped tcp_rate_check_app_limited() already allows marking while packets are in flight below cwnd, and it checks lost_out <= retrans_out per subflow.

Pending reinjection also looks like it is already covered by mptcp_send_head(), because __mptcp_retransmit_pending_data() sets msk->first_pending = rtx_head.

That means the common app-limited case is never marked: an application that writes slower than the path, where each write is sent at once while earlier data is still unacked. Since snd_una only advances on DATA_ACK, an idle subflow is also not marked while another subflow has unacked data.

Those low-rate samples then reach bbr_update_bw():

	if (!rs->is_app_limited || bw >= bbr_max_bw(sk)) {
		/* Incorporate new sample into our max bw filter. */
		minmax_running_max(&bbr->bw, bbr_bw_rtts, bbr->rtt_cnt, bw);

The bandwidth estimate can then decay toward the application rate. The fully idle case, which the series selftest checks, does work. The remaining patch in the series only touches selftests, so this code is unchanged at the end of the series.

Should the mptcp_rtx_head() check be dropped, or replaced with a test for data that is actually pending retransmission? If the restriction is intended, could the commit message describe and justify it?

[Severity: Low]
Can the plain read of msk->snd_una in mptcp_rtx_head() race with ack_update_msk()? Here mptcp_rtx_head() is called with only the msk socket owned, not under mptcp_data_lock().

In softirq, ack_update_msk() takes mptcp_data_lock(sk) and updates snd_una even when the msk is owned by user:

net/mptcp/options.c:__mptcp_snd_una_update() {
	msk->bytes_acked += new_snd_una - msk->snd_una;
	WRITE_ONCE(msk->snd_una, new_snd_una);
}

Only the rtx_queue cleanup is deferred, through MPTCP_CLEAN_UNA when sock_owned_by_user(). So the list access is fine, but the snd_una comparison is not serialized.

The existing mptcp_rtx_head() callers (__mptcp_clean_una(), __mptcp_retransmit_pending_data() and __mptcp_retrans()) all hold the data lock. Other lockless snd_una readers use READ_ONCE().

KCSAN would report this race. On 32-bit, the 64-bit read could tear and give a wrong app-limited decision.

Would READ_ONCE() work here? Another option is taking mptcp_data_lock() around the check and releasing it before taking the subflow locks.

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);
+	}
+}

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1793588257.git.tanggeliang%40kylinos.cn
author reviewer
#10 lore raw

PATCH v4 5/5 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.

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 in subflow app-limited accounting.

---
 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
#11 lore raw
In reply to Geliang Tang

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): Unstable: 3 failed test(s): bpftest_test_progs-cpuv4_mptcp bpftest_test_progs-no_alu32_mptcp bpftest_test_progs_mptcp ⚠️
- KVM Validation: btf-debug (only bpftest_all): Unstable: 3 failed test(s): bpftest_test_progs-cpuv4_mptcp bpftest_test_progs-no_alu32_mptcp bpftest_test_progs_mptcp ⚠️
- Perf: Unstable: 1 failed test(s): error:sched-mem-pressure ⚠️
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/41382640238

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

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)