Skip to contentSkip to conversation

mptcp: a few fixes

PATCH RESEND In review Paolo Abeni 5 participants 13 messages Aug 14 – Aug 21

Subsystems (2)
lore
Share & tools
lore

Paolo Abeni

author maintainer
#0 lore raw

cover mptcp: a few fixes

This is mostly a follow-up to the recent OoO queue pruning series. Explicitly targeting net as we have already a lot of patches pending for net-next, and no need to rush IMHO.

First 2 patches addresses explicit comments from sashiko, 3rd one is a somewhat unrelated cleanup I stumbled upon while implementing patch 4.

The last patch fixes another thing implided by sashiko while reviewing the mentioned series.
---
resent to hopefully trigger sashiko

Paolo Abeni (4):
mptcp: being below memory limit is a likely() condition
mptcp: avoid pruning for OoW data
mptcp: remove unneeded READ_ONCE() annotation
mptcp: do not reschedule the RTX timer for fallback sockets

 net/mptcp/options.c  |  4 ++--
 net/mptcp/protocol.c | 29 +++++++++++++++++------------
 net/mptcp/protocol.h |  1 +
 3 files changed, 20 insertions(+), 14 deletions(-)
Signature · 1 line
2.55.0
author maintainer
#1 lore raw

PATCH RESEND 1/4 mptcp: being below memory limit is a likely() condition

The current compiler hint annotation is wrong, due to inverted logic in the previous revision of the relevant code.

Fixes e468d371180d ("mptcp: implemented OoO queue pruning")
---
 net/mptcp/protocol.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +2 -2
index c2762d74f29d..f879b1061f2d 100644
@@ -289,8 +289,8 @@ static void mptcp_prune_ofo_queue(struct sock *sk,
  */
 static bool mptcp_can_ingest(const struct sock *sk)
 {
-	return unlikely(sk_rmem_alloc_get(sk) <= READ_ONCE(sk->sk_rcvbuf)) ||
-			__mptcp_check_fallback(mptcp_sk(sk));
+	return likely(sk_rmem_alloc_get(sk) <= READ_ONCE(sk->sk_rcvbuf)) ||
+	       __mptcp_check_fallback(mptcp_sk(sk));
 }
 
 static bool mptcp_try_rmem_schedule(struct sock *sk, const struct sk_buff *skb)
Signature · 1 line
2.55.0
author maintainer
#2 lore raw

PATCH RESEND 2/4 mptcp: avoid pruning for OoW data

In reply to Paolo Abeni

Pruning is expansive and destructive, do it only when we expect to accept the skb triggering the cleanup.

Fixes e468d371180d ("mptcp: implemented OoO queue pruning")
---
 net/mptcp/protocol.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +6 -6
index f879b1061f2d..2ee23e9411be 100644
@@ -313,12 +313,6 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
 	u64 seq, end_seq, max_seq;
 	struct sk_buff *skb1;
 
-	if (!mptcp_try_rmem_schedule(sk, skb)) {
-		MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RCVPRUNED);
-		mptcp_drop(sk, skb);
-		return;
-	}
-
 	seq = MPTCP_SKB_CB(skb)->map_seq;
 	end_seq = MPTCP_SKB_CB(skb)->end_seq;
 	max_seq = atomic64_read(&msk->rcv_wnd_sent);
@@ -335,6 +329,12 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
 		return;
 	}
 
+	if (!mptcp_try_rmem_schedule(sk, skb)) {
+		MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RCVPRUNED);
+		mptcp_drop(sk, skb);
+		return;
+	}
+
 	p = &msk->out_of_order_queue.rb_node;
 	MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOQUEUE);
 	if (RB_EMPTY_ROOT(&msk->out_of_order_queue)) {
Signature · 1 line
2.55.0
author maintainer
#3 lore raw

PATCH RESEND 3/4 mptcp: remove unneeded READ_ONCE() annotation

In reply to Paolo Abeni

The subflow->fully_established flag is always written under the subflow socket lock. Reading such value under the same lock does not require any ONCE annotation.

Fixes 581c8cbfa934 ("mptcp: annotate data-races around subflow->fully_established")
---
 net/mptcp/options.c  | 4 ++--
 net/mptcp/protocol.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
net/mptcp/options.c +2 -2
index 1bb486daf56a..8a299a8ef5e0 100644
@@ -529,7 +529,7 @@ static bool mptcp_established_options_mp(struct sock *sk, struct sk_buff *skb,
 		return false;
 
 	/* MPC/MPJ needed only on 3rd ack packet, DATA_FIN and TCP shutdown take precedence */
-	if (READ_ONCE(subflow->fully_established) || snd_data_fin_enable ||
+	if (subflow->fully_established || snd_data_fin_enable ||
 	    subflow->snd_isn != TCP_SKB_CB(skb)->seq ||
 	    sk->sk_state != TCP_ESTABLISHED)
 		return false;
@@ -980,7 +980,7 @@ static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
 	/* here we can process OoO, in-window pkts, only in-sequence 4th ack
 	 * will make the subflow fully established
 	 */
-	if (likely(READ_ONCE(subflow->fully_established))) {
+	if (likely(subflow->fully_established)) {
 		/* on passive sockets, check for 3rd ack retransmission
 		 * note that msk is always set by subflow_syn_recv_sock()
 		 * for mp_join subflows
net/mptcp/protocol.c +1 -1
index 2ee23e9411be..b311fe30c785 100644
@@ -3912,7 +3912,7 @@ static void schedule_3rdack_retransmission(struct sock *ssk)
 	struct tcp_sock *tp = tcp_sk(ssk);
 	unsigned long timeout;
 
-	if (READ_ONCE(mptcp_subflow_ctx(ssk)->fully_established))
+	if (mptcp_subflow_ctx(ssk)->fully_established)
 		return;
 
 	/* reschedule with a timeout above RTT, as we must look only for drop */
Signature · 1 line
2.55.0
author maintainer
#4 lore raw

PATCH RESEND 4/4 mptcp: do not reschedule the RTX timer for fallback sockets

In reply to Paolo Abeni

On fallback socket the retrans timer is a quite convoluted no-op, but currently nothing prevents the MPTCP core to keep rescheduling it.

Additionally gate RTX timer reset to the msk not being fallen back to TCP yet. To avoid adding multiple tests in fast-path, use a new flags bit for such condition.

Fixes b51f9b80c032 ("mptcp: introduce MPTCP retransmission timer")

---
In fact so convoluted that sashiko thinks otherwise. Sashiko:
in case of fallback there could be a single active subflow; it can't become stale

---
 net/mptcp/protocol.c | 11 ++++++++---
 net/mptcp/protocol.h |  1 +
 2 files changed, 9 insertions(+), 3 deletions(-)
net/mptcp/protocol.c +8 -3
index b311fe30c785..f22d64ab1c53 100644
@@ -96,6 +96,7 @@ bool __mptcp_try_fallback(struct mptcp_sock *msk, int fb_mib)
 
 	msk->allow_subflows = false;
 	set_bit(MPTCP_FALLBACK_DONE, &msk->flags);
+	set_bit(MPTCP_RTX_DISABLED, &msk->flags);
 	__MPTCP_INC_STATS(net, fb_mib);
 	spin_unlock_bh(&msk->fallback_lock);
 	return true;
@@ -1121,13 +1122,14 @@ static bool mptcp_rtx_timer_pending(struct sock *sk)
 
 static void mptcp_reset_rtx_timer(struct sock *sk)
 {
+	struct mptcp_sock *msk = mptcp_sk(sk);
 	unsigned long tout;
 
-	/* prevent rescheduling on close */
-	if (unlikely(inet_sk_state_load(sk) == TCP_CLOSE))
+	/* Prevent rescheduling on close and in case of fallback. */
+	if (test_bit(MPTCP_RTX_DISABLED, &msk->flags))
 		return;
 
-	tout = mptcp_sk(sk)->timer_ival;
+	tout = msk->timer_ival;
 	sk_reset_timer(sk, &sk->mptcp_retransmit_timer, jiffies + tout);
 }
 
@@ -3360,6 +3362,9 @@ void mptcp_set_state(struct sock *sk, int state)
 		 * transition from TCP_SYN_RECV to TCP_CLOSE_WAIT.
 		 */
 		break;
+	case TCP_CLOSE:
+		set_bit(MPTCP_RTX_DISABLED, &mptcp_sk(sk)->flags);
+		fallthrough;
 	default:
 		if (oldstate == TCP_ESTABLISHED || oldstate == TCP_CLOSE_WAIT)
 			MPTCP_DEC_STATS(sock_net(sk), MPTCP_MIB_CURRESTAB);
net/mptcp/protocol.h +1 -0
index 7e168e450fb0..f9300d644ff3 100644
@@ -116,6 +116,7 @@
 #define MPTCP_WORK_RTX		1
 #define MPTCP_FALLBACK_DONE	2
 #define MPTCP_WORK_CLOSE_SUBFLOW 3
+#define MPTCP_RTX_DISABLED	4
 
 /* MPTCP socket release cb flags */
 #define MPTCP_PUSH_PENDING	1
Signature · 1 line
2.55.0
#5 lore raw

Re: [PATCH resend mptcp-net 4/4] mptcp: do not reschedule the RTX timer for fallback sockets

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] The MPTCP_RTX_DISABLED flag makes the TCP_CLOSE state sticky for the RTX timer, permanently…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The MPTCP_RTX_DISABLED flag makes the TCP_CLOSE state sticky for the RTX timer, permanently disabling retransmissions on reused connections and their accepted children. --

--- Patch [4]: [PATCH resend mptcp-net 4/4] mptcp: do not reschedule the RTX timer for fallback sockets --- commit 227375cb381dd3864273cd7170dd28e0f079ff8b
Author: Paolo Abeni <[email protected]>

mptcp: do not reschedule the RTX timer for fallback sockets

This patch introduces the MPTCP_RTX_DISABLED flag to prevent the RTX timer from being rescheduled on fallback sockets and when the socket state is TCP_CLOSE.

Quoted 4 lines
net/mptcp/protocol.c +0 -0
index b311fe30c7855..f22d64ab1c53b 100644

[ ... ]

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

Quoted 12 lines
net/mptcp/protocol.c +3 -2
@@ -1121,13 +1122,14 @@ static bool mptcp_rtx_timer_pending(struct sock *sk)
 
 static void mptcp_reset_rtx_timer(struct sock *sk)
 {
+	struct mptcp_sock *msk = mptcp_sk(sk);
 	unsigned long tout;
 
-	/* prevent rescheduling on close */
-	if (unlikely(inet_sk_state_load(sk) == TCP_CLOSE))
+	/* Prevent rescheduling on close and in case of fallback. */
+	if (test_bit(MPTCP_RTX_DISABLED, &msk->flags))
 		return;

[Severity: High]
Since this flag is checked here to prevent rescheduling, will the timer be permanently disabled if the flag is never cleared?

[ ... ]

net/mptcp/protocol.c void mptcp_set_state(struct sock *sk, int state) · line 3368

Quoted 8 lines
net/mptcp/protocol.c +3 -0
@@ -3360,6 +3362,9 @@ void mptcp_set_state(struct sock *sk, int state)
 		 * transition from TCP_SYN_RECV to TCP_CLOSE_WAIT.
 		 */
 		break;
+	case TCP_CLOSE:
+		set_bit(MPTCP_RTX_DISABLED, &mptcp_sk(sk)->flags);
+		fallthrough;
 	default:

[Severity: High]
Does setting MPTCP_RTX_DISABLED here without a corresponding clear logic make the TCP_CLOSE state sticky for the RTX timer?

If an MPTCP socket transitions to TCP_CLOSE (like a failed connect() attempt or an explicit disconnect()), and the application then reuses the socket to connect() again, it appears the flag will remain set.

Furthermore, if listen() is called on such a reused socket, would sk_clone_lock() copy the flags to all child sockets? This could cause every accepted connection to inherit the MPTCP_RTX_DISABLED flag, permanently breaking MPTCP-level retransmissions for all clients.

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

Re: [PATCH resend mptcp-net 4/4] mptcp: do not reschedule the RTX timer for fallback sockets

Quoted 50 lines · On 8/14/26 4:03 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The MPTCP_RTX_DISABLED flag makes the TCP_CLOSE state sticky for the RTX timer, permanently disabling retransmissions on reused connections and their accepted children. --

--- Patch [4]: [PATCH resend mptcp-net 4/4] mptcp: do not reschedule the RTX timer for fallback sockets --- commit 227375cb381dd3864273cd7170dd28e0f079ff8b
Author: Paolo Abeni <[email protected]>

mptcp: do not reschedule the RTX timer for fallback sockets

This patch introduces the MPTCP_RTX_DISABLED flag to prevent the RTX timer from being rescheduled on fallback sockets and when the socket state is TCP_CLOSE.

Quoted 4 lines
net/mptcp/protocol.c +0 -0
index b311fe30c7855..f22d64ab1c53b 100644

[ ... ]

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

Quoted 12 lines
net/mptcp/protocol.c +3 -2
@@ -1121,13 +1122,14 @@ static bool mptcp_rtx_timer_pending(struct sock *sk)
 
 static void mptcp_reset_rtx_timer(struct sock *sk)
 {
+	struct mptcp_sock *msk = mptcp_sk(sk);
 	unsigned long tout;
 
-	/* prevent rescheduling on close */
-	if (unlikely(inet_sk_state_load(sk) == TCP_CLOSE))
+	/* Prevent rescheduling on close and in case of fallback. */
+	if (test_bit(MPTCP_RTX_DISABLED, &msk->flags))
 		return;

[Severity: High]
Since this flag is checked here to prevent rescheduling, will the timer be permanently disabled if the flag is never cleared?

[ ... ]

net/mptcp/protocol.c void mptcp_set_state(struct sock *sk, int state) · line 3368

Quoted 8 lines
net/mptcp/protocol.c +3 -0
@@ -3360,6 +3362,9 @@ void mptcp_set_state(struct sock *sk, int state)
 		 * transition from TCP_SYN_RECV to TCP_CLOSE_WAIT.
 		 */
 		break;
+	case TCP_CLOSE:
+		set_bit(MPTCP_RTX_DISABLED, &mptcp_sk(sk)->flags);
+		fallthrough;
 	default:

[Severity: High]
Does setting MPTCP_RTX_DISABLED here without a corresponding clear logic make the TCP_CLOSE state sticky for the RTX timer?

Quoted 8 lines

If an MPTCP socket transitions to TCP_CLOSE (like a failed connect() attempt or an explicit disconnect()), and the application then reuses the socket to connect() again, it appears the flag will remain set.

Furthermore, if listen() is called on such a reused socket, would sk_clone_lock() copy the flags to all child sockets? This could cause every accepted connection to inherit the MPTCP_RTX_DISABLED flag, permanently breaking MPTCP-level retransmissions for all clients.

On nice, I did not read an hallucination this allucinated since a while...

without disconnect() a closed socket can not transition to other non closed states, because the network-level ops check the 'struct socket' state, which in turn is cleared only by disconnect().

mptcp_disconnect() explicitly clears msk->flags.

No real issues above.

/P

#7 lore raw
In reply to Paolo Abeni

Hi Paolo,

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): Unstable: 1 failed test(s): selftest_simult_flows ⚠️
- 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! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/31806665824

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

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)

maintainer Reviewed-by on the v1 series
#8 lore raw
In reply to Paolo Abeni

Hi Paolo,

Quoted 9 lines · Paolo Abeni

This is mostly a follow-up to the recent OoO queue pruning series. Explicitly targeting net as we have already a lot of patches pending for net-next, and no need to rush IMHO.

First 2 patches addresses explicit comments from sashiko, 3rd one is a somewhat unrelated cleanup I stumbled upon while implementing patch 4.

The last patch fixes another thing implided by sashiko while reviewing the mentioned series.

Thank you for this series, it looks good to me:

I will wait for the net-next → net merge to apply them to export-net.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
reviewer
#9 lore raw

Hi Matt,

Quoted 17 lines · Matthieu Baerts

Hi Paolo,

Quoted 5 lines · Paolo Abeni

This is mostly a follow-up to the recent OoO queue pruning series. Explicitly targeting net as we have already a lot of patches pending for
net-next, and no need to rush IMHO.

Quoted 8 lines

First 2 patches addresses explicit comments from sashiko, 3rd one is a
somewhat unrelated cleanup I stumbled upon while implementing patch 4.

The last patch fixes another thing implided by sashiko while reviewing
the mentioned series.

Quoted 5 lines

Thank you for this series, it looks good to me:

I will wait for the net-next → net merge to apply them to export-net.

If you have time, could you please merge this series into the export branch at your earliest convenience? My ongoing series, "Reduce the differences between TCP and MPTCP for TLS usage", conflicts with this one.

Thanks,
-Geliang

Quoted 3 lines

Cheers,
Matt

maintainer
#10 lore raw

Hi Geliang,

Quoted 22 lines · Geliang Tang

Hi Matt,

Quoted 19 lines · Matthieu Baerts

Hi Paolo,

Quoted 5 lines · Paolo Abeni

This is mostly a follow-up to the recent OoO queue pruning series. Explicitly targeting net as we have already a lot of patches pending for
net-next, and no need to rush IMHO.

Quoted 8 lines

First 2 patches addresses explicit comments from sashiko, 3rd one is a
somewhat unrelated cleanup I stumbled upon while implementing patch 4.

The last patch fixes another thing implided by sashiko while reviewing
the mentioned series.

Thank you for this series, it looks good to me:

Quoted 8 lines
Quoted 3 lines

I will wait for the net-next → net merge to apply them to export-net.

If you have time, could you please merge this series into the export branch at your earliest convenience? My ongoing series, "Reduce the differences between TCP and MPTCP for TLS usage", conflicts with this one.

If that's OK, I will wait for the Net maintainers to send their PR to Linus, which should be done in a day or two I suppose. Is that OK?

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
reviewer
#11 lore raw

Hi Matt,

Quoted 33 lines · Matthieu Baerts

Hi Geliang,

Quoted 30 lines · Geliang Tang

Hi Matt,

Quoted 26 lines · Matthieu Baerts

Hi Paolo,

Quoted 13 lines · Paolo Abeni

This is mostly a follow-up to the recent OoO queue pruning series.
Explicitly targeting net as we have already a lot of patches pending for
net-next, and no need to rush IMHO.

First 2 patches addresses explicit comments from sashiko, 3rd one
is a
somewhat unrelated cleanup I stumbled upon while implementing patch
4.

Quoted 3 lines

The last patch fixes another thing implided by sashiko while reviewing
the mentioned series.

Thank you for this series, it looks good to me:

I will wait for the net-next → net merge to apply them to export- net.

Quoted 8 lines
Quoted 6 lines

If you have time, could you please merge this series into the export
branch at your earliest convenience? My ongoing series, "Reduce the differences between TCP and MPTCP for TLS usage", conflicts with this
one.

If that's OK, I will wait for the Net maintainers to send their PR to Linus, which should be done in a day or two I suppose. Is that OK?

Yes, absolutely - that works for me. Please take your time.

Thanks,
-Geliang

Quoted 3 lines

Cheers,
Matt

maintainer
#12 lore raw
In reply to Paolo Abeni

Hi Paolo, Geliang,

Quoted 9 lines · Paolo Abeni

This is mostly a follow-up to the recent OoO queue pruning series. Explicitly targeting net as we have already a lot of patches pending for net-next, and no need to rush IMHO.

First 2 patches addresses explicit comments from sashiko, 3rd one is a somewhat unrelated cleanup I stumbled upon while implementing patch 4.

The last patch fixes another thing implided by sashiko while reviewing the mentioned series.

Now in our tree:

New patches for t/upstream-net and t/upstream:
- 6280287c0ef2: mptcp: being below memory limit is a likely() condition
- e66f97348c99: mptcp: avoid pruning for OoW data
- cdd6976ab76f: mptcp: remove unneeded READ_ONCE() annotation
- 285d84ee4b60: mptcp: do not reschedule the RTX timer for fallback sockets
- Results: 6bb246941708..70d6bffa3696 (export-net)
- Results: 2f5abecdd265..0afd98c500bf (export)

Tests are now in progress:

- export-net:
https://github.com/multipath-tcp/mptcp_net-next/commit/71a020c17359779f858419627d7933171dafee9a/checks
- export:
https://github.com/multipath-tcp/mptcp_net-next/commit/8ff26825a673fb98ff86413940a0254088cf0bd3/checks

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.