From nobody Mon Nov 23 20:26:59 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794563934; b=0twcolQrATr+/3FshXWaZ3nOk4OTx//b7PXguEow3Hczo+Jg56NvuEDwlY1JfRj8zybH hINyOVMkjY86+nNE8YqXeFd0nBrsnDRObadHZungd7K264h74dHcCDsk7/0kpJ7nZj3eG xEi7/NfMQjByyJajeS4H1pe+/LfJxdzLoKNPDykys+GliuldEN2cf4CDsfb9EJ6NcSC0G 87AFO0H3sYaa5xZA1Z2hXZY5cwhuw0z7mxJYZxtfi+6wEWHBlC2g3aIOJcxPE+ClZv9bM 99PRuQEMVlbJq2nncA/ekh+A7Zx5xJEK3gDbr7lZ01TACqSqG0gPGk9/dQSLV4nNcMg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794563934; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=OPjoxduqZzmd7ahkHmj7hjSn658/nJ6CC+7kI5cnp5o=; b=fnlGEzx0cW+TOyzpYcypEHWfDApWJO039xpArSTCHo2N+JlVvCDmAkw934XvUIT2pGr0 DoarohFJoxkYmtAuyTR+3r152OqAypoCWjvdofGED76Axr1+2FlmlFysRS53W+PQYsAAJ UlOJMBYNJRHfcB1n8RPiDOnPs8tbDAXUUDhzbP2z254mkvysFg3FTo+czroA9jAynu1GN l+MCLdA0f/UkXW+ng27EvYEspisacfWrcPmWBp7nSxQP/aUkMwtq3CQ6bw7Qhu9+j1jpH PipiXekHrs/NGoYdv1cC+d+/zxjiBFLZofxqs7OP3squkuxEqW0laa5PcjR0Z4yxXuA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=J8QHw8y+; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7FFD606A323 for ; Fri, 13 Nov 2026 09:58:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=J8QHw8y+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 014161F000C5 for ; Fri, 13 Nov 2026 09:58:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794563934; bh=OPjoxduqZzmd7ahkHmj7hjSn658/nJ6CC+7kI5cnp5o=; h=From:To:Subject:Date:In-Reply-To:References; b=J8QHw8y+GWAVQsnP6NI4JsTleEqqDjWBZOnZz2WkmMhrkLWshibKeG3nS1MK7LLh/ zttr0MF/6n/mEKubqcSmlXHTmcIyR5WushaSbKS5nbkFuMxo6J4XF/BaXn7tYddkvw npN7ZGpSdDKwFWNMpuag9jMlcNIL03oWWj0URXce6bi3On4YaAZOOD/S24mwBRYiU+ kI1XXERzw2lscmjBjpdGnXcwK8C0sQ+ipV0hM0eLeX/73oMEpTxpZLH2ycsRen9nXy OBVizDoz9Q/E+6zqIXxlJzaG11WmyQy3jVxqDr/qSq3uED6etipmJfzGyuTXMWhcjy 7LmCSJ26eN82w== From: Geliang Tang To: mptcp@lists.linux.dev Subject: [PATCH mptcp-net v26 1/8] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint Date: Fri, 13 Nov 2026 17:58:40 +0800 Message-ID: X-Mailer: git-send-email 2.55.0 In-Reply-To: References: X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang 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 =3D iasn + len", almost always >=3D 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. This change also affects non-TFO connections after DATA_FIN: with N bytes unread, both SIOCINQ and TCP_CM_INQ now report N instead of N+1. This differs from TCP, which reports N+1 because the FIN consumes a sequence number. The EOF hint of 1 is preserved for the empty-queue case when the socket is closed or shutdown. Fixes: f03afb3aeb9d ("mptcp: drop __mptcp_fastopen_gen_msk_ackseq()") Co-developed-by: Paolo Abeni Signed-off-by: Paolo Abeni Signed-off-by: Geliang Tang --- net/mptcp/protocol.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 50de5cedfd0f..f2644e7a6a05 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -2404,22 +2404,16 @@ static bool mptcp_move_skbs(struct sock *sk) static unsigned int mptcp_inq_hint(const struct sock *sk) { const struct mptcp_sock *msk =3D mptcp_sk(sk); - const struct sk_buff *skb; + u64 hint_val =3D mptcp_data_avail(msk); =20 - skb =3D skb_peek(&sk->sk_receive_queue); - if (skb) { - u64 hint_val =3D READ_ONCE(msk->ack_seq) - MPTCP_SKB_CB(skb)->map_seq; + if (hint_val >=3D INT_MAX) + return INT_MAX; =20 - if (hint_val >=3D INT_MAX) - return INT_MAX; - - return (unsigned int)hint_val; - } - - if (sk->sk_state =3D=3D TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN)) + if (!hint_val && + (sk->sk_state =3D=3D TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN))) return 1; =20 - return 0; + return (unsigned int)hint_val; } =20 static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, --=20 2.55.0 From nobody Mon Nov 23 20:26:59 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794563936; b=BwAkUfp/RM7nu1YcPuqdyenGyF3BKMV7f0dMcwpqXVPJSUpNGZTqj19h5PNJ+l/AUfFy 7rhQ7mtWrm6V/OliL5VoDd6ndTYEUYRtgkRoprqVUQP8irFqw9qzxPXoTiuq6pweCNkr7 h4SpXbirqXNZF/tOc+USbjyWHcSQVL8KjS8KqmaJm4N12PhGRMr8lch+jbp4XOPpofKG+ /RCAFSVgq0qNWNbcvAv+R31UJ8RbEi72nRrnVxTN8IrFhFFZoMaecqgYFchkwC8CdPRQt sCXtHjTySTZN3M5npkRitdLY6W8pupMNLnG3INEyfS6UtyuFSYQfo41U/PfIVRhS/Dw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794563936; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=xE4S3cTlve8RX7XJCkdjvgdnj0+PjTmwVj3DJPkuYJE=; b=fhSxKp8GMJ18vAGewafYyEfZyWFlVP1bOS+lnC1aPVlLXM/AHx+qHozeYqcKLDdlxV2G VIdKvE2pQlTa9c1bFBIq9Wy/hXz7Ffn0wF8Gl+jGAgMdDh2woozE61TRwOXJIOhKrt81A tQ01sahMd1THaBMAVF7Qig6DxrbeBKZ9girRVL9T1ksLNjwyDOT04isO9atw1s131Q6+p BEtg8PFRt7JjO2v0e1+qIi5R8rbfe+U/Lo8lyuh4TN736VZbKxaii03nvE7mbuPaMzFuG AZHJAHfUSVBJS/QV54YzCmzzGDR5kuUbzEP/g30EmWFValnvK/aJtOcvPiAOsdMJk1Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QdpzuzM0; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF3DF606A32A for ; Fri, 13 Nov 2026 09:58:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QdpzuzM0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C3E81F000C5 for ; Fri, 13 Nov 2026 09:58:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794563936; bh=xE4S3cTlve8RX7XJCkdjvgdnj0+PjTmwVj3DJPkuYJE=; h=From:To:Subject:Date:In-Reply-To:References; b=QdpzuzM0D4QPsIN41p6eLKPHkQmpY4H9KO/AylGcNPlXKdP2rXFxMra5Nnaumkc5Y Cb8zVJdLzLr+BewosFywPC1rRJIvzg0YZn+b6Y3CkhTpbNWKfdywDwT40HrDfpu19o NlVN8Dac9fy8KfcotXavOfFuE+gB4L7lMrgII88XxJj7FgNkt1RkAxrULgLOGu/TlC z1+cO6evS0NE10+IK/LwN6+rba4b81Q8ZmKQnSV6h0fd6iy8uEM55ngY0opmN9cC8J Y/s0cxTEaBc6QYZADW5itcUnKYSMMcRExoGQSWLiq4eyX9PErTZKyJUK6y7mFCU6Gt 94jCIkdx6U4Eg== From: Geliang Tang To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next v26 2/8] selftests: mptcp: connect: check TFO SIOCINQ overflow Date: Fri, 13 Nov 2026 17:58:41 +0800 Message-ID: <4b9d85bac42429d8d566497d0f8f2c76ebb7e663.1794563432.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.55.0 In-Reply-To: References: X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Add a SIOCINQ check in mptcp_connect's server mode when the MPTFO socket option is enabled to detect TFO SIOCINQ overflow regressions. When a TFO connection is accepted, the test waits for the MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED flag using poll(), ensuring the third ACK has been processed. Using poll() instead of usleep() allows immediate detection of dead connections via POLLHUP/POLLERR, preventing infinite loops when the connection is reset or the client exits early. The wait is bounded by poll_timeout (default 10s). It then checks if SIOCINQ returns INT_MAX, which would indicate the regression where mptcp_inq_hint() incorrectly returns INT_MAX for passive TFO connections. Add SOL_MPTCP fallback definition for compatibility with older libc headers. Handle ENOPROTOOPT and EOPNOTSUPP errors from getsockopt() to skip the wait for TCP sockets or MPTCP sockets that fell back to TCP. Print a warning if the remote key does not arrive within the timeout, but continue with the SIOCINQ check rather than failing the test. Signed-off-by: Geliang Tang --- .../selftests/net/mptcp/mptcp_connect.c | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/test= ing/selftests/net/mptcp/mptcp_connect.c index 178d98d91fea..152976d39d46 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c @@ -34,6 +34,7 @@ #include #include #include +#include =20 extern int optind; =20 @@ -43,6 +44,9 @@ extern int optind; #ifndef TCP_ULP #define TCP_ULP 31 #endif +#ifndef SOL_MPTCP +#define SOL_MPTCP 284 +#endif =20 static int poll_timeout =3D 10 * 1000; static bool listen_mode; @@ -1176,6 +1180,47 @@ static void maybe_close(int fd) close(fd); } =20 +static int wait_for_remote_key(int fd) +{ + struct mptcp_info info; + int timeout_ms =3D 10; + struct pollfd pfd; + int elapsed =3D 0; + socklen_t olen; + int ret; + + pfd.fd =3D fd; + pfd.events =3D 0; + + while (elapsed < poll_timeout || poll_timeout < 0) { + ret =3D poll(&pfd, 1, timeout_ms); + if (ret < 0) { + perror("TFO: poll"); + return -1; + } + + if (pfd.revents & (POLLHUP | POLLERR)) { + fprintf(stderr, "TFO: connection closed or reset\n"); + return -1; + } + + olen =3D sizeof(info); + if (getsockopt(fd, SOL_MPTCP, MPTCP_INFO, &info, &olen) < 0) { + /* Not an MPTCP socket (TCP or fallback), skip wait */ + if (errno =3D=3D ENOPROTOOPT || errno =3D=3D EOPNOTSUPP) + return 0; + perror("TFO: getsockopt(MPTCP_INFO)"); + return -1; + } + if (info.mptcpi_flags & MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED) + return 0; + + elapsed +=3D timeout_ms; + } + fprintf(stderr, "TFO: timeout waiting for remote key\n"); + return 0; +} + int main_loop_s(int listensock) { struct sockaddr_storage ss; @@ -1207,6 +1252,22 @@ int main_loop_s(int listensock) check_sockaddr(pf, &ss, salen); check_getpeername(remotesock, &ss, salen); =20 + if (cfg_sockopt_types.mptfo) { + int avail; + + if (wait_for_remote_key(remotesock) < 0) { + close(remotesock); + return 1; + } + + if (ioctl(remotesock, SIOCINQ, &avail) =3D=3D 0 && + avail =3D=3D INT_MAX) { + fprintf(stderr, "TFO SIOCINQ overflow\n"); + close(remotesock); + return 1; + } + } + if (cfg_input) { fd =3D open(cfg_input, O_RDONLY); if (fd < 0) --=20 2.55.0 From nobody Mon Nov 23 20:26:59 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794563937; b=YysNqfm5j+sOuFssezjvWHgE2OY4ec843UfVoSabXg/bCYksoFrevfOCSvxMTDG4jBUa ZTCfmLuTqAE9qU0L3zVeuBVm839sOtAPDQEbsQkYGaVey+km4sbrnX3Lgl/5CYeQ7bPFw JCV6vWZ5lo2repCosEdwc6S5s1T2Ds/SWNwEu4LHD85pJJ1FJhcuKrp8j8tQJezcjBiao WKcDpTlbKcIifFpHQQN0EVyxvYzREb1XtY9+KunAXJqKkeRstqKspmXqSHYBkTrlpJbv1 iZ4un7i+IW3r4K0FnpLIgKuoDl+65hxbtPKe9MHbTOV/9EWJe2OIn4y3PxezsO3bcSQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794563937; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=K0ucOvjIjrcBa4o4gYqu3rYj0YatnSeO8vFYHsOpG+k=; b=q5fXJ4w+LVcXlj9LtoAI8giE2jsXT/gU+zb90+kDLIdrKK448EQs0MQQrGU1W4/J3Ppg DNR0mfULRDOlDjoodmvum6ZgsuQlES6bz4bMYlwaY145psk9zI3xX4+FjyZNt6ct+fqT4 cvC4dBk6GYDGxoD/oVSek/biZoBbNzYEB/xvi4T96UkvRn9bUpp4q97gkXFphDk+S3JT4 H0NJaHy0jgcNG/4hQg7oI/O97E6t1VCRESuwENmawJzN6q7CFBpSk7fVOiGFirIu06vyp 8WbxTmtDeYQR8tvSIiF779zEqy6tOHd+kcFS9ogWk9uZLf3nentuxV3H4zhnF+HtuYg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AxINSliE; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1FC5606A323 for ; Fri, 13 Nov 2026 09:58:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AxINSliE Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7A441F000C5 for ; Fri, 13 Nov 2026 09:58:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794563937; bh=K0ucOvjIjrcBa4o4gYqu3rYj0YatnSeO8vFYHsOpG+k=; h=From:To:Subject:Date:In-Reply-To:References; b=AxINSliEsjagVr/y0NmDS2IVNrWuDbjJPEF/31sZaXsYSPXfegi2lNYKaDarV4/kP Er0Ps2FdZONzXgjM/adYoqZTgqw/8+j/LciIiKE8RnMwFGmA/TMJI+KEOljsdaLHf/ d9v8bTmjyF54VGA/yJ+bgbkrKtiDJWuFxb+QDAvqtn7KL03nQMj22ULy7UQBujC6nz mIMyHE+FVI8ANyyqstcq5qVBfgaZglwsuoewvfgM4EthoCw3i6aPWgcse2tOXop+gQ zV7vtxwwY9p8Fkzg/u+cadDo/IpaO+vOGhzsRa/h4VLofGLIgdq6aPNV1kXkiLIGS7 G193Li9japlpQ== From: Geliang Tang To: mptcp@lists.linux.dev Subject: [PATCH mptcp-net v26 3/8] mptcp: fix fallback dummy mapping anchor Date: Fri, 13 Nov 2026 17:58:42 +0800 Message-ID: X-Mailer: git-send-email 2.55.0 In-Reply-To: References: X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Commit 2834f8edd74d ("mptcp: cleanup fallback dummy mapping generation") anchored map_seq at the DSN of skb->seq but left map_subflow_seq anchored at copied_seq. This caused mptcp_subflow_get_mapped_dsn() to return the DSN at skb->seq instead of copied_seq. When TCP queues a partially overlapping segment (seq < rcv_nxt), the skb starts before copied_seq, giving offset > 0. mptcp_init_skb() then sets map_seq to the wrong DSN, causing __mptcp_move_skb() to skip data or drop the skb, leaving a hole in the stream. Fix by anchoring map_subflow_seq at TCP_SKB_CB(skb)->seq, ensuring mptcp_subflow_get_mapped_dsn() returns the correct DSN at copied_seq. Fixes: 2834f8edd74d ("mptcp: cleanup fallback dummy mapping generation") Signed-off-by: Geliang Tang --- net/mptcp/subflow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 00677fb3efcd..6f07544bfe40 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -1496,7 +1496,7 @@ static bool subflow_check_data_avail(struct sock *ssk) skb =3D skb_peek(&ssk->sk_receive_queue); subflow->map_valid =3D 1; subflow->map_data_len =3D skb->len; - subflow->map_subflow_seq =3D tcp_sk(ssk)->copied_seq - subflow->ssn_offse= t; + subflow->map_subflow_seq =3D TCP_SKB_CB(skb)->seq - subflow->ssn_offset; subflow->map_seq =3D __mptcp_expand_seq(subflow->map_seq, subflow->iasn + TCP_SKB_CB(skb)->seq - --=20 2.55.0 From nobody Mon Nov 23 20:26:59 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794563939; b=Uy1prZkJQxI00imHWVCQCWVghbafXvhNw8CLmR4vbFRVQOgNxgUiLaBJa6Mf/ux5ei/k IwppInBb5yyAfBPask8VU+WRsLh5hzBPNxS2XDc5Cr+fVW/GMyXbp3tGCjVqHdWkxPvAJ Tb9vTDtxpkO+I5LftJ9rV9IrvTutCczAK7ZdLfJ8qj7GNsJAreVUJr0Y0nS43jZ8SSdak q/5GGv0i0rfR85thMubMObrR7LiqAWQomycaCypJ5ALeHW4sCE76cOe1tkMCBuBVC7BMV 7Xht3n9LgDPMCPl/UH0yHs/oJlaRF7e6qHg7k4gQA2T55bwUT88C+oGNzIXRGYaJy2Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794563939; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=5/Kp05SKHtNtpk3tmxGUxvBUWZJxCkxUzpNm5CkanUI=; b=lbact+Fhp83Ro1JRGopoyORJg+Dl+3PomCI9T7xD/mro0Pq0ANQmxlkLYr6LmLI5+R9i w+cPHVs2d5iyBFftTzcVAfr+pUw9YXJV1dOfxH2xhPNv964PeFF+bgkyYFjcsETdieZad cV3jfw6RlS35M30QjO5bOskk5Nu3zrJXkOzEhQ44DEX2oriAXv+SvVRgXfodBNm25SvB6 9mS3VAtk73oKafOzjTPCrfMWbWPfhLfEofNPr9BabdAfdcsXM1spiY6TkJiHovdyaCAd0 u/3HZAoaYsConmjFsvKr6fV5DO4ZzM12Rk8fUOGGLWLisAO/zkLF0cW0oMU8yFJKAlg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RDXL+jqy; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86C6B606A321 for ; Fri, 13 Nov 2026 09:58:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RDXL+jqy Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C96A1F000C8 for ; Fri, 13 Nov 2026 09:58:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794563939; bh=5/Kp05SKHtNtpk3tmxGUxvBUWZJxCkxUzpNm5CkanUI=; h=From:To:Subject:Date:In-Reply-To:References; b=RDXL+jqyC6NnjMKVz+69sNRgN6lkJ+ri1J8NXr1/c7zBgFOxMMn1rXDOzTVzfMWA+ HoejDAJ0bO3kU8VG+U77NpaDsIWPVz8binujHaa7u+jd9xyi1yyXjBiDpUOcChGFo+ pP0hXk/2v8RG3ehKbL65Sx67SSDcGVdgKWr7CPu1/j6hW0wyTRSSsfNAyHCS78k41t CnQGJuV4FTs/61bbIrbab9lemTI+X5ZHAakz9ZlDMJdhpkQwX2nENo3HNTCd/8YDs5 3mi1V3QY3b4uWf9HVaVeU7uwmpY2/lq/60ps2CBY+XmiW0kLalc21XOnxhcw2sQMia cDFzU8tvj+iOA== From: Geliang Tang To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next v26 4/8] mptcp: drop the mptcp_ooo_try_coalesce() helper Date: Fri, 13 Nov 2026 17:58:43 +0800 Message-ID: X-Mailer: git-send-email 2.55.0 In-Reply-To: References: X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Paolo Abeni 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 Signed-off-by: Geliang Tang Signed-off-by: Paolo Abeni --- 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 f2644e7a6a05..16b81e8dc90e 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -167,7 +167,8 @@ static bool __mptcp_try_coalesce(struct sock *sk, struc= t sk_buff *to, { int limit =3D READ_ONCE(sk->sk_rcvbuf); =20 - if (unlikely(MPTCP_SKB_CB(to)->cant_coalesce) || + if (MPTCP_SKB_CB(from)->map_seq !=3D 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; } =20 -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 !=3D 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 =3D list_last_entry(&msk->backlog_list, struct sk_buff, list); =20 - if (tail && MPTCP_SKB_CB(skb)->map_seq =3D=3D MPTCP_SKB_CB(tail)->end_seq= && - ssk =3D=3D tail->sk && + if (tail && ssk =3D=3D tail->sk && __mptcp_try_coalesce(sk, tail, skb, &fragstolen, &delta)) { skb->truesize -=3D delta; kfree_skb_partial(skb, fragstolen); @@ -902,7 +893,7 @@ static bool __mptcp_ofo_queue(struct mptcp_sock *msk) =20 end_seq =3D MPTCP_SKB_CB(skb)->end_seq; tail =3D 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 =3D msk->ack_seq - MPTCP_SKB_CB(skb)->map_seq; =20 /* skip overlapping data, if any */ --=20 2.55.0 From nobody Mon Nov 23 20:26:59 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794563940; b=PZkk6OIs+XHb0F5JzAFfsQ5oKYRT6DeVu8GLwqQwGnm4K2hZmPAbJoDjtENVVUPJO6CZ OldcTL+P+GZNOZ/YtSBTjxSv6wxIF5x39JabNruYZ/8c5u8hYOBMGmfgmczPHifqMSU/F T3J2Ddb58uNFa/2ItR2XOSvf0hk7tYCx2CoxFWd6f6YcwFacZMjy9J8+1I+GDNmv0V+xk xCzX2rsm91luWc38TsLXkfa1TVNCa0f04mORLhBf2uleLKAntSSxH1SeZoMiel+byIO2+ 6n4jR6oXxwcUCoJKBw5M9Ndz+z0trXsTs/KEP2ZLL+pi3tVkO9tA2r5kDayee/TFBTg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794563940; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=WqwLh6dlFrrTy4ZHEOR0s3SkQsEy8qJ/O9U+FZwKuUU=; b=dTAuN99c8H+21ly5uxzTVyQsPlmyckUt9coy0lUqbLBgs/l3pR1OcxnieGkfXs5HtfAe eRJgQ5Ry+g3nPMXMADvsQIIWdiI4e33N58klvcc0awUOZX8i2B7LDDOemKXEHCmm3qqmR Ph1dBtnRu9g++mMkue3Y8+AAjmPerNHJBjggP6bodaNeh3KQmPxSnWntpkEi5QjQKYuLx FnXOL5ed0UeaswibFinvE7LaNnuKJJSkzgPzvAMsIEkw/pnsDSbgtFIMgvtP9/bHQphiL g4Kd1vHxU6W4aeoR90yNL805/XciOn5vayxaIZQ0rVNRiwIcmxF6C7gLFxS/0noaZTw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Jo0loZgg; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDE10606A323 for ; Fri, 13 Nov 2026 09:59:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Jo0loZgg Received: by smtp.kernel.org (Postfix) with ESMTPSA id B88FA1F000C7 for ; Fri, 13 Nov 2026 09:58:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794563940; bh=WqwLh6dlFrrTy4ZHEOR0s3SkQsEy8qJ/O9U+FZwKuUU=; h=From:To:Subject:Date:In-Reply-To:References; b=Jo0loZggTUzFUmhTJqGuiCrH6ItWsg7wxZYEm+rE/iC9AW5NUc1cl5DSAgV1kOg82 UQQtuJYWCFmlOMsqjEE75jFQb33tnk+n5hlG2+L4KCA1GwNsn7FFkdLxGJ0c+qzock fkPzTZbgRdTVPAm2qbcIgIEnDzXqOQ9Uokm01yEFXd7eE9pxdq6FL3z62XfI1DvWR9 +qPUx7e6aVocZj/LJM9dhrbajYh4JeSkfb70aAa9c0UBdr1ytgWlCydIPhvVIhZQ17 H3G+nJIqc3nTlaV4dEn/PvyfH7IeTtQ2iijEdxGVgo5PWueztCL9otBLJQh2DOl3y9 tet40MmDy4Mhg== From: Geliang Tang To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next v26 5/8] mptcp: drop the cant_coalesce CB field Date: Fri, 13 Nov 2026 17:58:44 +0800 Message-ID: X-Mailer: git-send-email 2.55.0 In-Reply-To: References: X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Paolo Abeni 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 Signed-off-by: Geliang Tang Signed-off-by: Paolo Abeni --- 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 mp= tcp_subflow_context *subf MPTCP_SKB_CB(skb)->end_seq =3D 0; MPTCP_SKB_CB(skb)->offset =3D 0; MPTCP_SKB_CB(skb)->has_rxtstamp =3D has_rxtstamp; - MPTCP_SKB_CB(skb)->cant_coalesce =3D 1; =20 mptcp_data_lock(sk); DEBUG_NET_WARN_ON_ONCE(sock_owned_by_user_nocheck(sk)); =20 + msk =3D mptcp_sk(sk); + msk->rcvd_dummy_seq =3D 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 +=3D skb->len; + msk->bytes_received +=3D skb->len; =20 sk->sk_data_ready(sk); =20 diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 16b81e8dc90e..41fc2429d2fe 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -168,7 +168,6 @@ static bool __mptcp_try_coalesce(struct sock *sk, struc= t sk_buff *to, int limit =3D READ_ONCE(sk->sk_rcvbuf); =20 if (MPTCP_SKB_CB(from)->map_seq !=3D 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 =3D MPTCP_SKB_CB(skb)->map_seq + copy_len; MPTCP_SKB_CB(skb)->offset =3D offset; MPTCP_SKB_CB(skb)->has_rxtstamp =3D has_rxtstamp; - MPTCP_SKB_CB(skb)->cant_coalesce =3D 0; =20 __skb_unlink(skb, &ssk->sk_receive_queue); =20 @@ -438,6 +436,25 @@ static void mptcp_init_skb(struct sock *ssk, struct sk= _buff *skb, int offset, skb_dst_drop(skb); } =20 +void __mptcp_sync_rcv_sequence(struct sock *sk) +{ + struct mptcp_sock *msk =3D 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 =3D false; + skb =3D skb_peek_tail(&sk->sk_receive_queue); + if (!skb) + return; + + MPTCP_SKB_CB(skb)->map_seq =3D msk->tfo_iasn - skb->len + + MPTCP_SKB_CB(skb)->offset; + MPTCP_SKB_CB(skb)->end_seq =3D msk->tfo_iasn; +} + static bool __mptcp_move_skb(struct sock *sk, struct sk_buff *skb) { u64 copy_len =3D 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 s= k_buff *skb) =20 mptcp_borrow_fwdmem(sk, skb); =20 + /* 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 =3D=3D msk->ack_seq) { /* in sequence */ insert: @@ -2377,7 +2400,13 @@ static bool mptcp_move_skbs(struct sock *sk) u32 moved =3D 0; =20 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 |=3D __mptcp_move_skbs(sk, &skbs, &moved); =20 @@ -3676,6 +3705,8 @@ static int mptcp_disconnect(struct sock *sk, int flag= s) msk->bytes_retrans =3D 0; msk->rcvspace_init =3D 0; msk->fastclosing =3D 0; + msk->tfo_iasn =3D 0; + msk->rcvd_dummy_seq =3D false; mptcp_init_rtt_est(msk); =20 /* for fallback's sake */ @@ -3878,6 +3909,9 @@ static void mptcp_release_cb(struct sock *sk) struct list_head join_list, skbs; bool spool_bl; =20 + if (__test_and_clear_bit(MPTCP_SYNC_SEQ, &msk->cb_flags)) + __mptcp_sync_rcv_sequence(sk); + spool_bl =3D mptcp_can_spool_backlog(sk, &skbs); if (!flags && !spool_bl) break; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 3be60da12924..b4e49d719200 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 =20 struct mptcp_skb_cb { u64 map_seq; u64 end_seq; u32 offset; u8 has_rxtstamp; - u8 cant_coalesce; }; =20 #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); =20 +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..f9dfb6662e3c 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -519,6 +519,8 @@ static void subflow_set_remote_key(struct mptcp_sock *m= sk, struct mptcp_subflow_context *subflow, const struct mptcp_options_received *mp_opt) { + struct sock *sk =3D (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 =3D subflow->iasn; + + if (!sock_owned_by_user(sk)) + __mptcp_sync_rcv_sequence(sk); + else + set_bit(MPTCP_SYNC_SEQ, &msk->cb_flags); } =20 static void mptcp_propagate_state(struct sock *sk, struct sock *ssk, --=20 2.55.0 From nobody Mon Nov 23 20:26:59 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794563942; b=qFwKHatQOJhm0If9t/Mk6H2mvL9UXg10JoQE6JbAD6poqeR9jxf8Q03+nZmO7xHSZOf1 d0PR7vktTnCmewDuwNPxY60EJ5WyAebdFc9pKkZlXLyFmAT7IAqvs02ATVci9Si7+bn0H q7xO/e5jAOfUR238yoijmDKghUDPXL2FXgs+hKv81lobNcNioGY6USO3PFtHoucxPGPFq 52TP9CMNyThT7yVLBfRlJwo32fDgfd2p5g4fmjv09QhucTUG6JiAPyqZCZbyNwT55r0Pa MopL0bjV2qUxGkrdrfbqPDMsKK/06XgdzhJ7hZtP5Kj9QZgF5hAmSQTecmwvDph6qyw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794563942; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=20c0LKgm7EiXbMe1XTG/XJ5QNZDf2UH/A6pGS/zsbBY=; b=3ShrLziD07UNiYhd+bkJ4MaartXU+uqdlTM0UmMd9ci9yQM1cxreMhNUaRx1BTun6td3 oWCwr2K24sUce6WaPPqQQSGJVIuZF3iUEtofAgwt/0A5/CBbvev9sR5VSSK3qk2aAbouZ moYW9VzlPvHsEmQiQBl/yxtTsRK+Dnho8IRVI7m8BUe9SCwX/OKHTzx/wcNhWO/DD9G8x +Q8FfVnj213KlcmoOlRj9UVQdJwvBxibGMxPLj5/Zpn3W2eE4qJaWOOwNLdl9sEB8LsnC cqu/U7VpjtuJ8tcWxGYh68qajiCdSSVWG5wK8EyzZnqI4KjzdQhrhD0IDIhf8iGEN5A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QId4mu7X; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C3C1606A323 for ; Fri, 13 Nov 2026 09:59:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QId4mu7X Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E5721F000C4 for ; Fri, 13 Nov 2026 09:59:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794563942; bh=20c0LKgm7EiXbMe1XTG/XJ5QNZDf2UH/A6pGS/zsbBY=; h=From:To:Subject:Date:In-Reply-To:References; b=QId4mu7XQa0mxjOxvpEPgGT2+1areZ8Sj7F5wsuZlkeMjKq9559IjK5f1FrLATdjy 5earx6hcfzVot8jK1hxggO8A3gja7cJLRK9SzLhBijiz1q4n61cIb1Zf4KB3lTSfMJ eLVc6OJbgYbxqQ0H7T+McsDrsQetgxec86NzoKJMFPnFFqp8l+LFIfyfUMtkMhkXHK Zvmy/aArZ7/7xvRAVZs54kYKo873RAyvf+nr7O9mfonNuhIza4j5EK26EWiCMprmtI pXdQrdbq8c8iFTT6FQ7C0q7ip7IbPf1NiDktlsirnSkkcwgvB8mTu7CwSsgNKxDI9i NntEKOaWJXoQQ== From: Geliang Tang To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next v26 6/8] mptcp: remove CB offset field Date: Fri, 13 Nov 2026 17:58:45 +0800 Message-ID: <0bd74213de97c6d796b835f567e0f426bee89008.1794563432.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.55.0 In-Reply-To: References: X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Paolo Abeni 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 mptcp_move_skbs() and 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. In mptcp_init_skb(), map_seq is computed as mptcp_subflow_get_mapped_dsn() minus offset. A mapping boundary check using before() for proper 32-bit modular arithmetic detects when the skb spans multiple DSS mappings (offset > 0 and skb starts before the current mapping). In that case, the consumed prefix bytes belong to an old mapping and must be removed before setting map_seq. The function now returns bool to indicate success. When removing the prefix, we handle linear and paged data separately. For offset within linear data where offset <=3D skb_headlen, use skb_pull() which is safe and doesn't modify truesize. For offset in paged data where offset > skb_headlen, use pskb_pull() which may expand the skb head. To avoid truesize corruption in pskb_expand_head(), we first orphan the skb to disconnect it from the socket, perform the pull, recompute truesize manually, then reattach with skb_set_owner_r(). This ensures proper memory accounting. When mptcp_init_skb() fails, the caller increments seq to skip the problematic skb, records the failure via MPTCP_MIB_RCVPRUNED, and jumps to cleanup to ensure tp->copied_seq and more_data_avail are properly updated. This maintains TCP/MPTCP state consistency, and MPTCP-level retransmission will fill any resulting gaps. When the skb stays within a single mapping and offset > 0, map_seq is rewound to cover the already-consumed prefix. A new MPTCP_SKB_CB_F_OFFSET flag marks such skbs. __mptcp_try_coalesce() refuses to coalesce when the from skb carries this flag, preventing an unvalidated prefix from being merged into a validated buffer. mptcp_data_queue_ofo() skips the rb_replace_node() replacement when the new skb covers an existing OFO entry and carries the flag, so that previously validated data is not overwritten by an unvalidated prefix; the new skb is inserted after the existing entry instead, and the prefix is naturally skipped when the OFO queue is later processed. To prevent offset calculation underflow when a protocol-violating peer sends data after DATA_FIN, __mptcp_move_skb() rejects skbs whose map_seq is at or beyond rcv_data_fin_seq when DATA_FIN has been received. Since copied_seq tracks only payload bytes and cannot advance past the DATA_FIN sequence number, accepting data after DATA_FIN would cause the read position calculation (copied_seq - map_seq) to underflow. 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 Signed-off-by: Geliang Tang Signed-off-by: Paolo Abeni --- net/mptcp/fastopen.c | 9 ++-- net/mptcp/protocol.c | 117 ++++++++++++++++++++++++------------------- net/mptcp/protocol.h | 5 +- net/mptcp/subflow.c | 6 ++- 4 files changed, 79 insertions(+), 58 deletions(-) diff --git a/net/mptcp/fastopen.c b/net/mptcp/fastopen.c index e18b31028e7e..48298bfe85a4 100644 --- a/net/mptcp/fastopen.c +++ b/net/mptcp/fastopen.c @@ -45,10 +45,12 @@ void mptcp_fastopen_subflow_synack_set_params(struct mp= tcp_subflow_context *subf subflow->ssn_offset +=3D skb->len; has_rxtstamp =3D TCP_SKB_CB(skb)->has_rxtstamp; =20 - /* Only the sequence delta is relevant */ - MPTCP_SKB_CB(skb)->map_seq =3D -skb->len; + /* The TFO segment data sits before the IASN; before receiving + * the remote key, IASN is assumed being 0. + */ + MPTCP_SKB_CB(skb)->map_seq =3D -(u64)skb->len; MPTCP_SKB_CB(skb)->end_seq =3D 0; - MPTCP_SKB_CB(skb)->offset =3D 0; + MPTCP_SKB_CB(skb)->flags =3D 0; MPTCP_SKB_CB(skb)->has_rxtstamp =3D has_rxtstamp; =20 mptcp_data_lock(sk); @@ -56,6 +58,7 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptc= p_subflow_context *subf =20 msk =3D mptcp_sk(sk); msk->rcvd_dummy_seq =3D true; + msk->copied_seq =3D 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 41fc2429d2fe..99dfcd0488a4 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -167,8 +167,9 @@ static bool __mptcp_try_coalesce(struct sock *sk, struc= t sk_buff *to, { int limit =3D READ_ONCE(sk->sk_rcvbuf); =20 - if (MPTCP_SKB_CB(from)->map_seq !=3D MPTCP_SKB_CB(to)->end_seq || - MPTCP_SKB_CB(from)->offset || + if (MPTCP_SKB_CB(from)->map_seq !=3D MPTCP_SKB_CB(to)->map_seq + + to->len || + MPTCP_SKB_CB(from)->flags & MPTCP_SKB_CB_F_OFFSET || ((to->len + from->len) > (limit >> 3)) || !skb_try_coalesce(to, from, fragstolen, delta)) return false; @@ -306,7 +307,7 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk= , struct sk_buff *skb) struct sk_buff *skb1; =20 seq =3D MPTCP_SKB_CB(skb)->map_seq; - end_seq =3D MPTCP_SKB_CB(skb)->end_seq; + end_seq =3D MPTCP_SKB_CB(skb)->map_seq + skb->len; max_seq =3D atomic64_read(&msk->rcv_wnd_sent); =20 pr_debug("msk=3D%p seq=3D%llx limit=3D%llx empty=3D%d\n", msk, seq, max_s= eq, @@ -346,7 +347,8 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk= , struct sk_buff *skb) } =20 /* 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_SKB_CB(msk->ooo_last_skb)->map_seq + + msk->ooo_last_skb->len)) { MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOQUEUETAIL); parent =3D &msk->ooo_last_skb->rbnode; p =3D &parent->rb_right; @@ -362,8 +364,9 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk= , struct sk_buff *skb) p =3D &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_SKB_CB(skb1)->map_seq + skb1->len)) { + if (!after64(end_seq, + MPTCP_SKB_CB(skb1)->map_seq + skb1->len)) { /* All the bits are present. Drop. */ mptcp_drop(sk, skb); MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA); @@ -400,7 +403,8 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk= , struct sk_buff *skb) merge_right: /* Remove other segments covered by skb. */ while ((skb1 =3D skb_rb_next(skb)) !=3D NULL) { - if (before64(end_seq, MPTCP_SKB_CB(skb1)->end_seq)) + if (before64(end_seq, + MPTCP_SKB_CB(skb1)->map_seq + skb1->len)) break; rb_erase(&skb1->rbnode, &msk->out_of_order_queue); mptcp_drop(sk, skb1); @@ -425,9 +429,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 =3D mptcp_subflow_get_mapped_dsn(subflow); + MPTCP_SKB_CB(skb)->map_seq =3D mptcp_subflow_get_mapped_dsn(subflow) - + offset; MPTCP_SKB_CB(skb)->end_seq =3D MPTCP_SKB_CB(skb)->map_seq + copy_len; - MPTCP_SKB_CB(skb)->offset =3D offset; + MPTCP_SKB_CB(skb)->flags =3D offset ? MPTCP_SKB_CB_F_OFFSET : 0; MPTCP_SKB_CB(skb)->has_rxtstamp =3D has_rxtstamp; =20 __skb_unlink(skb, &ssk->sk_receive_queue); @@ -450,17 +455,24 @@ void __mptcp_sync_rcv_sequence(struct sock *sk) if (!skb) return; =20 - MPTCP_SKB_CB(skb)->map_seq =3D msk->tfo_iasn - skb->len + - MPTCP_SKB_CB(skb)->offset; - MPTCP_SKB_CB(skb)->end_seq =3D msk->tfo_iasn; + MPTCP_SKB_CB(skb)->map_seq =3D msk->tfo_iasn - skb->len; + MPTCP_SKB_CB(skb)->end_seq =3D MPTCP_SKB_CB(skb)->map_seq + skb->len; } =20 static bool __mptcp_move_skb(struct sock *sk, struct sk_buff *skb) { u64 copy_len =3D MPTCP_SKB_CB(skb)->end_seq - MPTCP_SKB_CB(skb)->map_seq; + u64 dsn =3D MPTCP_SKB_CB(skb)->map_seq + skb->len - copy_len; struct mptcp_sock *msk =3D mptcp_sk(sk); struct sk_buff *tail; =20 + if (READ_ONCE(msk->rcv_data_fin) && + !before64(MPTCP_SKB_CB(skb)->map_seq, + READ_ONCE(msk->rcv_data_fin_seq))) { + mptcp_drop(sk, skb); + return false; + } + mptcp_borrow_fwdmem(sk, skb); =20 /* Be sure to sync the eventual fastopen dummy mapping before any other @@ -469,7 +481,7 @@ static bool __mptcp_move_skb(struct sock *sk, struct sk= _buff *skb) if (unlikely(msk->rcvd_dummy_seq)) __mptcp_sync_rcv_sequence(sk); =20 - if (MPTCP_SKB_CB(skb)->map_seq =3D=3D msk->ack_seq) { + if (dsn =3D=3D msk->ack_seq) { /* in sequence */ insert: if (!mptcp_try_rmem_schedule(sk, skb)) { @@ -487,7 +499,7 @@ 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; } @@ -495,10 +507,6 @@ static bool __mptcp_move_skb(struct sock *sk, struct s= k_buff *skb) /* Partial packet */ if (after64(MPTCP_SKB_CB(skb)->end_seq, msk->ack_seq)) { copy_len =3D MPTCP_SKB_CB(skb)->end_seq - msk->ack_seq; - MPTCP_SKB_CB(skb)->offset +=3D msk->ack_seq - - MPTCP_SKB_CB(skb)->map_seq; - MPTCP_SKB_CB(skb)->map_seq +=3D msk->ack_seq - - MPTCP_SKB_CB(skb)->map_seq; goto insert; } =20 @@ -896,35 +904,35 @@ static bool __mptcp_ofo_queue(struct mptcp_sock *msk) bool moved =3D false; struct rb_node *p; u64 end_seq; + u64 dsn; =20 p =3D rb_first(&msk->out_of_order_queue); pr_debug("msk=3D%p empty=3D%d\n", msk, RB_EMPTY_ROOT(&msk->out_of_order_q= ueue)); while (p) { skb =3D rb_to_skb(p); - if (after64(MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq)) + dsn =3D MPTCP_SKB_CB(skb)->map_seq + skb->len - + (MPTCP_SKB_CB(skb)->end_seq - MPTCP_SKB_CB(skb)->map_seq); + if (after64(dsn, msk->ack_seq)) break; =20 p =3D rb_next(p); rb_erase(&skb->rbnode, &msk->out_of_order_queue); =20 - if (unlikely(!after64(MPTCP_SKB_CB(skb)->end_seq, + if (unlikely(!after64(MPTCP_SKB_CB(skb)->map_seq + skb->len, msk->ack_seq))) { mptcp_drop(sk, skb); MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA); continue; } =20 - end_seq =3D MPTCP_SKB_CB(skb)->end_seq; + end_seq =3D MPTCP_SKB_CB(skb)->map_seq + skb->len; tail =3D skb_peek_tail(&sk->sk_receive_queue); if (!tail || !mptcp_try_coalesce(sk, tail, skb)) { int delta =3D msk->ack_seq - MPTCP_SKB_CB(skb)->map_seq; =20 - /* skip overlapping data, if any */ pr_debug("uncoalesced seq=3D%llx ack seq=3D%llx delta=3D%d\n", MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq, delta); - MPTCP_SKB_CB(skb)->offset +=3D delta; - MPTCP_SKB_CB(skb)->map_seq +=3D delta; __skb_queue_tail(&sk->sk_receive_queue, skb); } msk->bytes_received +=3D end_seq - msk->ack_seq; @@ -2209,33 +2217,24 @@ static void mptcp_eat_recv_skb(struct sock *sk, str= uct sk_buff *skb) } =20 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 =3D mptcp_sk(sk); struct sk_buff *skb, *tmp; - int total_data_len =3D 0; int copied =3D 0; =20 skb_queue_walk_safe(&sk->sk_receive_queue, skb, tmp) { - u32 delta, offset =3D MPTCP_SKB_CB(skb)->offset; + u64 offset =3D *seq - MPTCP_SKB_CB(skb)->map_seq; u32 data_len =3D skb->len - offset; u32 count; int err; =20 - if (flags & MSG_PEEK) { - /* skip already peeked skbs */ - if (total_data_len + data_len <=3D copied_total) { - total_data_len +=3D data_len; - *last =3D skb; - continue; - } - - /* skip the already peeked data in the current skb */ - delta =3D copied_total - total_data_len; - offset +=3D delta; - data_len -=3D delta; + /* Skip the already peeked data. */ + if (offset >=3D skb->len) { + *last =3D skb; + continue; } =20 count =3D min_t(size_t, len - copied, data_len); @@ -2255,14 +2254,12 @@ static int __mptcp_recvmsg_mskq(struct sock *sk, st= ruct msghdr *msg, } =20 copied +=3D count; + *seq +=3D count; =20 if (!(flags & MSG_PEEK)) { msk->bytes_consumed +=3D count; - if (count < data_len) { - MPTCP_SKB_CB(skb)->offset +=3D count; - MPTCP_SKB_CB(skb)->map_seq +=3D count; + if (count < data_len) break; - } =20 mptcp_eat_recv_skb(sk, skb); } else { @@ -2401,8 +2398,10 @@ static bool mptcp_move_skbs(struct sock *sk) =20 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 +=3D msk->tfo_iasn; __mptcp_sync_rcv_sequence(sk); + } =20 if (!mptcp_can_spool_backlog(sk, &skbs)) break; @@ -2442,6 +2441,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msgh= dr *msg, size_t len, struct mptcp_sock *msk =3D mptcp_sk(sk); struct scm_timestamping_internal tss; int copied =3D 0, cmsg_flags =3D 0; + u64 peek_seq, *seq; int target; long timeo; =20 @@ -2460,6 +2460,11 @@ static int mptcp_recvmsg(struct sock *sk, struct msg= hdr *msg, size_t len, =20 len =3D min_t(size_t, len, INT_MAX); target =3D sock_rcvlowat(sk, flags & MSG_WAITALL, len); + seq =3D &msk->copied_seq; + if (flags & MSG_PEEK) { + peek_seq =3D msk->copied_seq; + seq =3D &peek_seq; + } =20 if (unlikely(msk->recvmsg_inq)) cmsg_flags =3D MPTCP_CMSG_INQ; @@ -2469,7 +2474,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msgh= dr *msg, size_t len, int err, bytes_read; =20 bytes_read =3D __mptcp_recvmsg_mskq(sk, msg, len - copied, flags, - copied, &tss, &cmsg_flags, + seq, &tss, &cmsg_flags, &last); if (unlikely(bytes_read < 0)) { if (!copied) @@ -2479,8 +2484,11 @@ static int mptcp_recvmsg(struct sock *sk, struct msg= hdr *msg, size_t len, =20 copied +=3D bytes_read; =20 - 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 =3D msk->copied_seq + copied; continue; + } =20 /* only the MPTCP socket status is relevant here. The exit * conditions mirror closely tcp_recvmsg() @@ -2523,6 +2531,10 @@ static int mptcp_recvmsg(struct sock *sk, struct msg= hdr *msg, size_t len, copied =3D copied ? : err; goto out_err; } + + /* Recompute peek offset after eventual seq resync. */ + if (flags & MSG_PEEK) + peek_seq =3D msk->copied_seq + copied; } =20 mptcp_cleanup_rbuf(msk, copied); @@ -3699,6 +3711,7 @@ static int mptcp_disconnect(struct sock *sk, int flag= s) mptcp_pm_data_reset(msk); mptcp_ca_reset(sk); msk->bytes_consumed =3D 0; + msk->copied_seq =3D 0; msk->bytes_acked =3D 0; msk->bytes_received =3D 0; msk->bytes_sent =3D 0; @@ -3909,8 +3922,10 @@ static void mptcp_release_cb(struct sock *sk) struct list_head join_list, skbs; bool spool_bl; =20 - 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 +=3D msk->tfo_iasn; __mptcp_sync_rcv_sequence(sk); + } =20 spool_bl =3D mptcp_can_spool_backlog(sk, &skbs); if (!flags && !spool_bl) @@ -4631,7 +4646,7 @@ static struct sk_buff *mptcp_recv_skb(struct sock *sk= , u32 *off) mptcp_move_skbs(sk); =20 while ((skb =3D skb_peek(&sk->sk_receive_queue)) !=3D NULL) { - offset =3D MPTCP_SKB_CB(skb)->offset; + offset =3D msk->copied_seq - MPTCP_SKB_CB(skb)->map_seq; if (offset < skb->len) { *off =3D offset; return skb; @@ -4673,11 +4688,9 @@ static int __mptcp_read_sock(struct sock *sk, read_d= escriptor_t *desc, copied +=3D count; =20 msk->bytes_consumed +=3D count; - if (count < data_len) { - MPTCP_SKB_CB(skb)->offset +=3D count; - MPTCP_SKB_CB(skb)->map_seq +=3D count; + msk->copied_seq +=3D count; + if (count < data_len) break; - } =20 mptcp_eat_recv_skb(sk, skb); if (!desc->count) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index b4e49d719200..e195993f7aec 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 =20 +#define MPTCP_SKB_CB_F_OFFSET 0x0100 + struct mptcp_skb_cb { u64 map_seq; u64 end_seq; - u32 offset; + u16 flags; u8 has_rxtstamp; }; =20 @@ -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; diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index f9dfb6662e3c..83beaa54b634 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 =3D subflow->iasn; =20 - if (!sock_owned_by_user(sk)) + if (!sock_owned_by_user(sk)) { + msk->copied_seq +=3D subflow->iasn; __mptcp_sync_rcv_sequence(sk); - else + } else { set_bit(MPTCP_SYNC_SEQ, &msk->cb_flags); + } } =20 static void mptcp_propagate_state(struct sock *sk, struct sock *ssk, --=20 2.55.0 From nobody Mon Nov 23 20:26:59 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794563943; b=u8ujToyMrXdpe6+X/lPGBgBKATG/NLDn0dekkI8rAS/j1xd3YbFxsql/l0PO0llls6Jg vWGlGa63hs8W5W89K0hSHAHzacl2VHj2y8ixD7rlL92z5YEbqsXv1348pNvm2X56llaV2 5oPDfPDEv5ID8k/rzFge0ZtI0JtMEYzM6L8DRNNA9AdkbiJK8dkmB97lHJiSe/7d5x0cr yz9C1uYdK5sbd7+IAyOOz3Ag5/c60w9vmGJDl4Jqzx262HXAwA0SFI24qMgxKLZzUS4sX lgjscqFzn1UbincIAfxTN15u6spWxL/J16bMnozlOXgKDow/iNWRFEjf3D6ixJvQB0w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794563943; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=kzbRxsbzGSWFcVikn1/P3s9Ss9UEpi9d3M5amLdtxmc=; b=vMM4PAu3fig63zzYjknG/uH9TP7IyToYzjsRNAW6lL7roM2B54I4/6XfG0fDYPQb7K8W OvGEKoXqdGyIcQpgMQxtAPf2kc9g8zfIezZKbNRtkMb8PKT8kwNfPkUrvqctYYauSDNld /k0fEASbX0KhNRqZg7ZAxaz7lVjnNyv6u59e/b6elaTu4JkWRdFxr3l5D/FMtlqcxsCj6 nfexIUrg0vIONklwhIr44qf4uQoO3YToY7Dqf3+mMMZcCbfW+Pl3neSejOMfhpN7T7KIu tFLoaFZlI+b/vui2vT8V1UaMcg04trPrKS4XbJZRCss51XVLdtVgDOW8KkGLkmp9Tfg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=K7YyntXH; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73A13606A31C for ; Fri, 13 Nov 2026 09:59:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=K7YyntXH Received: by smtp.kernel.org (Postfix) with ESMTPSA id 920301F000C9 for ; Fri, 13 Nov 2026 09:59:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794563943; bh=kzbRxsbzGSWFcVikn1/P3s9Ss9UEpi9d3M5amLdtxmc=; h=From:To:Subject:Date:In-Reply-To:References; b=K7YyntXHl8D4Z2RnwQ7K1f5SxTJjTycEUszofOMMIbc0ZkI9L76wzx+vYDncd6mRs CfrvnuaOchaAmfcx+36pKrnle4IMFHybNuzKCdJKi7BiSh5OPtGUU3GFI4XHZjEpg3 i4NRDOp0oP0+gdUzxALv2SMzHQ7gWo614ZPhnnC+Aj6x10z4Fz8itgAiD6aOIXVi09 dIgo7DKXS7/zWz8Az1WL1abiaWXPsVI/pJw/vSg4Uaj+ulnuey7ueOCTXtC3aElhIl JWOQ0dXklb9nhzRMdkaMqI71zDmV8K4+21kLF8Ib53PalLCHZsER+MO6ItS+riIssb YbqPg6Ygt6L9A== From: Geliang Tang To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next v26 7/8] mptcp: sync mptcp skb cb layout with tcp one Date: Fri, 13 Nov 2026 17:58:46 +0800 Message-ID: <328ddc33883506606aecad77f6645616df082740.1794563432.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.55.0 In-Reply-To: References: X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Paolo Abeni 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, coalescing checks, and DATA_FIN validation. __mptcp_try_coalesce() gains a map_seq64 contiguity check to ensure skbs are truly adjacent in the 64-bit DSN space. The DATA_FIN check in __mptcp_move_skb() now uses map_seq64 to compare against rcv_data_fin_seq in the full 64-bit DSN space. Co-developed-by: Geliang Tang Signed-off-by: Geliang Tang Signed-off-by: Paolo Abeni --- net/mptcp/fastopen.c | 5 ++- net/mptcp/protocol.c | 96 +++++++++++++++++++++++++------------------- net/mptcp/protocol.h | 6 ++- 3 files changed, 62 insertions(+), 45 deletions(-) diff --git a/net/mptcp/fastopen.c b/net/mptcp/fastopen.c index 48298bfe85a4..bd52e9528b29 100644 --- a/net/mptcp/fastopen.c +++ b/net/mptcp/fastopen.c @@ -48,7 +48,8 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptc= p_subflow_context *subf /* The TFO segment data sits before the IASN; before receiving * the remote key, IASN is assumed being 0. */ - MPTCP_SKB_CB(skb)->map_seq =3D -(u64)skb->len; + MPTCP_SKB_CB(skb)->map_seq64 =3D -(u64)skb->len; + MPTCP_SKB_CB(skb)->map_seq =3D MPTCP_SKB_CB(skb)->map_seq64; MPTCP_SKB_CB(skb)->end_seq =3D 0; MPTCP_SKB_CB(skb)->flags =3D 0; MPTCP_SKB_CB(skb)->has_rxtstamp =3D has_rxtstamp; @@ -58,7 +59,7 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptc= p_subflow_context *subf =20 msk =3D mptcp_sk(sk); msk->rcvd_dummy_seq =3D true; - msk->copied_seq =3D MPTCP_SKB_CB(skb)->map_seq; + msk->copied_seq =3D 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 99dfcd0488a4..d124b702c957 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -167,14 +167,14 @@ static bool __mptcp_try_coalesce(struct sock *sk, str= uct sk_buff *to, { int limit =3D READ_ONCE(sk->sk_rcvbuf); =20 - if (MPTCP_SKB_CB(from)->map_seq !=3D MPTCP_SKB_CB(to)->map_seq + - to->len || + if (MPTCP_SKB_CB(from)->map_seq64 !=3D MPTCP_SKB_CB(to)->map_seq64 + + to->len || MPTCP_SKB_CB(from)->flags & MPTCP_SKB_CB_F_OFFSET || ((to->len + from->len) > (limit >> 3)) || !skb_try_coalesce(to, from, fragstolen, delta)) return false; =20 - 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 =3D MPTCP_SKB_CB(from)->end_seq; @@ -256,8 +256,8 @@ static void mptcp_prune_ofo_queue(struct sock *sk, struct sk_buff *skb =3D rb_to_skb(node); =20 /* 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 (after(MPTCP_SKB_CB(in_skb)->map_seq, + MPTCP_SKB_CB(skb)->map_seq)) break; =20 pruned =3D true; @@ -303,14 +303,15 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *m= sk, struct sk_buff *skb) { struct sock *sk =3D (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; =20 seq =3D MPTCP_SKB_CB(skb)->map_seq; - end_seq =3D MPTCP_SKB_CB(skb)->map_seq + skb->len; + end_seq =3D MPTCP_SKB_CB(skb)->map_seq64 + skb->len; max_seq =3D atomic64_read(&msk->rcv_wnd_sent); =20 - pr_debug("msk=3D%p seq=3D%llx limit=3D%llx empty=3D%d\n", msk, seq, max_s= eq, + pr_debug("msk=3D%p seq=3D%x limit=3D%llx empty=3D%d\n", msk, seq, max_seq, RB_EMPTY_ROOT(&msk->out_of_order_queue)); if (after64(end_seq, max_seq)) { /* out of window */ @@ -347,8 +348,8 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk= , struct sk_buff *skb) } =20 /* Can avoid an rbtree lookup if we are adding skb after ooo_last_skb */ - if (!before64(seq, MPTCP_SKB_CB(msk->ooo_last_skb)->map_seq + - msk->ooo_last_skb->len)) { + if (!before(seq, MPTCP_SKB_CB(msk->ooo_last_skb)->map_seq + + msk->ooo_last_skb->len)) { MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOQUEUETAIL); parent =3D &msk->ooo_last_skb->rbnode; p =3D &parent->rb_right; @@ -360,19 +361,19 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *m= sk, struct sk_buff *skb) while (*p) { parent =3D *p; skb1 =3D rb_to_skb(parent); - if (before64(seq, MPTCP_SKB_CB(skb1)->map_seq)) { + if (before(seq, MPTCP_SKB_CB(skb1)->map_seq)) { p =3D &parent->rb_left; continue; } - if (before64(seq, MPTCP_SKB_CB(skb1)->map_seq + skb1->len)) { - if (!after64(end_seq, - MPTCP_SKB_CB(skb1)->map_seq + skb1->len)) { + if (before(seq, MPTCP_SKB_CB(skb1)->map_seq + skb1->len)) { + if (!after((u32)end_seq, + MPTCP_SKB_CB(skb1)->map_seq + skb1->len)) { /* 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 (after(seq, MPTCP_SKB_CB(skb1)->map_seq)) { /* partial overlap: * | skb | * | skb1 | @@ -403,8 +404,8 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk= , struct sk_buff *skb) merge_right: /* Remove other segments covered by skb. */ while ((skb1 =3D skb_rb_next(skb)) !=3D NULL) { - if (before64(end_seq, - MPTCP_SKB_CB(skb1)->map_seq + skb1->len)) + if (before((u32)end_seq, + MPTCP_SKB_CB(skb1)->map_seq + skb1->len)) break; rb_erase(&skb1->rbnode, &msk->out_of_order_queue); mptcp_drop(sk, skb1); @@ -427,10 +428,11 @@ static void mptcp_init_skb(struct sock *ssk, struct s= k_buff *skb, int offset, =20 /* 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 =3D mptcp_subflow_get_mapped_dsn(subflow) - - offset; + MPTCP_SKB_CB(skb)->map_seq64 =3D mptcp_subflow_get_mapped_dsn(subflow) - + offset; + MPTCP_SKB_CB(skb)->map_seq =3D (u32)MPTCP_SKB_CB(skb)->map_seq64; MPTCP_SKB_CB(skb)->end_seq =3D MPTCP_SKB_CB(skb)->map_seq + copy_len; MPTCP_SKB_CB(skb)->flags =3D offset ? MPTCP_SKB_CB_F_OFFSET : 0; MPTCP_SKB_CB(skb)->has_rxtstamp =3D has_rxtstamp; @@ -455,19 +457,20 @@ void __mptcp_sync_rcv_sequence(struct sock *sk) if (!skb) return; =20 - MPTCP_SKB_CB(skb)->map_seq =3D msk->tfo_iasn - skb->len; + MPTCP_SKB_CB(skb)->map_seq64 =3D msk->tfo_iasn - skb->len; + MPTCP_SKB_CB(skb)->map_seq =3D (u32)MPTCP_SKB_CB(skb)->map_seq64; MPTCP_SKB_CB(skb)->end_seq =3D MPTCP_SKB_CB(skb)->map_seq + skb->len; } =20 static bool __mptcp_move_skb(struct sock *sk, struct sk_buff *skb) { - u64 copy_len =3D MPTCP_SKB_CB(skb)->end_seq - MPTCP_SKB_CB(skb)->map_seq; - u64 dsn =3D MPTCP_SKB_CB(skb)->map_seq + skb->len - copy_len; + u32 copy_len =3D MPTCP_SKB_CB(skb)->end_seq - MPTCP_SKB_CB(skb)->map_seq; + u64 dsn =3D MPTCP_SKB_CB(skb)->map_seq64 + skb->len - copy_len; struct mptcp_sock *msk =3D mptcp_sk(sk); struct sk_buff *tail; =20 if (READ_ONCE(msk->rcv_data_fin) && - !before64(MPTCP_SKB_CB(skb)->map_seq, + !before64(MPTCP_SKB_CB(skb)->map_seq64, READ_ONCE(msk->rcv_data_fin_seq))) { mptcp_drop(sk, skb); return false; @@ -505,8 +508,8 @@ static bool __mptcp_move_skb(struct sock *sk, struct sk= _buff *skb) } =20 /* Partial packet */ - if (after64(MPTCP_SKB_CB(skb)->end_seq, msk->ack_seq)) { - copy_len =3D MPTCP_SKB_CB(skb)->end_seq - msk->ack_seq; + if (after64(MPTCP_SKB_CB(skb)->map_seq64 + skb->len, msk->ack_seq)) { + copy_len =3D MPTCP_SKB_CB(skb)->end_seq - (u32)msk->ack_seq; goto insert; } =20 @@ -901,42 +904,41 @@ static bool __mptcp_ofo_queue(struct mptcp_sock *msk) { struct sock *sk =3D (struct sock *)msk; struct sk_buff *skb, *tail; + u32 seq_delta, ack_seq; bool moved =3D false; struct rb_node *p; - u64 end_seq; u64 dsn; =20 p =3D rb_first(&msk->out_of_order_queue); pr_debug("msk=3D%p empty=3D%d\n", msk, RB_EMPTY_ROOT(&msk->out_of_order_q= ueue)); while (p) { + ack_seq =3D msk->ack_seq; skb =3D rb_to_skb(p); - dsn =3D MPTCP_SKB_CB(skb)->map_seq + skb->len - + dsn =3D MPTCP_SKB_CB(skb)->map_seq64 + skb->len - (MPTCP_SKB_CB(skb)->end_seq - MPTCP_SKB_CB(skb)->map_seq); - if (after64(dsn, msk->ack_seq)) + if (after((u32)dsn, ack_seq)) break; =20 p =3D rb_next(p); rb_erase(&skb->rbnode, &msk->out_of_order_queue); =20 - if (unlikely(!after64(MPTCP_SKB_CB(skb)->map_seq + skb->len, - msk->ack_seq))) { + if (unlikely(!after(MPTCP_SKB_CB(skb)->map_seq + skb->len, + ack_seq))) { mptcp_drop(sk, skb); MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA); continue; } =20 - end_seq =3D MPTCP_SKB_CB(skb)->map_seq + skb->len; + seq_delta =3D MPTCP_SKB_CB(skb)->map_seq + skb->len - ack_seq; tail =3D skb_peek_tail(&sk->sk_receive_queue); if (!tail || !mptcp_try_coalesce(sk, tail, skb)) { - int delta =3D msk->ack_seq - MPTCP_SKB_CB(skb)->map_seq; - - pr_debug("uncoalesced seq=3D%llx ack seq=3D%llx delta=3D%d\n", - MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq, - delta); + pr_debug("uncoalesced seq=3D%x ack seq=3D%x delta=3D%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 +=3D end_seq - msk->ack_seq; - WRITE_ONCE(msk->ack_seq, end_seq); + msk->bytes_received +=3D seq_delta; + WRITE_ONCE(msk->ack_seq, msk->ack_seq + seq_delta); moved =3D true; } return moved; @@ -2226,7 +2228,7 @@ static int __mptcp_recvmsg_mskq(struct sock *sk, stru= ct msghdr *msg, int copied =3D 0; =20 skb_queue_walk_safe(&sk->sk_receive_queue, skb, tmp) { - u64 offset =3D *seq - MPTCP_SKB_CB(skb)->map_seq; + u32 offset =3D (u32)(*seq) - MPTCP_SKB_CB(skb)->map_seq; u32 data_len =3D skb->len - offset; u32 count; int err; @@ -4646,7 +4648,7 @@ static struct sk_buff *mptcp_recv_skb(struct sock *sk= , u32 *off) mptcp_move_skbs(sk); =20 while ((skb =3D skb_peek(&sk->sk_receive_queue)) !=3D NULL) { - offset =3D msk->copied_seq - MPTCP_SKB_CB(skb)->map_seq; + offset =3D (u32)msk->copied_seq - MPTCP_SKB_CB(skb)->map_seq; if (offset < skb->len) { *off =3D offset; return skb; @@ -4896,11 +4898,23 @@ static int mptcp_napi_poll(struct napi_struct *napi= , int budget) return work_done; } =20 +#define CHK_CB_FIELD(mptcp_field, tcp_field) \ + ({ \ + BUILD_BUG_ON(offsetof(struct mptcp_skb_cb, mptcp_field) !=3D \ + offsetof(struct tcp_skb_cb, tcp_field)); \ + BUILD_BUG_ON(offsetofend(struct mptcp_skb_cb, mptcp_field) !=3D \ + offsetofend(struct tcp_skb_cb, tcp_field)); \ + }) + void __init mptcp_proto_init(void) { struct mptcp_delegated_action *delegated; int cpu; =20 + CHK_CB_FIELD(map_seq, seq); + CHK_CB_FIELD(end_seq, end_seq); + CHK_CB_FIELD(flags, tcp_flags); + mptcp_prot.h.hashinfo =3D tcp_prot.h.hashinfo; =20 if (percpu_counter_init(&mptcp_sockets_allocated, 0, GFP_KERNEL)) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index e195993f7aec..90d67c170e7a 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -131,10 +131,12 @@ #define MPTCP_SKB_CB_F_OFFSET 0x0100 =20 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; }; =20 #define MPTCP_SKB_CB(__skb) ((struct mptcp_skb_cb *)&((__skb)->cb[0])) --=20 2.55.0 From nobody Mon Nov 23 20:26:59 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794563944; b=EVX8cebN7f22e4qG18w7Pmo4r5MC4IZcFFqIN52s356GxkbxElL/MwvrAVtLE05sYd+/ XrvLCHmakL6tMEk7yTiDKdIqCrquufcRVnIiQ94w/D55maCZ23m1TlRogThV0B6clkE7n Bsawd25Grexpq39ku2KcIOnDjeog1fcCJ5LmAlyhEP0naolZDl7AtGoFxTZkGbf9yAkc8 usSuZVgifrZrTyormS43u1so9cW04m1GnIxAagRqU2sNJvsHY6PCDUBKlhsiA0BFlCDI3 pB5WklW5oQbjpcd6tSxWPZ154FX3RxV6k9xCGd5wTzOIvtYYRJXJG/aYoafBiAPGGbQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794563944; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=DST1zhERE856v/nfXndxoiikTj9pXm8KaJCOR4lzXQ4=; b=34cb7+sR7JCOVUPWHkWhXb+H3WV1mo8Fas7HGyI7G2odWjiiwYivmIYX3DDxRh6w7Z1n /W2q1keBknh94ZUlZgIP5A91k4Zq1X2C3r19Lk7mG7Uk8ijpFHMV+nJIbyPDwVYBghzLl k4oe5ZznKKacMXtpC83QlrZBycsTwyyL9ZwmYXmkMASC4ALKiF6xsOBXApfyvDA0UtpaT 70LxZ+Hwf7rSNVRfsHnptRbG+p0K7qHQccDs5JxLJ7h7rPXex6cptFmw00AcVDhY16Hc8 rDdktoLRjPjrgdp0tjC5tCMVDs7GvN4vgSmc1Y871DflqviTKOr7vJsPgzmuDuHN6Dg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oNapJvXD; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1FDB606A31C for ; Fri, 13 Nov 2026 09:59:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oNapJvXD Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6EDE1F000C8 for ; Fri, 13 Nov 2026 09:59:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794563944; bh=DST1zhERE856v/nfXndxoiikTj9pXm8KaJCOR4lzXQ4=; h=From:To:Subject:Date:In-Reply-To:References; b=oNapJvXDzc2ha+QnM3Hrcbmh2XlUJD5NMAIQAv+l/n1/w7Hn9k9+I83KXbwZUsJzs p2mJVDwQEmS3/LvK5sAGpmndRdzKrhl9NHk9IEkGjw0t2F7fqwUKUn2ai9Dic37FrQ H8P64aVG16sVzNRuuCi8BByiLrYnZgmx0Zk0/sEWJgfF9ECcKm7JPb7N6sc+rZkkZl flVOX/BCeAhCVEuXAUeCacJ2KLVqFBM1abJGZFkKA4OUlNgOSLL/zqRuMnRbrUeeg3 aPDY6s/0dHZk0SkDGPT7jUp3QgNa/HhUY7roaqrwL7ln4SpJePYtLHwy6hSwbwJn/d u5Iva2lXHrswg== From: Geliang Tang To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next v26 8/8] mptcp: defer read_sock cleanup to mptcp_worker Date: Fri, 13 Nov 2026 17:58:47 +0800 Message-ID: <00ee9df4e862fe136c4b2a953abf065d2507a173.1794563432.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.55.0 In-Reply-To: References: X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang 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 Signed-off-by: Geliang Tang --- 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 d124b702c957..91523bdd1b30 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); } =20 +static void mptcp_read_complete(struct sock *sk) +{ + struct mptcp_sock *msk =3D mptcp_sk(sk); + int read_copied; + + mptcp_data_lock(sk); + read_copied =3D msk->read_copied; + msk->read_copied =3D 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); =20 + if (test_and_clear_bit(MPTCP_WORK_READ_COMPLETE, &msk->flags)) + mptcp_read_complete(sk); + fail_tout =3D 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 =3D tcp_jiffies32; msk->last_data_recv =3D tcp_jiffies32; msk->last_ack_recv =3D tcp_jiffies32; + msk->read_copied =3D 0; =20 mptcp_pm_data_init(msk); spin_lock_init(&msk->fallback_lock); @@ -3722,6 +3741,7 @@ static int mptcp_disconnect(struct sock *sk, int flag= s) msk->fastclosing =3D 0; msk->tfo_iasn =3D 0; msk->rcvd_dummy_seq =3D false; + msk->read_copied =3D 0; mptcp_init_rtt_est(msk); =20 /* for fallback's sake */ @@ -4644,7 +4664,7 @@ static struct sk_buff *mptcp_recv_skb(struct sock *sk= , u32 *off) struct sk_buff *skb; u32 offset; =20 - if (!list_empty(&msk->backlog_list)) + if (sock_owned_by_user(sk) && !list_empty(&msk->backlog_list)) mptcp_move_skbs(sk); =20 while ((skb =3D skb_peek(&sk->sk_receive_queue)) !=3D NULL) { @@ -4661,6 +4681,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) @@ -4702,11 +4723,18 @@ static int __mptcp_read_sock(struct sock *sk, read_= descriptor_t *desc, if (noack) goto out; =20 - 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 +=3D 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 90d67c170e7a..4fee626b33cb 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 =20 /* 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; + int read_copied; unsigned long timer_ival; u32 token; u64 tfo_iasn; --=20 2.55.0