From: sashiko-bot@kernel.org
To: "Geliang Tang" <geliang@kernel.org>, mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next v8 4/7] mptcp: add MSG_ZEROCOPY support
Date: Mon, 23 Nov 2026 08:46:44 +0000 [thread overview]
Message-ID: <sashiko-outbox-228911@kernel.org> (raw)
In-Reply-To: <3f30ee2209176e73f716ad379bb6385145b05fa8.1795421388.git.tanggeliang@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] mptcp: off-by-one U16_MAX check in
mptcp_sendmsg_zerocopy_iter()
- [Medium] mptcp: unbalanced sk_wmem_schedule() in
mptcp_sendmsg_zerocopy_iter()
- [Medium] mptcp: missing DEFER_CONNECT check for MSG_ZEROCOPY in
mptcp_sendmsg()
- [Medium] mptcp: missing zerocopy notification on copy fallback in
mptcp_sendmsg()
--
commit 6f18d9c0894cba580b4859b23fbe02de7c4fe368
Author: Geliang Tang <geliang@kernel.org>
mptcp: add MSG_ZEROCOPY support
This commit adds MSG_ZEROCOPY support to MPTCP sockets by pinning user pages
into mptcp_data_frag entries and tracking completion across both the MPTCP
retransmission queue and subflow skbs.
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 84848cb0a5e9c..9cd3e12d5546c 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -1186,9 +1186,11 @@ static bool mptcp_frag_can_collapse_to(const struct mptcp_sock *msk,
> df->data_seq + df->data_len == msk->write_seq;
> }
>
> -static void dfrag_uncharge(struct sock *sk, int len)
> +static void dfrag_uncharge(struct sock *sk, int len,
> + struct mptcp_data_frag *dfrag)
> {
> - sk_mem_uncharge(sk, len);
> + if (!dfrag->ubuf)
> + sk_mem_uncharge(sk, len);
> sk_wmem_queued_add(sk, -len);
> }
[ ... ]
> @@ -2040,22 +2065,110 @@ static void mptcp_rps_record_subflows(const struct mptcp_sock *msk)
> }
> }
>
> +static ssize_t mptcp_sendmsg_zerocopy_iter(struct sock *sk, struct msghdr *msg,
> + struct ubuf_info *ubuf,
> + u32 copy_limit)
> +{
> + struct mptcp_sock *msk = mptcp_sk(sk);
> + struct mptcp_data_frag *dfrag;
> + struct page *pages[1] = {};
> + size_t pg_off = 0;
> + ssize_t pg_len;
> +
> + pg_len = iov_iter_get_pages2(&msg->msg_iter, pages,
> + copy_limit, 1, &pg_off);
> + if (pg_len < 0)
> + return pg_len;
> + /* pg_len == 0 means the iterator is exhausted */
> + if (pg_len == 0)
> + return -EFAULT;
> +
> + if (pg_len > U16_MAX) {
> + iov_iter_revert(&msg->msg_iter, pg_len - U16_MAX);
> + pg_len = U16_MAX;
> + }
> +
> + if (pg_off > U16_MAX) {
> + iov_iter_revert(&msg->msg_iter, pg_len);
> + put_page(pages[0]);
> + return -EFAULT;
> + }
> +
> + if (pg_off + pg_len > U16_MAX) {
> + size_t len = U16_MAX - pg_off;
> +
> + iov_iter_revert(&msg->msg_iter, pg_len - len);
> + pg_len = len;
> + if (WARN_ON_ONCE(!pg_len)) {
> + put_page(pages[0]);
> + return -EFAULT;
> + }
> + }
[Severity: High]
Does pg_off + pg_len > U16_MAX trigger WARN_ON_ONCE(!pg_len) and return
-EFAULT whenever pg_off reaches U16_MAX on a kernel with PAGE_SIZE >= 64 KiB?
On a 64 KiB page kernel, sending a 64 KiB page-aligned buffer caps the first
dfrag at U16_MAX (65535) bytes and leaves msg->msg_iter at page offset 65535
with 1 byte left. On the next iteration, pg_off is U16_MAX, so pg_off >
U16_MAX is false and len = U16_MAX - pg_off is 0.
Since dfrag->offset and dfrag->data_len are u16 and partial-ACK advancement in
__mptcp_clean_una() only adds delta < dfrag->data_len, capping pg_off + pg_len
at U16_MAX + 1 avoids overflowing either field while allowing the final byte
at offset 65535.
> +
> + dfrag = kzalloc_obj(*dfrag, GFP_KERNEL_ACCOUNT);
> + if (!dfrag) {
> + iov_iter_revert(&msg->msg_iter, pg_len);
> + put_page(pages[0]);
> + return -ENOMEM;
> + }
> +
> + if (!sk_wmem_schedule(sk, pg_len + sizeof(*dfrag))) {
> + kfree(dfrag);
> + iov_iter_revert(&msg->msg_iter, pg_len);
> + put_page(pages[0]);
> + return -EAGAIN;
> + }
[Severity: Medium]
Should mptcp_sendmsg_zerocopy_iter() skip sk_wmem_schedule() here, the same
way mptcp_sendmsg_frag() skips it for zerocopy dfrags?
Calling sk_wmem_schedule(sk, pg_len + sizeof(*dfrag)) raises
sk->sk_forward_alloc and charges protocol memory, but this path never deducts
it with sk_mem_charge() or sk_forward_alloc_add(), and dfrag_uncharge() skips
sk_mem_uncharge() when dfrag->ubuf is set. The forward-allocated pages stay
pinned on sk until the socket closes, and zerocopy sends can fail with -EAGAIN
under socket memory pressure even though zerocopy pages bypass socket memory
accounting.
[ ... ]
> @@ -2062,15 +2175,27 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
>
> /* silently ignore everything else */
> msg->msg_flags &= MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL |
> - MSG_FASTOPEN | MSG_EOR;
> + MSG_FASTOPEN | MSG_EOR | MSG_ZEROCOPY;
>
> lock_sock(sk);
>
> mptcp_rps_record_subflows(msk);
>
> + if (msg->msg_flags & MSG_FASTOPEN || !sock_flag(sk, SOCK_ZEROCOPY))
> + msg->msg_flags &= ~MSG_ZEROCOPY;
> +
> + if ((msg->msg_flags & MSG_ZEROCOPY) && len) {
> + ubuf = msg_zerocopy_realloc(sk, len, NULL, false);
> + if (!ubuf) {
> + ret = -ENOBUFS;
> + goto do_error;
> + }
> + zc = true;
> + }
> +
> if (unlikely(inet_test_bit(DEFER_CONNECT, sk) ||
> msg->msg_flags & MSG_FASTOPEN)) {
[Severity: Medium]
Does the MSG_ZEROCOPY downgrade check also need to test
inet_test_bit(DEFER_CONNECT, sk)?
When TCP_FASTOPEN_CONNECT sets DEFER_CONNECT and sendmsg() is called with
MSG_ZEROCOPY (without MSG_FASTOPEN), mptcp_sendmsg() allocates ubuf and then
enters mptcp_sendmsg_fastopen(), which passes NULL for uarg to
tcp_sendmsg_fastopen():
net/mptcp/protocol.c:mptcp_sendmsg_fastopen() {
...
ret = tcp_sendmsg_fastopen(ssk, msg, copied_syn, len, NULL);
...
}
The SYN payload is copied without taking a reference on ubuf or clearing
ubuf->zerocopy, so when mptcp_sendmsg() jumps to out: and calls
net_zcopy_put(ubuf), it immediately queues a zerocopy completion notification
while the SYN data is still in flight.
[ ... ]
> @@ -2094,6 +2207,25 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
> if (!copy_limit)
> goto wait_for_memory;
>
> + if (zc) {
> + ret = mptcp_sendmsg_zerocopy_iter(sk, msg, ubuf,
> + copy_limit);
> + if (ret == -EAGAIN || ret == -ENOMEM)
> + goto wait_for_memory;
> + if (ret == -EFAULT) {
> + if (copied)
> + goto do_error;
> + net_zcopy_put_abort(ubuf, true);
> + zc = false;
> + ubuf = NULL;
[Severity: Medium]
Does calling net_zcopy_put_abort() before falling back to the regular copy
path suppress the required MSG_ZEROCOPY completion notification when the copy
succeeds?
net_zcopy_put_abort() decrements sk->sk_zckey and zeroes uarg->len, so when
the loop falls through to do_copy_data_nocache() and returns a positive byte
count, no SO_EE_ORIGIN_ZEROCOPY notification (with SO_EE_CODE_ZEROCOPY_COPIED)
is queued on sk->sk_error_queue. Applications waiting for a completion per
successful MSG_ZEROCOPY sendmsg() call will lose track of sk_zckey or hang on
MSG_ERRQUEUE.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795421388.git.tanggeliang@kylinos.cn?part=4
next prev parent reply other threads:[~2026-11-23 8:46 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 8:19 [PATCH mptcp-next v8 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
2026-11-23 8:19 ` [PATCH mptcp-next v8 1/7] ipv4: fix uninitialized memory in zerocopy cmsg Geliang Tang
2026-11-23 8:37 ` sashiko-bot
2026-11-23 8:19 ` [PATCH mptcp-next v8 2/7] mptcp: use local variable tp in sendmsg_frag Geliang Tang
2026-11-23 8:19 ` [PATCH mptcp-next v8 3/7] mptcp: remove redundant orig_offset in carve_data_frag Geliang Tang
2026-11-23 8:19 ` [PATCH mptcp-next v8 4/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
2026-11-23 8:46 ` sashiko-bot [this message]
2026-11-23 8:19 ` [PATCH mptcp-next v8 5/7] mptcp: handle SO_ZEROCOPY in setsockopt Geliang Tang
2026-11-23 8:36 ` sashiko-bot
2026-11-23 8:19 ` [PATCH mptcp-next v8 6/7] selftests: mptcp: connect: add zerocopy io mode Geliang Tang
2026-11-23 8:37 ` sashiko-bot
2026-11-23 8:19 ` [PATCH mptcp-next v8 7/7] selftests: mptcp: connect: cover zerocopy mode Geliang Tang
2026-11-23 10:42 ` [PATCH mptcp-next v8 0/7] mptcp: add MSG_ZEROCOPY support MPTCP CI
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-228911@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=geliang@kernel.org \
--cc=mptcp@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox