* [PATCH mptcp-next v13 1/8] mptcp: add eat_recv_skb helper
2025-10-23 5:56 [PATCH mptcp-next v13 0/8] implement mptcp read_sock Geliang Tang
@ 2025-10-23 5:56 ` Geliang Tang
2025-10-23 5:56 ` [PATCH mptcp-next v13 2/8] mptcp: implement .read_sock Geliang Tang
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Geliang Tang @ 2025-10-23 5:56 UTC (permalink / raw)
To: mptcp, hare; +Cc: Geliang Tang
From: Geliang Tang <tanggeliang@kylinos.cn>
This patch extracts the free skb related code in __mptcp_recvmsg_mskq()
into a new helper mptcp_eat_recv_skb().
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
net/mptcp/protocol.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index ee4d88e22888..813d438bbea8 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1992,6 +1992,17 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied);
+static void mptcp_eat_recv_skb(struct sock *sk, struct sk_buff *skb)
+{
+ /* avoid the indirect call, we know the destructor is sock_rfree */
+ skb->destructor = NULL;
+ skb->sk = NULL;
+ atomic_sub(skb->truesize, &sk->sk_rmem_alloc);
+ sk_mem_uncharge(sk, skb->truesize);
+ __skb_unlink(skb, &sk->sk_receive_queue);
+ skb_attempt_defer_free(skb);
+}
+
static int __mptcp_recvmsg_mskq(struct sock *sk, struct msghdr *msg,
size_t len, int flags, int copied_total,
struct scm_timestamping_internal *tss,
@@ -2046,13 +2057,7 @@ static int __mptcp_recvmsg_mskq(struct sock *sk, struct msghdr *msg,
break;
}
- /* avoid the indirect call, we know the destructor is sock_rfree */
- skb->destructor = NULL;
- skb->sk = NULL;
- atomic_sub(skb->truesize, &sk->sk_rmem_alloc);
- sk_mem_uncharge(sk, skb->truesize);
- __skb_unlink(skb, &sk->sk_receive_queue);
- skb_attempt_defer_free(skb);
+ mptcp_eat_recv_skb(sk, skb);
}
if (copied >= len)
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH mptcp-next v13 2/8] mptcp: implement .read_sock
2025-10-23 5:56 [PATCH mptcp-next v13 0/8] implement mptcp read_sock Geliang Tang
2025-10-23 5:56 ` [PATCH mptcp-next v13 1/8] mptcp: add eat_recv_skb helper Geliang Tang
@ 2025-10-23 5:56 ` Geliang Tang
2025-10-23 5:56 ` [PATCH mptcp-next v13 3/8] tcp: add recv_should_stop helper Geliang Tang
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Geliang Tang @ 2025-10-23 5:56 UTC (permalink / raw)
To: mptcp, hare; +Cc: Geliang Tang
From: Geliang Tang <tanggeliang@kylinos.cn>
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 <hare@kernel.org>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
net/mptcp/protocol.c | 75 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 813d438bbea8..3f29236ce5fc 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -4197,6 +4197,79 @@ static __poll_t mptcp_poll(struct file *file, struct socket *sock,
return mask;
}
+static struct sk_buff *mptcp_recv_skb(struct sock *sk, u32 *off)
+{
+ struct mptcp_sock *msk = mptcp_sk(sk);
+ struct sk_buff *skb;
+ u32 offset;
+
+ if (!list_empty(&msk->backlog_list))
+ mptcp_move_skbs(sk);
+
+ while ((skb = skb_peek(&sk->sk_receive_queue)) != NULL) {
+ offset = MPTCP_SKB_CB(skb)->offset;
+ if (offset < skb->len) {
+ *off = 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 = mptcp_sk(sk);
+ size_t len = sk->sk_rcvbuf;
+ struct sk_buff *skb;
+ int copied = 0;
+ u32 offset;
+
+ if (sk->sk_state == TCP_LISTEN)
+ return -ENOTCONN;
+ while ((skb = mptcp_recv_skb(sk, &offset)) != NULL) {
+ u32 data_len = skb->len - offset;
+ int count;
+ u32 size;
+
+ size = min_t(size_t, len - copied, data_len);
+ count = recv_actor(desc, skb, offset, size);
+ if (count <= 0) {
+ if (!copied)
+ copied = count;
+ break;
+ }
+
+ copied += count;
+
+ msk->bytes_consumed += count;
+ if (count < data_len) {
+ MPTCP_SKB_CB(skb)->offset += count;
+ MPTCP_SKB_CB(skb)->map_seq += count;
+ break;
+ }
+
+ mptcp_eat_recv_skb(sk, skb);
+
+ if (copied >= 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 = {
.family = PF_INET,
.owner = THIS_MODULE,
@@ -4217,6 +4290,7 @@ static const struct proto_ops mptcp_stream_ops = {
.recvmsg = inet_recvmsg,
.mmap = sock_no_mmap,
.set_rcvlowat = mptcp_set_rcvlowat,
+ .read_sock = mptcp_read_sock,
};
static struct inet_protosw mptcp_protosw = {
@@ -4321,6 +4395,7 @@ static const struct proto_ops mptcp_v6_stream_ops = {
.compat_ioctl = inet6_compat_ioctl,
#endif
.set_rcvlowat = mptcp_set_rcvlowat,
+ .read_sock = mptcp_read_sock,
};
static struct proto mptcp_v6_prot;
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH mptcp-next v13 3/8] tcp: add recv_should_stop helper
2025-10-23 5:56 [PATCH mptcp-next v13 0/8] implement mptcp read_sock Geliang Tang
2025-10-23 5:56 ` [PATCH mptcp-next v13 1/8] mptcp: add eat_recv_skb helper Geliang Tang
2025-10-23 5:56 ` [PATCH mptcp-next v13 2/8] mptcp: implement .read_sock Geliang Tang
@ 2025-10-23 5:56 ` Geliang Tang
2025-10-23 5:56 ` [PATCH mptcp-next v13 4/8] mptcp: use " Geliang Tang
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Geliang Tang @ 2025-10-23 5:56 UTC (permalink / raw)
To: mptcp, hare; +Cc: Geliang Tang, Paolo Abeni
From: Geliang Tang <tanggeliang@kylinos.cn>
Factor out a new helper tcp_recv_should_stop() from tcp_recvmsg_locked()
and tcp_splice_read() to check whether to stop receiving. It will be used
for MPTCP too.
Suggested-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
include/net/tcp.h | 23 +++++++++++++++
net/ipv4/tcp.c | 73 ++++++++---------------------------------------
2 files changed, 35 insertions(+), 61 deletions(-)
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 190b3714e93b..4492397a5377 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -2935,4 +2935,27 @@ enum skb_drop_reason tcp_inbound_hash(struct sock *sk,
const void *saddr, const void *daddr,
int family, int dif, int sdif);
+static inline int tcp_recv_should_stop(struct sock *sk, long timeo)
+{
+ if (sock_flag(sk, SOCK_DONE))
+ return -ENETDOWN;
+
+ if (sk->sk_err)
+ return sock_error(sk);
+
+ if (sk->sk_shutdown & RCV_SHUTDOWN)
+ return -ESHUTDOWN;
+
+ if (sk->sk_state == TCP_CLOSE)
+ return -ENOTCONN;
+
+ if (!timeo)
+ return -EAGAIN;
+
+ if (signal_pending(current))
+ return sock_intr_errno(timeo);
+
+ return 0;
+}
+
#endif /* _TCP_H */
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index adc9edd2e9bb..c5653daa2201 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -842,26 +842,14 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
if (ret < 0)
break;
else if (!ret) {
+ int err;
+
if (spliced)
break;
- if (sock_flag(sk, SOCK_DONE))
- break;
- if (sk->sk_err) {
- ret = sock_error(sk);
- break;
- }
- if (sk->sk_shutdown & RCV_SHUTDOWN)
- break;
- if (sk->sk_state == TCP_CLOSE) {
- /*
- * This occurs when user tries to read
- * from never connected socket.
- */
- ret = -ENOTCONN;
- break;
- }
- if (!timeo) {
- ret = -EAGAIN;
+ err = tcp_recv_should_stop(sk, timeo);
+ if (err < 0) {
+ if (err != -ENETDOWN && err != -ESHUTDOWN)
+ ret = err;
break;
}
/* if __tcp_splice_read() got nothing while we have
@@ -873,10 +861,6 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
ret = sk_wait_data(sk, &timeo, NULL);
if (ret < 0)
break;
- if (signal_pending(current)) {
- ret = sock_intr_errno(timeo);
- break;
- }
continue;
}
tss.len -= ret;
@@ -887,9 +871,7 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
release_sock(sk);
lock_sock(sk);
- if (sk->sk_err || sk->sk_state == TCP_CLOSE ||
- (sk->sk_shutdown & RCV_SHUTDOWN) ||
- signal_pending(current))
+ if (tcp_recv_should_stop(sk, timeo))
break;
}
@@ -2730,42 +2712,11 @@ static int tcp_recvmsg_locked(struct sock *sk, struct msghdr *msg, size_t len,
if (copied >= target && !READ_ONCE(sk->sk_backlog.tail))
break;
- if (copied) {
- if (!timeo ||
- sk->sk_err ||
- sk->sk_state == TCP_CLOSE ||
- (sk->sk_shutdown & RCV_SHUTDOWN) ||
- signal_pending(current))
- break;
- } else {
- if (sock_flag(sk, SOCK_DONE))
- break;
-
- if (sk->sk_err) {
- copied = sock_error(sk);
- break;
- }
-
- if (sk->sk_shutdown & RCV_SHUTDOWN)
- break;
-
- if (sk->sk_state == TCP_CLOSE) {
- /* This occurs when user tries to read
- * from never connected socket.
- */
- copied = -ENOTCONN;
- break;
- }
-
- if (!timeo) {
- copied = -EAGAIN;
- break;
- }
-
- if (signal_pending(current)) {
- copied = sock_intr_errno(timeo);
- break;
- }
+ err = tcp_recv_should_stop(sk, timeo);
+ if (err < 0) {
+ if (!copied && err != -ENETDOWN && err != -ESHUTDOWN)
+ copied = err;
+ break;
}
if (copied >= target) {
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH mptcp-next v13 4/8] mptcp: use recv_should_stop helper
2025-10-23 5:56 [PATCH mptcp-next v13 0/8] implement mptcp read_sock Geliang Tang
` (2 preceding siblings ...)
2025-10-23 5:56 ` [PATCH mptcp-next v13 3/8] tcp: add recv_should_stop helper Geliang Tang
@ 2025-10-23 5:56 ` Geliang Tang
2025-10-23 5:56 ` [PATCH mptcp-next v13 5/8] tcp: export tcp_splice_state Geliang Tang
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Geliang Tang @ 2025-10-23 5:56 UTC (permalink / raw)
To: mptcp, hare; +Cc: Geliang Tang
From: Geliang Tang <tanggeliang@kylinos.cn>
Use the newly added tcp_recv_should_stop() helper in mptcp_recvmsg() to
check whether to stop receiving.
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
net/mptcp/protocol.c | 35 +++++------------------------------
1 file changed, 5 insertions(+), 30 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 3f29236ce5fc..1955717e7dfc 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2306,36 +2306,11 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
if (copied >= target)
break;
- if (copied) {
- if (sk->sk_err ||
- sk->sk_state == TCP_CLOSE ||
- (sk->sk_shutdown & RCV_SHUTDOWN) ||
- !timeo ||
- signal_pending(current))
- break;
- } else {
- if (sk->sk_err) {
- copied = sock_error(sk);
- break;
- }
-
- if (sk->sk_shutdown & RCV_SHUTDOWN)
- break;
-
- if (sk->sk_state == TCP_CLOSE) {
- copied = -ENOTCONN;
- break;
- }
-
- if (!timeo) {
- copied = -EAGAIN;
- break;
- }
-
- if (signal_pending(current)) {
- copied = sock_intr_errno(timeo);
- break;
- }
+ err = tcp_recv_should_stop(sk, timeo);
+ if (err < 0) {
+ if (!copied && err != -ESHUTDOWN)
+ copied = err;
+ break;
}
pr_debug("block timeout %ld\n", timeo);
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH mptcp-next v13 5/8] tcp: export tcp_splice_state
2025-10-23 5:56 [PATCH mptcp-next v13 0/8] implement mptcp read_sock Geliang Tang
` (3 preceding siblings ...)
2025-10-23 5:56 ` [PATCH mptcp-next v13 4/8] mptcp: use " Geliang Tang
@ 2025-10-23 5:56 ` Geliang Tang
2025-10-23 5:56 ` [PATCH mptcp-next v13 6/8] mptcp: implement .splice_read Geliang Tang
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Geliang Tang @ 2025-10-23 5:56 UTC (permalink / raw)
To: mptcp, hare; +Cc: Geliang Tang, Paolo Abeni
From: Geliang Tang <tanggeliang@kylinos.cn>
Export struct tcp_splice_state into net/tcp.h so that it can be used
by MPTCP.
Suggested-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
include/net/tcp.h | 9 +++++++++
net/ipv4/tcp.c | 9 ---------
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 4492397a5377..b54227ba79ce 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -2958,4 +2958,13 @@ static inline int tcp_recv_should_stop(struct sock *sk, long timeo)
return 0;
}
+/*
+ * TCP splice context
+ */
+struct tcp_splice_state {
+ struct pipe_inode_info *pipe;
+ size_t len;
+ unsigned int flags;
+};
+
#endif /* _TCP_H */
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index c5653daa2201..27786bebb101 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -318,15 +318,6 @@ EXPORT_SYMBOL(tcp_have_smc);
struct percpu_counter tcp_sockets_allocated ____cacheline_aligned_in_smp;
EXPORT_IPV6_MOD(tcp_sockets_allocated);
-/*
- * 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.
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH mptcp-next v13 6/8] mptcp: implement .splice_read
2025-10-23 5:56 [PATCH mptcp-next v13 0/8] implement mptcp read_sock Geliang Tang
` (4 preceding siblings ...)
2025-10-23 5:56 ` [PATCH mptcp-next v13 5/8] tcp: export tcp_splice_state Geliang Tang
@ 2025-10-23 5:56 ` Geliang Tang
2025-10-23 5:56 ` [PATCH mptcp-next v13 7/8] selftests: mptcp: add splice io mode Geliang Tang
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Geliang Tang @ 2025-10-23 5:56 UTC (permalink / raw)
To: mptcp, hare; +Cc: Geliang Tang
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 | 109 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 109 insertions(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 1955717e7dfc..91d3bf5e6a75 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -4245,6 +4245,113 @@ static int mptcp_read_sock(struct sock *sk, read_descriptor_t *desc,
return copied;
}
+static int mptcp_splice_data_recv(read_descriptor_t *rd_desc, struct sk_buff *skb,
+ unsigned int offset, size_t len)
+{
+ struct tcp_splice_state *tss = rd_desc->arg.data;
+ int ret;
+
+ ret = skb_splice_bits(skb, skb->sk, offset, tss->pipe,
+ min(rd_desc->count, len), tss->flags);
+ if (ret > 0)
+ rd_desc->count -= ret;
+ return ret;
+}
+
+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, mptcp_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;
+ 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,
@@ -4266,6 +4373,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 = {
@@ -4371,6 +4479,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
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH mptcp-next v13 7/8] selftests: mptcp: add splice io mode
2025-10-23 5:56 [PATCH mptcp-next v13 0/8] implement mptcp read_sock Geliang Tang
` (5 preceding siblings ...)
2025-10-23 5:56 ` [PATCH mptcp-next v13 6/8] mptcp: implement .splice_read Geliang Tang
@ 2025-10-23 5:56 ` Geliang Tang
2025-10-23 5:56 ` [PATCH mptcp-next v13 8/8] selftests: mptcp: connect: cover splice mode Geliang Tang
2025-10-23 7:54 ` [PATCH mptcp-next v13 0/8] implement mptcp read_sock MPTCP CI
8 siblings, 0 replies; 10+ messages in thread
From: Geliang Tang @ 2025-10-23 5:56 UTC (permalink / raw)
To: mptcp, hare; +Cc: Geliang Tang
From: Geliang Tang <tanggeliang@kylinos.cn>
This patch adds a new 'splice' io mode for mptcp_connect to test
the newly added read_sock() and splice_read() functions of MPTCP.
do_splice() efficiently transfers data directly between two file
descriptors (infd and outfd) without copying to userspace, using
Linux's splice() system call.
Usage:
./mptcp_connect.sh -m splice
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
.../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/testing/selftests/net/mptcp/mptcp_connect.c
index c030b08a7195..3834304f2b89 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,
};
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+write/sendfile\n");
+ fprintf(stderr, "\t-m [poll|mmap|sendfile|splice] -- use poll(default)/mmap+write/sendfile/splice\n");
fprintf(stderr, "\t-M mark -- set socket packet mark\n");
fprintf(stderr, "\t-o option -- test sockopt <option>\n");
fprintf(stderr, "\t-p num -- use port num\n");
@@ -926,6 +927,55 @@ static int copyfd_io_sendfile(int infd, int peerfd, int outfd,
return err;
}
+static int do_splice(const int infd, const int outfd, const size_t len,
+ struct wstate *winfo)
+{
+ int pipefd[2];
+ ssize_t bytes;
+ int err;
+
+ err = pipe(pipefd);
+ if (err)
+ return err;
+
+ while ((bytes = splice(infd, NULL, pipefd[1], NULL,
+ len - winfo->total_len,
+ SPLICE_F_MOVE | SPLICE_F_MORE)) > 0) {
+ splice(pipefd[0], NULL, outfd, NULL, bytes,
+ SPLICE_F_MOVE | SPLICE_F_MORE);
+ }
+
+ close(pipefd[0]);
+ close(pipefd[1]);
+
+ return 0;
+}
+
+static int copyfd_io_splice(int infd, int peerfd, int outfd, unsigned int size,
+ bool *in_closed_after_out, struct wstate *winfo)
+{
+ int err;
+
+ if (listen_mode) {
+ err = do_splice(peerfd, outfd, size, winfo);
+ if (err)
+ return err;
+
+ err = do_splice(infd, peerfd, size, winfo);
+ } else {
+ err = do_splice(infd, peerfd, size, winfo);
+ if (err)
+ return err;
+
+ shut_wr(peerfd);
+
+ err = do_splice(peerfd, outfd, size, winfo);
+ *in_closed_after_out = true;
+ }
+
+ return err;
+}
+
static int copyfd_io(int infd, int peerfd, int outfd, bool close_peerfd, struct wstate *winfo)
{
bool in_closed_after_out = false;
@@ -958,6 +1008,14 @@ static int copyfd_io(int infd, int peerfd, int outfd, bool close_peerfd, struct
&in_closed_after_out, winfo);
break;
+ case CFG_MODE_SPLICE:
+ file_size = get_infd_size(infd);
+ if (file_size < 0)
+ return file_size;
+ ret = copyfd_io_splice(infd, peerfd, outfd, file_size,
+ &in_closed_after_out, winfo);
+ break;
+
default:
fprintf(stderr, "Invalid mode %d\n", cfg_mode);
@@ -1371,12 +1429,15 @@ int parse_mode(const char *mode)
return CFG_MODE_MMAP;
if (!strcasecmp(mode, "sendfile"))
return CFG_MODE_SENDFILE;
+ if (!strcasecmp(mode, "splice"))
+ return CFG_MODE_SPLICE;
fprintf(stderr, "Unknown test mode: %s\n", mode);
fprintf(stderr, "Supported modes are:\n");
fprintf(stderr, "\t\t\"poll\" - interleaved read/write using poll()\n");
fprintf(stderr, "\t\t\"mmap\" - send entire input file (mmap+write), then read response (-l will read input first)\n");
fprintf(stderr, "\t\t\"sendfile\" - send entire input file (sendfile), then read response (-l will read input first)\n");
+ fprintf(stderr, "\t\t\"splice\" - send entire input file (splice), then read response (-l will read input first)\n");
die_usage();
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH mptcp-next v13 8/8] selftests: mptcp: connect: cover splice mode
2025-10-23 5:56 [PATCH mptcp-next v13 0/8] implement mptcp read_sock Geliang Tang
` (6 preceding siblings ...)
2025-10-23 5:56 ` [PATCH mptcp-next v13 7/8] selftests: mptcp: add splice io mode Geliang Tang
@ 2025-10-23 5:56 ` Geliang Tang
2025-10-23 7:54 ` [PATCH mptcp-next v13 0/8] implement mptcp read_sock MPTCP CI
8 siblings, 0 replies; 10+ messages in thread
From: Geliang Tang @ 2025-10-23 5:56 UTC (permalink / raw)
To: mptcp, hare; +Cc: Geliang Tang, Matthieu Baerts
From: Geliang Tang <tanggeliang@kylinos.cn>
The "splice" alternate mode for mptcp_connect.sh/.c is available now,
this patch adds mptcp_connect_splice.sh to test it in the MPTCP CI by
default.
Suggested-by: Matthieu Baerts <matttbe@kernel.org>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
tools/testing/selftests/net/mptcp/Makefile | 1 +
tools/testing/selftests/net/mptcp/mptcp_connect_splice.sh | 5 +++++
2 files changed, 6 insertions(+)
create mode 100755 tools/testing/selftests/net/mptcp/mptcp_connect_splice.sh
diff --git a/tools/testing/selftests/net/mptcp/Makefile b/tools/testing/selftests/net/mptcp/Makefile
index 15d144a25d82..30d9022119fa 100644
--- a/tools/testing/selftests/net/mptcp/Makefile
+++ b/tools/testing/selftests/net/mptcp/Makefile
@@ -10,6 +10,7 @@ TEST_PROGS := \
mptcp_connect_checksum.sh \
mptcp_connect_mmap.sh \
mptcp_connect_sendfile.sh \
+ mptcp_connect_splice.sh \
mptcp_join.sh \
mptcp_sockopt.sh \
pm_netlink.sh \
diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect_splice.sh b/tools/testing/selftests/net/mptcp/mptcp_connect_splice.sh
new file mode 100755
index 000000000000..241254a966c9
--- /dev/null
+++ b/tools/testing/selftests/net/mptcp/mptcp_connect_splice.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+MPTCP_LIB_KSFT_TEST="$(basename "${0}" .sh)" \
+ "$(dirname "${0}")/mptcp_connect.sh" -m splice "${@}"
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH mptcp-next v13 0/8] implement mptcp read_sock
2025-10-23 5:56 [PATCH mptcp-next v13 0/8] implement mptcp read_sock Geliang Tang
` (7 preceding siblings ...)
2025-10-23 5:56 ` [PATCH mptcp-next v13 8/8] selftests: mptcp: connect: cover splice mode Geliang Tang
@ 2025-10-23 7:54 ` MPTCP CI
8 siblings, 0 replies; 10+ messages in thread
From: MPTCP CI @ 2025-10-23 7:54 UTC (permalink / raw)
To: Geliang Tang; +Cc: mptcp
Hi Geliang,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal (except selftest_mptcp_join): Success! ✅
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Unstable: 1 failed test(s): selftest_simult_flows 🔴
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/18739490600
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/4ea4f2c38c12
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1014823
If there are some issues, you can reproduce them using the same environment as
the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normal
For more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a
stable tests suite when executed on a public CI like here, it is possible some
reported issues are not due to your modifications. Still, do not hesitate to
help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
^ permalink raw reply [flat|nested] 10+ messages in thread