implement .splice_eof
Subsystems (3)
Geliang Tang
reviewerv4 cover implement .splice_eof
From: Geliang Tang <[email protected]>
v4:
- patch 2, handle cases where sendfile returns 0 or a value larger than the remaining count. In such cases, break out of the loop to prevent unsigned integer underflow and potential infinite loop.
v3:
- drop do_tcp_splice_eof helper.
- invoke __mptcp_push_pending in mptcp_splice_eof.
- use lock_sock_nested in mptcp_splice_eof.
- set splice_eof in mptcp_v6_stream_ops too.
- Link: https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
RESEND:
- to trigger ai review.
- Link: https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v2:
- add sk_state check in mptcp_splice_eof. (Matt)
- call mptcp_rps_record_subflows in mptcp_splice_eof. (Matt)
- update commit logs.
This set implements .splice_eof for MPTCP and tests it.
v1:
- Link: https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
Geliang Tang (2):
mptcp: implement .splice_eof
selftests: mptcp: connect: trigger splice_eof
net/mptcp/protocol.c | 31 +++++++++++++++++++ .../selftests/net/mptcp/mptcp_connect.c | 5 ++- 2 files changed, 35 insertions(+), 1 deletion(-)
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v4 1/2 mptcp: implement .splice_eof
From: Geliang Tang <[email protected]>
This patch implements the .splice_eof interface for MPTCP, namely mptcp_splice_eof(), to flush any pending data when a sendfile() operation reaches end-of-file.
The implementation first calls __mptcp_push_pending() to push all unsent data from the MPTCP layer's write queue to the TCP subflows. Then, for each active subflow that still has data in its send queue, it acquires the subflow socket lock with lock_sock_nested(, SINGLE_DEPTH_NESTING) to avoid lockdep false positives (the MPTCP socket lock is already held). After that, it calls tcp_send_mss() and tcp_push() to flush the subflow's send buffer.
Without this .splice_eof support, MPTCP did not flush its pending data immediately when sendfile() reached EOF. While the data would eventually be sent after a short delay, this patch makes the behavior consistent with TCP.
Note: the .splice_eof field of mptcp_stream_ops is set to inet_splice_eof, which redirects to the protocol-specific .splice_eof (here, mptcp_splice_eof).
--- net/mptcp/protocol.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
net/mptcp/protocol.c +31 -0
@@ -4180,6 +4180,34 @@ static int mptcp_connect(struct sock *sk, struct sockaddr_unsized *uaddr,return 0 ; } +static void mptcp_splice_eof (struct socket *sock) +{ +struct mptcp_subflow_context *subflow; +struct sock *sk = sock->sk, *ssk; +struct mptcp_sock *msk; +int mss_now, size_goal; +struct tcp_sock *tp; + + msk =mptcp_sk (sk); + +lock_sock (sk); +__mptcp_push_pending (sk,0 ); +mptcp_rps_record_subflows (msk); +mptcp_for_each_subflow (msk, subflow) { + ssk =mptcp_subflow_tcp_sock (subflow); +if (ssk->sk_state ==TCP_CLOSE || + !tcp_write_queue_tail (ssk)) +continue ; + +lock_sock_nested (ssk,SINGLE_DEPTH_NESTING ); + tp =tcp_sk (ssk); + mss_now =tcp_send_mss (ssk, &size_goal,0 ); +tcp_push (ssk,0 , mss_now, tp->nonagle, size_goal); +release_sock (ssk); + } +release_sock (sk); +} +static struct proto mptcp_prot = { .name ="MPTCP" , .owner =THIS_MODULE ,
@@ -4211,6 +4239,7 @@ static struct proto mptcp_prot = { .obj_size = sizeof(struct mptcp_sock), .slab_flags = SLAB_TYPESAFE_BY_RCU, .no_autobind = true, + .splice_eof = mptcp_splice_eof, };static int mptcp_bind (struct socket *sock,struct sockaddr_unsized *uaddr,int addr_len)
@@ -4703,6 +4732,7 @@ static const struct proto_ops mptcp_stream_ops = { .set_rcvlowat = mptcp_set_rcvlowat, .read_sock = mptcp_read_sock, .splice_read = mptcp_splice_read, + .splice_eof = inet_splice_eof, };static struct inet_protosw mptcp_protosw = {
@@ -4815,6 +4845,7 @@ static const struct proto_ops mptcp_v6_stream_ops = { .set_rcvlowat = mptcp_set_rcvlowat, .read_sock = mptcp_read_sock, .splice_read = mptcp_splice_read, + .splice_eof = inet_splice_eof, };static struct proto mptcp_v6_prot;
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v4 2/2 selftests: mptcp: connect: trigger splice_eof
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
Increase the sendfile count by one to ensure the transmission size exceeds the actual data length. This triggers the splice_eof path in the kernel, allowing the newly implemented MPTCP splice_eof interface to be exercised during testing.
The change from 'count' to 'count + 1' forces the sendfile operation to attempt sending one more byte than available, which activates the end-of-file handling in the splicing logic and ensures coverage of the related MPTCP code paths.
Additionally, handle cases where sendfile returns 0 (no more data) or a value larger than the remaining count (e.g., due to concurrent file growth). In such cases, break out of the loop to prevent unsigned integer underflow and potential infinite loop.
--- tools/testing/selftests/net/mptcp/mptcp_connect.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/testing/selftests/net/mptcp/mptcp_connect.c +4 -1
@@ -870,12 +870,15 @@ static int do_sendfile(int infd, int outfd, unsigned int count,while (count >0 ) {ssize_t r; - r =sendfile (outfd, infd,NULL , count); + r =sendfile (outfd, infd,NULL , count +1 );if (r <0 ) {perror ("sendfile" );return 3 ; } +if (r ==0 || r > count) +break ; + count -= r; }
Signature · 1 line
2.43.0
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): Success! ✅
- 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/27178965576
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/4b0197466c9f
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1108212
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-normalFor 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)