From: sashiko-bot@kernel.org
To: "Geliang Tang" <geliang@kernel.org>, mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next v10 3/7] mptcp: add MSG_ZEROCOPY support
Date: Fri, 27 Nov 2026 05:04:15 +0000 [thread overview]
Message-ID: <sashiko-outbox-236633@kernel.org> (raw)
In-Reply-To: <73d24deb26196f8a9ee7060d93c117a7ce5bd265.1795753727.git.tanggeliang@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] mptcp: broken non-SG zerocopy fallback in mptcp_sendmsg_frag()
- [Medium] mptcp: incomplete fastopen zerocopy handling in
mptcp_sendmsg()
--
commit c58f22d48411d595b383144989fbe0b88bbec032
Author: Geliang Tang <geliang@kernel.org>
mptcp: add MSG_ZEROCOPY support
This commit adds MSG_ZEROCOPY support for MPTCP sockets by pinning user
pages into mptcp_data_frag structures and tracking ubuf_info_msgzc
references across the MPTCP retransmission queue and subflow skbs.
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 504d0b196d84b..d29ecdb05beb9 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
[ ... ]
> @@ -1530,25 +1552,42 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
> copy = min_t(size_t, copy, info->limit - info->sent);
>
> /* like TCP, allow some progress up to tcp_wmem[0] */
> - avail = tcp_wmem_schedule(ssk, copy);
> - if (avail <= 0) {
> + if (!dfrag->ubuf) {
> + avail = tcp_wmem_schedule(ssk, copy);
> + copy = avail > 0 ? avail : 0;
> + }
> +
> + if (!copy) {
> tcp_remove_empty_skb(ssk);
> return -ENOMEM;
> }
> - copy = avail;
>
> if (can_coalesce) {
> skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy);
> } else {
> get_page(dfrag->page);
> skb_fill_page_desc(skb, i, dfrag->page, offset, copy);
> +
> + if (dfrag->ubuf && !skb_zcopy(skb)) {
> + if (ssk->sk_route_caps & NETIF_F_SG) {
> + skb_zcopy_set(skb, dfrag->ubuf, NULL);
> + skb_shinfo(skb)->flags |= SKBFL_PURE_ZEROCOPY;
> + zc = true;
> + } else {
> + uarg_to_msgzc(dfrag->ubuf)->zerocopy = 0;
> + }
> + }
> }
>
> + if (!zc)
> + zc = skb_zcopy_pure(skb);
> +
> skb->len += copy;
> skb->data_len += copy;
> - skb->truesize += copy;
> - sk_wmem_queued_add(ssk, copy);
> - sk_mem_charge(ssk, copy);
> + skb->truesize += zc ? PAGE_SIZE : copy;
> + sk_wmem_queued_add(ssk, zc ? PAGE_SIZE : copy);
> + if (!zc)
> + sk_mem_charge(ssk, copy);
[Severity: High]
Does the non-NETIF_F_SG fallback corrupt ssk->sk_forward_alloc and leave
the pinned user page attached to skb without a dfrag->ubuf reference?
When dfrag->ubuf is set and ssk->sk_route_caps lacks NETIF_F_SG,
tcp_wmem_schedule() is skipped, but zc remains false and sk_mem_charge()
charges unscheduled bytes against ssk->sk_forward_alloc; freeing skb in
tcp_wmem_free_skb() then uncharges and reclaims memory that was never
scheduled.
In addition, dfrag->page is already a pinned user page attached via
skb_fill_page_desc(), so skipping skb_zcopy_set() leaves skb holding the
user page without a dfrag->ubuf reference or SKBFL_ZEROCOPY_FRAG, allowing
dfrag_clear() to complete the zerocopy notification while skb is still in
flight.
[ ... ]
> @@ -2048,27 +2088,116 @@ static void mptcp_rps_record_subflows(const struct mptcp_sock *msk)
[ ... ]
> if (unlikely(inet_test_bit(DEFER_CONNECT, sk) ||
> msg->msg_flags & MSG_FASTOPEN)) {
> int copied_syn = 0;
>
> - ret = mptcp_sendmsg_fastopen(sk, msg, len, &copied_syn);
> + if (zc && (msg->msg_flags & MSG_FASTOPEN)) {
> + uarg_to_msgzc(ubuf)->zerocopy = 0;
> + zc = false;
> + }
> +
> + ret = mptcp_sendmsg_fastopen(sk, msg, len, &copied_syn, ubuf);
> copied += copied_syn;
> if (ret == -EINPROGRESS && copied_syn > 0)
> goto out;
[Severity: Medium]
Can fastopen with MSG_ZEROCOPY complete ubuf prematurely or omit
SO_EE_CODE_ZEROCOPY_COPIED?
When MSG_FASTOPEN clears zc on a blocking send that has data remaining
after the SYN (or when no TFO cookie is cached and copied_syn is 0), the
send loop queues the remaining payload via the regular copy path without
taking a ubuf reference, so net_zcopy_put(ubuf) at out: fires the
completion notification before that data is acknowledged.
Also, when fastopen is entered via DEFER_CONNECT (TCP_FASTOPEN_CONNECT)
without MSG_FASTOPEN in msg->msg_flags, uarg_to_msgzc(ubuf)->zerocopy is
not cleared even though tcp_send_syn_data() copies the SYN payload into a
page_frag and attaches ubuf via skb_zcopy_set().
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795753727.git.tanggeliang@kylinos.cn?part=3
next prev parent reply other threads:[~2026-11-27 5:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 4:36 [PATCH mptcp-next v10 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
2026-11-27 4:36 ` [PATCH mptcp-next v10 1/7] mptcp: use local variable tp in sendmsg_frag Geliang Tang
2026-11-27 4:36 ` [PATCH mptcp-next v10 2/7] mptcp: remove redundant orig_offset in carve_data_frag Geliang Tang
2026-11-27 4:36 ` [PATCH mptcp-next v10 3/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
2026-11-27 5:04 ` sashiko-bot [this message]
2026-11-27 4:36 ` [PATCH mptcp-next v10 4/7] mptcp: handle SO_ZEROCOPY in setsockopt Geliang Tang
2026-11-27 4:36 ` [PATCH mptcp-next v10 5/7] Documentation: msg_zerocopy: add MPTCP support Geliang Tang
2026-11-27 4:36 ` [PATCH mptcp-next v10 6/7] selftests: net: " Geliang Tang
2026-11-27 4:36 ` [PATCH mptcp-next v10 7/7] selftests: mptcp: cover msg_zerocopy test Geliang Tang
2026-11-27 4:50 ` sashiko-bot
2026-11-27 7:24 ` [PATCH mptcp-next v10 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-236633@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