From: Geliang Tang <tanggeliang@kylinos.cn>
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).
Suggested-by: Matthieu Baerts <matttbe@kernel.org>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
net/mptcp/protocol.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index a4f7e99b30db..09c02d6e6024 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -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;
--
2.43.0
© 2016 - 2026 Red Hat, Inc.