From: sashiko-bot@kernel.org
To: "Geliang Tang" <geliang@kernel.org>, mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next v12 3/7] mptcp: add MSG_ZEROCOPY support
Date: Mon, 30 Nov 2026 06:56:12 +0000 [thread overview]
Message-ID: <sashiko-outbox-240531@kernel.org> (raw)
In-Reply-To: <ed8eb747ee5adf2f9a2c2078d2a7364d78ec549a.1796019473.git.tanggeliang@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] mptcp: unscheduled sk_mem_charge() on non-SG subflow in
mptcp_sendmsg_frag()
- [Medium] mptcp: unpaired sk_wmem_schedule() in
mptcp_sendmsg_zerocopy_iter()
- [Medium] mptcp: broken zcopy coalescing via skb_can_coalesce() in
mptcp_sendmsg_frag()
- [Low] mptcp: redundant fastopen check and dead ubuf argument in
mptcp_sendmsg()
--
commit d4266679151f932ab54555cc34d8a7aab160def5
Author: Geliang Tang <geliang@kernel.org>
mptcp: add MSG_ZEROCOPY support
This commit adds MSG_ZEROCOPY transmit support for MPTCP sockets by
pinning user pages into mptcp_data_frag entries and tracking zerocopy
completions across both the MPTCP retransmission queue and subflow skbs.
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index ab86f8ee1f033..3009d54eb3d92 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
[ ... ]
> @@ -1510,6 +1523,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);
[Severity: Medium]
Can skb_can_coalesce() ever return true when reusing a zerocopy subflow
skb?
skb_can_coalesce() calls skb_can_coalesce_netmem(), which immediately
returns false when skb_zcopy(skb) is set:
include/linux/skbuff.h:skb_can_coalesce_netmem() {
if (skb_zcopy(skb))
return false;
...
}
Because the first zerocopy fragment attaches dfrag->ubuf via
skb_zcopy_set(), any subsequent contiguous slice appended to the same skb
has can_coalesce == false, consuming a new frag slot, taking an extra page
reference, and charging another full PAGE_SIZE to skb->truesize and
ssk->sk_wmem_queued.
> if (!can_coalesce && i >= READ_ONCE(net_hotdata.sysctl_max_skb_frags)) {
> @@ -1571,26 +1591,41 @@ 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) {
> - tcp_remove_empty_skb(ssk);
> - return -ENOMEM;
> + if (!dfrag->ubuf) {
> + /* like TCP, allow some progress up to tcp_wmem[0] */
> + avail = tcp_wmem_schedule(ssk, copy);
> + if (avail <= 0) {
> + tcp_remove_empty_skb(ssk);
> + return -ENOMEM;
> + }
> + copy = avail;
> }
> - 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)) {
> + skb_zcopy_set(skb, dfrag->ubuf, NULL);
> + if (ssk->sk_route_caps & NETIF_F_SG) {
> + skb_shinfo(skb)->flags |= SKBFL_PURE_ZEROCOPY;
> + zc = true;
> + }
> + }
> }
>
> + 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);
> + truesize = (!can_coalesce && zc) ? PAGE_SIZE : copy;
> + skb->truesize += truesize;
> + sk_wmem_queued_add(ssk, truesize);
> + if (!zc)
> + sk_mem_charge(ssk, copy);
[Severity: High]
Does this charge ssk->sk_forward_alloc without scheduling memory when
ssk->sk_route_caps lacks NETIF_F_SG?
When dfrag->ubuf is set on a subflow without NETIF_F_SG,
tcp_wmem_schedule(ssk, copy) is skipped, but SKBFL_PURE_ZEROCOPY is not
set and zc stays false. sk_mem_charge(ssk, copy) then deducts copy from
ssk->sk_forward_alloc without a prior schedule, and tcp_wmem_free_skb()
later uncharges and reclaims memory from ssk that was never scheduled.
In addition, because skb_zcopy(skb) is set while skb_zcopy_pure(skb) is
false on that skb, the collapse check earlier in mptcp_sendmsg_frag()
(skb_zcopy_pure(skb) != !!dfrag->ubuf) prevents subsequent zerocopy dfrags
from collapsing into the skb while allowing a subsequent non-zerocopy
dfrag (dfrag->ubuf == NULL) to collapse into it.
[ ... ]
> @@ -2113,27 +2149,125 @@ 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)
> +{
[ ... ]
> + if (!sk_wmem_schedule(sk, PAGE_SIZE + dfrag->overhead)) {
> + kfree(dfrag);
> + iov_iter_revert(&msg->msg_iter, pg_len);
> + put_page(pages[0]);
> + return -ENOMEM;
> + }
> +
> + /* one ref for the dfrag; released in dfrag_clear */
> + net_zcopy_get(ubuf);
> +
> + WRITE_ONCE(msk->write_seq, msk->write_seq + pg_len);
> + sk_wmem_queued_add(sk, PAGE_SIZE + dfrag->overhead);
[Severity: Medium]
Is sk_wmem_schedule() intentionally called here without charging
sk->sk_forward_alloc?
sk_wmem_schedule(sk, PAGE_SIZE + dfrag->overhead) reserves pages into
sk->sk_forward_alloc, but mptcp_sendmsg_zerocopy_iter() never consumes
that reservation via sk_mem_charge() or sk_forward_alloc_add(), and
dfrag_uncharge() skips sk_mem_uncharge() when dfrag->ubuf is non-NULL.
The pages scheduled on the first zerocopy dfrag stay in
sk->sk_forward_alloc instead of being reclaimed by dfrag_clear(), and
every subsequent sk_wmem_schedule() call for the same size sees
sk->sk_forward_alloc >= PAGE_SIZE + dfrag->overhead and returns true
without checking memory limits.
> +
> + list_add_tail(&dfrag->list, &msk->rtx_queue);
> + if (!msk->first_pending)
> + msk->first_pending = dfrag;
> +
> + return pg_len;
> +}
> +
> static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
> {
[ ... ]
> 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 ||
> + inet_test_bit(DEFER_CONNECT, sk))) {
> + uarg_to_msgzc(ubuf)->zerocopy = 0;
> + zc = false;
> + }
> +
> + ret = mptcp_sendmsg_fastopen(sk, msg, len, &copied_syn,
> + zc ? ubuf : NULL);
[Severity: Low]
Since the inner condition repeats the outer if condition and always sets
zc = false, zc ? ubuf : NULL always evaluates to NULL. If fastopen and
DEFER_CONNECT sends are meant to downgrade to regular copy, can the inner
check be simplified to if (zc) and the unused ubuf parameter dropped from
mptcp_sendmsg_fastopen()?
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796019473.git.tanggeliang@kylinos.cn?part=3
next prev parent reply other threads:[~2026-11-30 6:56 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 6:25 [PATCH mptcp-next v12 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
2026-11-30 6:25 ` [PATCH mptcp-next v12 1/7] mptcp: use local variable tp in sendmsg_frag Geliang Tang
2026-11-30 6:29 ` sashiko-bot
2026-11-30 6:25 ` [PATCH mptcp-next v12 2/7] mptcp: remove redundant orig_offset in carve_data_frag Geliang Tang
2026-11-30 6:25 ` [PATCH mptcp-next v12 3/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
2026-11-30 6:56 ` sashiko-bot [this message]
2026-11-30 6:25 ` [PATCH mptcp-next v12 4/7] mptcp: handle SO_ZEROCOPY in setsockopt Geliang Tang
2026-11-30 6:25 ` [PATCH mptcp-next v12 5/7] Documentation: msg_zerocopy: add MPTCP support Geliang Tang
2026-11-30 6:25 ` [PATCH mptcp-next v12 6/7] selftests: net: " Geliang Tang
2026-11-30 6:25 ` [PATCH mptcp-next v12 7/7] selftests: mptcp: cover msg_zerocopy test Geliang Tang
2026-11-30 6:40 ` sashiko-bot
2026-11-30 7:30 ` [PATCH mptcp-next v12 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-240531@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