From nobody Tue Nov 24 11:17:55 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=1794305511; b=jACRWJPFMtFuyCRJEM+kmCiyaNfOLWLhJzr2eY0iF6IjVoleLHB3/fF6kAlk2DuaH9JB E8GbgGc1rh96JWD8i3F5I034bgSZqUubtRkQl0Duj2LdUYT4oXyaC9GCXsIsjO0mU4rhx XixdMRhFMMPxGVo1rO+GoWn3o07I0Pf4hfLnwwkn4VQXJHlNGks5lF6gFMC2gkIZn1aCa HuWkHiXIw31ZiKUXHXAnF2POt0uhyeGyMUfAzZFrD+UfMpA6C354pL/S5MeEfLMNcImyr yL1cRdQhy06CJ65unDnzTlgVEsoQnQiAwm8d6fit70nxmxHSioeJAG4cnITi1IY647A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794305511; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=izxWmwuAcYspgelSkIAUyDfqt3f4x4kyer12QO2nI+s=; b=wo9/mSD99X4TsJf3jApqfhnjyq1/CNO1K424UfHgAOOeCQp5zeVHsnDV3szuR9bW940p Vk2/rx5qAFvdCOWqGP1Djb92D1F8a1imBEDuO6uSuLPYHOP7trCd2Ml+r4d/q8pndJwjD FMoszvxrC7XW68OYAolzHFouGMb+gLy8G6i/H7u7tS/jDRlLrzg06xLxsSkFK3YriLCD8 1ZYnEf0ZabCQDus28FfCNM+jDv+Gs5KEPTkm0+56psHEwy8KCbLsZsmP/jRtrwIcipPne s77e6AnPbEKcy7Rj9wiLdK4QjEx5fzQpGwqZf0KhICWvI+BaGSVr9CFijPpz3VvjwSA== 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=l4S1IDSk; 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 46AA0606C5D7 for ; Tue, 10 Nov 2026 10:11:51 +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=l4S1IDSk Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96DBD1F008A2 for ; Tue, 10 Nov 2026 10:11:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794305511; bh=izxWmwuAcYspgelSkIAUyDfqt3f4x4kyer12QO2nI+s=; h=From:To:Subject:Date:In-Reply-To:References; b=l4S1IDSkyDitZBIyFevhERyct2ZJAxifTr5D9iMXbc7B/GdRhhO1co9Q8ijHJG5V5 +fidWB52EiDYNtakH+9ayCZ06NrrC/8BqEspABJMqxJsBUkZgpSEtcHMsQZHiB0ZnI cj/jrO9Mn9R15vp6/yQOi72RJU0yJKSOOIpw/t/Ov5j6Q2UZenWzR4r+DfVt7xT3PO /E1PpqmFMTIvlOVDnJyivLK+/tW22IGrxl+9ADQ7mQGDnbckxcb23BMl6+hEedYhBT oNJc58zYfypGzmFwPZceRIKs/T+YPwCmEoMWyQgAimjpIPLnPNtXE+uO9scI/kVf5j wkQXm+bU3lFgg== From: Geliang Tang To: mptcp@lists.linux.dev Subject: [PATCH mptcp-net v25 1/8] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint Date: Tue, 10 Nov 2026 18:11: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, SIOCINQ now reports N instead of N+1, aligning with TCP's SIOCINQ behavior. 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 02a4f479d9d8..fc4ffa326317 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -2402,22 +2402,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 Tue Nov 24 11:17:55 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=1794305512; b=jDenxJcYaDg2a9IM0VJQiN6KimFy2d9KN1J/dL02gR5oMyi4tsxcIaCLyjFaDi1Xl9r7 iv17w++zcTICuESqhG59buh+HP25R4gepiq6nG95m1TwzORlu9ysE9ic5ynoCDsR+OUnz QqD8oUVL7d29+7mwzzkFquFRhX90jsEqgxhgYkpTbiXTw6TQ2ORKw1F4QvGq4etmtYAvE Y8jadN2bheXN3r5Zt4CkPEoVGZSSnt5R7dyR4iiuwvjjdp8uh+YGbWQYGyZBiE878ckTo jFFIvq/271XP/azyuziFV8BWYvhbVocMoci2OCmLA8LfDPM3h6rwFYRz9Pjye8MBh9w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794305512; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=P3rVcv0f6ipvWmWRcOlC9OQYmBwG+XFf5XCqB/ypUGY=; b=CGNUvWr4p1WT1/f5mwIabx1ov3FFam5dhFdN2aTv7QKbYOcP6pkJlsAgzgBUtC57JViu JynC4YmF+PukYcuFGMPOCZGrVdA1u0+GRinfOt4N0rAhW6nYh1WoxQoSSoSiyNKR8Bj0r CKMbG7FdzGP8ZGXHoudY3Yercp4T3JhR7epAIB2RjdccIA0Skvj4uJuK88tYwCDcFqseq i+gRhCuSA3LSIXyEyR2NjUDPSoBdQkqe1KljdSG45jbe98NUmU63eektECOB1O88fP/bB H1Z82t6Hg21tVd0PwxBjfzZSzS4hc7RSlvgnbJ3Ify32WQk2SGdnylt0MgF5UXy6+PQ== 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=c85KuYPb; 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 45010606A33C for ; Tue, 10 Nov 2026 10:11:52 +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=c85KuYPb Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91F7C1F0089F for ; Tue, 10 Nov 2026 10:11:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794305512; bh=P3rVcv0f6ipvWmWRcOlC9OQYmBwG+XFf5XCqB/ypUGY=; h=From:To:Subject:Date:In-Reply-To:References; b=c85KuYPbbYK0Uv2ytk5/vRejtfvh/wLfmfG9EXgQ0ls82lh38HvkxrfCLNmx1zMKE UqWQQ2hUPsvIpN2Fsf1VQOmjd/f4pxp7mEHxjam0r2c6WACjYsoMozGlqVKrlLhBqi AdvKucXN6o0yL6U/iJ5aboF6+hW8LgpAMTrypAt5chZ4Be88Bizh/spd2MAj0lNfcT q6zIKqOwYriWjSMA1wXlbzwxK8d4/qatBuwqOJP5fpYqEdg9O/bPtSy7jahGEX59MV CDPnGKZW/QLIUYS/MomZwAPH3MxGClJpa1l0knrQcFI8p1H1Zt8sZJc5gUQbyo6QdS tkBE4Jz/et/Wg== From: Geliang Tang To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next v25 2/8] selftests: mptcp: connect: check TFO SIOCINQ overflow Date: Tue, 10 Nov 2026 18:11:41 +0800 Message-ID: <58a7c022d24c1fcbcba1dcafc62182ada49f5f35.1794304840.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 | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/test= ing/selftests/net/mptcp/mptcp_connect.c index 178d98d91fea..5b002dad25d7 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,41 @@ 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) + return -1; + + if (pfd.revents & (POLLHUP | POLLERR)) + 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; + return -1; + } + if (info.mptcpi_flags & MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED) + return 0; + + elapsed +=3D timeout_ms; + } + return 1; +} + int main_loop_s(int listensock) { struct sockaddr_storage ss; @@ -1207,6 +1246,27 @@ int main_loop_s(int listensock) check_sockaddr(pf, &ss, salen); check_getpeername(remotesock, &ss, salen); =20 + if (cfg_sockopt_types.mptfo) { + int ret =3D wait_for_remote_key(remotesock); + int avail; + + if (ret < 0) { + perror("TFO: getsockopt(MPTCP_INFO)"); + close(remotesock); + return 1; + } + if (ret > 0) + fprintf(stderr, + "TFO: timeout waiting for remote key\n"); + + 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 Tue Nov 24 11:17:55 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=1794305513; b=ltUeUsT95Y0eu0a4744TgpzCL4YVHmvsStfMO8lKiY+Y8VgcDcWjLlSfXE7T/fJnKjiE 9+kegUx3lLVZYaqaoHpKC8WMisjUv+IV4oMQdr+fnNu1V4qJ2Qa+mvhFjU+QtGoNChdIR dQxuT+qAfm/dlqxtCBxmOKovwI8J7FlbA1/Y8FtKB0KXwFFA/kBtQ4DhmJSOtLSCc0P77 toCZPkMqkpbvBQsbdnrRIqCVFshZOlMUxMbK6jVET8FVKikBlgSnyPvsJaQ8zD73GphBt FrNDf8WEfbSBn2hJukBHvSyxcgktH7H3pBtCJfuO3adndFsglt831OBupw0qJUadG8w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794305513; 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=OVXeWMnM4M3mg0ghGEbENrsk75oNAr9P2yUnItOMBgV+YFGHocBwvB9O31Uj9dyyGABt dAc+KVs+yJ6b6DWxzHTjUl6Urx9kTac9sDsgxTyG0P3dt6XJ2A6ojZGAu3gk4vY0qEgmZ IhVEX3jALzzMHfPIZy1j28Wta4wGuARa+dHS8rGx5hkFJz9mtb1/cQaDWuOVp7S2jZEq5 REL8zAV4mmlmXrWjkvDFboiymv6A2Byy5M97S1jVpgAYFpQ1jxFe4wD3OoOmHSCyZa350 0wJAAqC7S0s6Q2/i4f7wvC8VqbQ7m+1NRrhi5LGFRj/gtRjfcBw4rbqKmE1RZu/qwxQ== 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=bLpdokXn; 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 5DBD3606A33C for ; Tue, 10 Nov 2026 10:11:53 +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=bLpdokXn Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D03B1F008A1 for ; Tue, 10 Nov 2026 10:11:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794305513; bh=K0ucOvjIjrcBa4o4gYqu3rYj0YatnSeO8vFYHsOpG+k=; h=From:To:Subject:Date:In-Reply-To:References; b=bLpdokXnwfgK8fLtTXs6AmWbW5uibliSq8h2OKPmXww57QVI1mGVYdqWTRCiMG+42 W245mRpMmWrnJ+9wtVoleqsc+N+aoWiuNyRBTCr5vo0LEv+Hq7Y83/OM9Vpz8h+92q YD8bat7mnJkZzegEKdjH1x3dg0mSWL30/y5pGPQOOq5b4OuLqaiRt7+9dQh6d/Bur3 FLseNcch4vcPKo1e1fos8SmAYg1b7uVTQeZhIkQHFRJA74EbZ6MjC9WVKIfFNRQhZS Ba+NJPBymzDsNtj5nkpEAqzpokq2yEcUEbCb2QU9mXZeRsYacKGwARiElsDWE/bvPg P+wgYkIj2FvSw== From: Geliang Tang To: mptcp@lists.linux.dev Subject: [PATCH mptcp-net v25 3/8] mptcp: fix fallback dummy mapping anchor Date: Tue, 10 Nov 2026 18:11:42 +0800 Message-ID: <4c48d016490d43b6892c622cbae858b48f176cff.1794304840.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 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 Tue Nov 24 11:17:55 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=1794305514; b=DE6sytTIG4DKD0N1cCfigFKXFlZApJKvVmv5fEtrXxB+f9t3x7YvybAK25FgSq+vDh1q e378Wmyk1vb/0HBhuOid17Gy9srRJxSBI+u6H3sxU1WIjO4emm+poEEtqzyxtbvg/+5Ao PuycCFC4YC2f/JxaAXse4SP3vA08gGju6y2DZuOHxnVgahu4341SL3XNxag7ulaHkbajL 56gKF8yROdH5XsyMABcKdlGoQjwIrVHPjaS+mSP7e/vBe6TFXwXilWwBOZO+NPqZCjY/N pp9gSTXsbmRunS3e4x1LrKi6UTeJtU1OG+giapoqor6jln8UodscSsWGvB6vVymi93Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794305514; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=XDb+YnJ7YCU2Wk07FxmjUJYiMQTtGXc82amITCCPGwY=; b=0OkXiqFbC0EFTDRUnBWYRMRshx3w46auJUPXKBN9pTvGzdk5JvvguiZuOPpgPjsk1pTY AFPQOeKONH+Mrk8e0TtrkvE4II6MzIFd09IONHqhNu4YXlo5QurvAKG4q5glGl8Um6JBz +BIzCS7fyjKU8QYBwsCWUtbDNhZ4oKS0TmVnaMHhxTKzgfgzEQkogNSStbnt44Re0+N2k dGJ9ZkpGTO/KXPHqgavOBk6cOSqOS6f8bgpzlqnExTLu9K5rnxLJtUYPzOnXY1VZV+2fj swe945gSUIzj5LIWdc/ci1d2X6KdZ3c4GHa2t4tv6MW59qBjC1sriConIFddrl3KOUA== 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=i1YdHQ26; 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 7A9AF606A33C for ; Tue, 10 Nov 2026 10:11: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=i1YdHQ26 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C00221F008A1 for ; Tue, 10 Nov 2026 10:11:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794305514; bh=XDb+YnJ7YCU2Wk07FxmjUJYiMQTtGXc82amITCCPGwY=; h=From:To:Subject:Date:In-Reply-To:References; b=i1YdHQ26L5zWu3q3v7dOP1Ve568Y5WOzPS/0wmVDQH0NQ7I5/c9W5JPcsEtvI6pc0 fgljYxnL8QYHcliGD20FTg/xs3MnOW9nath5LQaz05EzjFtoTddACRfXvID1F66/p7 +QjbEWJRmC5K+vXj0eL1dplAKIXl4/jqbUdfAnNyK1STtYFUBx0mxqhxjlOzfQ3Kej t3ynqYRrK+Zdaa4GruA+cXG0SXDuFP9NFftor/SdBFz2v5xinaPSaPn9XduBhvGDgZ GRDOV+joB10iDb21+soVn+FMSuGc8kxpDHgYWaqqCdLGHcyPAvmWiRQ2uVaewZS9TL NMrKcjYUunlPA== From: Geliang Tang To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next v25 4/8] mptcp: drop the mptcp_ooo_try_coalesce() helper Date: Tue, 10 Nov 2026 18:11: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 fc4ffa326317..71f5b0209192 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 Tue Nov 24 11:17:55 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=1794305516; b=kIUdL3XCsIX4aqijtp7NmByav8GByaCNfKnYUYDr7/LnMDhT0zi+gLx0hkS2tc6wY295 cmW8R1zHAMToixO78QRnRvpjwQSzenO6kProj5/v44kHLwMG0focw8NoACqoTIjPKaZxO BIHXC7OHSRSAQEeBCifpT5HJGfGd7Wp0NlBibuPMa23aGClJQeKs4dVt4kbEPx0YnpjNV TmbhsyarITHBs4m8F1cmGIGxv0SWo8zpqsODO4IP/TYSPD77Z8gfxwj8CZmxODGRrEE4C yc3C/5h8NqHNy8Y8O8s5ptuV8n7l3P9BQCnnuY8QLiQ6qmqkbVNF83vYby1fp4EkWjQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794305516; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=5li1ySu2m5Obl1tzDM4IHURp1XTlyMK73oi7LSgQe3A=; b=jXiFFMg4P90Ut2FX6/7xp3YEqQ8rthxRhrTVFZvzIRaYm4dncQwa53jeVgpdkkdE9wrk kkIJmK+y6Aa7AY62MPWN7ZMVeBOyXHOahurO0KU2nSiF8/xoiwBI0AW8MYosvQylhOWpj mU5FMSQLPYcXfofm4Xj7Jqt/pGkrGDX9g0y1Ui9WfcEV6GSY1IM9aJo21D9e6GPhvDtIb HD5sGU+RzbEeohdP1E7vUVl4MO+d/joqA/RljmTPDKSdChyUb6zWBWBhLZ5zriXlSmzhh MTzS4tDnCouAZ1y0wPYrBxWjOwTxihXag15viRNElyAqTtYGt5GtkeIdT2ebffZBiqg== 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="Q/NGhawm"; 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 E453E606C5DC for ; Tue, 10 Nov 2026 10:11:55 +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=Q/NGhawm Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04AAF1F0089F for ; Tue, 10 Nov 2026 10:11:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794305515; bh=5li1ySu2m5Obl1tzDM4IHURp1XTlyMK73oi7LSgQe3A=; h=From:To:Subject:Date:In-Reply-To:References; b=Q/NGhawmGXYL3j7Ft5MwP42WzJfec1vGo97Ynzw4XsfCIkzwBpDDZLmfmXteHzPbj a+qPiQfKLxd7PyPZ6K7/SLCo0z9A3likoyS2ZRsHD3R5uuZC/pLDseMfXQcj+lAQTn 9e5bdXm0KG2nrNDBXbMHaoCXhoFoXxnTR8ya45QUmct8okf2Z67nNAmRXoI3j8Vwt/ 1Z6tsQItpwdOzNwEhpUQUvcV8mOQBRPAEAP3nXbDLh+jQ7x0uYQG3x6FHyCc2wAG+y ossfd7XiWuN7FePJL0yjroi5g+5DcQvP/Do9NN4Uq7fEhOW15QuTQ+L/ftN4NTZ8SF 6ABZaebJsVafQ== From: Geliang Tang To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next v25 5/8] mptcp: drop the cant_coalesce CB field Date: Tue, 10 Nov 2026 18:11:44 +0800 Message-ID: <61e30a5ecaa111377f7dfa573983f89d52af3df9.1794304840.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 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 | 39 ++++++++++++++++++++++++++++++++++++--- net/mptcp/protocol.h | 5 ++++- net/mptcp/subflow.c | 8 ++++++++ 4 files changed, 52 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 71f5b0209192..ce0f9c2e6fd1 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,24 @@ 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)->end_seq =3D MPTCP_SKB_CB(skb)->map_seq + skb->len; +} + 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 +462,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: @@ -2375,7 +2397,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 @@ -3674,6 +3702,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 */ @@ -3876,6 +3906,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 Tue Nov 24 11:17:55 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=1794305517; b=KhisO3OFJt5L/BNt/Gheng1Gk/plloq24aKCJKq3WYgbNauTq7inOWcQK5znBbaVhpDi urGYwR7JbdaZOgaTtytPyi23xOEWw5cNQGdT7EPmuv+AFHL+Q7am41Yx051XBJbTn0nID J4DzttCheUJuh5DlWugMX83QpWJOTpeTv4ltOVztFiSj/4AA4MihqWLi//qU7AIFmwu9w rGQtEX1BiFr1wd69cAadFX7d3a7QMlYc4Y9SmnzHWyAFtLAq4u+r31WWujQzN9kL2/qMs DI4gDpA4YTJy0P52rO4q6MPxIYAYCUHOSYwglnXhCGAFtFa5Ht7xMHzc/2QrLK/lbHg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794305517; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=Ds2ksEBXXBzmwzAA3NvbN9gQjvChceJ4f9q8XGecZfw=; b=16cIEruBIguNlcbHlyqvPXAoNXNTDdORyQdtdRRUrG2S+rLqz+8Rne3e7u1VPfqzPDOD mXQSUOs7lwMBH+FheCs6VZhNIuWVbLMzKYL2kri9/oIb3gwSUHZO5j5JCy8o3K25aWcKK nL+IeaPVrN2dnbwtd/v90xbyWQkdULo1j8QXE93biceNyfreKFt4PxdNlMhGGecLe6Agm 0D7r5XvH2s+a+iIdDNN7fwuPnFnA40nyHl59nVXnxDfbBfBblFLjOWSqaKxhncaZOYCKE hAEphptpu5jZfleklrbdg0O9FiuZh2MefNFxAQlTf7jxGODAGGC8RhyK+PIPm4Z19PQ== 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=CqGn1uIZ; 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 E5E9A606A33C for ; Tue, 10 Nov 2026 10:11: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=CqGn1uIZ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 233E31F008A1 for ; Tue, 10 Nov 2026 10:11:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794305516; bh=Ds2ksEBXXBzmwzAA3NvbN9gQjvChceJ4f9q8XGecZfw=; h=From:To:Subject:Date:In-Reply-To:References; b=CqGn1uIZtOfIWMr66bWHeYszr3MUvZAU7V4sE+oghKHbWQdVqxkt++bHlwdmH/Mh8 YrtTC9+bniM4FqWpMYnIxPKr4yZQx/pXqxGgVJe+DZObdt/nvSm6knwPONZ8R8WK+M Z1DJkZNlkIP/Etk5JrSR8TaatQnjYhemUp3AfuD621pEJvoeeYxzJiriarXHdAWaCM +hr1xVD0MuA649HXGguwyASa2PEXJG2ge4CJMmq2rsnJCqO6dhPuOqtySmTcJZxBIs NB0u43JvyVhKRSv8lmy42ThJnreOQFps8tUvgy+jw6UwWuvfn6xrjhBR1EK5LFhHyS Gzmd1BeXW6GEw== From: Geliang Tang To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next v25 6/8] mptcp: remove CB offset field Date: Tue, 10 Nov 2026 18:11:45 +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 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 set to mptcp_subflow_get_mapped_dsn() without subtracting offset, and end_seq is set to map_seq + copy_len. This keeps map_seq pointing to the actual start of new data, avoiding issues with OFO queue comparisons and coalescing when the skb spans multiple DSS mappings with non-contiguous DSNs. A new MPTCP_SKB_CB_F_OFFSET flag marks skbs where offset > 0. This flag is used in __mptcp_try_coalesce() to refuse coalescing when the from skb carries a prefix, preventing the prefix bytes from ending up in the middle of the merged skb which would break the offset calculation. A new helper mptcp_offset() computes the prefix length on-the-fly as skb->len - (end_seq - map_seq). The recvmsg path (__mptcp_recvmsg_mskq() and mptcp_recv_skb()) uses this helper to skip prefix bytes when reading data, instead of relying on a stored offset field. The partial packet handling in __mptcp_move_skb() and __mptcp_ofo_queue() no longer adjusts offset and map_seq, as the recvmsg path computes the correct read position using mptcp_offset(). 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 | 77 ++++++++++++++++++++++---------------------- net/mptcp/protocol.h | 11 ++++++- net/mptcp/subflow.c | 6 ++-- 4 files changed, 58 insertions(+), 45 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 ce0f9c2e6fd1..645eaf3078a9 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -168,7 +168,7 @@ 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 || + 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; @@ -421,13 +421,12 @@ static void mptcp_init_skb(struct sock *ssk, struct s= k_buff *skb, int offset, struct mptcp_subflow_context *subflow =3D mptcp_subflow_ctx(ssk); bool has_rxtstamp =3D TCP_SKB_CB(skb)->has_rxtstamp; =20 - /* the skb map_seq accounts for the skb offset: - * mptcp_subflow_get_mapped_dsn() is based on the current tp->copied_seq + /* 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)->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); @@ -494,10 +493,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 @@ -918,12 +913,9 @@ static bool __mptcp_ofo_queue(struct mptcp_sock *msk) 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; @@ -2207,33 +2199,25 @@ 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 + + mptcp_offset(skb); 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); @@ -2252,14 +2236,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 { @@ -2398,8 +2380,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; @@ -2439,6 +2423,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 @@ -2457,6 +2442,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; @@ -2466,7 +2456,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) @@ -2476,8 +2466,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() @@ -2520,6 +2513,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); @@ -3696,6 +3693,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; @@ -3906,8 +3904,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) @@ -4628,7 +4628,8 @@ 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 + + mptcp_offset(skb); if (offset < skb->len) { *off =3D offset; return skb; @@ -4670,11 +4671,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..2b583846a93e 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; @@ -1381,6 +1384,12 @@ static inline bool subflow_simultaneous_connect(stru= ct sock *sk) return sk->sk_state =3D=3D TCP_SYN_RECV && is_active_ssk(subflow); } =20 +static inline u32 mptcp_offset(const struct sk_buff *skb) +{ + return skb->len - + (MPTCP_SKB_CB(skb)->end_seq - 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); 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 Tue Nov 24 11:17:55 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=1794305518; b=fiD1Ay0Jq9nkZaVMdQRj9pKW3utG9QDdCmKAxKElkhTiCldHnhogDZleHO9vxkjX0vuK /kuysZTy/vEkHUkZonF8Fi4LaTBK3i091Ji1GuIcTsfjpi0NUynN9Mq9/XD6fSxlWY2HD k9eSR+uWYXE1ra6kDBD4cuqHinm4zjegIFvPaZfxJkffhHKRCdbxVYdndczLGmQRDevC8 7eRlE3GF2H6EN4exMSpk54PFpOYMck24sm4kKa6RFIbIp/5d27nuasmavRVQd/PyK6ep2 5dQ/EtR39YqhQfSacLcwhxrGSdLqHfSQAm3RvF6BfC4TdEie5UD3wld8RztLxFCG7lg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794305518; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=LEMtZ8va07BpETGPRTb5rDpXpyyk0X6Vj6YnKelij9s=; b=DY20uztq5QvZt/Xhb7wf+rCCmPpzKG2VwEBEls4quDnV3tUlJVLjKWrPU/I2MmXkv6BI Z0wVz5UG2DzcjUdU0oaXnAR+3TqrATTqGCAsvTrgjZPLSs6JVsotDOcxfYv8BNy9VkFpi IUqcB3wcsJbWIMTk1LT3GrPwmQBGlPwsQHJDwteezbaZXpPitWqazjCilzA3CItXcfhYn Rz9ObBkkAhV72wH92XFK5wJjIhZCW6hNSq3lBF6MTeA3Q6eddfYxT3DbR6Ox1Lj+Po5Tr i/V2gidggkzvtaY0Yq9dKmYdw6eEnyiPzol+1gQCzKWrcktt/N1k0jJXtrDVciPqv0A== 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=FlOhIeH7; 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 35BD3606C5DC for ; Tue, 10 Nov 2026 10:11: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=FlOhIeH7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4194E1F0089F for ; Tue, 10 Nov 2026 10:11:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794305517; bh=LEMtZ8va07BpETGPRTb5rDpXpyyk0X6Vj6YnKelij9s=; h=From:To:Subject:Date:In-Reply-To:References; b=FlOhIeH7PaYbG6HtJOWK0vefdb4YJgGWaqekTj0zbiif9II0WcaPj06A4Dd19d5SS W6A4DeM7nh8uSEcnX52KJziAL0QAMzIt2xogQ7gyjXq6ud0NH3HJpVz4GN8YjrtCnp ccbG7ujH2y/KfS9YlWx+L1R3Whpi7D0IZSoHIMXEd32euz6dJ77Uv9cINUVPhMALRA wPiEPHgjfX6VNkqVDdQaT3Wje442SEtgFxD2uYdv9vbjSvdf3l6DhhMyWcyKDhre0w Q4HcTqSbSxavPxB2SAdJQnjs2/AWglwTlsdpnXuRrOg+4S+9sXNG0hvwAISwKFPflA xrEdd019F+KVg== From: Geliang Tang To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next v25 7/8] mptcp: sync mptcp skb cb layout with tcp one Date: Tue, 10 Nov 2026 18:11:46 +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 The MPTCP protocol uses a significantly different CB layout WRT TCP, as it includes different information and uses 64 bits for the sequence numbers. As the msk-level rcvbuf buffer size is limited by the core socket code to INT_MAX, and after validating the incoming skb vs the current receive window, we can safely use 32 bits for MPTCP-level sequence numbers. This allows updating the MPTCP CB layout so that key fields with corresponding TCP-level data (map_seq/seq, end_seq/end_seq, flags/tcp_flags) use the same offsets inside the CB itself. 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. The 32-bit sequence numbers are safe because all SKBs in the receive queue and OFO queue have been validated against the receive window (max INT_MAX), so their sequence numbers are guaranteed to be within 2^31 of the current ack_seq or copied_seq. This ensures that 32-bit arithmetic (comparisons and subtractions) produces correct results even when 64-bit values cross the 2^32 boundary, as the relative distance remains small. 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. map_seq64 is set to mptcp_subflow_get_mapped_dsn() in mptcp_init_skb(), and map_seq is the lower 32 bits. end_seq is computed as map_seq + copy_len, which excludes any consumed prefix bytes. 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 Signed-off-by: Geliang Tang Signed-off-by: Paolo Abeni --- net/mptcp/fastopen.c | 5 ++- net/mptcp/protocol.c | 88 +++++++++++++++++++++++++++----------------- net/mptcp/protocol.h | 6 ++- 3 files changed, 61 insertions(+), 38 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 645eaf3078a9..981599a70216 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -168,12 +168,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)->end_seq || + MPTCP_SKB_CB(from)->map_seq64 !=3D MPTCP_SKB_CB(to)->map_seq64 + + (MPTCP_SKB_CB(to)->end_seq - MPTCP_SKB_CB(to)->map_seq) || 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; @@ -255,8 +257,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; @@ -302,16 +304,22 @@ 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)->end_seq; + end_seq =3D MPTCP_SKB_CB(skb)->map_seq64 + + (MPTCP_SKB_CB(skb)->end_seq - MPTCP_SKB_CB(skb)->map_seq); 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)) { + /* Use the full sequence space to perform the admission checks, to + * protect vs possible wrap-arounds. + */ + if (after64(MPTCP_SKB_CB(skb)->map_seq64, max_seq) || + after64(end_seq, max_seq)) { /* out of window */ mptcp_drop(sk, skb); pr_debug("oow by %lld, rcv_wnd_sent %llu\n", @@ -346,7 +354,7 @@ 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 (!before(seq, MPTCP_SKB_CB(msk->ooo_last_skb)->end_seq)) { MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOQUEUETAIL); parent =3D &msk->ooo_last_skb->rbnode; p =3D &parent->rb_right; @@ -358,18 +366,18 @@ 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)->end_seq)) { - if (!after64(end_seq, MPTCP_SKB_CB(skb1)->end_seq)) { + if (before(seq, MPTCP_SKB_CB(skb1)->end_seq)) { + if (!after((u32)end_seq, MPTCP_SKB_CB(skb1)->end_seq)) { /* 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 | @@ -400,7 +408,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 =3D skb_rb_next(skb)) !=3D NULL) { - if (before64(end_seq, MPTCP_SKB_CB(skb1)->end_seq)) + if (before((u32)end_seq, MPTCP_SKB_CB(skb1)->end_seq)) break; rb_erase(&skb1->rbnode, &msk->out_of_order_queue); mptcp_drop(sk, skb1); @@ -424,7 +432,8 @@ 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_seq64 =3D mptcp_subflow_get_mapped_dsn(subflow); + 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; @@ -449,13 +458,14 @@ 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; + u32 copy_len =3D MPTCP_SKB_CB(skb)->end_seq - MPTCP_SKB_CB(skb)->map_seq; struct mptcp_sock *msk =3D mptcp_sk(sk); struct sk_buff *tail; =20 @@ -467,7 +477,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 (MPTCP_SKB_CB(skb)->map_seq64 =3D=3D msk->ack_seq) { /* in sequence */ insert: if (!mptcp_try_rmem_schedule(sk, skb)) { @@ -485,14 +495,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(MPTCP_SKB_CB(skb)->map_seq64, msk->ack_seq)) { mptcp_data_queue_ofo(msk, skb); return false; } =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 + copy_len, msk->ack_seq)) { + copy_len =3D MPTCP_SKB_CB(skb)->end_seq - (u32)msk->ack_seq; goto insert; } =20 @@ -887,39 +897,37 @@ 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; =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); - if (after64(MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq)) + if (after(MPTCP_SKB_CB(skb)->map_seq, 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, - msk->ack_seq))) { + if (unlikely(!after(MPTCP_SKB_CB(skb)->end_seq, 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; + seq_delta =3D MPTCP_SKB_CB(skb)->end_seq - 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; @@ -2208,7 +2216,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 + mptcp_offset(skb); u32 data_len =3D skb->len - offset; u32 count; @@ -4628,7 +4636,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 + mptcp_offset(skb); if (offset < skb->len) { *off =3D offset; @@ -4879,11 +4887,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 2b583846a93e..175648ce13d3 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 Tue Nov 24 11:17:55 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=1794305519; b=DcvQugv9hIPwvfRxR7Sh0cJ+nOeSFclXbvrY+EPsaPrPIBQ9Hmlj1JQ5OYrvVe6Lb1dE /iTzO51Wfla7dg1f7iyyKtEO8rxHgbr+TxjMW67fbuh1KXunNopqTxDh9ggMTl4TZHas0 eZ+eNkIudtWMX5pOywzHGHcfMVvjB0hqfFJPAfRxob854iUWz00TckYlm7OsP08Zpq2nK PxTZl845kIX+laEcuaJMCAOEGD7KEzlEx3CLRpqUVXDau2kQelvArcW9/5GZH5DZodjaY 5mxtrdraPF1WP/6JxP2v1Cg+sa1vv+ztIJcw4r245fLNx3ZII2XAKkK85ArUKuNGxJg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794305519; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=yV7HkXlUTLrI88+p9R4JIjKEWzNXbsq/TRP03bVYmIU=; b=cgRDGcGR6CczzzPcFHJny1DE2i+8o+bmMKjsH2dArz95EDAADo2e+Vk9HJdPoCGNIZia 1FcKg++Hjq54THt1IooL6mzq7YlVCPgWFjy3VQjLp9b2/VOo8tXrUSM7s4oqpEDclWkZG 9rrTzrtbqwKlUKlgPownkGlw8iF3y5T8QHF7XTIPyyMzgd1sdRB2URnFnus3e/zdHSlLX OmwDn2m5HNdLdnrPoLp4eUNpeU43kS9CUpoQKv5CQpIBusqY3mwxkje6L8xzNitcji0fP vdkbTEyjXPNsz+tg/ZoM9S2ygpRPS/HWRAL92soOhr1k9P2B3uv2DTSaaxxLKlop0IA== 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=P8x18fjN; 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 E24CA606A33C for ; Tue, 10 Nov 2026 10:11:58 +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=P8x18fjN Received: by smtp.kernel.org (Postfix) with ESMTPSA id 456341F008A1 for ; Tue, 10 Nov 2026 10:11:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794305518; bh=yV7HkXlUTLrI88+p9R4JIjKEWzNXbsq/TRP03bVYmIU=; h=From:To:Subject:Date:In-Reply-To:References; b=P8x18fjNnrsjiXBxCvBObVktNJi1O1GiAJbYhytMTp/I28Q3FS+4ObyyHpN4VIfGz qZhVHd6rOTML6++co5M/ZFGVf4z6n8akL5EAdmVdebweOSadVszo7h4aQb3blSuvc4 xssloOUw8IbmqPYH3Ya+szkPEf12/vASxGoG3r/cbK7dSUXtvztE/GqJmlbbuzcBHc VK4vJiB9fk2ir9adk599muJraOY8cpTPs7ukqqZ3pj1wJ3ffsDCdEs9L8RHI1VRv/E GQwHYb0MGENX8OXMzaUgntmXWliD/xYcBDsILixFcPHKYCg7XqU65Uof9t6pm2dLuI YfjQeQqIWl+wA== From: Geliang Tang To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next v25 8/8] mptcp: defer read_sock cleanup to mptcp_worker Date: Tue, 10 Nov 2026 18:11:47 +0800 Message-ID: <7396957e6e466cb4cf6864734d805c823451a5a3.1794304840.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 callers are mptcp_splice_read() and svc_tcp_recvfrom(), both of which hold lock_sock() and run 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 981599a70216..5318b54920e4 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3145,6 +3145,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; @@ -3220,6 +3235,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); @@ -3263,6 +3281,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); @@ -3710,6 +3729,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 */ @@ -4632,7 +4652,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) { @@ -4650,6 +4670,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) @@ -4691,11 +4712,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 175648ce13d3..cf0750ecef54 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