:p
atchew
Login
From: Geliang Tang <tanggeliang@kylinos.cn> 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. RESEND: - to trigger ai review. - Link: https://patchwork.kernel.org/project/mptcp/cover/cover.1773740361.git.tanggeliang@kylinos.cn/ 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 (2): mptcp: implement .splice_eof selftests: mptcp: connect: trigger splice_eof net/mptcp/protocol.c | 31 +++++++++++++++++++ .../selftests/net/mptcp/mptcp_connect.c | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) -- 2.43.0
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 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; + 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, @@ -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 = { @@ -XXX,XX +XXX,XX @@ 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
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.43.0
From: Geliang Tang <tanggeliang@kylinos.cn> 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/cover.1780909894.git.tanggeliang@kylinos.cn/ RESEND: - to trigger ai review. - Link: https://patchwork.kernel.org/project/mptcp/cover/cover.1773740361.git.tanggeliang@kylinos.cn/ 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 (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(-) -- 2.43.0
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 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; + 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, @@ -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 = { @@ -XXX,XX +XXX,XX @@ 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
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. 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. Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn> --- tools/testing/selftests/net/mptcp/mptcp_connect.c | 5 ++++- 1 file changed, 4 insertions(+), 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; } + if (r == 0 || r > count) + break; + count -= r; } -- 2.43.0