From nobody Wed Sep 17 18:19:20 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C073A26B955 for ; Wed, 9 Jul 2025 07:25:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752045947; cv=none; b=f2yKXpgGzi7rH6VPWQqbFK9sfUmKh/otBVbhIu8PtjMwj3/V7hqBDAIA5S8uaGy74jS78UXof0pBSVRgux3lTTGUvdPTVaC3cWmG4+fN64ylzexMnpT/6+91k+930JWaftcu6T8uZU6qjqc1SK1w0MVhyt14UdP/xOoG1N6r0LQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752045947; c=relaxed/simple; bh=CO4KtAfcjEBQODMX1D6EQv4ipfEwpdp2u+Ty9rMcrK0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vBEtz3XpjZ2bdRZizE0G7R7ft/7a5Pub3PbmSuNBLv+erXq4gVP8Sy9vSYuX4pczGLcKf0QL54erVasP6cGvJMC8UiUa2S02H5G6fql9a9rmAvTT5eFEwyvjkJHorSoFCpO91X5IatvoIen7svb9ajjuMT6/w3+b5tJrMLCL+nk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=N+XYttOQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="N+XYttOQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2959CC4CEF1; Wed, 9 Jul 2025 07:25:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752045947; bh=CO4KtAfcjEBQODMX1D6EQv4ipfEwpdp2u+Ty9rMcrK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N+XYttOQoVlnNkvG30hxxsm8rn5MrHnNsYAw6bTijmhB5y4GmLTCAdoyyuD/DNxj1 NX45HBf+asYttbT25SfCY14wfK6Ga7rRGSIb2ctxfndZ9o7BPAz6aAPGGGsNjEhZWi MOj8YiojdGE2fzAwoBUAn23aY9JBAoEl8bnKVqGmrc/HnEeavGk+rXtibc7KlrySvY 3KYjTEE2apXumileiSwXhswR96x7iFKi5E7dKAghVB2WoO4bY6UExcOHx6nojGWkjU lqxzvpytjOoOAwk5U1WCG7FlfGhO9/QL+UrahrkMvisDsPIIaBuJ7bzdR4duI+7Pwc 3Q+Zvgjweev1w== From: Geliang Tang To: mptcp@lists.linux.dev, matttbe@kernel.org, hare@kernel.org, pabeni@redhat.com Cc: Geliang Tang Subject: [PATCH mptcp-next v8 1/7] mptcp: add eat_recv_skb helper Date: Wed, 9 Jul 2025 15:25:28 +0800 Message-ID: <59ab5dfdd73b79e58cb48a855af0753a72be730f.1752045499.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang This patch extracts the free skb related code in __mptcp_recvmsg_mskq() into a new helper mptcp_eat_recv_skb(). Use sk_eat_skb() in this helper instead of open-coding it. Signed-off-by: Geliang Tang --- net/mptcp/protocol.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 0c93b36373b1..48365d54bc06 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1845,6 +1845,15 @@ static int mptcp_sendmsg(struct sock *sk, struct msg= hdr *msg, size_t len) =20 static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied); =20 +static void mptcp_eat_recv_skb(struct sock *sk, struct sk_buff *skb) +{ + /* avoid the indirect call, we know the destructor is sock_wfree */ + skb->destructor =3D NULL; + atomic_sub(skb->truesize, &sk->sk_rmem_alloc); + sk_mem_uncharge(sk, skb->truesize); + sk_eat_skb(sk, skb); +} + static int __mptcp_recvmsg_mskq(struct sock *sk, struct msghdr *msg, size_t len, int flags, @@ -1887,12 +1896,7 @@ static int __mptcp_recvmsg_mskq(struct sock *sk, } =20 if (!(flags & MSG_PEEK)) { - /* avoid the indirect call, we know the destructor is sock_wfree */ - skb->destructor =3D NULL; - atomic_sub(skb->truesize, &sk->sk_rmem_alloc); - sk_mem_uncharge(sk, skb->truesize); - __skb_unlink(skb, &sk->sk_receive_queue); - __kfree_skb(skb); + mptcp_eat_recv_skb(sk, skb); msk->bytes_consumed +=3D count; } =20 --=20 2.48.1 From nobody Wed Sep 17 18:19:20 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B510226B955 for ; Wed, 9 Jul 2025 07:25:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752045950; cv=none; b=gi2dnyicJ6NE6hlZ3KxBozDmbwPv2hR+Lr/2+d/lX2Fe72VQbSfIxbmKuRS0EayRdFmLmpHqwqCTjYNqllt2pquk+NWrpZTtyd/uYwi90PANnUG2WASrqbKZzF1xq2sRGm4vOYqdy4+Jp6cF43Z4qGbbQ0F7P64CGy3JJ6m89MM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752045950; c=relaxed/simple; bh=8n62puhLgGmvz7HLSvNtW2zCtRBzAwcgEE++VU0F8JA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d6zz+kRqICZ7JYmeDqEa+aqBUspVDWAE+kXbKOxaU0jj1iHqNcz6A2EiLIz6wRzL7hxtO8hO5aUanTRgf3BdnVTe/pq+r5COv85bft5GSkppR26Q7DmTpQ+M2wafmRZ7jqQ3PbShyXgjbYTHsNkuoNoBJHBFBoiW0+7Tp5K+2MU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RUR9RLkc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RUR9RLkc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE696C4CEF5; Wed, 9 Jul 2025 07:25:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752045950; bh=8n62puhLgGmvz7HLSvNtW2zCtRBzAwcgEE++VU0F8JA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RUR9RLkckiQeNMnyYwm4UPgSE+VDC44Nf4iYxxEhGuYtdTOvQg0UCrU1IPPvBmrMv yFY75iJUI1+x7Atds1EixHJGTv6OO40G9ikuyNoQvNS7Z2OJb512oJ211TZT4VSk5S lJsBsG/ZSpt1VMJMRsK1cRsWESdF3U2gzKRAVThcJ1/qS40HGCCsA+2VUBY8Xw9E1V RsoWaqMONPuYVpxqwgjeSwKE2w1lBVSSueIx7A/+kn9jgC+P60GxYI+ekud7Z9ubI7 t9ee3t1VaKSvTgaAD4wC7Qr5NUV5ZT4YvhmRWlJixs0BZEYi9rCSrzT0w8+/qQEHtM OrAn682/vW9dQ== From: Geliang Tang To: mptcp@lists.linux.dev, matttbe@kernel.org, hare@kernel.org, pabeni@redhat.com Cc: Geliang Tang Subject: [PATCH mptcp-next v8 2/7] mptcp: implement .read_sock Date: Wed, 9 Jul 2025 15:25:29 +0800 Message-ID: <6d748c65b678c6040448eae87f4daf264b2ed023.1752045499.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang nvme_tcp_try_recv() needs to call .read_sock interface of struct proto_ops, but it's not implemented in MPTCP. This patch implements it with reference to __tcp_read_sock() and __mptcp_recvmsg_mskq(). Corresponding to tcp_recv_skb(), a new helper for MPTCP named mptcp_recv_skb() is added to peek a skb from sk->sk_receive_queue. Compared with __mptcp_recvmsg_mskq(), mptcp_read_sock() uses sk->sk_rcvbuf as the max read length. The LISTEN status is checked before the while loop, and mptcp_recv_skb() and mptcp_cleanup_rbuf() are invoked after the loop. In the loop, all flags checks for __mptcp_recvmsg_mskq() are removed. Reviewed-by: Hannes Reinecke Signed-off-by: Geliang Tang --- v2: - first check the sk_state (Matt), but not look for the end of the end of a connection like TCP in __tcp_read_sock(): if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) break; This will cause a use-after-free error: BUG: KASAN: slab-use-after-free in mptcp_read_sock. v3: - Use sk->sk_rcvbuf instead of INT_MAX as the max len. v4: - invoke __mptcp_move_skbs. --- net/mptcp/protocol.c | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 48365d54bc06..fc429d175ede 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3962,6 +3962,67 @@ static __poll_t mptcp_poll(struct file *file, struct= socket *sock, return mask; } =20 +static struct sk_buff *mptcp_recv_skb(struct sock *sk) +{ + if (skb_queue_empty(&sk->sk_receive_queue)) + __mptcp_move_skbs(sk); + + return skb_peek(&sk->sk_receive_queue); +} + +/* + * Note: + * - It is assumed that the socket was locked by the caller. + */ +static int mptcp_read_sock(struct sock *sk, read_descriptor_t *desc, + sk_read_actor_t recv_actor) +{ + struct mptcp_sock *msk =3D mptcp_sk(sk); + size_t len =3D sk->sk_rcvbuf; + struct sk_buff *skb; + int copied =3D 0; + + if (sk->sk_state =3D=3D TCP_LISTEN) + return -ENOTCONN; + while ((skb =3D mptcp_recv_skb(sk)) !=3D NULL) { + u32 offset =3D MPTCP_SKB_CB(skb)->offset; + u32 data_len =3D skb->len - offset; + u32 size =3D min_t(size_t, len - copied, data_len); + int count; + + count =3D recv_actor(desc, skb, offset, size); + if (count <=3D 0) { + if (!copied) + copied =3D count; + break; + } + + copied +=3D count; + + if (count < data_len) { + MPTCP_SKB_CB(skb)->offset +=3D count; + MPTCP_SKB_CB(skb)->map_seq +=3D count; + msk->bytes_consumed +=3D count; + break; + } + + mptcp_eat_recv_skb(sk, skb); + msk->bytes_consumed +=3D count; + + if (copied >=3D len) + break; + } + + mptcp_rcv_space_adjust(msk, copied); + + if (copied > 0) { + mptcp_recv_skb(sk); + mptcp_cleanup_rbuf(msk, copied); + } + + return copied; +} + static const struct proto_ops mptcp_stream_ops =3D { .family =3D PF_INET, .owner =3D THIS_MODULE, @@ -3982,6 +4043,7 @@ static const struct proto_ops mptcp_stream_ops =3D { .recvmsg =3D inet_recvmsg, .mmap =3D sock_no_mmap, .set_rcvlowat =3D mptcp_set_rcvlowat, + .read_sock =3D mptcp_read_sock, }; =20 static struct inet_protosw mptcp_protosw =3D { @@ -4086,6 +4148,7 @@ static const struct proto_ops mptcp_v6_stream_ops =3D= { .compat_ioctl =3D inet6_compat_ioctl, #endif .set_rcvlowat =3D mptcp_set_rcvlowat, + .read_sock =3D mptcp_read_sock, }; =20 static struct proto mptcp_v6_prot; --=20 2.48.1 From nobody Wed Sep 17 18:19:20 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F153E26CE31 for ; Wed, 9 Jul 2025 07:25:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752045956; cv=none; b=bBmBCwat8zo3gvZBy8ZxsRXmnxN1qtbWmX0q8D7W8cnXwPQ6Yjx6GOJddpzi+cDSJlJdvfDWlJ0vBtYIzYFjGRLhtmGPOSmKDgEx8PlnbD69wQE8ZcU7cCQX0GKgF4C4PKf8qYjdjz3hu3/7gu79MQfshEBFbVf1nlWhHp/1sLo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752045956; c=relaxed/simple; bh=DiAXIpVjhSZ+RvlYXOF3cPsZn4SUz/v2DfoI59ns5rk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pxylk9eIKPQlXJFL4A+BL7kc4Falp6TLp/JjGZkE/dx5th+HaZme05oqUKMqT/GYfzw+edMsaVPdcs3KdNX4nx4nN40OQuGSxePcBc2k3RZd5Xx+irafsO7slVT60jkEoV3NQ5ewdzHFeAKlrIVRxOmyRT/wiswDWTux/q6auGg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=upPAWz3b; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="upPAWz3b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A44EC4CEF1; Wed, 9 Jul 2025 07:25:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752045955; bh=DiAXIpVjhSZ+RvlYXOF3cPsZn4SUz/v2DfoI59ns5rk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=upPAWz3bAZI6GEgKkA5MCJLDrDJiboT7/XQhsUsM0GIqXqqELZB7jkZIXSfXDfohi nME7kH361cLpFy5a9dBX6zeayhgyQvStKl3k7atPDeGtq/esAj9GJDnY1cNArr9EvO S4gLzGlfBMsGhbOYO8qp3+cjW19hdeGNoEumtgg/NhFA7sUGestBpArWndmwwxFxF2 Mjl9XQvM4WsPbF5GoimW2czGDUCc7YC3O8zdY8ShDBdIiWDnqvDu4AgUGV7OOXc/7l jY5G0+FgVB5jkeJZeLSiV65BeCQXobg5LHq6Gu45KJpyVhJHgg1Y1u/NFMzCd8YLWD KHKEliHBT8aQQ== From: Geliang Tang To: mptcp@lists.linux.dev, matttbe@kernel.org, hare@kernel.org, pabeni@redhat.com Cc: Geliang Tang Subject: [PATCH mptcp-next v8 3/7] tcp: export tcp_splice_state Date: Wed, 9 Jul 2025 15:25:30 +0800 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Export struct tcp_splice_state and tcp_splice_data_recv() in net/tcp.h so that they can be used by MPTCP. Suggested-by: Paolo Abeni Signed-off-by: Geliang Tang --- include/net/tcp.h | 12 ++++++++++++ net/ipv4/tcp.c | 13 ++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index bc08de49805c..338b97a91278 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -258,6 +258,18 @@ static_assert((1 << ATO_BITS) > TCP_DELACK_MAX); */ #define TFO_SERVER_WO_SOCKOPT1 0x400 =20 +/* + * TCP splice context + */ +struct tcp_splice_state { + struct pipe_inode_info *pipe; + size_t len; + unsigned int flags; +}; + +int tcp_splice_data_recv(read_descriptor_t *rd_desc, struct sk_buff *skb, + unsigned int offset, size_t len); + =20 /* sysctl variables for tcp */ extern int sysctl_tcp_max_orphans; diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 8637dfce8c4a..505c3a123e2d 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -316,15 +316,6 @@ EXPORT_SYMBOL(tcp_have_smc); struct percpu_counter tcp_sockets_allocated ____cacheline_aligned_in_smp; EXPORT_IPV6_MOD(tcp_sockets_allocated); =20 -/* - * TCP splice context - */ -struct tcp_splice_state { - struct pipe_inode_info *pipe; - size_t len; - unsigned int flags; -}; - /* * Pressure flag: try to collapse. * Technical note: it is used by multiple contexts non atomically. @@ -757,8 +748,8 @@ void tcp_push(struct sock *sk, int flags, int mss_now, __tcp_push_pending_frames(sk, mss_now, nonagle); } =20 -static int tcp_splice_data_recv(read_descriptor_t *rd_desc, struct sk_buff= *skb, - unsigned int offset, size_t len) +int tcp_splice_data_recv(read_descriptor_t *rd_desc, struct sk_buff *skb, + unsigned int offset, size_t len) { struct tcp_splice_state *tss =3D rd_desc->arg.data; int ret; --=20 2.48.1 From nobody Wed Sep 17 18:19:20 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1270326B778 for ; Wed, 9 Jul 2025 07:25:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752045960; cv=none; b=FsJtlHekozn5l2JTqz+y318KPpnwyFlUIsy7Cn+Lks4IK89E8tMNkBQgBwKg64PLBibp97qEM85ys+tq6hKu38tZI/wEbZ+yWbtE26nlYaJePjYauWFEu/pHriswp/GWr0cVXEdopb9MzKk25M11+ljmWmslaCx9h67oFFI4xX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752045960; c=relaxed/simple; bh=OjbFbRCuqzvUduDjZoX/Ing2VFQrPaLPZMKGgUW54Bc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W5yRd8kmtOsWHKLoVLJXTUFDQiIezuGfifUaDGW+E9y90tr1dIvuKmSLb+bT9sJrLf0a8tfU/HiuaJYjjsX/O5IPM3LwlVUOV3WGiEz0whM1xn48CO4lk1RwARfqUPL3DQxvu7b5EhWm6TLxPheUnGEJwI9FDc/Mjw6Shxc3WJA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tfrXpU88; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tfrXpU88" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48B58C4CEF1; Wed, 9 Jul 2025 07:25:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752045959; bh=OjbFbRCuqzvUduDjZoX/Ing2VFQrPaLPZMKGgUW54Bc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tfrXpU88+W/GdVDacVTG7JKSYND+i0MJca+4IvlGbtyLml0i3DjfxBpOCAjcyMkxA FH2E5gLIJ5IdgFwHf+nQojPcrlgcDE0pjWLqxJnUq+f+Z1gz3KKTJews6kadDihtJd dqYhKVdn1QNBvhKwReILZjLd52Gry4izKTciaunrB+3ITtH8Bo+KIdNprQEkY06HLa EXf99YlX8JZlGizpYKb5nsri0sSD9ghlPUUeXEUAYoI2nSXalwOapQniN/NrxB8u1Q mdAxEUvuJl7pPM+LWc9vQ3NHyJ3U5Kfbvqnia6+S8cvkHEo6qYQgY8yeS1r730fGN1 0aPG7RXK6Luvw== From: Geliang Tang To: mptcp@lists.linux.dev, matttbe@kernel.org, hare@kernel.org, pabeni@redhat.com Cc: Geliang Tang Subject: [PATCH mptcp-next v8 4/7] mptcp: add recv_should_stop helper Date: Wed, 9 Jul 2025 15:25:31 +0800 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Factor out a new helper mptcp_recv_should_stop() from mptcp_recvmsg() to check whether to stop receiving. It will be used in mptcp_splice_read() too. Suggested-by: Paolo Abeni Signed-off-by: Geliang Tang --- net/mptcp/protocol.c | 59 ++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index fc429d175ede..1fe04ec05ebd 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -2090,12 +2090,40 @@ static unsigned int mptcp_inq_hint(const struct soc= k *sk) return 0; } =20 +static int mptcp_recv_should_stop(struct sock *sk, long timeo, int *shutdo= wn) +{ + if (sk->sk_err) + return sock_error(sk); + + if (sk->sk_shutdown & RCV_SHUTDOWN) { + *shutdown =3D 1; + /* race breaker: the shutdown could be after the + * previous receive queue check + */ + if (__mptcp_move_skbs(sk)) + *shutdown =3D 0; + return 0; + } + + if (sk->sk_state =3D=3D TCP_CLOSE) + return -ENOTCONN; + + if (!timeo) + return -EAGAIN; + + if (signal_pending(current)) + return sock_intr_errno(timeo); + + return 0; +} + static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int flags, int *addr_len) { struct mptcp_sock *msk =3D mptcp_sk(sk); struct scm_timestamping_internal tss; int copied =3D 0, cmsg_flags =3D 0; + int shutdown =3D -1; int target; long timeo; =20 @@ -2146,34 +2174,11 @@ static int mptcp_recvmsg(struct sock *sk, struct ms= ghdr *msg, size_t len, signal_pending(current)) break; } else { - if (sk->sk_err) { - copied =3D sock_error(sk); + copied =3D mptcp_recv_should_stop(sk, timeo, &shutdown); + if (copied < 0 || shutdown =3D=3D 1) break; - } - - if (sk->sk_shutdown & RCV_SHUTDOWN) { - /* race breaker: the shutdown could be after the - * previous receive queue check - */ - if (__mptcp_move_skbs(sk)) - continue; - break; - } - - if (sk->sk_state =3D=3D TCP_CLOSE) { - copied =3D -ENOTCONN; - break; - } - - if (!timeo) { - copied =3D -EAGAIN; - break; - } - - if (signal_pending(current)) { - copied =3D sock_intr_errno(timeo); - break; - } + if (shutdown =3D=3D 0) + continue; } =20 pr_debug("block timeout %ld\n", timeo); --=20 2.48.1 From nobody Wed Sep 17 18:19:20 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A808326B778 for ; Wed, 9 Jul 2025 07:26:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752045965; cv=none; b=paXsGql6j6ndCUq6bNB+MCLY3pZ4Mru/JF2ShTCJWCNVI9JrMbRakoR/hCrrOCpHYaSz8hUUWyn9wBqvIRsp17yS2UiMDM2toBtb4vYFyRl91ezCOgQt55vxkeaDhij0ob5uA9AZBtwn0J4JJ5k/BkyquRORPToCxDuB5UswG+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752045965; c=relaxed/simple; bh=NGwUigIslDVPImgvx0xZtp7aDWmdqnQcgVhNgltA91k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uOd9pS0eK9lokHPrxktCIW02fbHnZr29MPwPrKp27GiGv2NrkvnQ1i3G8wglqKyROIWOW/95p534uJ1qZAOn4B65oIfqFmm/pyjOosenV7eCSonlX/k49IULNQfO7l1PQ7V97oGo/rGCPDapr2+WFHwj699sSkdm6H5ywk4NEf8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NBDEHRvR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NBDEHRvR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3A0FC4CEF1; Wed, 9 Jul 2025 07:26:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752045965; bh=NGwUigIslDVPImgvx0xZtp7aDWmdqnQcgVhNgltA91k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NBDEHRvR87JcIGPOWAmu3QTOHnQeR9bY4+5b298eVrxYF2Ckz1w9ikrq+IIvwvaAC EPTPWSoeHKBq0kmKLc2kp/4G0HJpBfQ1dg4Eagjf9NaUA4NG32pGoaGJ7i1eRY3Pcy zU29gXgPHVaueAcP3g/AAULoUWl/YaJZ6RC2ib8fZPwkhMwDEcN1yoSDIzbofwhygW +WlIe5ARRQjK59606AyHFYy3CxXDSbSwLCThRNtfjxGWoc8/LWo4fxM8HgW2nA6bjw UaLQF9IWnT8p/SMeidIs27onxhK5keczOFflElZtZqvrSBCyUn7Xu/6DO2b3uRQflo HdBIqarMwrHKw== From: Geliang Tang To: mptcp@lists.linux.dev, matttbe@kernel.org, hare@kernel.org, pabeni@redhat.com Cc: Geliang Tang Subject: [PATCH mptcp-next v8 5/7] mptcp: implement .splice_read Date: Wed, 9 Jul 2025 15:25:32 +0800 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang This patch implements .splice_read interface of mptcp struct proto_ops as mptcp_splice_read() with reference to tcp_splice_read(). Corresponding to __tcp_splice_read(), __mptcp_splice_read() is defined, invoking mptcp_read_sock() instead of tcp_read_sock(). mptcp_splice_read() is almost the same as tcp_splice_read(), except for sock_rps_record_flow() and mptcp_recv_should_stop(). Signed-off-by: Geliang Tang --- net/mptcp/protocol.c | 99 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 1fe04ec05ebd..6b3be1d0668d 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -4028,6 +4028,103 @@ static int mptcp_read_sock(struct sock *sk, read_de= scriptor_t *desc, return copied; } =20 +static int __mptcp_splice_read(struct sock *sk, struct tcp_splice_state *t= ss) +{ + /* Store TCP splice context information in read_descriptor_t. */ + read_descriptor_t rd_desc =3D { + .arg.data =3D tss, + .count =3D tss->len, + }; + + return mptcp_read_sock(sk, &rd_desc, tcp_splice_data_recv); +} + +/** + * mptcp_splice_read - splice data from MPTCP socket to a pipe + * @sock: socket to splice from + * @ppos: position (not valid) + * @pipe: pipe to splice to + * @len: number of bytes to splice + * @flags: splice modifier flags + * + * Description: + * Will read pages from given socket and fill them into a pipe. + * + **/ +static ssize_t mptcp_splice_read(struct socket *sock, loff_t *ppos, + struct pipe_inode_info *pipe, size_t len, + unsigned int flags) +{ + struct tcp_splice_state tss =3D { + .pipe =3D pipe, + .len =3D len, + .flags =3D flags, + }; + struct sock *sk =3D sock->sk; + int shutdown =3D -1; + ssize_t spliced; + long timeo; + int ret; + + /* + * We can't seek on a socket input + */ + if (unlikely(*ppos)) + return -ESPIPE; + + spliced =3D 0; + ret =3D 0; + + lock_sock(sk); + + timeo =3D sock_rcvtimeo(sk, sock->file->f_flags & O_NONBLOCK); + while (tss.len) { + ret =3D __mptcp_splice_read(sk, &tss); + if (ret < 0) { + break; + } else if (!ret) { + if (spliced) + break; + if (sock_flag(sk, SOCK_DONE)) + break; + ret =3D mptcp_recv_should_stop(sk, timeo, &shutdown); + if (ret < 0 || shutdown =3D=3D 1) + break; + if (shutdown =3D=3D 0) + continue; + /* if __mptcp_splice_read() got nothing while we have + * an skb in receive queue, we do not want to loop. + * This might happen with URG data. + */ + if (!skb_queue_empty(&sk->sk_receive_queue)) + break; + ret =3D sk_wait_data(sk, &timeo, NULL); + if (ret < 0) + break; + continue; + } + tss.len -=3D ret; + spliced +=3D ret; + + if (!tss.len || !timeo) + break; + release_sock(sk); + lock_sock(sk); + + if (sk->sk_err || sk->sk_state =3D=3D TCP_CLOSE || + (sk->sk_shutdown & RCV_SHUTDOWN) || + signal_pending(current)) + break; + } + + release_sock(sk); + + if (spliced) + return spliced; + + return ret; +} + static const struct proto_ops mptcp_stream_ops =3D { .family =3D PF_INET, .owner =3D THIS_MODULE, @@ -4049,6 +4146,7 @@ static const struct proto_ops mptcp_stream_ops =3D { .mmap =3D sock_no_mmap, .set_rcvlowat =3D mptcp_set_rcvlowat, .read_sock =3D mptcp_read_sock, + .splice_read =3D mptcp_splice_read, }; =20 static struct inet_protosw mptcp_protosw =3D { @@ -4154,6 +4252,7 @@ static const struct proto_ops mptcp_v6_stream_ops =3D= { #endif .set_rcvlowat =3D mptcp_set_rcvlowat, .read_sock =3D mptcp_read_sock, + .splice_read =3D mptcp_splice_read, }; =20 static struct proto mptcp_v6_prot; --=20 2.48.1 From nobody Wed Sep 17 18:19:20 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8845226B778 for ; Wed, 9 Jul 2025 07:26:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752045970; cv=none; b=pvdXcBqRmWTIFg8SswC9DKAyWSCtg0unrel4DFvVgyi+jUr3UFontHbby5aXN5rb1qm7uOX+Gv5ES0fRVLnwmyPoleAOjlEeun3cBZCLNFU6XLL/9dyeOgPWBdq8XBcxlwwSWkAACG/AfM6J6hfggIVbDd/PU+00IPwtsPJb4+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752045970; c=relaxed/simple; bh=0wVYuIDMtKRHLcf4WDpGvtHORgcXBGmH0WJWPUkF1OM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UxhNrOJ5YcJAOIqcSRuaxPVnr6dLamwutRlZFaFeN0yahR+TbOj6/otF6EMeSThdMdrZPTLByNRiuCDNwWjiWx8WSqRmRrWNLgqijw1tGnPTLjAny1k9WueDNiEchkyeavzdYFbW6qLbyasjG7hhL3Kgfru7XxKrcMgWY7+HPB0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nQ6CyqMZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nQ6CyqMZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E5C5C4CEF0; Wed, 9 Jul 2025 07:26:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752045970; bh=0wVYuIDMtKRHLcf4WDpGvtHORgcXBGmH0WJWPUkF1OM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nQ6CyqMZArPjzjcwWgcKhBD1txSl6zl+HTorByRXNjar9Y82FMilwrp+GxAgMQYDU MFA4el5NsS3wD166bi+0/5MUt7Fy/t/mK3F9SQT7EaK8T6xwmcYcx7gqZVW7sx8g6D WnFp6ubEaLpsXe3MgpBvha2Vo0qEv1Z6Mq+69d3pl2saAPH9SOtYd8jZP6IP5jxOZ+ An8pt4lvILIcDQGX1HhdTNJm8TXqLh3dWjAGOi7NsmAxGXsBtsAHEt6I70RRGCWb4r 1i9vdIAe80+Lo+tMPJVC7HqOd+e0ong27FaHsi4ww6Iu59MRJiAjD6jNY+Y7BkdCW5 9HfPoArtl1DeQ== From: Geliang Tang To: mptcp@lists.linux.dev, matttbe@kernel.org, hare@kernel.org, pabeni@redhat.com Cc: Geliang Tang Subject: [PATCH mptcp-next v8 6/7] selftests: mptcp: add splice io mode Date: Wed, 9 Jul 2025 15:25:33 +0800 Message-ID: <4436cb208ce129223dfb1017438c0ba5425e8081.1752045499.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang This patch adds a new 'splice' io mode for mptcp_connect to test the newly added read_sock() and splice() functions of MPTCP. Usage: ./mptcp_connect.sh -m splice Signed-off-by: Geliang Tang --- .../selftests/net/mptcp/mptcp_connect.c | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/test= ing/selftests/net/mptcp/mptcp_connect.c index ac1349c4b9e5..4c219d620398 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c @@ -51,6 +51,7 @@ enum cfg_mode { CFG_MODE_POLL, CFG_MODE_MMAP, CFG_MODE_SENDFILE, + CFG_MODE_SPLICE, }; =20 enum cfg_peek { @@ -123,7 +124,7 @@ static void die_usage(void) fprintf(stderr, "\t-j -- add additional sleep at connection start and= tear down " "-- for MPJ tests\n"); fprintf(stderr, "\t-l -- listens mode, accepts incoming connection\n"= ); - fprintf(stderr, "\t-m [poll|mmap|sendfile] -- use poll(default)/mmap+writ= e/sendfile\n"); + fprintf(stderr, "\t-m [poll|mmap|sendfile|splice] -- use poll(default)/mm= ap+write/sendfile/splice\n"); fprintf(stderr, "\t-M mark -- set socket packet mark\n"); fprintf(stderr, "\t-o option -- test sockopt