From nobody Mon Nov 23 20:21:18 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=1793965033; b=Z7GxyI+OZLpzxLu4mjbe5yOQcaCiQ5IsqOh6P46cFGD973DQ4j0ou+I1eP1my4Rss9PQ gtJ5AuddMN+zOsdHVLN16cnDAVO/nBhM4qLQe4nHqOjL5v4EvY4fuQhrxgFnr17SxVGMP 5+vXHsK9B1bMpulQm7A+Fz2gOt3cF6Q/Ja1mrmEXQoy6ZxvKw0wF44vmPIrSVV1fzg/HA 0RCiYETNEt28J5X23CZeVMuw+U0TO7H7FIHzogmShDgP9cmQThQJo9vVUV2SfznwpnDwa 8RaAXMfPayH3sqjYTEFDi3an5iYKQoeYd1OAmTvWb7olGulZaFURb5jz8lbMarmLH8g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793965033; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=ENsdALkfUX9tGdOXL4nELYO0+LVHl7DFp0e6QBEKZkc=; b=qcZUc3LvLo5LS/gNitiifeKtyN/M4xc+xCQRAWdo/vN71eGxrqXv41JTFMi2q0yO1TtU DMgC67uDphBIpiKy/eMcJmLfvgKsF3/+sTcA0HAdOlk5zGoQgo8L38qjDy8++KU3ebZu9 doM5orTDq1VxHKz2HF57avXoGYnMkx0Xdzaj5MInCO3UUDhRwGET8K9xTJjVKgZXgE+Jj u/ZOSDE0hwIMCFI1nPGgETVJDv4jlbs/HNZRhquN9UHj+BHaOEHjIfBVt1QKQYhIu0Z6G CkB6mB5z/P3248k/HBzQxO2SyTcb3kPl9FjccCNIA4HUpiyKAYAUlWiCNgMy2RHCxow== 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=kRVxZAjb; 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 0E2CC606C6F2 for ; Fri, 6 Nov 2026 11:37:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kRVxZAjb Received: by smtp.kernel.org (Postfix) with ESMTPSA id 248C91F008A3; Fri, 6 Nov 2026 11:37:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793965032; bh=ENsdALkfUX9tGdOXL4nELYO0+LVHl7DFp0e6QBEKZkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kRVxZAjb7DEr/R07vWpO/bfMRtxLYKk+FRaFFM/Fej58CxNEmdNQIU3Eg/ZGon4v7 mAcZYgsKtSBz+yQswAJKaGNHl0KIAuPsKvMY2nPCjCm/RE7j/x8J5LaytHZ5yLL/DW WOcSBEbpJKyhSaa87mwMwCo6DNj05u4Mdvlpc3dTy3NapY9y0SgXnwTO16lUSVErOv xhY1E1f2BH+GMhlvCGohw6KeX+0oFWv31iMDWB8l88CxBeMvyiMga1IZwWGp2o8pR4 dFBAkMv0tfFzDV1vKmkzrKB6vvkX0AtZ8nKXgP0kXaEItbvoZXzYjOQW00XuRKVD+t yBPWyG+yExAmA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-net v22 1/8] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint Date: Fri, 6 Nov 2026 19:36:57 +0800 Message-ID: <751f1c0ccc0c0de2dadaf9bcb52bed01a7515ed2.1793964796.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 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. Using mptcp_data_avail() avoids this by tracking bytes directly. When RCV_SHUTDOWN is set (DATA_FIN received), add 1 to include the FIN byte, matching the previous ack_seq - map_seq behavior. Fixes: f03afb3aeb9d ("mptcp: drop __mptcp_fastopen_gen_msk_ackseq()") Signed-off-by: Geliang Tang --- net/mptcp/protocol.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 02a4f479d9d8..421df3af1ef9 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -2402,22 +2402,18 @@ 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; + if (sk->sk_shutdown & RCV_SHUTDOWN) + hint_val++; =20 - 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) 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:21:18 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=1793965035; b=S/FKZKhf2Mmy/VjEcl4VJf0+yPYSO/AYKEka9ymTjpZu7P8T1k1K7gqLPwOea5Fd4yM1 SdUm8HEDS8GqrHPXQxzrjRQCQAK3ZjoTeNNDT33hQScSdDG1nCNRu+Uqbkn33SJLhwi5X Io3K1fMWCIjh3La8nU4Avj4i0yKld4Ra3+xgYHNyGRY8eg2StyEtjQKd2DeNzoQav2hJx xpzVyr8huLtEzbvPInlksCl3uIQJIorUm70yiOeIWsvHvhc5uBmX2G2T9z/eG0Rj/zWK+ ZxomAJdO1927/0iTAAhDDv3xVuXOwc6gg2HbVGNomxWGX0XhQww1aT6C5/1lpJnm2Yw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793965035; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=6K3VF7qe7xqCuJ7XT+tgtmwumtm+zZmrEQTMAoysf3M=; b=LJwp32Dsq8PAdzIoWmstqBdc0sKXPDDw0MFyaRoL/wwTx/dtYOZz+ePe4UOQI0auBe4c 3I0MEdccAEX3BVsDqenQ31P0e7QIhWH69ExTrc3445oX7UctAM9seAjjIazXKv0Ojwtbo J4VQuyYO5EKVZ2riotDhmXqCfCbvkrQWlnMgSyZ1IZz9y8Fn2KALTZJkoXrOcqCh2ZpFA Jn/2SiFkMIrGA9ZkiuQOKUEEZKghBnAZk+A3MkrBEAYzJlLktAzLpdbss5D0voIR3DNFI aeDB0Ah85rXVoat1kXvCzcqhBdoC0pyRKgYuadyNsYnd1MlNcHvcBiycoKGnSegsrXw== 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=lv1M0yp9; 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 A7A1F606C6F4 for ; Fri, 6 Nov 2026 11:37:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lv1M0yp9 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5DBB31F008BE; Fri, 6 Nov 2026 11:37:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793965034; bh=6K3VF7qe7xqCuJ7XT+tgtmwumtm+zZmrEQTMAoysf3M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lv1M0yp92wjg1PMym4/gYDsugCm9ofsMVbwAkRSXNHmf7e+3/HzDXgHVqJpu0CRKa 9cOkSsZLMrw9zBxfruy5WD2XcdKBlMTDsd8NtdGwb464ylQbKiS4pjlVh2JtMq/1qY MAjcblSXcUpJHnl+SL+lx04Op7afOnAbHBG3VP8LvKxUJ43LpolO2vtkOMSLQUDQN2 c/k1joGDzardQEWiRJSZ7I5PYj83SiZ3/Q+Kt81ZK5HH7lKf+eBvq4sfVir0AJtU52 MNcDvsXgPA6NjNR9t4sEJQe3RE0OL6kJy+GbJR/DElypGwwUgF1I8iU+8qRasBe1/u 9PQbjeUjmBx8g== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v22 2/8] selftests: mptcp: connect: check TFO SIOCINQ overflow Date: Fri, 6 Nov 2026 19:36:58 +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 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 polls MPTCP_INFO until the MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED flag is set (with 100ms timeout), ensuring the third ACK has been processed. 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. Signed-off-by: Geliang Tang --- .../selftests/net/mptcp/mptcp_connect.c | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/test= ing/selftests/net/mptcp/mptcp_connect.c index 178d98d91fea..41eff818e950 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 @@ -1176,6 +1177,24 @@ static void maybe_close(int fd) close(fd); } =20 +static bool wait_for_remote_key(int fd) +{ + struct mptcp_info info; + int retries =3D 10; + socklen_t olen; + + while (retries > 0) { + olen =3D sizeof(info); + if (getsockopt(fd, SOL_MPTCP, MPTCP_INFO, &info, &olen) < 0) + return false; + if (info.mptcpi_flags & MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED) + return true; + usleep(10000); + retries--; + } + return false; +} + int main_loop_s(int listensock) { struct sockaddr_storage ss; @@ -1207,6 +1226,24 @@ 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)) { + fprintf(stderr, + "TFO: timeout waiting for third ACK\n"); + 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:21:18 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=1793965035; b=wgaIbZq5PgkLJyY7zLDtUkqez+OKU4lsL+Wqz3Jbn3NYqaOn2EUVlV/WgM80v81D+mWS PzyLusXweQWHIwpWrcO5lUyS9fEoVd+M9tHxqk607xsbJDXwyEv+bngckVdq0QH/Y5wlQ kd2aHmrMVrWAFp5ggQAWX1jwdSpUAA1fbvI79EYDkSFWpBylLZJXdWA+MQbclf8mp3YPI yCME55rbayFu2GVde5zIZvoTP3f2XG22e4hKUXq7cftRnNjIwve/WaJNwpVmhthh92aAQ yj6r8vrdT9AwEUzy1c5kMFMfOMUx520D0UE7Q7J7bjWO8Q9W2CFqmQufVzMDJsUp27w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793965035; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=K0ucOvjIjrcBa4o4gYqu3rYj0YatnSeO8vFYHsOpG+k=; b=hS3mISkhgy55OA4nv0+bxp+vEbs36VUx2L0xMfYVo4U07s1mogT41wEVy8QhVS+ynNNH nEzA7XeXR8ZdjOCDE10n8PyufHKiBI3oGM1siOrQ976SZJuo3HoJLKWZbb8J01yAxA2+D TZf8lOdyX97x9C6JXLJj5Z/K0aMCIiIdPEo92BpMi+7ggL2r1QHpds0C9h9+GQzvSKmAx Q7sAP56cDnzmuZWb3cyCI0cD4bWWkmGubIOMzp06hW4BWQp/8c09JBJzJzwT7G9LONJKH gxxW82TcGbhLBB2Y3GqDNiO0AV1JbamPF9jDLEo68F3Mkf58IAc24EvTbNghM4HZHUg== 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=blsPHWGQ; 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 9E362606C6C9 for ; Fri, 6 Nov 2026 11:37:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=blsPHWGQ Received: by smtp.kernel.org (Postfix) with ESMTPSA id A95FB1F008A3; Fri, 6 Nov 2026 11:37:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793965035; bh=K0ucOvjIjrcBa4o4gYqu3rYj0YatnSeO8vFYHsOpG+k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=blsPHWGQiwFSIJVLjN568aBhuNHolyxDXWpJbK+froq4Mg2iEb8nsJEUROnUCGi11 YCQjs5DWfB6e0IG+4UKCZBsC1WHO0TeD/TsqlqHuubMjep+KD9K8diUu7igaCLmOwS hMBWo73kzBh/9nhzr2Ae++YvylEGFoyZseVPLIIAAhI+9kYrqNeZ7q8ktWQGiijoM7 dmaAuzwWgBRKET3Dq6y6Bs6Z8tekvDyJE30JkyOFsCHhuytKFzKJwzG/jI19G1sniB yuDPeUuSYupQw0ZDscX6SHXRpvb0KjWPT9O3VNwecs+QIuQAKquOj6yaNtvlYrwtlC 0ZNDKVK/5Brjg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-net v22 3/8] mptcp: fix fallback dummy mapping anchor Date: Fri, 6 Nov 2026 19:36:59 +0800 Message-ID: <978cce15c0b5e46acfcdcad736d4bb7fc3367eaf.1793964796.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 Mon Nov 23 20:21:18 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=1793965037; b=ioOvCEVKaMu/3LLeJnwuzQlxTyyi8VnSvxtPepf44fAcFyfAThQi0BAtHAI25v0e52xn h63A4Vn9Znu35vMlAOlQzE8n+62N5H53gPwKEY4MP4Akm+ZGj8UhyCxamQ5Qjk3xKqMnN +C2BR/WYtCXMySdNiIItjv8vCYCWk2p8lun1CbD9oqlEgoyLApM+9oB9NBr1pR/wjlixi d9T1rgUTxmAjy3Y+jpuHBjUlkt73hjt58AKpqaUjqcWGl//Id/RuIZltXgbiSWujATdrO 2VDIMg99p8Yz/SD7EQkgQ7CLVq2bwsSty7RQG+2zgu0cQET56v/nja0K7fFQeNHNDaw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793965037; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=YDfrHzKAp3vQQH1BwFJa1vTRfzWydl6ciGNlNBcEfUk=; b=36ZJgFJKlLbS/S9qlrjtSv69x6NTCV1xc7VbLxGtWKcO9AMDlhPcM1XLNVTRNNfAPOLM ceggxtMwswInZ/k9ZskUIcZ4H4BFnOw4up+w+1fPTs6qefVVVfLAOXnxEaIBR14L+KQoA Xm+9GQmDdX0SJyHsxO/Q9Z5BQBR4BvH7N9Jf+QC2SFCQeaYYhbNH3babbQoDgkdcE/UUW BkQrhCuSf2vlcsx9fa7iZjCX5AOWoj/g1s4Iw3PWuYn/qcJeps8FHnFY+2TnigO8p5Dta pan4KD1uCy/a/k9NSjy34CRVcOwnm2I7OBsyblTcjescj6inNC5/5aprc/PigGD6YKQ== 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=hVzQFZKx; 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 574C6606C6F2 for ; Fri, 6 Nov 2026 11:37:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hVzQFZKx Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09BFA1F008A3; Fri, 6 Nov 2026 11:37:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793965037; bh=YDfrHzKAp3vQQH1BwFJa1vTRfzWydl6ciGNlNBcEfUk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hVzQFZKxtAlrYAHzuJ0i4wa122uBrtcYUyao8fjI0GtPiTE/o2oCAE98LLNXhtsAm 6T+T9436Nv9sip6229KnrEShcvWl7TDC1HIeTr4qVnUBAkSILA+KkHECpbIyuJJ170 xOH48EB7DBR62UWiM9v5d/kaHeoh5sTTRicqytxsoYCqOfl1K8L8F7UESS9o/q0/5w F2/e9HkYo61/5WJB3IUiS6GJyV53d2Sb+G8WD0eMxaeQJM7mDWzo1BLL05OujeNXgU FD3jkGVrjbzFrfbYYDgjcJfBWQcmGyCXEuc0TUu//4WuP9CYxRAVDRV5059N1K5bBD yDrAsBaPsjLSw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Paolo Abeni , Geliang Tang Subject: [PATCH mptcp-next v22 4/8] mptcp: drop the mptcp_ooo_try_coalesce() helper Date: Fri, 6 Nov 2026 19:37:00 +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 421df3af1ef9..4495a148b40c 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:21:18 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=1793965039; b=c3tYCGpQpz0WPa2tIGTgB99vnjSkCKTA32iHPxo0o9wWiHBkATgqM8zd8nJpkchPVlxw cnHjGeqyyHpMN4Tua1ceKNCWx6u6buWdrc/vlQfAGraeNUeH+C647z0aamYRSGUeyzg13 4O/t0i7TazaQ3d6qli2YJqMQqXPcyn7M6vBWCI7OaTmKqpnlnR94ku6pE10QMubKw8hB7 Oeup8neZhTTlHlvUh3ou9SydQzCn2mAjFYpOwwYgqUqLcEwowlDfCoZY/uDgfsdIos5ai LUKAyqDlUb+xmo62ZLX+h5rOGSJ5vHLL/yREDpYB2JXUUIpYtfu9JZzaL7g/Tt2vQMg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793965039; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=xQQg7SVlqyQvpGgnZ0O6DBdCuMozWfrxyFEmk6b2vf4=; b=dvQZVuN4Bj0aIUEkKT1MTUfF9G80/vn9R75oRpNPBydIxzcLlyprOK8K7QuLdQGJ8T4b s+OlMuh4pMdXHsqBemkobxJQy3Y21Vig57CkCRKEHxyf5jNg3leezc5ggOZhDJABCTf2y wPBetNgKHoUFg8dHzEtglBNjufXgRQ9QLfylmH8VxK4FIKUroAvN6JEmzSO+xmDjYiT+U BJdDoQKIr0hVR9QkyITVIH8lG4HAUc2nYjGP3+7/lFkIOoBuNK6MrULo0bDX1ouUavaU5 XIPW9iWj+0Avz9Jx/DPMA5aX/CTlCkfKwJGuwU0CjPVFzDuP6kQYy4tLo8la1LQUTow== 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="Ad7IEc/9"; 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 B64D7606C6EC for ; Fri, 6 Nov 2026 11:37:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Ad7IEc/9 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73E381F0089F; Fri, 6 Nov 2026 11:37:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793965038; bh=xQQg7SVlqyQvpGgnZ0O6DBdCuMozWfrxyFEmk6b2vf4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Ad7IEc/9j4xX4IeAylgpj11i1c3C94k1OJ/GXJ/zokN9OKIwB28EshcQ/YDi/mhGp vECQiQmIargiVp7jqbFMQDR2j2QiBqP2oUAMaN4yPUjM6Exrq1r4HKehmJL1U+mpK7 WBIu6OKWzs0y2vbujSEwlcCnzBL0HdwJe+fVGlnm689DmF4FhO4Soqu10au64DLIVq JX52GUMr3F9EOfN8NxoFX5Rir6qoRskLDGaHcSTv6QGkF/8LWpOJGoGt9tJWcwEsyo O56OCvxqovNbOEkacRJbZfgkO0j9LfQDpAtt9/MNuZcjavICtaJWIUSlt1r6JnBi+u bp/GF3g4hxRhw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Paolo Abeni , Geliang Tang Subject: [PATCH mptcp-next v22 5/8] mptcp: drop the cant_coalesce CB field Date: Fri, 6 Nov 2026 19:37:01 +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 | 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 4495a148b40c..74a94264111d 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 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 +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 @@ -3676,6 +3704,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 +3908,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:21:18 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=1793965040; b=CyofjmpHAHffkOU4ljWPvu6v6oN1L4tZEReBki62RC0Qn0rfPk45Fk+DpoUFeQx3jnNQ Fjvt2SUj7u/K2nhvKQW7EdKgBengRA4dse2PjgRjqM5eXn6L5X2VLG/4QJrM5UWLtik75 X+GzoOfEpknLIuV4OWs6I4jCMxf/Z8iggB5ppUGoDWDO5tyYr3Eei1pgLltL3l2z/WN+A GijVmTUpH4cGPW7yNtpr6vucmMgscarwpY8uEJbfSSTUMxkullpuFvDcKg1Ubv2T+fCy0 J/CSxx3QE0qbw13sF0jd0rHMP2KY72rS6Hhn1KSWD32sE7rSDBaNPSCNE9eaKPRbG7w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793965040; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=D5udrLFinlgXQBluWtT0MFlrh1xNzuBNqc+8FD+I5Tg=; b=webKdPfkYKgXo5epGlXeQtTUfwqvZhG1OHcqsZp+Z0LHa95ArxoVt6I9r2Be7XZeOX2n 3Vnx6obnnCSaNOj4DOulITo2yIOt+EEyjvVGQSMQYkYMFBQ+t6HQxaPw/jZEE+PbMHFEG 9Whe4T5i3bCs1ghG+mcRqxSi6aNBFFEW238iITTwdqzLVvsO1Ljgk10Bk0KKHu7IRobZl mQYhFs2saumoeavOrvp1OTl2LOgZVqExusFc1+bDuOtYzf9jKq57CedbNcqmEatTJU9GT s+UeZuwS/c9+a7Y9rjH4fdptIsRYvGbor7e0/5vx20Wfmijzj494FBgGlbANPrFNp/Q== 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=M2vMLbMs; 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 07328606C6EC for ; Fri, 6 Nov 2026 11:37:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=M2vMLbMs Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEDBF1F008A1; Fri, 6 Nov 2026 11:37:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793965039; bh=D5udrLFinlgXQBluWtT0MFlrh1xNzuBNqc+8FD+I5Tg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=M2vMLbMsm+WS1/acqDO7yW4NEIYPXFIX8gMoMLfAm96y16xELrdW4ynBaT3fQr8sh 1HtwXjYLcuE7/OWC54neoj6btpkqJeR+4Nh+0ouG/fhJwygsNDG/VgYev9I8kgVV5s zNu1IJ48adV7H1QXbA+C8dYBud0oYnlmxoqififRLDs41HZIRW5dcNvGVNZD97+Hhz wT5yBO6pK5tSPkkjSQQh8xt4IM1xXvHlh65fzgXvBDvHo2GUhT+Sz02GI2MJPcZl8P 293p11gFaemts8vKmE7VOsujOq2ZPurOm8hsnlucv0lMlO1VsLPANUOz1bQXi4hCSB y6mvXuO8zAa3g== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Paolo Abeni , Geliang Tang Subject: [PATCH mptcp-next v22 6/8] mptcp: remove CB offset field Date: Fri, 6 Nov 2026 19:37:02 +0800 Message-ID: <7c1d46fbe47ef7510fa106d0920580d64baa7187.1793964796.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 are removed via pskb_pull() (to handle non-linear skbs safely) before setting map_seq. The function now returns bool to indicate success, allowing the caller to skip the skb if pskb_pull() fails. 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 | 8 ++-- net/mptcp/protocol.c | 97 ++++++++++++++++++++++++-------------------- net/mptcp/protocol.h | 2 +- net/mptcp/subflow.c | 6 ++- 4 files changed, 64 insertions(+), 49 deletions(-) diff --git a/net/mptcp/fastopen.c b/net/mptcp/fastopen.c index e18b31028e7e..78481c100e2a 100644 --- a/net/mptcp/fastopen.c +++ b/net/mptcp/fastopen.c @@ -45,10 +45,11 @@ 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)->has_rxtstamp =3D has_rxtstamp; =20 mptcp_data_lock(sk); @@ -56,6 +57,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 74a94264111d..cedc91accc6b 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 || - MPTCP_SKB_CB(from)->offset || ((to->len + from->len) > (limit >> 3)) || !skb_try_coalesce(to, from, fragstolen, delta)) return false; @@ -415,25 +414,38 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *m= sk, struct sk_buff *skb) skb_set_owner_r(skb, sk); } =20 -static void mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int offs= et, - int copy_len) +static bool mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int offs= et) { struct mptcp_subflow_context *subflow =3D mptcp_subflow_ctx(ssk); bool has_rxtstamp =3D TCP_SKB_CB(skb)->has_rxtstamp; =20 + /* Detect mapping boundary: skb spans multiple mappings */ + if (unlikely(offset > 0 && + before(TCP_SKB_CB(skb)->seq - subflow->ssn_offset, + subflow->map_subflow_seq))) { + if (offset >=3D skb->len || !pskb_pull(skb, offset)) { + WARN_ON_ONCE(1); + sk_eat_skb(ssk, skb); + return false; + } + offset =3D 0; + } + /* the skb map_seq accounts for the skb 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)->end_seq =3D MPTCP_SKB_CB(skb)->map_seq + copy_len; - MPTCP_SKB_CB(skb)->offset =3D offset; + 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 + skb->len; MPTCP_SKB_CB(skb)->has_rxtstamp =3D has_rxtstamp; =20 __skb_unlink(skb, &ssk->sk_receive_queue); =20 skb_ext_reset(skb); skb_dst_drop(skb); + + return true; } =20 void __mptcp_sync_rcv_sequence(struct sock *sk) @@ -451,7 +463,7 @@ void __mptcp_sync_rcv_sequence(struct sock *sk) return; =20 MPTCP_SKB_CB(skb)->map_seq =3D msk->tfo_iasn - skb->len; - MPTCP_SKB_CB(skb)->end_seq =3D msk->tfo_iasn; + 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) @@ -494,10 +506,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 @@ -855,7 +863,8 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp= _sock *msk, if (offset < skb->len) { size_t len =3D skb->len - offset; =20 - mptcp_init_skb(ssk, skb, offset, len); + if (!mptcp_init_skb(ssk, skb, offset)) + continue; =20 if (own_msk) { mptcp_subflow_lend_fwdmem(subflow, skb); @@ -918,12 +927,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 +2213,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); @@ -2252,14 +2249,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 +2393,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; @@ -2441,6 +2438,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 @@ -2459,6 +2457,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; @@ -2468,7 +2471,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) @@ -2478,8 +2481,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() @@ -2522,6 +2528,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); @@ -3698,6 +3708,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; @@ -3908,8 +3919,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) @@ -4630,7 +4643,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; @@ -4672,11 +4685,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..7878e6ac6c0b 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -131,7 +131,6 @@ struct mptcp_skb_cb { u64 map_seq; u64 end_seq; - u32 offset; u8 has_rxtstamp; }; =20 @@ -311,6 +310,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:21:18 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=1793965041; b=VhShMPP3b04IGwop3OuBgBmuWuu23hJQp+f1KXIp2DJSc2+g1RMuZQLVpLdiver3VF7o DC5ACCuxIf6kfIrhSO4+5W1T8iCNW/0Ldhb03OzVi1eT1so98FsUb/CBz0JmMSpcdPZaV gQFz8aMk0fVBpw6FqzGXGq5ws2N5yaOUFOhEGK3LmCDA1ukJe1QOnfskvyVNBL9rhvqwL 1C7ohXoukj5RoDdY9/dioOTbyZMxDImDXm6Ad2wab4jAuPswGTUNKv69qNRjOTtY1D9Lq NxkAySKpid4myF9KLmLQ0eSdOL1tjdG8KKSkx3GYKWeJbckpmiUYG9uAUzWfXK2XrbA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793965041; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=DkB23p2wabNujXGibcbNYScQ52WnppBEOv/68fO9x3I=; b=3hrNTN4UswhYr+iHUQsDfCjtd8PhETLOhopWmXKInZ/KrFqbgfFcgMh429yrqy/uSPK9 k4f1UvFRs4xhUCF2aAYQadCSciiGGYbwMypFtdz54vQEVGXneXIQajzoyNL2XzySPkjNL VT1baMLQzAIFFXbdJPBp9fiUGD1O8cAvzKVVw/BaHL/wfBpTfE4hUvrMZXGpRTu6gB0kz 7c8c6ixnBiU5df2SvpwRGqj8VGDvaJjdB9ALTBc4VGSrW1u0H7pflYZjJ6MpviD4Luphh 74MbrR+kKY9BWZyB2UKQ0BmEQmhH5UYaYE/5Cjeg+ZoGEu6Ho3p2q1VAzyh7AZ89Gag== 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=daPNbapI; 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 7EF40606C6F7 for ; Fri, 6 Nov 2026 11:37:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=daPNbapI Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C38F1F0089F; Fri, 6 Nov 2026 11:37:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793965041; bh=DkB23p2wabNujXGibcbNYScQ52WnppBEOv/68fO9x3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=daPNbapI4IeRD9cdTUYNiugdZh6EFN1gb2l+rS4ZtgN8be6CdFGdbbIUlkuxVAELh yaArrVqxfBILXw7wZJiNVOGTWp2F8/umJLNnfstBzRajc7cIy9B1ZUfAAsBkoHRcxz TbTClRsXCeMiRJe+ToC7ctQOo8KaqutOnbviKHjUVzjCHFcHxBxAuS2wXHHyw9q1Ux n3b6/7BDIcR8wB2+Eth7aKOnWylAxsX3rN6Knp99TGjJkp8KSAqTG/7uLvAzKigPgw CBhf1N6SzBX8ARIYVrCfOKufY7vyVvCeSYx7STgtSF9uZlBQXnUQzgULRChxwJ+MBz 0x00n7hR1Pl1Q== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Paolo Abeni , Geliang Tang Subject: [PATCH mptcp-next v22 7/8] mptcp: sync mptcp skb cb layout with tcp one Date: Fri, 6 Nov 2026 19:37:03 +0800 Message-ID: <20676e77a7ed0b1715bd1b539c21fb396d109a23.1793964796.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. 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 fields with a corresponding TCP-level data use the same area 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 adds a flags field. 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 shared fields. In mptcp_init_skb(), map_seq64 is computed as mptcp_subflow_get_mapped_dsn() minus offset, and map_seq is the lower 32 bits. The receive path now uses 32-bit before()/after() helpers for most sequence comparisons, while map_seq64 is used for window validation and coalescing checks. __mptcp_try_coalesce() gains a map_seq64 contiguity check to ensure skbs are truly adjacent in the 64-bit DSN space. Co-developed-by: Geliang Tang Signed-off-by: Geliang Tang Signed-off-by: Paolo Abeni --- net/mptcp/fastopen.c | 6 ++- net/mptcp/protocol.c | 94 +++++++++++++++++++++++++++----------------- net/mptcp/protocol.h | 7 +++- 3 files changed, 67 insertions(+), 40 deletions(-) diff --git a/net/mptcp/fastopen.c b/net/mptcp/fastopen.c index 78481c100e2a..bd52e9528b29 100644 --- a/net/mptcp/fastopen.c +++ b/net/mptcp/fastopen.c @@ -48,8 +48,10 @@ void mptcp_fastopen_subflow_synack_set_params(struct mpt= cp_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; =20 mptcp_data_lock(sk); @@ -57,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 cedc91accc6b..ced34e8cd25c 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -168,11 +168,13 @@ 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 + + to->len || ((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; @@ -254,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; @@ -301,16 +303,23 @@ 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 + skb->len; max_seq =3D atomic64_read(&msk->rcv_wnd_sent); + if (after64(READ_ONCE(msk->ack_seq), max_seq)) + max_seq =3D READ_ONCE(msk->ack_seq); =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", @@ -345,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; @@ -357,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 | @@ -399,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); @@ -433,11 +442,13 @@ static bool 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 + skb->len; + MPTCP_SKB_CB(skb)->flags =3D 0; MPTCP_SKB_CB(skb)->has_rxtstamp =3D has_rxtstamp; =20 __skb_unlink(skb, &ssk->sk_receive_queue); @@ -462,13 +473,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 @@ -480,7 +492,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)) { @@ -498,14 +510,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 + skb->len, msk->ack_seq)) { + copy_len =3D MPTCP_SKB_CB(skb)->end_seq - (u32)msk->ack_seq; goto insert; } =20 @@ -901,39 +913,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; @@ -2222,7 +2232,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; @@ -4643,7 +4653,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; @@ -4893,11 +4903,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 7878e6ac6c0b..fa54f70ab501 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -129,9 +129,12 @@ #define MPTCP_SYNC_SEQ 8 =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:21:18 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=1793965043; b=R8HVmgGSCMibYcACd6CkHOUEMx89O/v8ORIFQsOJi9I78j58iFu77hEjGY+g+RJAdSNf 3H29Zog145rEz4eXe+Ex2EKOYOhoYkMR1pDGw6yjDtn8By483MPkCiEibyvZIeOflFk3D uHZaSX6nHO1yLxCHM0kgZJL3TlW+e8P+1bcVq3magX1KXY/St51k0IJkLO39nmJNhVmEO h6tcZTNid9sOtMZMQ8e+xPloWI6vXSRXxPtPHXrWivne3dxdJwKGt8hOk196C6twQdRjQ KUmX4FQZskwOZ2ySIEGX92qf7eNFG29ewMAOX7iqBObXaIj/hWPcI/5k1lEAsVEkr0g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793965043; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=ghjivGT3KkRvOjBl9IdXDkTaN0jLumS52KQXvBF/FOA=; b=nfyuAmvR3Alcaqy1W1WJib/OTJbBW6VU7jLYPF6ElW+PZcjtW+bMKT/rFXF0bWOAqssG 8xHGSsZp3/VY0IKG9j3ReLywztGwSr1HRJ1CaDq0LHFirz6NVBULTQpZC+py/XqOIAyyL BA6L29ThnNln+KbSoaStJmLb2q0gKndmUpvKDtnn3BoNX00Yl79DbV0h4RtIBVal3xJ+w qH9RW+MBMA/yni0vv0Yyme4oKvbn6cs6TzFPpgp79mbg9LEYZO2TaFfeGcszQhUkjZFrE Hay8nKbPxsAXusSsvqgs2K+NruUyBOYJ6kDfaYWBBRVL31HF+JlYjrUdVe8XqW/QNGw== 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=G5XXZhPQ; 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 E863A606C6FA for ; Fri, 6 Nov 2026 11:37:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=G5XXZhPQ Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD9031F008A1; Fri, 6 Nov 2026 11:37:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793965042; bh=ghjivGT3KkRvOjBl9IdXDkTaN0jLumS52KQXvBF/FOA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=G5XXZhPQTl54mAXLjAzG/fjretsK6G5hZd+ZKe1LDeDOJl9Lz46TdxXhTiF+9D587 Vqr6jtmmW0fY9BbWW1uT2UkaB1DCnIzxdpLXCKKU1UVkbxyFFOFKd8PGToX+nQ06Tw L7Zo3LfOyFVNvVLrZbE18vUgwom6Xduhun75IBk1kHdQ6TYXft2GZhREv7ZOtwp7aQ xhp/mTC3svz1bgW9OoNRqiLUgetLz7zUxYwhGUJqKpZXZ+I3Tmcwgc7nqaQHQCn/GC WrSsVEx1JgzEclSqgdmDdUMLg+BjLdUy8MaOiNZPk9rtU0WSnFZQUAAQokOYFCjBgi TL7XFZmuLUG1g== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Paolo Abeni Subject: [PATCH mptcp-next v22 8/8] mptcp: defer read_sock cleanup to mptcp_worker Date: Fri, 6 Nov 2026 19:37:04 +0800 Message-ID: <2ad403ceaeb4a85913979b39448f90e2cc3a91b1.1793964796.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. Note: The BH call path does not exist in the current tree. This is groundwork for the upcoming TLS-over-MPTCP series. Currently, the only callers are mptcp_splice_read() and svc_tcp_recvfrom(), both of which hold lock_sock() and run in 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. Restore the backlog flush in mptcp_recv_skb() with a sock_owned_by_user() check. This ensures process context callers flush the backlog before processing skbs, while future BH context callers skip it to avoid deadlock on mptcp_data_lock(). Initialize msk->read_copied in __mptcp_init_sock() and reset it in mptcp_disconnect(). 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 ced34e8cd25c..b23159d9044c 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3162,6 +3162,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; @@ -3237,6 +3252,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); @@ -3280,6 +3298,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); @@ -3727,6 +3746,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 */ @@ -4649,7 +4669,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) { @@ -4666,6 +4686,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) @@ -4707,11 +4728,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 fa54f70ab501..3580cf66f303 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 @@ -326,6 +327,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