From: Mat Martineau <martineau@kernel.org>
To: Geliang Tang <geliang@kernel.org>
Cc: mptcp@lists.linux.dev, Geliang Tang <tanggeliang@kylinos.cn>
Subject: Re: [PATCH mptcp-next v14 6/8] mptcp: implement .splice_read
Date: Fri, 5 Dec 2025 16:22:01 -0800 (PST) [thread overview]
Message-ID: <088efdb2-4f2b-3c37-ce09-19a855f4f08f@kernel.org> (raw)
In-Reply-To: <cff194b2736d851c1ad28e2d6e38eb7e890de2a4.1763974740.git.tanggeliang@kylinos.cn>
On Mon, 24 Nov 2025, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> 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().
>
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
> net/mptcp/protocol.c | 96 ++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 96 insertions(+)
>
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 9302b372910e..abd0f44ad63f 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -4355,6 +4355,100 @@ static int mptcp_read_sock(struct sock *sk, read_descriptor_t *desc,
> return __mptcp_read_sock(sk, desc, recv_actor, false);
> }
>
> +static int __mptcp_splice_read(struct sock *sk, struct tcp_splice_state *tss)
> +{
> + /* Store TCP splice context information in read_descriptor_t. */
> + read_descriptor_t rd_desc = {
> + .arg.data = tss,
> + .count = 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 = {
> + .pipe = pipe,
> + .len = len,
> + .flags = flags,
> + };
> + struct sock *sk = sock->sk;
> + ssize_t spliced = 0;
> + int ret = 0;
> + long timeo;
> +
> + /*
> + * We can't seek on a socket input
> + */
> + if (unlikely(*ppos))
> + return -ESPIPE;
> +
> + lock_sock(sk);
> +
> + mptcp_rps_record_subflows(mptcp_sk(sk));
> +
> + timeo = sock_rcvtimeo(sk, sock->file->f_flags & O_NONBLOCK);
> + while (tss.len) {
> + ret = __mptcp_splice_read(sk, &tss);
> + if (ret < 0) {
> + break;
> + } else if (!ret) {
> + int err;
> +
> + if (spliced)
> + break;
> + err = tcp_recv_should_stop(sk, timeo);
> + if (err < 0) {
> + if (err != -ESHUTDOWN)
> + ret = err;
> + break;
> + }
> + /* 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;
Hi Geliang -
This queue could also be non-empty due to the length limit in patch 2.
Maybe another reason to remove that length limit.
- Mat
> + ret = sk_wait_data(sk, &timeo, NULL);
> + if (ret < 0)
> + break;
> + continue;
> + }
> + tss.len -= ret;
> + spliced += ret;
> +
> + if (!tss.len || !timeo)
> + break;
> + release_sock(sk);
> + lock_sock(sk);
> +
> + if (tcp_recv_should_stop(sk, timeo))
> + break;
> + }
> +
> + release_sock(sk);
> +
> + if (spliced)
> + return spliced;
> +
> + return ret;
> +}
> +
> static const struct proto_ops mptcp_stream_ops = {
> .family = PF_INET,
> .owner = THIS_MODULE,
> @@ -4376,6 +4470,7 @@ static const struct proto_ops mptcp_stream_ops = {
> .mmap = sock_no_mmap,
> .set_rcvlowat = mptcp_set_rcvlowat,
> .read_sock = mptcp_read_sock,
> + .splice_read = mptcp_splice_read,
> };
>
> static struct inet_protosw mptcp_protosw = {
> @@ -4481,6 +4576,7 @@ static const struct proto_ops mptcp_v6_stream_ops = {
> #endif
> .set_rcvlowat = mptcp_set_rcvlowat,
> .read_sock = mptcp_read_sock,
> + .splice_read = mptcp_splice_read,
> };
>
> static struct proto mptcp_v6_prot;
> --
> 2.43.0
>
>
>
next prev parent reply other threads:[~2025-12-06 0:22 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-24 9:12 [PATCH mptcp-next v14 0/8] implement mptcp read_sock Geliang Tang
2025-11-24 9:12 ` [PATCH mptcp-next v14 1/8] mptcp: add eat_recv_skb helper Geliang Tang
2025-11-24 9:12 ` [PATCH mptcp-next v14 2/8] mptcp: implement .read_sock Geliang Tang
2025-12-06 0:17 ` Mat Martineau
2025-12-08 2:14 ` Geliang Tang
2025-11-24 9:12 ` [PATCH mptcp-next v14 3/8] tcp: add recv_should_stop helper Geliang Tang
2025-12-06 0:20 ` Mat Martineau
2025-12-10 1:30 ` Mat Martineau
2025-11-24 9:12 ` [PATCH mptcp-next v14 4/8] mptcp: use " Geliang Tang
2025-11-24 9:12 ` [PATCH mptcp-next v14 5/8] tcp: export tcp_splice_state Geliang Tang
2025-11-24 9:12 ` [PATCH mptcp-next v14 6/8] mptcp: implement .splice_read Geliang Tang
2025-12-06 0:22 ` Mat Martineau [this message]
2025-11-24 9:12 ` [PATCH mptcp-next v14 7/8] selftests: mptcp: add splice io mode Geliang Tang
2025-11-24 9:12 ` [PATCH mptcp-next v14 8/8] selftests: mptcp: connect: cover splice mode Geliang Tang
2025-11-24 10:39 ` [PATCH mptcp-next v14 0/8] implement mptcp read_sock MPTCP CI
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=088efdb2-4f2b-3c37-ce09-19a855f4f08f@kernel.org \
--to=martineau@kernel.org \
--cc=geliang@kernel.org \
--cc=mptcp@lists.linux.dev \
--cc=tanggeliang@kylinos.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox