:p
atchew
Login
From: Geliang Tang <tanggeliang@kylinos.cn> This set implements .splice_eof for MPTCP and tests it. Geliang Tang (3): tcp: export do_tcp_splice_eof mptcp: implement .splice_eof selftests: mptcp: connect: trigger splice_eof include/net/tcp.h | 1 + net/ipv4/tcp.c | 8 ++++++-- net/mptcp/protocol.c | 16 ++++++++++++++++ .../testing/selftests/net/mptcp/mptcp_connect.c | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) -- 2.51.0
From: Geliang Tang <tanggeliang@kylinos.cn> Extract a do_tcp_splice_eof() helper from tcp_splice_eof() and export it to net/tcp.h, so that it can be used in MPTCP. Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn> --- include/net/tcp.h | 1 + net/ipv4/tcp.c | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index XXXXXXX..XXXXXXX 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -XXX,XX +XXX,XX @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size); int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size); int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *copied, size_t size, struct ubuf_info *uarg); +void do_tcp_splice_eof(struct sock *sk); void tcp_splice_eof(struct socket *sock); int tcp_send_mss(struct sock *sk, int *size_goal, int flags); int tcp_wmem_schedule(struct sock *sk, int copy); diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index XXXXXXX..XXXXXXX 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -XXX,XX +XXX,XX @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) } EXPORT_SYMBOL(tcp_sendmsg); -void tcp_splice_eof(struct socket *sock) +void do_tcp_splice_eof(struct sock *sk) { - struct sock *sk = sock->sk; struct tcp_sock *tp = tcp_sk(sk); int mss_now, size_goal; @@ -XXX,XX +XXX,XX @@ void tcp_splice_eof(struct socket *sock) tcp_push(sk, 0, mss_now, tp->nonagle, size_goal); release_sock(sk); } + +void tcp_splice_eof(struct socket *sock) +{ + do_tcp_splice_eof(sock->sk); +} EXPORT_IPV6_MOD_GPL(tcp_splice_eof); /* -- 2.51.0
From: Geliang Tang <tanggeliang@kylinos.cn> This patch implements the .splice_eof interface for MPTCP, namely mptcp_splice_eof(), which sequentially calls do_tcp_splice_eof() for each subflow. Suggested-by: Matthieu Baerts <matttbe@kernel.org> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn> --- net/mptcp/protocol.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index XXXXXXX..XXXXXXX 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -XXX,XX +XXX,XX @@ 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; + + lock_sock(sk); + mptcp_for_each_subflow(mptcp_sk(sk), subflow) { + ssk = mptcp_subflow_tcp_sock(subflow); + + do_tcp_splice_eof(ssk); + } + release_sock(sk); +} + static struct proto mptcp_prot = { .name = "MPTCP", .owner = THIS_MODULE, @@ -XXX,XX +XXX,XX @@ 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) @@ -XXX,XX +XXX,XX @@ 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 = { -- 2.51.0
From: Geliang Tang <tanggeliang@kylinos.cn> 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. Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn> --- tools/testing/selftests/net/mptcp/mptcp_connect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c index XXXXXXX..XXXXXXX 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c @@ -XXX,XX +XXX,XX @@ 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; -- 2.51.0
From: Geliang Tang <tanggeliang@kylinos.cn> RESEND: - to trigger ai review. 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/cover.1770023932.git.tanggeliang@kylinos.cn/ Geliang Tang (3): tcp: export do_tcp_splice_eof mptcp: implement .splice_eof selftests: mptcp: connect: trigger splice_eof include/net/tcp.h | 1 + net/ipv4/tcp.c | 8 +++++-- net/mptcp/protocol.c | 23 +++++++++++++++++++ .../selftests/net/mptcp/mptcp_connect.c | 2 +- 4 files changed, 31 insertions(+), 3 deletions(-) -- 2.53.0
From: Geliang Tang <tanggeliang@kylinos.cn> Extract a do_tcp_splice_eof() helper from tcp_splice_eof() and export it to net/tcp.h, so that it can be used in MPTCP. Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn> --- include/net/tcp.h | 1 + net/ipv4/tcp.c | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index XXXXXXX..XXXXXXX 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -XXX,XX +XXX,XX @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size); int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size); int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *copied, size_t size, struct ubuf_info *uarg); +void do_tcp_splice_eof(struct sock *sk); void tcp_splice_eof(struct socket *sock); int tcp_send_mss(struct sock *sk, int *size_goal, int flags); int tcp_wmem_schedule(struct sock *sk, int copy); diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index XXXXXXX..XXXXXXX 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -XXX,XX +XXX,XX @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) } EXPORT_SYMBOL(tcp_sendmsg); -void tcp_splice_eof(struct socket *sock) +void do_tcp_splice_eof(struct sock *sk) { - struct sock *sk = sock->sk; struct tcp_sock *tp = tcp_sk(sk); int mss_now, size_goal; @@ -XXX,XX +XXX,XX @@ void tcp_splice_eof(struct socket *sock) tcp_push(sk, 0, mss_now, tp->nonagle, size_goal); release_sock(sk); } + +void tcp_splice_eof(struct socket *sock) +{ + do_tcp_splice_eof(sock->sk); +} EXPORT_IPV6_MOD_GPL(tcp_splice_eof); /* -- 2.53.0
From: Geliang Tang <tanggeliang@kylinos.cn> This patch implements the .splice_eof interface for MPTCP, namely mptcp_splice_eof(), which calls do_tcp_splice_eof() for each active subflow when a sendfile() operation reaches end-of-file. do_tcp_splice_eof() flushes any remaining data in the TCP send queue. MPTCP operates over multiple TCP subflows, and each subflow may have pending data in its send buffer that needs to be properly finalized when splicing data through an MPTCP socket. sock_splice_eof() calls the .splice_eof interface from struct proto_ops. To maintain consistency with regular TCP behavior, the .splice_eof interface of mptcp_stream_ops is set to inet_splice_eof, which will switch to the protocol-specific implementation (sk->sk_prot->splice_eof) - for MPTCP, that is mptcp_splice_eof(). This is an improvement; nothing was broken before. MPTCP previously did not handle the splice EOF notification, while TCP did. Without .splice_eof() support, the queue is not flushed immediately when sendfile() reaches EOF, but it will eventually be flushed after a small delay. Suggested-by: Matthieu Baerts <matttbe@kernel.org> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn> --- net/mptcp/protocol.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index XXXXXXX..XXXXXXX 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -XXX,XX +XXX,XX @@ 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; + + msk = mptcp_sk(sk); + + lock_sock(sk); + mptcp_rps_record_subflows(msk); + mptcp_for_each_subflow(msk, subflow) { + ssk = mptcp_subflow_tcp_sock(subflow); + + if (ssk->sk_state == TCP_CLOSE) + continue; + + do_tcp_splice_eof(ssk); + } + release_sock(sk); +} + static struct proto mptcp_prot = { .name = "MPTCP", .owner = THIS_MODULE, @@ -XXX,XX +XXX,XX @@ 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) @@ -XXX,XX +XXX,XX @@ 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 = { -- 2.53.0
From: Geliang Tang <tanggeliang@kylinos.cn> 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. Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn> --- tools/testing/selftests/net/mptcp/mptcp_connect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c index XXXXXXX..XXXXXXX 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c @@ -XXX,XX +XXX,XX @@ 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; -- 2.53.0