From nobody Sat Oct 11 08:07:56 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 15B2927A900 for ; Sat, 27 Sep 2025 12:31:38 +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=1758976300; cv=none; b=FXwaB1Z+a4cMZFlC6g00lzp+zV0LXsMzD238g71J2CFr22Zpjf7P7qGTtJc52JNE/DHF8J1YrSK98ILcq1uFp1S6LpgSx4AK+nOzYthwUzA+QZVCC04RLNy3z58jO4atkzm+teOKle6eD33lqt0Wt7X4lfEHl+ZqQWlT1X8lkg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758976300; c=relaxed/simple; bh=kAO0rb/tHrkcMFGp2LhqpXQkx7OXrBt5JdXbJn8olhE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PvO44uMp7Y8UkS/wEVHNz1Qqr2EqmfM+hUI4+ivL03OLW19/nTw/PSbV75Mana90J3dYVGYzDlQy5T/V//YcqEyKXrbxm97qZzSdW3AiQSeb3TPUQ8eaZ66TJkavf7H/dzRArn95S6tyfm42DJubrvWIsGoCjh/PKXBrs5X14C0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QXkqMGVY; 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="QXkqMGVY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A729C4CEE7; Sat, 27 Sep 2025 12:31:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758976298; bh=kAO0rb/tHrkcMFGp2LhqpXQkx7OXrBt5JdXbJn8olhE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QXkqMGVYvlm09i9tQ18MvUgaNVgi6gfl+pNPDaDhcVV6QDx9+/crGvqxCld6sSy45 hCTxkyrSoNpPJCS/aBIZTHLztPQ+nLqLzdyCRN0jtCam/XF0aRWiqPzKkwUqhGMvx6 cgcj82XaITE5h7x4r8RWl9h0iBnssrqmYxrrW+UNmdFkpDIQdB8Dv4EbDYTsV/GQ9W 56lDgaZlXa7ijfgtVT8cEe7DfRfHNrZQku9XnA+HuPjPQ1RrpceScdJemPk1L1rvMQ ZqZkqVPALjI1ap3TD+h3tl2EI5L7oqGmnBjS3QF9W2Ji7ndvp62OJLA/u4qouFMLa2 itbooh/WFHkyQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Hannes Reinecke Subject: [PATCH mptcp-next v12 2/8] mptcp: implement .read_sock Date: Sat, 27 Sep 2025 20:30:19 +0800 Message-ID: <2f159972f4aac7002a46ebc03b9d3898ece4c081.1758975929.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 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 --- net/mptcp/protocol.c | 74 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index e12dad700a58..dda16dbae9fd 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -4055,6 +4055,78 @@ static __poll_t mptcp_poll(struct file *file, struct= socket *sock, return mask; } =20 +static struct sk_buff *mptcp_recv_skb(struct sock *sk, u32 *off) +{ + struct sk_buff *skb; + u32 offset; + + if (skb_queue_empty(&sk->sk_receive_queue)) + __mptcp_move_skbs(sk); + + while ((skb =3D skb_peek(&sk->sk_receive_queue)) !=3D NULL) { + offset =3D MPTCP_SKB_CB(skb)->offset; + if (offset < skb->len) { + *off =3D offset; + return skb; + } + mptcp_eat_recv_skb(sk, skb); + } + return NULL; +} + +/* + * 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; + u32 offset; + + if (sk->sk_state =3D=3D TCP_LISTEN) + return -ENOTCONN; + while ((skb =3D mptcp_recv_skb(sk, &offset)) !=3D NULL) { + 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, &offset); + mptcp_cleanup_rbuf(msk, copied); + } + + return copied; +} + static const struct proto_ops mptcp_stream_ops =3D { .family =3D PF_INET, .owner =3D THIS_MODULE, @@ -4075,6 +4147,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 { @@ -4179,6 +4252,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.43.0