From nobody Wed Sep 17 18:36:13 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 E4CDBC2D1 for ; Tue, 2 Sep 2025 02:35:12 +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=1756780513; cv=none; b=uhYP1TevjsWRvkn6B+8jXONXmdjWOzfpGPEY1i8XydPJwxzcXcta2Gg4KKINb8KvMKY9JYOLqjMCLRHpiBa6XXgI6Z99f+NYf5n7x8lIk+V9WjgUzrizlvX4NDD6GatsjBRcNYRl9hVk9d6YN2Xb0BLEVpE0LDkrDEdriRtE3wU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756780513; c=relaxed/simple; bh=Pykskwwp8qZH4CptxGNkVBFJWN0QF4c7cXkxDCazJn4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RCZXGAUNZGzLtzBm4l3H7KIYM4a0D+sA6RTmLA0+lzA7p3aEY7lgQHGik3W6xSAHehMDGwgL4UUmaL4yDS+gppyKUUxr+nQOAXvkChMULsCMA/4QUKEoA/IRkVQboOrETvW8QjTN2Nk0XxFLQ+EBOhk9M31FNPxRgPHxkJCMvD0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VUVsan80; 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="VUVsan80" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 369A8C4CEF0; Tue, 2 Sep 2025 02:35:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756780512; bh=Pykskwwp8qZH4CptxGNkVBFJWN0QF4c7cXkxDCazJn4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VUVsan80VXAzC7ul44M2vhSYEB7fCQDhCaSlnQX80/m+1JFaHSpNULt6ohmiFFcwI UZRZEHL7aCfdvJBuPdB5YkUpLlO9vy9YZEb2hl34mDfabjNUAlusuhVqvC9WrN0Ky7 NR8snZi2MHTDGGjtoONbLUMxZmTvTUSAvTzBgjQMxih6yAahrUrBKLN4GBm4d1VsFl DRd8SC8Ewxsz9Q/229AvfzKe48V+F7bv37qq53hbDYbmD1bHWMrZSodVi13bvXtijQ U8pS13X4sR79ZmUJyRk8CGvjSLVwfTudexkoVyMLNLWXuYc9RS9rx+ms07W52uvCD0 RbHbkFHGqUKFg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Hannes Reinecke Subject: [PATCH mptcp-next v10 2/9] mptcp: implement .read_sock Date: Tue, 2 Sep 2025 10:34:53 +0800 Message-ID: <53276621ab42624e6a6ddb58869eabfb049b87b0.1756780274.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 --- net/mptcp/protocol.c | 74 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index df82584a6f7a..f55185410e5b 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -4039,6 +4039,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, @@ -4059,6 +4131,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 { @@ -4163,6 +4236,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