* [PATCH mptcp-net v29 1/8] mptcp: clear rcv_data_fin_seq in mptcp_disconnect
2026-11-19 5:10 [PATCH mptcp-next v29 0/8] Reduce the differences between TCP and MPTCP for TLS usage Geliang Tang
@ 2026-11-19 5:10 ` Geliang Tang
2026-11-20 18:41 ` netdev-bot+sashiko
2026-11-19 5:10 ` [PATCH mptcp-net v29 2/8] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint Geliang Tang
` (6 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Geliang Tang @ 2026-11-19 5:10 UTC (permalink / raw)
To: mptcp
From: Geliang Tang <tanggeliang@kylinos.cn>
mptcp_disconnect() resets rcv_data_fin to false but does not reset
rcv_data_fin_seq to 0. If a socket is disconnected and reused, the
stale non-zero rcv_data_fin_seq from the previous connection persists.
This can cause mptcp_pending_data_fin() to incorrectly match the old
rcv_data_fin_seq against the new connection's ack_seq, triggering a
spurious DATA_FIN processing.
Fixes: b29fcfb54cd7 ("mptcp: full disconnect implementation")
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
net/mptcp/protocol.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 01f05b3c4322..382da2532037 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -3679,6 +3679,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)
WRITE_ONCE(msk->can_ack, false);
WRITE_ONCE(msk->fully_established, false);
WRITE_ONCE(msk->rcv_data_fin, false);
+ WRITE_ONCE(msk->rcv_data_fin_seq, 0);
WRITE_ONCE(msk->snd_data_fin_enable, false);
WRITE_ONCE(msk->rcv_fastclose, false);
WRITE_ONCE(msk->use_64bit_ack, false);
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH mptcp-net v29 1/8] mptcp: clear rcv_data_fin_seq in mptcp_disconnect
2026-11-19 5:10 ` [PATCH mptcp-net v29 1/8] mptcp: clear rcv_data_fin_seq in mptcp_disconnect Geliang Tang
@ 2026-11-20 18:41 ` netdev-bot+sashiko
0 siblings, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-20 18:41 UTC (permalink / raw)
To: geliang; +Cc: mptcp, kuba
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 message describes a failure that cannot happen.
- [Low] The From and Signed-off-by addresses don't match.
--
mptcp: clear rcv_data_fin_seq in mptcp_disconnect
This commit resets msk->rcv_data_fin_seq to 0 in mptcp_disconnect(), right
after the existing rcv_data_fin reset. A disconnected and reused socket then
no longer keeps the DATA_FIN sequence from its previous connection.
> This can cause mptcp_pending_data_fin() to incorrectly match the old
> rcv_data_fin_seq against the new connection's ack_seq, triggering a
> spurious DATA_FIN processing.
[Severity: Low]
Can this sequence actually happen?
In mptcp_pending_data_fin() in net/mptcp/protocol.c, rcv_data_fin_seq is
only read after the rcv_data_fin check passes:
if (READ_ONCE(msk->rcv_data_fin) &&
((1 << inet_sk_state_load(sk)) &
(TCPF_ESTABLISHED | TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2))) {
u64 rcv_data_fin_seq = READ_ONCE(msk->rcv_data_fin_seq);
mptcp_disconnect() already clears rcv_data_fin. The only place that sets it
again is mptcp_update_rcv_data_fin() in net/mptcp/options.c. That function
writes a fresh rcv_data_fin_seq just before it sets the flag:
WRITE_ONCE(msk->rcv_data_fin_seq,
mptcp_expand_seq(READ_ONCE(msk->ack_seq), data_fin_seq, use_64bit));
WRITE_ONCE(msk->rcv_data_fin, 1);
Every caller goes through this helper: mptcp_incoming_options(),
get_mapping_status() (twice) and subflow_sched_work_if_closed(). So the
stale value seems to be overwritten every time before
mptcp_pending_data_fin() can read it.
The reset still looks necessary, but because of the next patch in the
series, "mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint". That patch adds
a reader in mptcp_inq_hint() that does not check rcv_data_fin first:
if (READ_ONCE(msk->rcv_data_fin_seq))
hint_val += 1;
Without this reset, that check would count a FIN byte after disconnect and
reuse, even though no DATA_FIN was received.
Could the commit message give that dependency as the reason instead? As
written, the Fixes: b29fcfb54cd7 tag points to a mptcp_pending_data_fin()
problem that doesn't seem to exist. That could give stable maintainers the
wrong reason and the wrong backport range.
> Fixes: b29fcfb54cd7 ("mptcp: full disconnect implementation")
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
[Severity: Low]
This isn't a bug, but the From and Signed-off-by addresses don't match. The
author is Geliang Tang <geliang@kernel.org>, while the only sign-off uses
tanggeliang@kylinos.cn. Because of this, checkpatch.pl warns with
FROM_SIGN_OFF_MISMATCH.
Other patches in the same series sign off with the kernel.org address.
Could the author be changed to the kylinos.cn address, or a Signed-off-by
with the kernel.org address be added?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795063943.git.tanggeliang%40kylinos.cn
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH mptcp-net v29 2/8] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
2026-11-19 5:10 [PATCH mptcp-next v29 0/8] Reduce the differences between TCP and MPTCP for TLS usage Geliang Tang
2026-11-19 5:10 ` [PATCH mptcp-net v29 1/8] mptcp: clear rcv_data_fin_seq in mptcp_disconnect Geliang Tang
@ 2026-11-19 5:10 ` Geliang Tang
2026-11-19 5:26 ` sashiko-bot
2026-11-20 18:41 ` netdev-bot+sashiko
2026-11-19 5:10 ` [PATCH mptcp-next v29 3/8] mptcp: drop the mptcp_ooo_try_coalesce() helper Geliang Tang
` (5 subsequent siblings)
7 siblings, 2 replies; 17+ messages in thread
From: Geliang Tang @ 2026-11-19 5:10 UTC (permalink / raw)
To: mptcp
From: Geliang Tang <tanggeliang@kylinos.cn>
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.
Without the removed __mptcp_fastopen_gen_msk_ackseq() to adjust the TFO
skb's map_seq, mptcp_inq_hint() computes "ack_seq - map_seq = iasn + len",
almost always >= INT_MAX, causing SIOCINQ/FIONREAD and TCP_CM_INQ to
report INT_MAX. This also breaks receive buffer autotuning, as
mptcp_rcv_space_adjust() uses mptcp_inq_hint() to measure consumed data.
The bogus hint prevents mptcp_rcvbuf_grow() from being called until the
entire TFO skb has been read.
Using mptcp_data_avail() avoids this by tracking bytes directly. The FIN
byte (+1) is now guarded by rcv_data_fin_seq != 0, so the hint only
counts a FIN when a DATA_FIN was actually received. Without this guard,
local shutdown(SHUT_RD) and MP_FASTCLOSE (which set RCV_SHUTDOWN or
TCP_CLOSE without a DATA_FIN) would incorrectly inflate the hint by 1.
This means with N bytes unread after DATA_FIN, both SIOCINQ and TCP_CM_INQ
report N+1 when rcv_data_fin_seq is set, or N otherwise. This differs
from TCP, which always reports N+1 after FIN because the FIN consumes a
sequence number.
Fixes: f03afb3aeb9d ("mptcp: drop __mptcp_fastopen_gen_msk_ackseq()")
Co-developed-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
net/mptcp/protocol.c | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 382da2532037..072725c6ab5d 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -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;
- if (hint_val >= INT_MAX)
- return INT_MAX;
+ if (READ_ONCE(msk->rcv_data_fin_seq))
+ hint_val += 1;
- return (unsigned int)hint_val;
- }
-
- if (sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN))
- return 1;
-
- return 0;
+ return (unsigned int)hint_val;
}
static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH mptcp-net v29 2/8] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
2026-11-19 5:10 ` [PATCH mptcp-net v29 2/8] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint Geliang Tang
@ 2026-11-19 5:26 ` sashiko-bot
2026-11-20 18:41 ` netdev-bot+sashiko
1 sibling, 0 replies; 17+ messages in thread
From: sashiko-bot @ 2026-11-19 5:26 UTC (permalink / raw)
To: Geliang Tang, mptcp
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mptcp: premature or missed FIN accounting in mptcp_inq_hint()
--
commit 6ab8c08660030a284e407817bd6afd88a1c90988
Author: Geliang Tang <geliang@kernel.org>
mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
This commit changes mptcp_inq_hint() to compute available bytes from
mptcp_data_avail() and add 1 when msk->rcv_data_fin_seq is non-zero.
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 382da25320378..072725c6ab5d1 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -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;
>
> - if (hint_val >= INT_MAX)
> - return INT_MAX;
> + if (READ_ONCE(msk->rcv_data_fin_seq))
> + hint_val += 1;
>
> - return (unsigned int)hint_val;
> - }
> -
> - if (sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN))
> - return 1;
> -
> - return 0;
> + return (unsigned int)hint_val;
> }
[Severity: Medium]
Can checking msk->rcv_data_fin_seq here add the FIN byte before the
in-order stream has reached DATA_FIN?
mptcp_update_rcv_data_fin() sets msk->rcv_data_fin_seq as soon as a
DATA_FIN option is parsed on any subflow, while mptcp_check_data_fin()
only sets RCV_SHUTDOWN once msk->ack_seq catches up to rcv_data_fin_seq.
If DATA_FIN arrives out of order across subflows while mptcp_data_avail()
is 0, SIOCINQ and TCP_CM_INQ will report 1, but a subsequent non-blocking
mptcp_recvmsg() will fail with -EAGAIN (or block) because RCV_SHUTDOWN is
not set yet.
Also, on an active connection that falls back to plain TCP before
receiving MP_CAPABLE and closes with 0 payload bytes,
subflow_sched_work_if_closed() records rcv_data_fin_seq as 0, so
READ_ONCE(msk->rcv_data_fin_seq) stays false and omits the FIN byte at
EOF.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795063943.git.tanggeliang@kylinos.cn?part=2
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: [PATCH mptcp-net v29 2/8] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
2026-11-19 5:10 ` [PATCH mptcp-net v29 2/8] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint Geliang Tang
2026-11-19 5:26 ` sashiko-bot
@ 2026-11-20 18:41 ` netdev-bot+sashiko
1 sibling, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-20 18:41 UTC (permalink / raw)
To: geliang; +Cc: mptcp, kuba
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] mptcp_inq_hint() in net/mptcp/protocol.c adds the FIN byte
whenever msk->rcv_data_fin_seq is non-zero.
- [Low] The commit message gets TCP's behavior wrong.
--
mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
This commit changes mptcp_inq_hint() to compute available bytes with
mptcp_data_avail() instead of ack_seq minus the head skb's map_seq. This
fixes the bogus INT_MAX value on passive TFO connections. It also changes
the FIN accounting so the extra byte is counted only when rcv_data_fin_seq
is non-zero.
> This means with N bytes unread after DATA_FIN, both SIOCINQ and TCP_CM_INQ
> report N+1 when rcv_data_fin_seq is set, or N otherwise. This differs
> from TCP, which always reports N+1 after FIN because the FIN consumes a
> sequence number.
[Severity: Low]
Is this description of TCP accurate for SIOCINQ?
tcp_ioctl(SIOCINQ) uses tcp_inq(), which subtracts the FIN:
include/net/tcp.h:tcp_inq() {
...
answ = tp->rcv_nxt - tp->copied_seq;
/* Subtract 1, if FIN was received */
if (answ && sock_flag(sk, SOCK_DONE))
answ--;
...
}
So TCP FIONREAD reports N after FIN, and 0 once all data has been read.
Only TCP_CM_INQ, through tcp_inq_hint(), reports N+1.
mptcp_ioctl(SIOCINQ) returns mptcp_inq_hint() directly. That means MPTCP
matches TCP for TCP_CM_INQ but is off by one for SIOCINQ, which looks like
the opposite of what the message says. The SIOCINQ off-by-one already
existed before this patch.
The message also says the guard avoids wrongly inflating the hint for
SHUT_RD and MP_FASTCLOSE. With an empty queue, though, RST, MP_FASTCLOSE
and SHUT_RD used to report 1 and now report 0.
Could the commit message describe that as a user-visible behavior change,
and correct the TCP comparison?
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 382da25320378..072725c6ab5d1 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -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;
>
> - if (hint_val >= INT_MAX)
> - return INT_MAX;
> + if (READ_ONCE(msk->rcv_data_fin_seq))
> + hint_val += 1;
[Severity: Medium]
Can this count the FIN byte before the DATA_FIN has been reached in
sequence?
rcv_data_fin_seq is written as soon as the DATA_FIN option is parsed in
subflow context:
net/mptcp/options.c:mptcp_update_rcv_data_fin() {
...
WRITE_ONCE(msk->rcv_data_fin_seq,
mptcp_expand_seq(READ_ONCE(msk->ack_seq), data_fin_seq, use_64bit));
WRITE_ONCE(msk->rcv_data_fin, 1);
...
}
Two paths reach this, and neither checks ack_seq: the zero-length DSS path
in mptcp_incoming_options(), and get_mapping_status() while a previous
mapping is still valid. The in-tree comment there says as much:
/* A DATA_FIN might arrive in a DSS
* option before the previous mapping
* has been fully consumed. Continue
* handling the existing mapping.
*/
The DATA_FIN only counts as reached later, in
mptcp_check_data_fin()->mptcp_pending_data_fin(), which requires:
if (READ_ONCE(msk->ack_seq) == rcv_data_fin_seq) {
Also, rcv_data_fin_seq is not cleared until mptcp_disconnect(). A non-zero
value therefore only means the option was parsed, not that the FIN was
reached in sequence. The commit message's "only counts a FIN when a
DATA_FIN was actually received" doesn't make that distinction.
Take two subflows where data on subflow A is delayed and a DATA_FIN-only
pure ACK arrives on subflow B. The same thing happens on a single subflow
when a data segment is lost and the next pure ACK carries the DATA_FIN.
In that state, would SIOCINQ/FIONREAD and TCP_CM_INQ report N+1 for N bytes
of in-order data? Once those bytes are drained, would they report 1, even
though recv() blocks and poll does not report the socket readable?
A similar case: get_mapping_status() parses a DATA_FIN mapping while the
owner is in recvmsg, and the data goes to the backlog. The TCP_CM_INQ cmsg
would then report N+1, which suggests EOF after N bytes, but more data
follows.
The code before this patch counted the FIN only after the in-sequence
point. It did so through the bumped ack_seq, or through
RCV_SHUTDOWN/TCP_CLOSE when the queue was empty. tcp_inq_hint() works the
same way, using rcv_nxt and SOCK_DONE:
if (inq == 0 && sock_flag(sk, SOCK_DONE))
inq = 1;
The same code is still there at the end of the series.
Would a guard such as (sk->sk_shutdown & RCV_SHUTDOWN) && rcv_data_fin_seq,
or !READ_ONCE(msk->rcv_data_fin) && rcv_data_fin_seq, better match the
point where the DATA_FIN has actually been consumed?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795063943.git.tanggeliang%40kylinos.cn
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH mptcp-next v29 3/8] mptcp: drop the mptcp_ooo_try_coalesce() helper
2026-11-19 5:10 [PATCH mptcp-next v29 0/8] Reduce the differences between TCP and MPTCP for TLS usage Geliang Tang
2026-11-19 5:10 ` [PATCH mptcp-net v29 1/8] mptcp: clear rcv_data_fin_seq in mptcp_disconnect Geliang Tang
2026-11-19 5:10 ` [PATCH mptcp-net v29 2/8] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint Geliang Tang
@ 2026-11-19 5:10 ` Geliang Tang
2026-11-19 5:10 ` [PATCH mptcp-next v29 4/8] mptcp: drop the cant_coalesce CB field Geliang Tang
` (4 subsequent siblings)
7 siblings, 0 replies; 17+ messages in thread
From: Geliang Tang @ 2026-11-19 5:10 UTC (permalink / raw)
To: mptcp
From: Paolo Abeni <pabeni@redhat.com>
It's used to save an additional comparison for in-order skbs, but is
also a barrier to remove CB offset. Remove the helper, let
__mptcp_try_coalesce() always perform the sequence check and remove
duplicate checks from the callers.
Co-developed-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
net/mptcp/protocol.c | 21 ++++++---------------
1 file changed, 6 insertions(+), 15 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 072725c6ab5d..485520a7f377 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -167,7 +167,8 @@ static bool __mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
{
int limit = READ_ONCE(sk->sk_rcvbuf);
- if (unlikely(MPTCP_SKB_CB(to)->cant_coalesce) ||
+ if (MPTCP_SKB_CB(from)->map_seq != MPTCP_SKB_CB(to)->end_seq ||
+ unlikely(MPTCP_SKB_CB(to)->cant_coalesce) ||
MPTCP_SKB_CB(from)->offset ||
((to->len + from->len) > (limit >> 3)) ||
!skb_try_coalesce(to, from, fragstolen, delta))
@@ -200,15 +201,6 @@ static bool mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
return true;
}
-static bool mptcp_ooo_try_coalesce(struct mptcp_sock *msk, struct sk_buff *to,
- struct sk_buff *from)
-{
- if (MPTCP_SKB_CB(from)->map_seq != MPTCP_SKB_CB(to)->end_seq)
- return false;
-
- return mptcp_try_coalesce((struct sock *)msk, to, from);
-}
-
/* "inspired" by tcp_rcvbuf_grow(), main difference:
* - mptcp does not maintain a msk-level window clamp
* - returns true when the receive buffer is actually updated
@@ -348,7 +340,7 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
/* with 2 subflows, adding at end of ooo queue is quite likely
* Use of ooo_last_skb avoids the O(Log(N)) rbtree lookup.
*/
- if (mptcp_ooo_try_coalesce(msk, msk->ooo_last_skb, skb)) {
+ if (mptcp_try_coalesce(sk, msk->ooo_last_skb, skb)) {
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOMERGE);
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOQUEUETAIL);
return;
@@ -394,7 +386,7 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
goto merge_right;
}
- } else if (mptcp_ooo_try_coalesce(msk, skb1, skb)) {
+ } else if (mptcp_try_coalesce(sk, skb1, skb)) {
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOMERGE);
return;
}
@@ -777,8 +769,7 @@ static void __mptcp_add_backlog(struct sock *sk,
if (!list_empty(&msk->backlog_list))
tail = list_last_entry(&msk->backlog_list, struct sk_buff, list);
- if (tail && MPTCP_SKB_CB(skb)->map_seq == MPTCP_SKB_CB(tail)->end_seq &&
- ssk == tail->sk &&
+ if (tail && ssk == tail->sk &&
__mptcp_try_coalesce(sk, tail, skb, &fragstolen, &delta)) {
skb->truesize -= delta;
kfree_skb_partial(skb, fragstolen);
@@ -902,7 +893,7 @@ static bool __mptcp_ofo_queue(struct mptcp_sock *msk)
end_seq = MPTCP_SKB_CB(skb)->end_seq;
tail = skb_peek_tail(&sk->sk_receive_queue);
- if (!tail || !mptcp_ooo_try_coalesce(msk, tail, skb)) {
+ if (!tail || !mptcp_try_coalesce(sk, tail, skb)) {
int delta = msk->ack_seq - MPTCP_SKB_CB(skb)->map_seq;
/* skip overlapping data, if any */
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH mptcp-next v29 4/8] mptcp: drop the cant_coalesce CB field
2026-11-19 5:10 [PATCH mptcp-next v29 0/8] Reduce the differences between TCP and MPTCP for TLS usage Geliang Tang
` (2 preceding siblings ...)
2026-11-19 5:10 ` [PATCH mptcp-next v29 3/8] mptcp: drop the mptcp_ooo_try_coalesce() helper Geliang Tang
@ 2026-11-19 5:10 ` Geliang Tang
2026-11-20 18:41 ` netdev-bot+sashiko
2026-11-19 5:10 ` [PATCH mptcp-next v29 5/8] mptcp: encapsulate CB DSN field access with helpers Geliang Tang
` (3 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Geliang Tang @ 2026-11-19 5:10 UTC (permalink / raw)
To: mptcp
From: Paolo Abeni <pabeni@redhat.com>
Such field is used to ensure in-sequence processing in case of fastopen.
Instead let's perform synchronization of the fastopen skb sequence
when the IASN becomes available with the 3rd ack.
When the cant_coalesce field has been introduced, commit f03afb3aeb9d
("mptcp: drop __mptcp_fastopen_gen_msk_ackseq()") noted that updating the
already queued skb for passive fastopen socket at 3rd ack time would be
difficult and race prone. The main point is that such update don't need
to be synchronously performed at 3rd ack time, but is sufficient to
perform it before the next segment is introduced into the msk.
To such extent, add __mptcp_sync_rcv_sequence() to update the TFO skb
map_seq and end_seq using the IASN stored in msk->tfo_iasn, and call it
from __mptcp_move_skb() before any new skb lands into the msk.
When the 3rd ack arrives while the msk is owned by user space, defer the
sync via MPTCP_SYNC_SEQ in cb_flags. subflow_set_remote_key() stores
tfo_iasn and either calls __mptcp_sync_rcv_sequence() directly (when the
socket is not locked) or sets MPTCP_SYNC_SEQ for deferred processing.
mptcp_move_skbs() and mptcp_release_cb() check MPTCP_SYNC_SEQ at each
iteration before spooling the backlog, using __test_and_clear_bit() since
the cb_flags are protected by the msk data lock. A rcvd_dummy_seq flag
tracks whether the TFO skb still carries the dummy mapping and needs
synchronization.
Co-developed-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
net/mptcp/fastopen.c | 6 ++++--
net/mptcp/protocol.c | 40 +++++++++++++++++++++++++++++++++++++---
net/mptcp/protocol.h | 5 ++++-
net/mptcp/subflow.c | 8 ++++++++
4 files changed, 53 insertions(+), 6 deletions(-)
diff --git a/net/mptcp/fastopen.c b/net/mptcp/fastopen.c
index f717750906ff..e18b31028e7e 100644
--- a/net/mptcp/fastopen.c
+++ b/net/mptcp/fastopen.c
@@ -9,6 +9,7 @@
void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subflow,
struct request_sock *req)
{
+ struct mptcp_sock *msk;
struct sock *sk, *ssk;
struct sk_buff *skb;
struct tcp_sock *tp;
@@ -49,15 +50,16 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subf
MPTCP_SKB_CB(skb)->end_seq = 0;
MPTCP_SKB_CB(skb)->offset = 0;
MPTCP_SKB_CB(skb)->has_rxtstamp = has_rxtstamp;
- MPTCP_SKB_CB(skb)->cant_coalesce = 1;
mptcp_data_lock(sk);
DEBUG_NET_WARN_ON_ONCE(sock_owned_by_user_nocheck(sk));
+ msk = mptcp_sk(sk);
+ msk->rcvd_dummy_seq = true;
mptcp_borrow_fwdmem(sk, skb);
skb_set_owner_r(skb, sk);
__skb_queue_tail(&sk->sk_receive_queue, skb);
- mptcp_sk(sk)->bytes_received += skb->len;
+ msk->bytes_received += skb->len;
sk->sk_data_ready(sk);
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 485520a7f377..6548f8c703d6 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -168,7 +168,6 @@ static bool __mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
int limit = READ_ONCE(sk->sk_rcvbuf);
if (MPTCP_SKB_CB(from)->map_seq != MPTCP_SKB_CB(to)->end_seq ||
- unlikely(MPTCP_SKB_CB(to)->cant_coalesce) ||
MPTCP_SKB_CB(from)->offset ||
((to->len + from->len) > (limit >> 3)) ||
!skb_try_coalesce(to, from, fragstolen, delta))
@@ -430,7 +429,6 @@ static void mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int offset,
MPTCP_SKB_CB(skb)->end_seq = MPTCP_SKB_CB(skb)->map_seq + copy_len;
MPTCP_SKB_CB(skb)->offset = offset;
MPTCP_SKB_CB(skb)->has_rxtstamp = has_rxtstamp;
- MPTCP_SKB_CB(skb)->cant_coalesce = 0;
__skb_unlink(skb, &ssk->sk_receive_queue);
@@ -438,6 +436,25 @@ static void mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int offset,
skb_dst_drop(skb);
}
+void __mptcp_sync_rcv_sequence(struct sock *sk)
+{
+ struct mptcp_sock *msk = mptcp_sk(sk);
+ struct sk_buff *skb;
+
+ if (likely(!msk->rcvd_dummy_seq))
+ return;
+
+ /* User space can have already received the TFO skb. */
+ msk->rcvd_dummy_seq = false;
+ skb = skb_peek_tail(&sk->sk_receive_queue);
+ if (!skb)
+ return;
+
+ MPTCP_SKB_CB(skb)->map_seq = msk->tfo_iasn - skb->len +
+ MPTCP_SKB_CB(skb)->offset;
+ MPTCP_SKB_CB(skb)->end_seq = msk->tfo_iasn;
+}
+
static bool __mptcp_move_skb(struct sock *sk, struct sk_buff *skb)
{
u64 copy_len = MPTCP_SKB_CB(skb)->end_seq - MPTCP_SKB_CB(skb)->map_seq;
@@ -446,6 +463,12 @@ static bool __mptcp_move_skb(struct sock *sk, struct sk_buff *skb)
mptcp_borrow_fwdmem(sk, skb);
+ /* Be sure to sync the eventual fastopen dummy mapping before any other
+ * skb lands into the msk.
+ */
+ if (unlikely(msk->rcvd_dummy_seq))
+ __mptcp_sync_rcv_sequence(sk);
+
if (MPTCP_SKB_CB(skb)->map_seq == msk->ack_seq) {
/* in sequence */
insert:
@@ -2377,7 +2400,13 @@ static bool mptcp_move_skbs(struct sock *sk)
u32 moved = 0;
mptcp_data_lock(sk);
- while (mptcp_can_spool_backlog(sk, &skbs)) {
+ while (1) {
+ if (__test_and_clear_bit(MPTCP_SYNC_SEQ, &msk->cb_flags))
+ __mptcp_sync_rcv_sequence(sk);
+
+ if (!mptcp_can_spool_backlog(sk, &skbs))
+ break;
+
mptcp_data_unlock(sk);
enqueued |= __mptcp_move_skbs(sk, &skbs, &moved);
@@ -3677,6 +3706,8 @@ static int mptcp_disconnect(struct sock *sk, int flags)
msk->bytes_retrans = 0;
msk->rcvspace_init = 0;
msk->fastclosing = 0;
+ msk->tfo_iasn = 0;
+ msk->rcvd_dummy_seq = false;
mptcp_init_rtt_est(msk);
/* for fallback's sake */
@@ -3879,6 +3910,9 @@ static void mptcp_release_cb(struct sock *sk)
struct list_head join_list, skbs;
bool spool_bl;
+ if (__test_and_clear_bit(MPTCP_SYNC_SEQ, &msk->cb_flags))
+ __mptcp_sync_rcv_sequence(sk);
+
spool_bl = mptcp_can_spool_backlog(sk, &skbs);
if (!flags && !spool_bl)
break;
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 6dc9ccf7ec7f..ee07f17eecd5 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -126,13 +126,13 @@
#define MPTCP_FLUSH_JOIN_LIST 5
#define MPTCP_SYNC_STATE 6
#define MPTCP_SYNC_SNDBUF 7
+#define MPTCP_SYNC_SEQ 8
struct mptcp_skb_cb {
u64 map_seq;
u64 end_seq;
u32 offset;
u8 has_rxtstamp;
- u8 cant_coalesce;
};
#define MPTCP_SKB_CB(__skb) ((struct mptcp_skb_cb *)&((__skb)->cb[0]))
@@ -325,6 +325,7 @@ struct mptcp_sock {
u32 last_ack_recv;
unsigned long timer_ival;
u32 token;
+ u64 tfo_iasn;
unsigned long flags;
unsigned long cb_flags;
bool recovery; /* closing subflow write queue reinjected */
@@ -336,6 +337,7 @@ struct mptcp_sock {
bool use_64bit_ack; /* Set when we received a 64-bit DSN */
bool csum_enabled;
bool allow_infinite_fallback;
+ bool rcvd_dummy_seq;
u8 pending_state; /* A subflow asked to set this sk_state,
* protected by the msk data lock
*/
@@ -1193,6 +1195,7 @@ void mptcp_event_pm_listener(const struct sock *ssk,
enum mptcp_event_type event);
bool mptcp_userspace_pm_active(const struct mptcp_sock *msk);
+void __mptcp_sync_rcv_sequence(struct sock *sk);
void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subflow,
struct request_sock *req);
int mptcp_pm_genl_fill_addr(struct sk_buff *msg,
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 6f07544bfe40..8f64a9aef2c1 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -519,6 +519,8 @@ static void subflow_set_remote_key(struct mptcp_sock *msk,
struct mptcp_subflow_context *subflow,
const struct mptcp_options_received *mp_opt)
{
+ struct sock *sk = (struct sock *)msk;
+
/* active MPC subflow will reach here multiple times:
* at subflow_finish_connect() time and at 4th ack time
*/
@@ -537,6 +539,12 @@ static void subflow_set_remote_key(struct mptcp_sock *msk,
WRITE_ONCE(msk->ack_seq, subflow->iasn);
WRITE_ONCE(msk->can_ack, true);
atomic64_set(&msk->rcv_wnd_sent, subflow->iasn);
+ msk->tfo_iasn = subflow->iasn;
+
+ if (!sock_owned_by_user(sk))
+ __mptcp_sync_rcv_sequence(sk);
+ else
+ __set_bit(MPTCP_SYNC_SEQ, &msk->cb_flags);
}
static void mptcp_propagate_state(struct sock *sk, struct sock *ssk,
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH mptcp-next v29 4/8] mptcp: drop the cant_coalesce CB field
2026-11-19 5:10 ` [PATCH mptcp-next v29 4/8] mptcp: drop the cant_coalesce CB field Geliang Tang
@ 2026-11-20 18:41 ` netdev-bot+sashiko
0 siblings, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-20 18:41 UTC (permalink / raw)
To: geliang; +Cc: mptcp, kuba
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 message for "mptcp: drop the cant_coalesce CB field"
has three problems.
--
mptcp: drop the cant_coalesce CB field
This patch removes the cant_coalesce field from struct mptcp_skb_cb. The
passive TFO skb is no longer blocked from coalescing. Instead, its map_seq
and end_seq are rewritten from the IASN (stored in msk->tfo_iasn) before
any further skb lands in the msk. When the msk is owned by user space, the
update is deferred through the new MPTCP_SYNC_SEQ cb_flags bit.
> mptcp: drop the cant_coalesce CB field
>
> Such field is used to ensure in-sequence processing in case of fastopen.
> Instead let's perform synchronization of the fastopen skb sequence
> when the IASN becomes available with the 3rd ack.
[Severity: Low]
Does this describe the removed field accurately?
Before this patch, the only reader of cant_coalesce is
__mptcp_try_coalesce() in net/mptcp/protocol.c. There it stops new data
from being merged into the passive TFO skb, which carries the dummy mapping
(map_seq = -len, end_seq = 0).
The field plays no part in the in-sequence, out-of-order or old-data
decision in __mptcp_move_skb(). That decision compares the incoming skb's
mapping against msk->ack_seq.
Commit f03afb3aeb9d ("mptcp: drop __mptcp_fastopen_gen_msk_ackseq()"),
which added the field, says it prevents "collapsing to the first skb of a
fastopen connect". Would similar wording be clearer here?
The message also doesn't give a reason for the change. struct
mptcp_skb_cb uses well under the 48 bytes of skb->cb, so space doesn't
explain it. To replace the one-byte field, the patch adds:
tfo_iasn and rcvd_dummy_seq in struct mptcp_sock
the MPTCP_SYNC_SEQ cb_flags bit
a per-skb branch in __mptcp_move_skb()
new checks in mptcp_move_skbs() and mptcp_release_cb()
If this prepares for the later "mptcp: remove CB offset field" and "mptcp:
sync mptcp skb cb layout with tcp one" patches in the series, could the
message say so?
Finally, there is a change in behaviour that the message doesn't
describe. After __mptcp_sync_rcv_sequence() sets the TFO skb's end_seq to
tfo_iasn, the next in-sequence skb (map_seq == ack_seq == iasn) passes
this check in __mptcp_try_coalesce():
if (MPTCP_SKB_CB(from)->map_seq != MPTCP_SKB_CB(to)->end_seq ||
MPTCP_SKB_CB(from)->offset ||
...
skb_try_coalesce() can then merge it into the TFO skb, which cant_coalesce
used to prevent.
The new behaviour looks correct, because tfo_iasn - len + offset keeps
map_seq - offset consistent across partial reads. Could the commit message
mention this coalescing change?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795063943.git.tanggeliang%40kylinos.cn
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH mptcp-next v29 5/8] mptcp: encapsulate CB DSN field access with helpers
2026-11-19 5:10 [PATCH mptcp-next v29 0/8] Reduce the differences between TCP and MPTCP for TLS usage Geliang Tang
` (3 preceding siblings ...)
2026-11-19 5:10 ` [PATCH mptcp-next v29 4/8] mptcp: drop the cant_coalesce CB field Geliang Tang
@ 2026-11-19 5:10 ` Geliang Tang
2026-11-20 18:41 ` netdev-bot+sashiko
2026-11-19 5:10 ` [PATCH mptcp-next v29 6/8] mptcp: remove CB offset field Geliang Tang
` (2 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Geliang Tang @ 2026-11-19 5:10 UTC (permalink / raw)
To: mptcp
From: Geliang Tang <tanggeliang@kylinos.cn>
Add mptcp_dsn() and mptcp_end_dsn() helper functions to access the DSN
(Data Sequence Number) from MPTCP skb CB. mptcp_dsn() returns the start
DSN (map_seq) and mptcp_end_dsn() returns the end DSN (end_seq).
Replace direct accesses to MPTCP_SKB_CB(skb)->map_seq and end_seq with
these helpers where appropriate. This encapsulation will make it easier
to change the CB layout in subsequent commits.
This is a pure refactoring patch with no behavior change.
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
include/trace/events/mptcp.h | 2 +-
net/mptcp/protocol.c | 37 ++++++++++++++++++------------------
net/mptcp/protocol.h | 10 ++++++++++
3 files changed, 29 insertions(+), 20 deletions(-)
diff --git a/include/trace/events/mptcp.h b/include/trace/events/mptcp.h
index c47fa2672b84..cb990186ec30 100644
--- a/include/trace/events/mptcp.h
+++ b/include/trace/events/mptcp.h
@@ -223,7 +223,7 @@ TRACE_EVENT(mptcp_rcvbuf_grow,
__entry->space = msk->rcvq_space.space;
ofo_empty = RB_EMPTY_ROOT(&msk->out_of_order_queue);
__entry->ooo_space = ofo_empty ? 0 :
- MPTCP_SKB_CB(msk->ooo_last_skb)->end_seq -
+ (u32)mptcp_end_dsn(msk->ooo_last_skb) -
msk->ack_seq;
__entry->rcvbuf = sk->sk_rcvbuf;
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 6548f8c703d6..1a5d1f97c087 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -167,7 +167,7 @@ static bool __mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
{
int limit = READ_ONCE(sk->sk_rcvbuf);
- if (MPTCP_SKB_CB(from)->map_seq != MPTCP_SKB_CB(to)->end_seq ||
+ if (MPTCP_SKB_CB(from)->map_seq != mptcp_end_dsn(to) ||
MPTCP_SKB_CB(from)->offset ||
((to->len + from->len) > (limit >> 3)) ||
!skb_try_coalesce(to, from, fragstolen, delta))
@@ -255,8 +255,7 @@ static void mptcp_prune_ofo_queue(struct sock *sk,
struct sk_buff *skb = rb_to_skb(node);
/* Stop pruning if the incoming skb would land in OoO tail. */
- if (after64(MPTCP_SKB_CB(in_skb)->map_seq,
- MPTCP_SKB_CB(skb)->map_seq))
+ if (after64(mptcp_dsn(in_skb), mptcp_dsn(skb)))
break;
pruned = true;
@@ -305,8 +304,8 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
u64 seq, end_seq, max_seq;
struct sk_buff *skb1;
- seq = MPTCP_SKB_CB(skb)->map_seq;
- end_seq = MPTCP_SKB_CB(skb)->end_seq;
+ seq = mptcp_dsn(skb);
+ end_seq = mptcp_end_dsn(skb);
max_seq = atomic64_read(&msk->rcv_wnd_sent);
pr_debug("msk=%p seq=%llx limit=%llx empty=%d\n", msk, seq, max_seq,
@@ -346,7 +345,7 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
}
/* Can avoid an rbtree lookup if we are adding skb after ooo_last_skb */
- if (!before64(seq, MPTCP_SKB_CB(msk->ooo_last_skb)->end_seq)) {
+ if (!before64(seq, mptcp_end_dsn(msk->ooo_last_skb))) {
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOQUEUETAIL);
parent = &msk->ooo_last_skb->rbnode;
p = &parent->rb_right;
@@ -358,18 +357,18 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
while (*p) {
parent = *p;
skb1 = rb_to_skb(parent);
- if (before64(seq, MPTCP_SKB_CB(skb1)->map_seq)) {
+ if (before64(seq, mptcp_dsn(skb1))) {
p = &parent->rb_left;
continue;
}
- if (before64(seq, MPTCP_SKB_CB(skb1)->end_seq)) {
- if (!after64(end_seq, MPTCP_SKB_CB(skb1)->end_seq)) {
+ if (before64(seq, mptcp_end_dsn(skb1))) {
+ if (!after64(end_seq, mptcp_end_dsn(skb1))) {
/* All the bits are present. Drop. */
mptcp_drop(sk, skb);
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
return;
}
- if (after64(seq, MPTCP_SKB_CB(skb1)->map_seq)) {
+ if (after64(seq, mptcp_dsn(skb1))) {
/* partial overlap:
* | skb |
* | skb1 |
@@ -400,7 +399,7 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
merge_right:
/* Remove other segments covered by skb. */
while ((skb1 = skb_rb_next(skb)) != NULL) {
- if (before64(end_seq, MPTCP_SKB_CB(skb1)->end_seq))
+ if (before64(end_seq, mptcp_end_dsn(skb1)))
break;
rb_erase(&skb1->rbnode, &msk->out_of_order_queue);
mptcp_drop(sk, skb1);
@@ -459,6 +458,7 @@ static bool __mptcp_move_skb(struct sock *sk, struct sk_buff *skb)
{
u64 copy_len = MPTCP_SKB_CB(skb)->end_seq - MPTCP_SKB_CB(skb)->map_seq;
struct mptcp_sock *msk = mptcp_sk(sk);
+ u64 dsn = mptcp_dsn(skb);
struct sk_buff *tail;
mptcp_borrow_fwdmem(sk, skb);
@@ -469,7 +469,7 @@ static bool __mptcp_move_skb(struct sock *sk, struct sk_buff *skb)
if (unlikely(msk->rcvd_dummy_seq))
__mptcp_sync_rcv_sequence(sk);
- if (MPTCP_SKB_CB(skb)->map_seq == msk->ack_seq) {
+ if (dsn == msk->ack_seq) {
/* in sequence */
insert:
if (!mptcp_try_rmem_schedule(sk, skb)) {
@@ -487,14 +487,14 @@ static bool __mptcp_move_skb(struct sock *sk, struct sk_buff *skb)
skb_set_owner_r(skb, sk);
__skb_queue_tail(&sk->sk_receive_queue, skb);
return true;
- } else if (after64(MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq)) {
+ } else if (after64(dsn, msk->ack_seq)) {
mptcp_data_queue_ofo(msk, skb);
return false;
}
/* Partial packet */
- if (after64(MPTCP_SKB_CB(skb)->end_seq, msk->ack_seq)) {
- copy_len = MPTCP_SKB_CB(skb)->end_seq - msk->ack_seq;
+ if (after64(mptcp_end_dsn(skb), msk->ack_seq)) {
+ copy_len = mptcp_end_dsn(skb) - msk->ack_seq;
MPTCP_SKB_CB(skb)->offset += msk->ack_seq -
MPTCP_SKB_CB(skb)->map_seq;
MPTCP_SKB_CB(skb)->map_seq += msk->ack_seq -
@@ -901,20 +901,19 @@ static bool __mptcp_ofo_queue(struct mptcp_sock *msk)
pr_debug("msk=%p empty=%d\n", msk, RB_EMPTY_ROOT(&msk->out_of_order_queue));
while (p) {
skb = rb_to_skb(p);
- if (after64(MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq))
+ if (after64(mptcp_dsn(skb), msk->ack_seq))
break;
p = rb_next(p);
rb_erase(&skb->rbnode, &msk->out_of_order_queue);
- if (unlikely(!after64(MPTCP_SKB_CB(skb)->end_seq,
- msk->ack_seq))) {
+ if (unlikely(!after64(mptcp_end_dsn(skb), msk->ack_seq))) {
mptcp_drop(sk, skb);
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
continue;
}
- end_seq = MPTCP_SKB_CB(skb)->end_seq;
+ end_seq = mptcp_end_dsn(skb);
tail = skb_peek_tail(&sk->sk_receive_queue);
if (!tail || !mptcp_try_coalesce(sk, tail, skb)) {
int delta = msk->ack_seq - MPTCP_SKB_CB(skb)->map_seq;
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index ee07f17eecd5..9f0cfda70b23 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -1385,6 +1385,16 @@ static inline bool subflow_simultaneous_connect(struct sock *sk)
return sk->sk_state == TCP_SYN_RECV && is_active_ssk(subflow);
}
+static inline u64 mptcp_end_dsn(const struct sk_buff *skb)
+{
+ return MPTCP_SKB_CB(skb)->end_seq;
+}
+
+static inline u64 mptcp_dsn(const struct sk_buff *skb)
+{
+ return MPTCP_SKB_CB(skb)->map_seq;
+}
+
#ifdef CONFIG_SYN_COOKIES
void subflow_init_req_cookie_join_save(const struct mptcp_subflow_request_sock *subflow_req,
struct sk_buff *skb);
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH mptcp-next v29 5/8] mptcp: encapsulate CB DSN field access with helpers
2026-11-19 5:10 ` [PATCH mptcp-next v29 5/8] mptcp: encapsulate CB DSN field access with helpers Geliang Tang
@ 2026-11-20 18:41 ` netdev-bot+sashiko
0 siblings, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-20 18:41 UTC (permalink / raw)
To: geliang; +Cc: mptcp, kuba
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 From:/Signed-off-by: identities don't match in commit "mptcp:
encapsulate CB DSN field access with helpers".
--
mptcp: encapsulate CB DSN field access with helpers
This commit adds the mptcp_dsn() and mptcp_end_dsn() helpers. They return
the start and end DSN from the MPTCP skb CB. Direct accesses to
MPTCP_SKB_CB(skb)->map_seq and end_seq in protocol.c and in the
mptcp_rcvbuf_grow tracepoint now go through these helpers, so the CB
layout can change in later commits.
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
[Severity: Low]
This isn't a bug, but the author address and the sign-off address don't
match. The commit author is:
Author: Geliang Tang <geliang@kernel.org>
The only trailer is:
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
No Signed-off-by uses the author address. checkpatch.pl reports this as
FROM_SIGN_OFF_MISMATCH. Documentation/process/submitting-patches.rst
expects the author to sign off.
The series isn't consistent about this either. "mptcp: remove CB offset
field" and "mptcp: sync mptcp skb cb layout with tcp one" use
Signed-off-by: Geliang Tang <geliang@kernel.org>. This patch, "mptcp:
clear rcv_data_fin_seq in mptcp_disconnect" and "mptcp: defer read_sock
cleanup to mptcp_worker" sign off only with the kylinos.cn address.
Could a Signed-off-by for the kernel.org address be added, or the From:
header be changed to the kylinos.cn address?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795063943.git.tanggeliang%40kylinos.cn
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH mptcp-next v29 6/8] mptcp: remove CB offset field
2026-11-19 5:10 [PATCH mptcp-next v29 0/8] Reduce the differences between TCP and MPTCP for TLS usage Geliang Tang
` (4 preceding siblings ...)
2026-11-19 5:10 ` [PATCH mptcp-next v29 5/8] mptcp: encapsulate CB DSN field access with helpers Geliang Tang
@ 2026-11-19 5:10 ` Geliang Tang
2026-11-20 18:41 ` netdev-bot+sashiko
2026-11-19 5:10 ` [PATCH mptcp-next v29 7/8] mptcp: sync mptcp skb cb layout with tcp one Geliang Tang
2026-11-19 5:10 ` [PATCH mptcp-next v29 8/8] mptcp: defer read_sock cleanup to mptcp_worker Geliang Tang
7 siblings, 1 reply; 17+ messages in thread
From: Geliang Tang @ 2026-11-19 5:10 UTC (permalink / raw)
To: mptcp
From: Paolo Abeni <pabeni@redhat.com>
Instead, use a new msk-level field to track the bytes already consumed
inside each skb, carrying the amount of bytes already copied to
user-space, alike what TCP is already doing.
The newly introduced 'copied_seq' field is always accessed under the msk
socket lock, delegating the synchronization with IASN to the msk release
CB, when the socket is owned by the user-space at remote key reception
time. Such synchronization preserves any partial progress (copy) made on
the TFO packet.
Note that the explicit synchronization in __mptcp_move_skb() is needed to
ensure that the TFO skb in the receive queue got its map_seq synched
before the next skb lands into the receive queue when spooling the backlog
at mptcp_release_cb() time, as the release CB synchronization will happen
later.
Prior to this patch, the TFO skb dummy mapping was always ignored, now it
affects the 'copied_seq' initial update: be sure to extend the sign
correctly of such mapping initialization time.
The end_seq field changes meaning: it now stores map_seq + copy_len
(where copy_len = skb->len - offset) rather than the end DSN. Helper
functions mptcp_dsn() and mptcp_end_dsn() are updated to compute the
actual DSN and end DSN from map_seq, end_seq and skb length.
Overall this simplifies a bit the __mptcp_recvmsg_mskq() and the
__mptcp_move_skb() code and will also make possible the next patch.
Co-developed-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
net/mptcp/fastopen.c | 5 ++-
net/mptcp/protocol.c | 102 ++++++++++++++++++++++++++-----------------
net/mptcp/protocol.h | 10 +++--
net/mptcp/subflow.c | 6 ++-
4 files changed, 76 insertions(+), 47 deletions(-)
diff --git a/net/mptcp/fastopen.c b/net/mptcp/fastopen.c
index e18b31028e7e..8dcfcff9087f 100644
--- a/net/mptcp/fastopen.c
+++ b/net/mptcp/fastopen.c
@@ -46,9 +46,9 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subf
has_rxtstamp = TCP_SKB_CB(skb)->has_rxtstamp;
/* Only the sequence delta is relevant */
- MPTCP_SKB_CB(skb)->map_seq = -skb->len;
+ MPTCP_SKB_CB(skb)->map_seq = -(u64)skb->len;
MPTCP_SKB_CB(skb)->end_seq = 0;
- MPTCP_SKB_CB(skb)->offset = 0;
+ MPTCP_SKB_CB(skb)->flags = 0;
MPTCP_SKB_CB(skb)->has_rxtstamp = has_rxtstamp;
mptcp_data_lock(sk);
@@ -56,6 +56,7 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subf
msk = mptcp_sk(sk);
msk->rcvd_dummy_seq = true;
+ msk->copied_seq = MPTCP_SKB_CB(skb)->map_seq;
mptcp_borrow_fwdmem(sk, skb);
skb_set_owner_r(skb, sk);
__skb_queue_tail(&sk->sk_receive_queue, skb);
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 1a5d1f97c087..1ed232a4e8b4 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -168,7 +168,8 @@ static bool __mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
int limit = READ_ONCE(sk->sk_rcvbuf);
if (MPTCP_SKB_CB(from)->map_seq != mptcp_end_dsn(to) ||
- MPTCP_SKB_CB(from)->offset ||
+ (MPTCP_SKB_CB(from)->flags | MPTCP_SKB_CB(to)->flags) &
+ MPTCP_SKB_CB_F_OFFSET ||
((to->len + from->len) > (limit >> 3)) ||
!skb_try_coalesce(to, from, fragstolen, delta))
return false;
@@ -424,9 +425,10 @@ static void mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int offset,
* mptcp_subflow_get_mapped_dsn() is based on the current tp->copied_seq
* value
*/
- MPTCP_SKB_CB(skb)->map_seq = mptcp_subflow_get_mapped_dsn(subflow);
+ MPTCP_SKB_CB(skb)->map_seq = mptcp_subflow_get_mapped_dsn(subflow) -
+ offset;
MPTCP_SKB_CB(skb)->end_seq = MPTCP_SKB_CB(skb)->map_seq + copy_len;
- MPTCP_SKB_CB(skb)->offset = offset;
+ MPTCP_SKB_CB(skb)->flags = offset ? MPTCP_SKB_CB_F_OFFSET : 0;
MPTCP_SKB_CB(skb)->has_rxtstamp = has_rxtstamp;
__skb_unlink(skb, &ssk->sk_receive_queue);
@@ -449,9 +451,8 @@ void __mptcp_sync_rcv_sequence(struct sock *sk)
if (!skb)
return;
- MPTCP_SKB_CB(skb)->map_seq = msk->tfo_iasn - skb->len +
- MPTCP_SKB_CB(skb)->offset;
- MPTCP_SKB_CB(skb)->end_seq = msk->tfo_iasn;
+ MPTCP_SKB_CB(skb)->map_seq = msk->tfo_iasn - skb->len;
+ MPTCP_SKB_CB(skb)->end_seq = MPTCP_SKB_CB(skb)->map_seq + skb->len;
}
static bool __mptcp_move_skb(struct sock *sk, struct sk_buff *skb)
@@ -495,10 +496,6 @@ static bool __mptcp_move_skb(struct sock *sk, struct sk_buff *skb)
/* Partial packet */
if (after64(mptcp_end_dsn(skb), msk->ack_seq)) {
copy_len = mptcp_end_dsn(skb) - msk->ack_seq;
- MPTCP_SKB_CB(skb)->offset += msk->ack_seq -
- MPTCP_SKB_CB(skb)->map_seq;
- MPTCP_SKB_CB(skb)->map_seq += msk->ack_seq -
- MPTCP_SKB_CB(skb)->map_seq;
goto insert;
}
@@ -918,12 +915,9 @@ static bool __mptcp_ofo_queue(struct mptcp_sock *msk)
if (!tail || !mptcp_try_coalesce(sk, tail, skb)) {
int delta = msk->ack_seq - MPTCP_SKB_CB(skb)->map_seq;
- /* skip overlapping data, if any */
pr_debug("uncoalesced seq=%llx ack seq=%llx delta=%d\n",
MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq,
delta);
- MPTCP_SKB_CB(skb)->offset += delta;
- MPTCP_SKB_CB(skb)->map_seq += delta;
__skb_queue_tail(&sk->sk_receive_queue, skb);
}
msk->bytes_received += end_seq - msk->ack_seq;
@@ -2208,33 +2202,39 @@ static void mptcp_eat_recv_skb(struct sock *sk, struct sk_buff *skb)
}
static int __mptcp_recvmsg_mskq(struct sock *sk, struct msghdr *msg,
- size_t len, int flags, int copied_total,
+ size_t len, int flags, u64 *seq,
struct scm_timestamping_internal *tss,
int *cmsg_flags, struct sk_buff **last)
{
struct mptcp_sock *msk = mptcp_sk(sk);
struct sk_buff *skb, *tmp;
- int total_data_len = 0;
int copied = 0;
skb_queue_walk_safe(&sk->sk_receive_queue, skb, tmp) {
- u32 delta, offset = MPTCP_SKB_CB(skb)->offset;
- u32 data_len = skb->len - offset;
+ u32 data_len;
+ u64 offset;
u32 count;
int err;
- if (flags & MSG_PEEK) {
- /* skip already peeked skbs */
- if (total_data_len + data_len <= copied_total) {
- total_data_len += data_len;
+ if (unlikely(before64(*seq, MPTCP_SKB_CB(skb)->map_seq))) {
+ *seq = mptcp_end_dsn(skb);
+ msk->bytes_consumed += skb->len;
+ if (!(flags & MSG_PEEK))
+ mptcp_eat_recv_skb(sk, skb);
+ else
*last = skb;
- continue;
- }
+ continue;
+ }
- /* skip the already peeked data in the current skb */
- delta = copied_total - total_data_len;
- offset += delta;
- data_len -= delta;
+ offset = *seq - MPTCP_SKB_CB(skb)->map_seq;
+ data_len = skb->len - offset;
+
+ if (offset >= skb->len) {
+ if (!(flags & MSG_PEEK))
+ mptcp_eat_recv_skb(sk, skb);
+ else
+ *last = skb;
+ continue;
}
count = min_t(size_t, len - copied, data_len);
@@ -2254,14 +2254,12 @@ static int __mptcp_recvmsg_mskq(struct sock *sk, struct msghdr *msg,
}
copied += count;
+ *seq += count;
if (!(flags & MSG_PEEK)) {
msk->bytes_consumed += count;
- if (count < data_len) {
- MPTCP_SKB_CB(skb)->offset += count;
- MPTCP_SKB_CB(skb)->map_seq += count;
+ if (count < data_len)
break;
- }
mptcp_eat_recv_skb(sk, skb);
} else {
@@ -2400,8 +2398,10 @@ static bool mptcp_move_skbs(struct sock *sk)
mptcp_data_lock(sk);
while (1) {
- if (__test_and_clear_bit(MPTCP_SYNC_SEQ, &msk->cb_flags))
+ if (__test_and_clear_bit(MPTCP_SYNC_SEQ, &msk->cb_flags)) {
+ msk->copied_seq += msk->tfo_iasn;
__mptcp_sync_rcv_sequence(sk);
+ }
if (!mptcp_can_spool_backlog(sk, &skbs))
break;
@@ -2440,6 +2440,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
struct mptcp_sock *msk = mptcp_sk(sk);
struct scm_timestamping_internal tss;
int copied = 0, cmsg_flags = 0;
+ u64 peek_seq, *seq;
int target;
long timeo;
@@ -2458,6 +2459,11 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
len = min_t(size_t, len, INT_MAX);
target = sock_rcvlowat(sk, flags & MSG_WAITALL, len);
+ seq = &msk->copied_seq;
+ if (flags & MSG_PEEK) {
+ peek_seq = msk->copied_seq;
+ seq = &peek_seq;
+ }
if (unlikely(msk->recvmsg_inq))
cmsg_flags = MPTCP_CMSG_INQ;
@@ -2467,7 +2473,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
int err, bytes_read;
bytes_read = __mptcp_recvmsg_mskq(sk, msg, len - copied, flags,
- copied, &tss, &cmsg_flags,
+ seq, &tss, &cmsg_flags,
&last);
if (unlikely(bytes_read < 0)) {
if (!copied)
@@ -2477,8 +2483,11 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
copied += bytes_read;
- if (!list_empty(&msk->backlog_list) && mptcp_move_skbs(sk))
+ if (!list_empty(&msk->backlog_list) && mptcp_move_skbs(sk)) {
+ if (flags & MSG_PEEK)
+ peek_seq = msk->copied_seq + copied;
continue;
+ }
/* only the MPTCP socket status is relevant here. The exit
* conditions mirror closely tcp_recvmsg()
@@ -2521,6 +2530,10 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
copied = copied ? : err;
goto out_err;
}
+
+ /* Recompute peek offset after eventual seq resync. */
+ if (flags & MSG_PEEK)
+ peek_seq = msk->copied_seq + copied;
}
mptcp_cleanup_rbuf(msk, copied);
@@ -3699,6 +3712,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)
mptcp_pm_data_reset(msk);
mptcp_ca_reset(sk);
msk->bytes_consumed = 0;
+ msk->copied_seq = 0;
msk->bytes_acked = 0;
msk->bytes_received = 0;
msk->bytes_sent = 0;
@@ -3909,8 +3923,10 @@ static void mptcp_release_cb(struct sock *sk)
struct list_head join_list, skbs;
bool spool_bl;
- if (__test_and_clear_bit(MPTCP_SYNC_SEQ, &msk->cb_flags))
+ if (__test_and_clear_bit(MPTCP_SYNC_SEQ, &msk->cb_flags)) {
+ msk->copied_seq += msk->tfo_iasn;
__mptcp_sync_rcv_sequence(sk);
+ }
spool_bl = mptcp_can_spool_backlog(sk, &skbs);
if (!flags && !spool_bl)
@@ -4631,7 +4647,15 @@ static struct sk_buff *mptcp_recv_skb(struct sock *sk, u32 *off)
mptcp_move_skbs(sk);
while ((skb = skb_peek(&sk->sk_receive_queue)) != NULL) {
- offset = MPTCP_SKB_CB(skb)->offset;
+ if (unlikely(before64(msk->copied_seq,
+ MPTCP_SKB_CB(skb)->map_seq))) {
+ msk->copied_seq = mptcp_end_dsn(skb);
+ msk->bytes_consumed += skb->len;
+ mptcp_eat_recv_skb(sk, skb);
+ continue;
+ }
+
+ offset = msk->copied_seq - MPTCP_SKB_CB(skb)->map_seq;
if (offset < skb->len) {
*off = offset;
return skb;
@@ -4673,11 +4697,9 @@ static int __mptcp_read_sock(struct sock *sk, read_descriptor_t *desc,
copied += count;
msk->bytes_consumed += count;
- if (count < data_len) {
- MPTCP_SKB_CB(skb)->offset += count;
- MPTCP_SKB_CB(skb)->map_seq += count;
+ msk->copied_seq += count;
+ if (count < data_len)
break;
- }
mptcp_eat_recv_skb(sk, skb);
if (!desc->count)
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 9f0cfda70b23..147dc209725a 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -128,10 +128,12 @@
#define MPTCP_SYNC_SNDBUF 7
#define MPTCP_SYNC_SEQ 8
+#define MPTCP_SKB_CB_F_OFFSET (TCPHDR_FLAGS_MASK + 1)
+
struct mptcp_skb_cb {
u64 map_seq;
u64 end_seq;
- u32 offset;
+ u16 flags;
u8 has_rxtstamp;
};
@@ -311,6 +313,7 @@ struct mptcp_sock {
u64 rcv_data_fin_seq;
u64 bytes_retrans;
u64 bytes_consumed;
+ u64 copied_seq;
int snd_burst;
int old_wspace;
u64 recovery_snd_nxt; /* in recovery mode accept up to this seq;
@@ -1387,12 +1390,13 @@ static inline bool subflow_simultaneous_connect(struct sock *sk)
static inline u64 mptcp_end_dsn(const struct sk_buff *skb)
{
- return MPTCP_SKB_CB(skb)->end_seq;
+ return MPTCP_SKB_CB(skb)->map_seq + skb->len;
}
static inline u64 mptcp_dsn(const struct sk_buff *skb)
{
- return MPTCP_SKB_CB(skb)->map_seq;
+ return MPTCP_SKB_CB(skb)->map_seq + skb->len -
+ (MPTCP_SKB_CB(skb)->end_seq - MPTCP_SKB_CB(skb)->map_seq);
}
#ifdef CONFIG_SYN_COOKIES
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 8f64a9aef2c1..a7e8d03452ec 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -541,10 +541,12 @@ static void subflow_set_remote_key(struct mptcp_sock *msk,
atomic64_set(&msk->rcv_wnd_sent, subflow->iasn);
msk->tfo_iasn = subflow->iasn;
- if (!sock_owned_by_user(sk))
+ if (!sock_owned_by_user(sk)) {
+ msk->copied_seq += subflow->iasn;
__mptcp_sync_rcv_sequence(sk);
- else
+ } else {
__set_bit(MPTCP_SYNC_SEQ, &msk->cb_flags);
+ }
}
static void mptcp_propagate_state(struct sock *sk, struct sock *ssk,
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH mptcp-next v29 6/8] mptcp: remove CB offset field
2026-11-19 5:10 ` [PATCH mptcp-next v29 6/8] mptcp: remove CB offset field Geliang Tang
@ 2026-11-20 18:41 ` netdev-bot+sashiko
0 siblings, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-20 18:41 UTC (permalink / raw)
To: geliang; +Cc: mptcp, kuba
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · 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] The resync skip branch this patch adds to
__mptcp_recvmsg_mskq() and mptcp_recv_skb() runs when the reader…
- [Medium] Before this patch, __mptcp_move_skb() (partial-packet path)
and __mptcp_ofo_queue() moved CB offset/map_seq up to msk->ack_seq.
- [Low] The commit message says only that the CB offset field is removed
and that end_seq changes meaning.
- [Low] The commit message justifies the explicit
__mptcp_sync_rcv_sequence() call in __mptcp_move_skb() as needed 'when…
--
mptcp: remove CB offset field
This commit drops the per-skb MPTCP CB offset field. A new msk-level
copied_seq now tracks the bytes already copied to user space, as TCP
does. end_seq now stores map_seq + copy_len, and mptcp_dsn() and
mptcp_end_dsn() derive the DSNs from map_seq, end_seq and skb->len.
> Note that the explicit synchronization in __mptcp_move_skb() is needed to
> ensure that the TFO skb in the receive queue got its map_seq synched
> before the next skb lands into the receive queue when spooling the backlog
> at mptcp_release_cb() time, as the release CB synchronization will happen
> later.
[Severity: Low]
Is this description accurate? Both mptcp_release_cb() and
mptcp_move_skbs() handle MPTCP_SYNC_SEQ at the top of every loop
iteration. That happens before mptcp_can_spool_backlog() splices the
backlog:
net/mptcp/protocol.c:mptcp_release_cb() {
...
if (__test_and_clear_bit(MPTCP_SYNC_SEQ, &msk->cb_flags)) {
msk->copied_seq += msk->tfo_iasn;
__mptcp_sync_rcv_sequence(sk);
}
spool_bl = mptcp_can_spool_backlog(sk, &skbs);
...
}
The earlier commit "mptcp: drop the cant_coalesce CB field" describes
the same ordering.
The other caller of __mptcp_move_skb() is the BH path through
__mptcp_move_skbs_from_subflow(). It only runs when the msk is not owned,
and in that case subflow_set_remote_key() has already updated copied_seq
and synced map_seq together.
So the sync in __mptcp_move_skb() seems to matter only when tfo_iasn is
0 (TFO followed by fallback before the remote key arrives). In that case
it leaves map_seq unchanged and just clears rcvd_dummy_seq.
The map_seq sync and the copied_seq += tfo_iasn update are now separate.
They stay consistent only if __mptcp_move_skb() never runs while
MPTCP_SYNC_SEQ is pending. Could the commit message state that invariant
instead?
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 1a5d1f97c0875..1ed232a4e8b4d 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -168,7 +168,8 @@ static bool __mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
> int limit = READ_ONCE(sk->sk_rcvbuf);
>
> if (MPTCP_SKB_CB(from)->map_seq != mptcp_end_dsn(to) ||
> - MPTCP_SKB_CB(from)->offset ||
> + (MPTCP_SKB_CB(from)->flags | MPTCP_SKB_CB(to)->flags) &
> + MPTCP_SKB_CB_F_OFFSET ||
> ((to->len + from->len) > (limit >> 3)) ||
> !skb_try_coalesce(to, from, fragstolen, delta))
> return false;
[Severity: Low]
This isn't a bug, but the commit message leaves out two changes. First,
offset is replaced by a new u16 flags field that carries
MPTCP_SKB_CB_F_OFFSET. Second, __mptcp_try_coalesce() now also refuses
to coalesce when the destination skb (to) has an initial offset. Before
this patch, only MPTCP_SKB_CB(from)->offset blocked coalescing.
The new restriction on to looks necessary with the new end_seq encoding.
Copying from->end_seq into a to skb that has an offset would make
mptcp_dsn(to) collapse to map_seq.
It is still a behaviour change. Skbs with an offset are common with
reinjection, where subflow_check_data_avail() discards prefixes that were
already acked. Such skbs can no longer absorb later in-sequence skbs, in
the receive queue or in the OFO queue.
Why MPTCP_SKB_CB_F_OFFSET is tied to TCPHDR_FLAGS_MASK only becomes
clear in the later commit "mptcp: sync mptcp skb cb layout with tcp
one".
Could the changelog mention the new flags field and the coalescing
change?
[ ... ]
> @@ -495,10 +496,6 @@ static bool __mptcp_move_skb(struct sock *sk, struct sk_buff *skb)
> /* Partial packet */
> if (after64(mptcp_end_dsn(skb), msk->ack_seq)) {
> copy_len = mptcp_end_dsn(skb) - msk->ack_seq;
> - MPTCP_SKB_CB(skb)->offset += msk->ack_seq -
> - MPTCP_SKB_CB(skb)->map_seq;
> - MPTCP_SKB_CB(skb)->map_seq += msk->ack_seq -
> - MPTCP_SKB_CB(skb)->map_seq;
> goto insert;
> }
[Severity: Medium]
Without this clamping, can the reader deliver a different number of
bytes than the copy_len credited to bytes_received?
Before this patch, both this partial path and __mptcp_ofo_queue() moved
offset and map_seq up to msk->ack_seq. The reader therefore delivered
exactly copy_len bytes. Now the reader computes the offset from its own
copied_seq:
offset = *seq - MPTCP_SKB_CB(skb)->map_seq;
data_len = skb->len - offset;
bytes_received, however, is still credited relative to ack_seq. The two
diverge once ack_seq moves without matching queued data. One example is
the DATA_FIN increment in mptcp_check_data_fin():
WRITE_ONCE(msk->ack_seq, msk->ack_seq + 1);
Say a peer DATA_FIN at F has been processed, so ack_seq is F+1 and the
reader's copied_seq is F. The peer then sends a 15-byte mapping starting
at F-5:
subflow_check_data_avail()
mptcp_subflow_discard_data() /* drops 6 bytes, up to ack_seq */
mptcp_init_skb() /* offset 6, map_seq F-5, copy_len 9 */
__mptcp_move_skb() /* dsn == ack_seq, bytes_received += 9 */
__mptcp_recvmsg_mskq() /* offset = F - (F-5) = 5, copies 10 */
Does the reader then give user space a byte the subflow had already
discarded as a duplicate, and add 10 to bytes_consumed? That would make
bytes_consumed larger than bytes_received and wrap the u64 subtraction
in mptcp_data_avail(). The effects would be:
- SIOCINQ and TCP_CM_INQ report INT_MAX
- rcvbuf autotuning is skipped
- EPOLLIN is always reported
- mptcp_close() does an MP_FASTCLOSE instead of a graceful close
If the peer instead sends in-sequence data at F+1, map_seq is after
copied_seq. The new resync branch in the reader then silently drops the
whole payload.
Nothing in the rx path seems to reject data after DATA_FIN.
mptcp_data_ready() only checks subflow->closing, and
__mptcp_add_backlog() only drops in TCP_CLOSE. The final patch in the
series still leaves this partial path unclamped.
[ ... ]
> @@ -2208,33 +2202,39 @@ static int __mptcp_recvmsg_mskq(struct sock *sk, struct msghdr *msg,
[ ... ]
> skb_queue_walk_safe(&sk->sk_receive_queue, skb, tmp) {
> - u32 delta, offset = MPTCP_SKB_CB(skb)->offset;
> - u32 data_len = skb->len - offset;
> + u32 data_len;
> + u64 offset;
> u32 count;
> int err;
>
> - if (flags & MSG_PEEK) {
> - /* skip already peeked skbs */
> - if (total_data_len + data_len <= copied_total) {
> - total_data_len += data_len;
> + if (unlikely(before64(*seq, MPTCP_SKB_CB(skb)->map_seq))) {
> + *seq = mptcp_end_dsn(skb);
> + msk->bytes_consumed += skb->len;
> + if (!(flags & MSG_PEEK))
> + mptcp_eat_recv_skb(sk, skb);
> + else
> *last = skb;
> - continue;
> - }
> + continue;
> + }
[Severity: Medium]
Should bytes_consumed be updated here when MSG_PEEK is set? With
MSG_PEEK the skb stays queued (*last = skb) and msk->copied_seq does not
move. The normal copy path in this same function only updates
bytes_consumed when !(flags & MSG_PEEK).
mptcp_recvmsg() also rebuilds peek_seq from copied_seq after
mptcp_move_skbs() and after sk_wait_data():
if (flags & MSG_PEEK)
peek_seq = msk->copied_seq + copied;
This throws away the jump to mptcp_end_dsn(skb) that the branch just
made, so the branch fires again for the same skb. Every later peek adds
skb->len again. So does the final real read, whether through recvmsg()
or through mptcp_recv_skb() for read_sock and splice:
net/mptcp/protocol.c:mptcp_recv_skb() {
...
if (unlikely(before64(msk->copied_seq,
MPTCP_SKB_CB(skb)->map_seq))) {
msk->copied_seq = mptcp_end_dsn(skb);
msk->bytes_consumed += skb->len;
mptcp_eat_recv_skb(sk, skb);
continue;
}
...
}
Can bytes_consumed then grow past bytes_received and wrap the u64
subtraction in mptcp_data_avail()?
return READ_ONCE(msk->bytes_received) - READ_ONCE(msk->bytes_consumed);
The branch is reachable once ack_seq is ahead of the queued data. For
example, after a DATA_FIN at F, mptcp_check_data_fin() bumps ack_seq to
F+1. If the peer then sends in-sequence data mapped at F+1,
subflow_check_data_avail() and __mptcp_add_backlog() accept it in
CLOSE_WAIT. The reader at copied_seq == F is before map_seq F+1, so it
takes the skip branch.
The consequences would be:
- mptcp_inq_hint() returns INT_MAX
- rcvbuf autotuning is skipped in mptcp_rcv_space_adjust()
- mptcp_epollin_ready() always returns true
- mptcp_close() picks MP_FASTCLOSE because of apparent unread data
The skipped payload is also dropped without a MIB counter or a warning.
The commit message does not mention this new way of dropping data.
The final patch in the series still has the unconditional
bytes_consumed += skb->len in both __mptcp_recvmsg_mskq() and
mptcp_recv_skb().
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795063943.git.tanggeliang%40kylinos.cn
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH mptcp-next v29 7/8] mptcp: sync mptcp skb cb layout with tcp one
2026-11-19 5:10 [PATCH mptcp-next v29 0/8] Reduce the differences between TCP and MPTCP for TLS usage Geliang Tang
` (5 preceding siblings ...)
2026-11-19 5:10 ` [PATCH mptcp-next v29 6/8] mptcp: remove CB offset field Geliang Tang
@ 2026-11-19 5:10 ` Geliang Tang
2026-11-19 5:43 ` sashiko-bot
2026-11-20 18:41 ` netdev-bot+sashiko
2026-11-19 5:10 ` [PATCH mptcp-next v29 8/8] mptcp: defer read_sock cleanup to mptcp_worker Geliang Tang
7 siblings, 2 replies; 17+ messages in thread
From: Geliang Tang @ 2026-11-19 5:10 UTC (permalink / raw)
To: mptcp
From: Paolo Abeni <pabeni@redhat.com>
The MPTCP protocol uses a significantly different CB layout WRT TCP, as it
includes different information and uses 64 bits for the sequence numbers.
The CB layout changes map_seq and end_seq from u64 to u32, adds a new
map_seq64 field to track the full 64-bit DSN, and aligns the existing flags
field with TCP's tcp_flags offset. Add a build time check to ensure the CB
layout matches TCP's layout for the three shared fields: map_seq, end_seq,
and flags.
The 32-bit sequence numbers are safe because the relative distances remain
small. For OFO queue skbs, sequence numbers are validated against
rcv_wnd_sent in mptcp_data_queue_ofo(), bounded by the TCP-scaled receive
window. For receive queue skbs, no window check is performed, but the
unsigned offset calculations in __mptcp_recvmsg_mskq() and mptcp_recv_skb()
are safe because copied_seq always falls inside or at the edge of the head
skb. This ensures that 32-bit arithmetic (comparisons and subtractions)
produces correct results even when 64-bit values cross the 2^32 boundary.
map_seq64 is computed as mptcp_subflow_get_mapped_dsn() in mptcp_init_skb()
minus offset, and map_seq is the lower 32 bits.
The receive path now uses 32-bit before()/after() helpers for most sequence
comparisons, while map_seq64 is used for window validation and coalescing
checks. __mptcp_try_coalesce() gains a map_seq64 contiguity check to ensure
skbs are truly adjacent in the 64-bit DSN space.
Co-developed-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
net/mptcp/fastopen.c | 5 +--
net/mptcp/protocol.c | 82 ++++++++++++++++++++++++++------------------
net/mptcp/protocol.h | 10 +++---
3 files changed, 57 insertions(+), 40 deletions(-)
diff --git a/net/mptcp/fastopen.c b/net/mptcp/fastopen.c
index 8dcfcff9087f..952f04dffc9e 100644
--- a/net/mptcp/fastopen.c
+++ b/net/mptcp/fastopen.c
@@ -46,7 +46,8 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subf
has_rxtstamp = TCP_SKB_CB(skb)->has_rxtstamp;
/* Only the sequence delta is relevant */
- MPTCP_SKB_CB(skb)->map_seq = -(u64)skb->len;
+ MPTCP_SKB_CB(skb)->map_seq64 = -(u64)skb->len;
+ MPTCP_SKB_CB(skb)->map_seq = MPTCP_SKB_CB(skb)->map_seq64;
MPTCP_SKB_CB(skb)->end_seq = 0;
MPTCP_SKB_CB(skb)->flags = 0;
MPTCP_SKB_CB(skb)->has_rxtstamp = has_rxtstamp;
@@ -56,7 +57,7 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subf
msk = mptcp_sk(sk);
msk->rcvd_dummy_seq = true;
- msk->copied_seq = MPTCP_SKB_CB(skb)->map_seq;
+ msk->copied_seq = MPTCP_SKB_CB(skb)->map_seq64;
mptcp_borrow_fwdmem(sk, skb);
skb_set_owner_r(skb, sk);
__skb_queue_tail(&sk->sk_receive_queue, skb);
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 1ed232a4e8b4..707a40850ada 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -167,14 +167,14 @@ static bool __mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
{
int limit = READ_ONCE(sk->sk_rcvbuf);
- if (MPTCP_SKB_CB(from)->map_seq != mptcp_end_dsn(to) ||
+ if (MPTCP_SKB_CB(from)->map_seq64 != mptcp_end_dsn(to) ||
(MPTCP_SKB_CB(from)->flags | MPTCP_SKB_CB(to)->flags) &
MPTCP_SKB_CB_F_OFFSET ||
((to->len + from->len) > (limit >> 3)) ||
!skb_try_coalesce(to, from, fragstolen, delta))
return false;
- pr_debug("colesced seq %llx into %llx new len %d new end seq %llx\n",
+ pr_debug("colesced seq %x into %x new len %d new end seq %x\n",
MPTCP_SKB_CB(from)->map_seq, MPTCP_SKB_CB(to)->map_seq,
to->len, MPTCP_SKB_CB(from)->end_seq);
MPTCP_SKB_CB(to)->end_seq = MPTCP_SKB_CB(from)->end_seq;
@@ -256,7 +256,7 @@ static void mptcp_prune_ofo_queue(struct sock *sk,
struct sk_buff *skb = rb_to_skb(node);
/* Stop pruning if the incoming skb would land in OoO tail. */
- if (after64(mptcp_dsn(in_skb), mptcp_dsn(skb)))
+ if (after((u32)mptcp_dsn(in_skb), (u32)mptcp_dsn(skb)))
break;
pruned = true;
@@ -302,14 +302,15 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
{
struct sock *sk = (struct sock *)msk;
struct rb_node **p, *parent;
- u64 seq, end_seq, max_seq;
+ u64 end_seq, max_seq;
struct sk_buff *skb1;
+ u32 seq;
- seq = mptcp_dsn(skb);
+ seq = (u32)mptcp_dsn(skb);
end_seq = mptcp_end_dsn(skb);
max_seq = atomic64_read(&msk->rcv_wnd_sent);
- pr_debug("msk=%p seq=%llx limit=%llx empty=%d\n", msk, seq, max_seq,
+ pr_debug("msk=%p seq=%x limit=%llx empty=%d\n", msk, seq, max_seq,
RB_EMPTY_ROOT(&msk->out_of_order_queue));
if (after64(end_seq, max_seq)) {
/* out of window */
@@ -346,7 +347,7 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
}
/* Can avoid an rbtree lookup if we are adding skb after ooo_last_skb */
- if (!before64(seq, mptcp_end_dsn(msk->ooo_last_skb))) {
+ if (!before(seq, (u32)mptcp_end_dsn(msk->ooo_last_skb))) {
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOQUEUETAIL);
parent = &msk->ooo_last_skb->rbnode;
p = &parent->rb_right;
@@ -358,18 +359,18 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
while (*p) {
parent = *p;
skb1 = rb_to_skb(parent);
- if (before64(seq, mptcp_dsn(skb1))) {
+ if (before(seq, (u32)mptcp_dsn(skb1))) {
p = &parent->rb_left;
continue;
}
- if (before64(seq, mptcp_end_dsn(skb1))) {
- if (!after64(end_seq, mptcp_end_dsn(skb1))) {
+ if (before(seq, (u32)mptcp_end_dsn(skb1))) {
+ if (!after((u32)end_seq, (u32)mptcp_end_dsn(skb1))) {
/* All the bits are present. Drop. */
mptcp_drop(sk, skb);
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
return;
}
- if (after64(seq, mptcp_dsn(skb1))) {
+ if (after(seq, (u32)mptcp_dsn(skb1))) {
/* partial overlap:
* | skb |
* | skb1 |
@@ -400,7 +401,7 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
merge_right:
/* Remove other segments covered by skb. */
while ((skb1 = skb_rb_next(skb)) != NULL) {
- if (before64(end_seq, mptcp_end_dsn(skb1)))
+ if (before((u32)end_seq, (u32)mptcp_end_dsn(skb1)))
break;
rb_erase(&skb1->rbnode, &msk->out_of_order_queue);
mptcp_drop(sk, skb1);
@@ -423,10 +424,11 @@ static void mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int offset,
/* the skb map_seq accounts for the skb offset:
* mptcp_subflow_get_mapped_dsn() is based on the current tp->copied_seq
- * value
+ * value; note that end seq number is only available in 32bits format.
*/
- MPTCP_SKB_CB(skb)->map_seq = mptcp_subflow_get_mapped_dsn(subflow) -
- offset;
+ MPTCP_SKB_CB(skb)->map_seq64 = mptcp_subflow_get_mapped_dsn(subflow) -
+ offset;
+ MPTCP_SKB_CB(skb)->map_seq = (u32)MPTCP_SKB_CB(skb)->map_seq64;
MPTCP_SKB_CB(skb)->end_seq = MPTCP_SKB_CB(skb)->map_seq + copy_len;
MPTCP_SKB_CB(skb)->flags = offset ? MPTCP_SKB_CB_F_OFFSET : 0;
MPTCP_SKB_CB(skb)->has_rxtstamp = has_rxtstamp;
@@ -451,13 +453,14 @@ void __mptcp_sync_rcv_sequence(struct sock *sk)
if (!skb)
return;
- MPTCP_SKB_CB(skb)->map_seq = msk->tfo_iasn - skb->len;
+ MPTCP_SKB_CB(skb)->map_seq64 = msk->tfo_iasn - skb->len;
+ MPTCP_SKB_CB(skb)->map_seq = (u32)MPTCP_SKB_CB(skb)->map_seq64;
MPTCP_SKB_CB(skb)->end_seq = MPTCP_SKB_CB(skb)->map_seq + skb->len;
}
static bool __mptcp_move_skb(struct sock *sk, struct sk_buff *skb)
{
- u64 copy_len = MPTCP_SKB_CB(skb)->end_seq - MPTCP_SKB_CB(skb)->map_seq;
+ u32 copy_len = MPTCP_SKB_CB(skb)->end_seq - MPTCP_SKB_CB(skb)->map_seq;
struct mptcp_sock *msk = mptcp_sk(sk);
u64 dsn = mptcp_dsn(skb);
struct sk_buff *tail;
@@ -495,7 +498,7 @@ static bool __mptcp_move_skb(struct sock *sk, struct sk_buff *skb)
/* Partial packet */
if (after64(mptcp_end_dsn(skb), msk->ack_seq)) {
- copy_len = mptcp_end_dsn(skb) - msk->ack_seq;
+ copy_len = (u32)mptcp_end_dsn(skb) - (u32)msk->ack_seq;
goto insert;
}
@@ -890,38 +893,37 @@ static bool __mptcp_ofo_queue(struct mptcp_sock *msk)
{
struct sock *sk = (struct sock *)msk;
struct sk_buff *skb, *tail;
+ u32 seq_delta, ack_seq;
bool moved = false;
struct rb_node *p;
- u64 end_seq;
p = rb_first(&msk->out_of_order_queue);
pr_debug("msk=%p empty=%d\n", msk, RB_EMPTY_ROOT(&msk->out_of_order_queue));
while (p) {
+ ack_seq = msk->ack_seq;
skb = rb_to_skb(p);
- if (after64(mptcp_dsn(skb), msk->ack_seq))
+ if (after((u32)mptcp_dsn(skb), ack_seq))
break;
p = rb_next(p);
rb_erase(&skb->rbnode, &msk->out_of_order_queue);
- if (unlikely(!after64(mptcp_end_dsn(skb), msk->ack_seq))) {
+ if (unlikely(!after((u32)mptcp_end_dsn(skb), ack_seq))) {
mptcp_drop(sk, skb);
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
continue;
}
- end_seq = mptcp_end_dsn(skb);
+ seq_delta = (u32)mptcp_end_dsn(skb) - ack_seq;
tail = skb_peek_tail(&sk->sk_receive_queue);
if (!tail || !mptcp_try_coalesce(sk, tail, skb)) {
- int delta = msk->ack_seq - MPTCP_SKB_CB(skb)->map_seq;
-
- pr_debug("uncoalesced seq=%llx ack seq=%llx delta=%d\n",
- MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq,
- delta);
+ pr_debug("uncoalesced seq=%x ack seq=%x delta=%d\n",
+ MPTCP_SKB_CB(skb)->map_seq, ack_seq,
+ ack_seq - MPTCP_SKB_CB(skb)->map_seq);
__skb_queue_tail(&sk->sk_receive_queue, skb);
}
- msk->bytes_received += end_seq - msk->ack_seq;
- WRITE_ONCE(msk->ack_seq, end_seq);
+ msk->bytes_received += seq_delta;
+ WRITE_ONCE(msk->ack_seq, msk->ack_seq + seq_delta);
moved = true;
}
return moved;
@@ -2212,11 +2214,11 @@ static int __mptcp_recvmsg_mskq(struct sock *sk, struct msghdr *msg,
skb_queue_walk_safe(&sk->sk_receive_queue, skb, tmp) {
u32 data_len;
- u64 offset;
+ u32 offset;
u32 count;
int err;
- if (unlikely(before64(*seq, MPTCP_SKB_CB(skb)->map_seq))) {
+ if (unlikely(before64(*seq, MPTCP_SKB_CB(skb)->map_seq64))) {
*seq = mptcp_end_dsn(skb);
msk->bytes_consumed += skb->len;
if (!(flags & MSG_PEEK))
@@ -2226,7 +2228,7 @@ static int __mptcp_recvmsg_mskq(struct sock *sk, struct msghdr *msg,
continue;
}
- offset = *seq - MPTCP_SKB_CB(skb)->map_seq;
+ offset = (u32)(*seq) - MPTCP_SKB_CB(skb)->map_seq;
data_len = skb->len - offset;
if (offset >= skb->len) {
@@ -4648,14 +4650,14 @@ static struct sk_buff *mptcp_recv_skb(struct sock *sk, u32 *off)
while ((skb = skb_peek(&sk->sk_receive_queue)) != NULL) {
if (unlikely(before64(msk->copied_seq,
- MPTCP_SKB_CB(skb)->map_seq))) {
+ MPTCP_SKB_CB(skb)->map_seq64))) {
msk->copied_seq = mptcp_end_dsn(skb);
msk->bytes_consumed += skb->len;
mptcp_eat_recv_skb(sk, skb);
continue;
}
- offset = msk->copied_seq - MPTCP_SKB_CB(skb)->map_seq;
+ offset = (u32)msk->copied_seq - MPTCP_SKB_CB(skb)->map_seq;
if (offset < skb->len) {
*off = offset;
return skb;
@@ -4905,11 +4907,23 @@ static int mptcp_napi_poll(struct napi_struct *napi, int budget)
return work_done;
}
+#define CHK_CB_FIELD(mptcp_field, tcp_field) \
+ ({ \
+ BUILD_BUG_ON(offsetof(struct mptcp_skb_cb, mptcp_field) != \
+ offsetof(struct tcp_skb_cb, tcp_field)); \
+ BUILD_BUG_ON(offsetofend(struct mptcp_skb_cb, mptcp_field) != \
+ offsetofend(struct tcp_skb_cb, tcp_field)); \
+ })
+
void __init mptcp_proto_init(void)
{
struct mptcp_delegated_action *delegated;
int cpu;
+ CHK_CB_FIELD(map_seq, seq);
+ CHK_CB_FIELD(end_seq, end_seq);
+ CHK_CB_FIELD(flags, tcp_flags);
+
mptcp_prot.h.hashinfo = tcp_prot.h.hashinfo;
if (percpu_counter_init(&mptcp_sockets_allocated, 0, GFP_KERNEL))
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 147dc209725a..1dbd84270b45 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -131,10 +131,12 @@
#define MPTCP_SKB_CB_F_OFFSET (TCPHDR_FLAGS_MASK + 1)
struct mptcp_skb_cb {
- u64 map_seq;
- u64 end_seq;
+ u32 map_seq;
+ u32 end_seq;
+ u32 unused;
u16 flags;
u8 has_rxtstamp;
+ u64 map_seq64;
};
#define MPTCP_SKB_CB(__skb) ((struct mptcp_skb_cb *)&((__skb)->cb[0]))
@@ -1390,12 +1392,12 @@ static inline bool subflow_simultaneous_connect(struct sock *sk)
static inline u64 mptcp_end_dsn(const struct sk_buff *skb)
{
- return MPTCP_SKB_CB(skb)->map_seq + skb->len;
+ return MPTCP_SKB_CB(skb)->map_seq64 + skb->len;
}
static inline u64 mptcp_dsn(const struct sk_buff *skb)
{
- return MPTCP_SKB_CB(skb)->map_seq + skb->len -
+ return MPTCP_SKB_CB(skb)->map_seq64 + skb->len -
(MPTCP_SKB_CB(skb)->end_seq - MPTCP_SKB_CB(skb)->map_seq);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH mptcp-next v29 7/8] mptcp: sync mptcp skb cb layout with tcp one
2026-11-19 5:10 ` [PATCH mptcp-next v29 7/8] mptcp: sync mptcp skb cb layout with tcp one Geliang Tang
@ 2026-11-19 5:43 ` sashiko-bot
2026-11-20 18:41 ` netdev-bot+sashiko
1 sibling, 0 replies; 17+ messages in thread
From: sashiko-bot @ 2026-11-19 5:43 UTC (permalink / raw)
To: Geliang Tang, mptcp
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mptcp: broken post-DATA_FIN skb handling in
__mptcp_recvmsg_mskq() and mptcp_recv_skb()
--
commit 620e51c1f06b815c8d3a402589fa67b46d950125
Author: Paolo Abeni <pabeni@redhat.com>
mptcp: sync mptcp skb cb layout with tcp one
This commit aligns struct mptcp_skb_cb with struct tcp_skb_cb by shrinking
map_seq and end_seq to u32, adding a 64-bit map_seq64 field, and switching
most receive-path sequence comparisons to 32-bit helpers.
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 1ed232a4e8b4d..707a40850ada5 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
[ ... ]
> @@ -423,10 +424,11 @@ static void mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int offset,
>
> /* the skb map_seq accounts for the skb offset:
> * mptcp_subflow_get_mapped_dsn() is based on the current tp->copied_seq
> - * value
> + * value; note that end seq number is only available in 32bits format.
> */
> - MPTCP_SKB_CB(skb)->map_seq = mptcp_subflow_get_mapped_dsn(subflow) -
> - offset;
> + MPTCP_SKB_CB(skb)->map_seq64 = mptcp_subflow_get_mapped_dsn(subflow) -
> + offset;
> + MPTCP_SKB_CB(skb)->map_seq = (u32)MPTCP_SKB_CB(skb)->map_seq64;
> MPTCP_SKB_CB(skb)->end_seq = MPTCP_SKB_CB(skb)->map_seq + copy_len;
> MPTCP_SKB_CB(skb)->flags = offset ? MPTCP_SKB_CB_F_OFFSET : 0;
> MPTCP_SKB_CB(skb)->has_rxtstamp = has_rxtstamp;
[ ... ]
> @@ -2212,11 +2214,11 @@ static int __mptcp_recvmsg_mskq(struct sock *sk, struct msghdr *msg,
>
> skb_queue_walk_safe(&sk->sk_receive_queue, skb, tmp) {
> u32 data_len;
> - u64 offset;
> + u32 offset;
> u32 count;
> int err;
>
> - if (unlikely(before64(*seq, MPTCP_SKB_CB(skb)->map_seq))) {
> + if (unlikely(before64(*seq, MPTCP_SKB_CB(skb)->map_seq64))) {
> *seq = mptcp_end_dsn(skb);
> msk->bytes_consumed += skb->len;
> if (!(flags & MSG_PEEK))
> @@ -2226,7 +2228,7 @@ static int __mptcp_recvmsg_mskq(struct sock *sk, struct msghdr *msg,
> continue;
> }
>
> - offset = *seq - MPTCP_SKB_CB(skb)->map_seq;
> + offset = (u32)(*seq) - MPTCP_SKB_CB(skb)->map_seq;
> data_len = skb->len - offset;
>
> if (offset >= skb->len) {
[Severity: Medium]
Can testing before64(*seq, MPTCP_SKB_CB(skb)->map_seq64) in
__mptcp_recvmsg_mskq() and mptcp_recv_skb() fail to drop post-DATA_FIN
skbs and deliver garbage or post-FIN bytes to userspace?
When mptcp_check_data_fin() processes a DATA_FIN at rcv_data_fin_seq, it
advances msk->ack_seq to rcv_data_fin_seq + 1 while msk->copied_seq stops
at rcv_data_fin_seq. __mptcp_move_skb() and __mptcp_ofo_queue() still
accept segments at dsn == rcv_data_fin_seq + 1 into sk_receive_queue, and
the before64(*seq, map_seq64) branch is meant to discard them.
Because mptcp_init_skb() sets map_seq64 to dsn - offset, a post-DATA_FIN
segment with a non-zero subflow offset (offset >= 1) has
map_seq64 == rcv_data_fin_seq + 1 - offset <= *seq. before64(*seq,
map_seq64) is then false, and (u32)(*seq) - map_seq evaluates to
offset - 1 < skb->len. __mptcp_recvmsg_mskq() and mptcp_recv_skb() copy
the discarded prefix byte plus copy_len post-DATA_FIN bytes to userspace
and add copy_len + 1 to msk->bytes_consumed (while msk->bytes_received was
only incremented by copy_len), underflowing mptcp_data_avail(msk).
Even when offset is 0, the discard branch sets *seq = mptcp_end_dsn(skb),
so a second post-DATA_FIN skb queued right after the first has
map_seq64 == *seq and is delivered to userspace instead of being dropped.
In __mptcp_recvmsg_mskq(), that branch also adds skb->len to
msk->bytes_consumed even when MSG_PEEK is set or when copy_len < skb->len.
Finally, if an out-of-order segment at rcv_data_fin_seq arrives before
DATA_FIN, __mptcp_ofo_queue() advances msk->ack_seq past rcv_data_fin_seq
before mptcp_pending_data_fin() runs, preventing DATA_FIN processing; and
if a post-DATA_FIN skb arrives after EOF has been read,
mptcp_data_avail(msk) becomes non-zero at close() and triggers
MP_FASTCLOSE.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795063943.git.tanggeliang@kylinos.cn?part=7
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: [PATCH mptcp-next v29 7/8] mptcp: sync mptcp skb cb layout with tcp one
2026-11-19 5:10 ` [PATCH mptcp-next v29 7/8] mptcp: sync mptcp skb cb layout with tcp one Geliang Tang
2026-11-19 5:43 ` sashiko-bot
@ 2026-11-20 18:41 ` netdev-bot+sashiko
1 sibling, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-20 18:41 UTC (permalink / raw)
To: geliang; +Cc: mptcp, kuba
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · 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).
- [High] A remote MPTCP peer can bypass the receive-window check and
desync the msk receive state.
- [Low] The commit message for "mptcp: sync mptcp skb cb layout with tcp
one" says what changes but not why.
--
mptcp: sync mptcp skb cb layout with tcp one
This commit changes the MPTCP skb control block so that map_seq, end_seq
and flags line up with the matching fields of struct tcp_skb_cb. It adds a
separate map_seq64 field that holds the full 64-bit DSN, converts most
receive path sequence comparisons to the 32-bit before()/after() helpers,
and adds a build time check for the shared field layout.
> The MPTCP protocol uses a significantly different CB layout WRT TCP, as it
> includes different information and uses 64 bits for the sequence numbers.
[ ... ]
> The receive path now uses 32-bit before()/after() helpers for most sequence
> comparisons, while map_seq64 is used for window validation and coalescing
> checks. __mptcp_try_coalesce() gains a map_seq64 contiguity check to ensure
> skbs are truly adjacent in the 64-bit DSN space.
[Severity: Low]
This isn't a bug, but could the commit message explain why the layout
needs to match the TCP one?
In net/mptcp, every TCP_SKB_CB() access is on subflow or TX skbs, and that
is still true at the end of the series. Nothing in tree reads msk receive
queue skbs through TCP_SKB_CB(). The only hint is in the next patch's
message ("groundwork for the upcoming MPTCP TLS series").
The change does have a cost. The DSN is now stored twice, and every writer
has to keep map_seq = (u32)map_seq64 in sync by hand. That happens in
mptcp_init_skb(), __mptcp_sync_rcv_sequence() and
mptcp_fastopen_subflow_synack_set_params(). Several receive path
comparisons also become 32-bit, and their safety depends on the window
bound discussed below.
Also, is the "gains a map_seq64 contiguity check" wording accurate? The
pre-patch __mptcp_try_coalesce() already had the same 64-bit test, because
map_seq was u64:
if (MPTCP_SKB_CB(from)->map_seq != mptcp_end_dsn(to) ||
This patch only renames the field to map_seq64.
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 1ed232a4e8b4d..707a40850ada5 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
[ ... ]
> @@ -302,14 +302,15 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
> {
> struct sock *sk = (struct sock *)msk;
> struct rb_node **p, *parent;
> - u64 seq, end_seq, max_seq;
> + u64 end_seq, max_seq;
> struct sk_buff *skb1;
> + u32 seq;
>
> - seq = mptcp_dsn(skb);
> + seq = (u32)mptcp_dsn(skb);
> end_seq = mptcp_end_dsn(skb);
> max_seq = atomic64_read(&msk->rcv_wnd_sent);
>
> - pr_debug("msk=%p seq=%llx limit=%llx empty=%d\n", msk, seq, max_seq,
> + pr_debug("msk=%p seq=%x limit=%llx empty=%d\n", msk, seq, max_seq,
> RB_EMPTY_ROOT(&msk->out_of_order_queue));
> if (after64(end_seq, max_seq)) {
> /* out of window */
[Severity: High]
Now that the code after this point uses 32-bit comparisons, can a remote
peer get past this window check?
The commit message says "For OFO queue skbs, sequence numbers are
validated against rcv_wnd_sent in mptcp_data_queue_ofo()". That
validation is a single signed 64-bit comparison, and it wraps for DSNs
about 2^63 ahead of ack_seq.
The peer controls the DSN. With dsn64=1, get_mapping_status() uses it
unchanged:
net/mptcp/subflow.c:get_mapping_status() {
...
map_seq = mptcp_expand_seq(READ_ONCE(msk->ack_seq), mpext->data_seq, mpext->dsn64);
...
}
subflow_check_data_avail() only rejects before64(ack_seq, old_ack), so
there is no upper bound.
Let A = msk->ack_seq, W = rcv_wnd_sent - A, and c = the skb payload
length. Say the peer sends a mapping with DSN = A + 2^63 - k, where
1 <= k < c - W:
__mptcp_move_skb()
after64(dsn, msk->ack_seq) is true
-> mptcp_data_queue_ofo()
(s64)(max_seq - end_seq) == (s64)(2^63 - (c - W - k)) > 0
so the after64(end_seq, max_seq) drop is skipped
seq = (u32)mptcp_dsn(skb) == (u32)A - k
2^63 is 0 mod 2^32, so in 32-bit space the skb now looks k bytes behind
ack_seq. __mptcp_ofo_queue() then promotes it:
if (after((u32)mptcp_dsn(skb), ack_seq)) /* false */
break;
...
if (unlikely(!after((u32)mptcp_end_dsn(skb), ack_seq))) /* false */
...
seq_delta = (u32)mptcp_end_dsn(skb) - ack_seq; /* c - k */
The skb is appended to sk_receive_queue. It can't coalesce because the
map_seq64 values differ. Both ack_seq and bytes_received advance by c - k.
__mptcp_recvmsg_mskq() then does this, and mptcp_recv_skb() does the same:
if (unlikely(before64(*seq, MPTCP_SKB_CB(skb)->map_seq64))) {
*seq = mptcp_end_dsn(skb);
msk->bytes_consumed += skb->len;
copied_seq jumps to about A + 2^63, and bytes_consumed grows by c, which
is k more than was received.
The next legitimate skb, at DSN A + c - k, then gives
copied_seq - map_seq64 == 2^63. That skb is also skipped and its data is
silently dropped.
After that, bytes_consumed stays k above bytes_received, so
mptcp_data_avail() underflows:
return READ_ONCE(msk->bytes_received) - READ_ONCE(msk->bytes_consumed);
Wouldn't that cause the following?
- mptcp_epollin_ready() and mptcp_check_readable() report EPOLLIN while
the receive queue is empty, so poll users busy-loop.
- mptcp_inq_hint() returns INT_MAX for SIOCINQ and TCP_CM_INQ, and the
bad value also feeds receive-buffer autotuning.
- mptcp_close() takes the fastclose path.
The 32-bit overlap checks later in mptcp_data_queue_ofo(), including the
merge_right loop, can also drop legitimate in-window OFO segments as
DUPDATA.
Before this patch, the after64(mptcp_dsn(skb), msk->ack_seq) test in
__mptcp_ofo_queue() kept such an skb in the OFO tree, so it never reached
the receive queue.
The next patch in the series ("mptcp: defer read_sock cleanup to
mptcp_worker") doesn't touch this code, so the problem seems to remain at
the end of the series.
Could the DSN be bounded in full 64-bit terms before the 32-bit
arithmetic is relied on? For example, the skb could be rejected when the
unsigned distance end_seq - ack_seq is larger than max_seq - ack_seq.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795063943.git.tanggeliang%40kylinos.cn
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH mptcp-next v29 8/8] mptcp: defer read_sock cleanup to mptcp_worker
2026-11-19 5:10 [PATCH mptcp-next v29 0/8] Reduce the differences between TCP and MPTCP for TLS usage Geliang Tang
` (6 preceding siblings ...)
2026-11-19 5:10 ` [PATCH mptcp-next v29 7/8] mptcp: sync mptcp skb cb layout with tcp one Geliang Tang
@ 2026-11-19 5:10 ` Geliang Tang
7 siblings, 0 replies; 17+ messages in thread
From: Geliang Tang @ 2026-11-19 5:10 UTC (permalink / raw)
To: mptcp
From: Geliang Tang <tanggeliang@kylinos.cn>
This patch prepares __mptcp_read_sock() for future MPTCP TLS support,
where it may be reached from BH context. In that case, calling
mptcp_rcv_space_adjust() and mptcp_cleanup_rbuf() is not safe as both
expect process context.
Conditionally defer cleanup to mptcp_worker(): when the caller doesn't
own the socket lock (BH context), accumulate consumed bytes in
msk->read_copied and signal the worker through MPTCP_WORK_READ_COMPLETE.
When the caller owns the lock (process context), perform inline cleanup
to avoid delaying window updates and autotuning.
The existing backlog flush in mptcp_recv_skb() is now gated on
sock_owned_by_user(). This ensures process context callers flush the
backlog before processing skbs, while future BH context callers skip it.
The reason is that BH callers would already hold the msk spinlock, so
mptcp_data_lock() inside mptcp_move_skbs() would self-deadlock.
Initialize msk->read_copied in __mptcp_init_sock() and reset it in
mptcp_disconnect().
Note: The BH call path does not exist in the current tree. This is
groundwork for the upcoming MPTCP TLS series. Currently, the only
in-tree caller is mptcp_splice_read(), which holds lock_sock() and runs
in process context.
Suggested-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
net/mptcp/protocol.c | 38 +++++++++++++++++++++++++++++++++-----
net/mptcp/protocol.h | 2 ++
2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 707a40850ada..a4d82841a0ff 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -3157,6 +3157,21 @@ static void mptcp_backlog_purge(struct sock *sk)
sk_mem_reclaim(sk);
}
+static void mptcp_read_complete(struct sock *sk)
+{
+ struct mptcp_sock *msk = mptcp_sk(sk);
+ u32 read_copied;
+
+ mptcp_data_lock(sk);
+ read_copied = msk->read_copied;
+ msk->read_copied = 0;
+ mptcp_data_unlock(sk);
+
+ mptcp_rcv_space_adjust(msk, read_copied);
+ if (read_copied > 0)
+ mptcp_cleanup_rbuf(msk, read_copied);
+}
+
static void mptcp_do_fastclose(struct sock *sk)
{
struct mptcp_subflow_context *subflow, *tmp;
@@ -3232,6 +3247,9 @@ static void mptcp_worker(struct work_struct *work)
if (test_and_clear_bit(MPTCP_WORK_RTX, &msk->flags))
__mptcp_retrans(sk);
+ if (test_and_clear_bit(MPTCP_WORK_READ_COMPLETE, &msk->flags))
+ mptcp_read_complete(sk);
+
fail_tout = msk->first ? READ_ONCE(mptcp_subflow_ctx(msk->first)->fail_tout) : 0;
if (fail_tout && time_after(jiffies, fail_tout))
mptcp_mp_fail_no_response(msk);
@@ -3275,6 +3293,7 @@ static void __mptcp_init_sock(struct sock *sk)
msk->last_data_sent = tcp_jiffies32;
msk->last_data_recv = tcp_jiffies32;
msk->last_ack_recv = tcp_jiffies32;
+ msk->read_copied = 0;
mptcp_pm_data_init(msk);
spin_lock_init(&msk->fallback_lock);
@@ -3723,6 +3742,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)
msk->fastclosing = 0;
msk->tfo_iasn = 0;
msk->rcvd_dummy_seq = false;
+ msk->read_copied = 0;
mptcp_init_rtt_est(msk);
/* for fallback's sake */
@@ -4645,7 +4665,7 @@ static struct sk_buff *mptcp_recv_skb(struct sock *sk, u32 *off)
struct sk_buff *skb;
u32 offset;
- if (!list_empty(&msk->backlog_list))
+ if (sock_owned_by_user(sk) && !list_empty(&msk->backlog_list))
mptcp_move_skbs(sk);
while ((skb = skb_peek(&sk->sk_receive_queue)) != NULL) {
@@ -4670,6 +4690,7 @@ static struct sk_buff *mptcp_recv_skb(struct sock *sk, u32 *off)
/*
* Note:
* - It is assumed that the socket was locked by the caller.
+ * - Can be invoked in BH scope.
*/
static int __mptcp_read_sock(struct sock *sk, read_descriptor_t *desc,
sk_read_actor_t recv_actor, bool noack)
@@ -4711,11 +4732,18 @@ static int __mptcp_read_sock(struct sock *sk, read_descriptor_t *desc,
if (noack)
goto out;
- mptcp_rcv_space_adjust(msk, copied);
-
if (copied > 0) {
- mptcp_recv_skb(sk, &offset);
- mptcp_cleanup_rbuf(msk, copied);
+ if (sock_owned_by_user(sk)) {
+ /* Process context: inline cleanup */
+ mptcp_rcv_space_adjust(msk, copied);
+ mptcp_recv_skb(sk, &offset);
+ mptcp_cleanup_rbuf(msk, copied);
+ } else {
+ /* BH context: defer to worker */
+ msk->read_copied += copied;
+ set_bit(MPTCP_WORK_READ_COMPLETE, &msk->flags);
+ mptcp_schedule_work(sk);
+ }
}
out:
return copied;
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 1dbd84270b45..febec1269d2c 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -117,6 +117,7 @@
#define MPTCP_FALLBACK_DONE 2
#define MPTCP_WORK_CLOSE_SUBFLOW 3
#define MPTCP_RTX_ENABLED 4
+#define MPTCP_WORK_READ_COMPLETE 5
/* MPTCP socket release cb flags */
#define MPTCP_PUSH_PENDING 1
@@ -328,6 +329,7 @@ struct mptcp_sock {
u32 last_data_sent;
u32 last_data_recv;
u32 last_ack_recv;
+ u32 read_copied;
unsigned long timer_ival;
u32 token;
u64 tfo_iasn;
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread