From: sashiko-bot@kernel.org
To: "Geliang Tang" <geliang@kernel.org>, mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next v11 3/7] mptcp: add MSG_ZEROCOPY support
Date: Fri, 27 Nov 2026 13:13:18 +0000 [thread overview]
Message-ID: <sashiko-outbox-237474@kernel.org> (raw)
In-Reply-To: <3d7cbfa8e9f5a84f1a8d830ba671f4ce0f450a1e.1795783388.git.tanggeliang@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] mptcp: untracked user page on non-SG subflow skb in
mptcp_sendmsg_frag()
- [Medium] mptcp: broken fastopen zerocopy handling in mptcp_sendmsg()
- [Medium] mptcp: unbalanced tcp_wmem_schedule() for zerocopy in
mptcp_sendmsg_frag()
- [Medium] mptcp: broken zcopy coalescing via skb_can_coalesce() in
mptcp_sendmsg_frag()
--
commit 3ce08c733a49cce9f3069eefc44768187f8af9ea
Author: Geliang Tang <geliang@kernel.org>
mptcp: add MSG_ZEROCOPY support
This commit adds MSG_ZEROCOPY support to MPTCP by pinning user pages into
mptcp_data_frag structures 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 504d0b196d84b..864967702b2c3 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
[ ... ]
> @@ -1488,6 +1500,13 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
> goto alloc_skb;
> }
>
> + if (skb_zcopy_pure(skb) != !!dfrag->ubuf ||
> + (dfrag->ubuf && skb_zcopy(skb) &&
> + skb_zcopy(skb) != dfrag->ubuf)) {
> + tcp_mark_push(tp, skb);
> + goto alloc_skb;
> + }
> +
> i = skb_shinfo(skb)->nr_frags;
> can_coalesce = skb_can_coalesce(skb, i, dfrag->page, offset);
> if (!can_coalesce && i >= READ_ONCE(net_hotdata.sysctl_max_skb_frags)) {
[Severity: Medium]
Does skb_can_coalesce() always return false when reusing a zerocopy
subflow skb?
skb_can_coalesce() calls skb_can_coalesce_netmem(), which rejects any skb
where skb_zcopy(skb) is set:
include/linux/skbuff.h:skb_can_coalesce_netmem() {
if (skb_zcopy(skb))
return false;
...
}
Because skb_zcopy_set() is called when the first fragment is attached to
the skb, every subsequent slice of the same dfrag page appended to that
skb takes the !can_coalesce path, consuming an extra frag slot and page
reference while adding another full PAGE_SIZE to skb->truesize and
ssk->sk_wmem_queued.
> @@ -1542,13 +1561,24 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
> } else {
> get_page(dfrag->page);
> skb_fill_page_desc(skb, i, dfrag->page, offset, copy);
> +
> + if (dfrag->ubuf && !skb_zcopy(skb) &&
> + ssk->sk_route_caps & NETIF_F_SG) {
> + skb_zcopy_set(skb, dfrag->ubuf, NULL);
> + skb_shinfo(skb)->flags |= SKBFL_PURE_ZEROCOPY;
> + zc = true;
> + }
> }
[Severity: High]
When a subflow route lacks NETIF_F_SG, does this attach the pinned user
page dfrag->page to skb without taking a reference on dfrag->ubuf?
With skb_zcopy(skb) left NULL, the subflow skb holds no ubuf reference.
Once dfrag_clear() drops the MPTCP-level reference (for example, after
another subflow acknowledges the data or after TCP fallback), ubuf->refcnt
reaches 0 while skb still holds and transmits dfrag->page. That triggers
a premature SO_EE_ORIGIN_ZEROCOPY completion notification and unaccounted
pinned pages while the kernel is still reading from the user page.
Leaving skb_zcopy(skb) unset also bypasses skb_orphan_frags_rx() and
skb_orphan_frags() page copying on loopback or clone paths, and causes
skb_zcopy_pure(skb) != !!dfrag->ubuf to force a new skb allocation on
every subsequent zerocopy fragment.
>
> + 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: Medium]
Does skipping sk_mem_charge() when zc is true leave the memory scheduled
earlier in mptcp_sendmsg_frag() by tcp_wmem_schedule(ssk, copy)
unconsumed in ssk->sk_forward_alloc?
For SKBFL_PURE_ZEROCOPY skbs, tcp_wmem_free_skb() only uncharges the skb
header truesize, which __mptcp_alloc_tx_skb() already scheduled and
charged. Calling tcp_wmem_schedule(ssk, copy) without a matching
sk_mem_charge(ssk, copy) inflates ssk->sk_forward_alloc and protocol
memory accounting, and can cause pure zerocopy sends to fail with -ENOMEM
under memory pressure. In tcp_sendmsg_locked(), tcp_wmem_schedule() is
only called when !skb_zcopy_pure(skb).
[ ... ]
> @@ -2048,27 +2079,117 @@ 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,
> + zc ? ubuf : NULL);
> copied += copied_syn;
> if (ret == -EINPROGRESS && copied_syn > 0)
> goto out;
[Severity: Medium]
Does clearing zc before passing zc ? ubuf : NULL to
mptcp_sendmsg_fastopen() cause ubuf to complete before the data is
acknowledged?
When MSG_FASTOPEN is set, zc is set to false, so mptcp_sendmsg_fastopen()
receives NULL instead of ubuf, and any remaining bytes queued by the send
loop also use non-zerocopy dfrags without taking a reference on ubuf.
When mptcp_sendmsg() reaches out: and calls net_zcopy_put(ubuf), the sole
reference drops and fires the completion notification immediately while
the SYN and any post-SYN data are still in flight.
Conversely, when DEFER_CONNECT (TCP_FASTOPEN_CONNECT) is used without
MSG_FASTOPEN in msg->msg_flags, zc and uarg_to_msgzc(ubuf)->zerocopy
remain 1 even though tcp_send_syn_data() copies the SYN payload into a
kernel buffer without clearing uarg_to_msgzc(ubuf)->zerocopy, so
completion is reported without SO_EE_CODE_ZEROCOPY_COPIED.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795783388.git.tanggeliang@kylinos.cn?part=3
next prev parent reply other threads:[~2026-11-27 13:13 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 12:45 [PATCH mptcp-next v11 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
2026-11-27 12:45 ` [PATCH mptcp-next v11 1/7] mptcp: use local variable tp in sendmsg_frag Geliang Tang
2026-11-27 12:45 ` [PATCH mptcp-next v11 2/7] mptcp: remove redundant orig_offset in carve_data_frag Geliang Tang
2026-11-27 12:45 ` [PATCH mptcp-next v11 3/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
2026-11-27 13:13 ` sashiko-bot [this message]
2026-11-27 12:45 ` [PATCH mptcp-next v11 4/7] mptcp: handle SO_ZEROCOPY in setsockopt Geliang Tang
2026-11-27 12:45 ` [PATCH mptcp-next v11 5/7] Documentation: msg_zerocopy: add MPTCP support Geliang Tang
2026-11-27 12:45 ` [PATCH mptcp-next v11 6/7] selftests: net: " Geliang Tang
2026-11-27 13:00 ` sashiko-bot
2026-11-27 12:45 ` [PATCH mptcp-next v11 7/7] selftests: mptcp: cover msg_zerocopy test Geliang Tang
2026-11-27 13:06 ` sashiko-bot
2026-11-27 14:57 ` [PATCH mptcp-next v11 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-237474@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.