Skip to contentSkip to conversation

mptcp: a few fixes

PATCH Superseded Paolo Abeni 2 participants 9 messages Aug 12 – Aug 14

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.

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 | 27 ++++++++++++++++-----------
 net/mptcp/protocol.h |  1 +
 3 files changed, 19 insertions(+), 13 deletions(-)
Signature · 1 line
2.55.0
author maintainer
#3 lore raw

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

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 97da22668dbe..11bad5670d06 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 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
author maintainer
#2 lore raw

PATCH 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
#1 lore raw

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

In reply to Paolo Abeni

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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/mptcp/protocol.c +1 -1
index 68d766c0206e..f879b1061f2d 100644
@@ -289,7 +289,7 @@ 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)) ||
+	return likely(sk_rmem_alloc_get(sk) <= READ_ONCE(sk->sk_rcvbuf)) ||
 	       __mptcp_check_fallback(mptcp_sk(sk));
 }
 
Signature · 1 line
2.55.0
maintainer
#5 lore raw
In reply to Paolo Abeni

Hi Paolo,

Thank you for the fixes!

12 Aug 2026 19:08:30 Paolo Abeni <[email protected]>:

Quoted 3 lines

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.

(I hope it was OK for me to send a few small cleanup patches)

Quoted 5 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.

When reading this, it sounds like there should be 5 patches but only 4 have been shared. Just to be sure: is everything there?

Cheers,
Matt

author maintainer
#6 lore raw
Quoted 7 lines · Matthieu Baerts

12 Aug 2026 19:08:30 Paolo Abeni <[email protected]>:

Quoted 3 lines

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.

(I hope it was OK for me to send a few small cleanup patches)

ATM I haven't checked yet if you already did... but pw says ~400 patches to be processed before EoW, I would love if such count is not going to increase:)

Quoted 8 lines
Quoted 5 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.

When reading this, it sounds like there should be 5 patches but only 4 have been shared. Just to be sure: is everything there?

Yes, patch 4 == last patch.

Also patch 4 is the one I think opus 5 could raise some concern on. A safer alternative would be replacing it with the following, which is simpler, but I'm not fancy of adding another conditional.

Staging the series a little bit in the export branch will give some time to ponder about a better solution.

---

net/mptcp/protocol.c +4 -2
index ca644ec53eed..45d627981f15 100644
@@ -995,13 +995,15 @@ 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))
+	if (unlikely(inet_sk_state_load(sk) == TCP_CLOSE) ||
+	    test_bit(MPTCP_FALLBACK_DONE, msk->flags))
 		return;
 
-	tout = mptcp_sk(sk)->timer_ival;
+	tout = msk->timer_ival;
 	sk_reset_timer(sk, &sk->mptcp_retransmit_timer, jiffies + tout);
 }
 
maintainer
#7 lore raw

Hi Paolo,

Quoted 11 lines · Paolo Abeni
Quoted 7 lines · Matthieu Baerts

12 Aug 2026 19:08:30 Paolo Abeni <[email protected]>:

Quoted 3 lines

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.

(I hope it was OK for me to send a few small cleanup patches)

ATM I haven't checked yet if you already did... but pw says ~400 patches to be processed before EoW, I would love if such count is not going to increase:)

Indeed, I understand.

(If I did, can I say it was my cat walking on the keyboard? 😇 Sorry..)

Quoted 9 lines
Quoted 8 lines
Quoted 5 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.

When reading this, it sounds like there should be 5 patches but only 4 have been shared. Just to be sure: is everything there?

Yes, patch 4 == last patch.

OK, thanks!

Quoted 3 lines

Also patch 4 is the one I think opus 5 could raise some concern on. A safer alternative would be replacing it with the following, which is simpler, but I'm not fancy of adding another conditional.

Thank you!

Quoted 2 lines

Staging the series a little bit in the export branch will give some time to ponder about a better solution.

Fine for me!

Quoted 12 lines

---

net/mptcp/protocol.c +1 -0
index ca644ec53eed..45d627981f15 100644
@@ -995,13 +995,15 @@ 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;
 

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

Quoted 10 lines
net/mptcp/protocol.c +3 -2
 	/* prevent rescheduling on close */
-	if (unlikely(inet_sk_state_load(sk) == TCP_CLOSE))
+	if (unlikely(inet_sk_state_load(sk) == TCP_CLOSE) ||
+	    test_bit(MPTCP_FALLBACK_DONE, msk->flags))
 		return;
 
-	tout = mptcp_sk(sk)->timer_ival;
+	tout = msk->timer_ival;
 	sk_reset_timer(sk, &sk->mptcp_retransmit_timer, jiffies + tout);
 }

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author maintainer
#8 lore raw
In reply to Paolo Abeni
Quoted 2 lines · Paolo Abeni

Staging the series a little bit in the export branch will give some time to ponder about a better solution.

Slightly related, sashiko could not apply the patches. I'll rebase and re-send them to get such review.

/P