Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796021773; b=nKtLI04c36MJ/n1glK46KKH8ZBiVvCtwv+RfL6g4ACwnjSRLVKxRNIPkAlRNFNszmMZZ iNNa3MExecQFtSfYIpldwxd8v6we+ENp1bH3mIhxXZBqMAMJQ+7N8p/L9drNESLDem6Zz PrsmE2CPlvLobYAZTwpu4pjME57tQsP8S11Z+1GrRbcLYxqnDwW64iFTajYCZAaVerF8z gtPS7VgbhjAJOdiYvAeJ7PNB+ls075yR4fy78gaUPF9nCpA7XWFWd2ljolbVTmMOemNMf J/fdNkDVSLXHsPuaQOTE7nWdxYcy267HOpVrbKIUXGdUj/C+DKAbBquLErnaR0p9Cfg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796021773; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=/buIoB4qoxpYexn5W9PXyg3FMEL4C43B2CGf/FvZOD0=; b=qJxL6VfsK5cUmGhQ6c48u6Dez/LKSdrccZXSOuDbn741AjadXQYcNLX+M38hS2W0p8V0 KduIUCims1vYEN6dEplZNYBPD8fgkiBqWwAw098+/HTx+F+vmSjObh1dnTSmQ0o7KMoZ4 jai6j7bwBuG+fZUT5cuBLgnalLQlJjJUbLRU3zMdZbA7isatiU94jQAMfZdI3bR3zvGq0 uhGsHUiAXLbUKhUbmO+qcXG99gcw4f1DQ2x5VNVcAvXuB4hO0eq/4rJJU9GBCbEF47OxU FFwjS2e6I8CwfjrbDAAfgfISQ6XGh8lRmsVW4ZVRkf0ciKrv8TJ1vSbyPmqE40c4seQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aZPxW9ao; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7E70606A31C for ; Mon, 30 Nov 2026 06:56:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aZPxW9ao Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32C211F00896; Mon, 30 Nov 2026 06:56:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796021773; bh=/buIoB4qoxpYexn5W9PXyg3FMEL4C43B2CGf/FvZOD0=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=aZPxW9aoxa9BqueFpcrHlXu22ST8UCnZ1dWJ9hoG5rq+ry6ZfsxQfoJS3LhNmkw5S GwzuvsENPYdwl70rJ0ojcq1dLZeHK1obdo8EpJgf62BPn2Z++paFFrWKz4TJ4oaCPz VqWPSFBW3p+Q747CVKQItw/H/jQGB/WvoEmRQgozeeHdTBcMOTJTmROaZh75xhcFJ5 m2GKS0UWldx0D7OJh/BvpIbkb+xZdz05vdO8zteLejjqf2DluiL0pEyD4B9+m6szxg DqkbvmxGHcuPmAuC1mEGkTDz8RwM+7dnLGzE+jMWYS+x8n6n+fOgPBqDPyYwauUKeB Nc9+oBcV/zAHA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH mptcp-next v12 3/7] mptcp: add MSG_ZEROCOPY support Reply-To: sashiko-reviews@lists.linux.dev To: "Geliang Tang" , mptcp@lists.linux.dev In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 06:56:12 +0000 X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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, str= uct sock *ssk, > goto alloc_skb; > } > =20 > + if (skb_zcopy_pure(skb) !=3D !!dfrag->ubuf || > + (dfrag->ubuf && skb_zcopy(skb) && > + skb_zcopy(skb) !=3D dfrag->ubuf)) { > + tcp_mark_push(tp, skb); > + goto alloc_skb; > + } > + > i =3D skb_shinfo(skb)->nr_frags; > can_coalesce =3D 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 =3D=3D false, consuming a new frag slot, taking an extra p= age reference, and charging another full PAGE_SIZE to skb->truesize and ssk->sk_wmem_queued. > if (!can_coalesce && i >=3D READ_ONCE(net_hotdata.sysctl_max_skb_frags= )) { > @@ -1571,26 +1591,41 @@ static int mptcp_sendmsg_frag(struct sock *sk, st= ruct sock *ssk, > =20 > copy =3D min_t(size_t, copy, info->limit - info->sent); > =20 > - /* like TCP, allow some progress up to tcp_wmem[0] */ > - avail =3D tcp_wmem_schedule(ssk, copy); > - if (avail <=3D 0) { > - tcp_remove_empty_skb(ssk); > - return -ENOMEM; > + if (!dfrag->ubuf) { > + /* like TCP, allow some progress up to tcp_wmem[0] */ > + avail =3D tcp_wmem_schedule(ssk, copy); > + if (avail <=3D 0) { > + tcp_remove_empty_skb(ssk); > + return -ENOMEM; > + } > + copy =3D avail; > } > - copy =3D avail; > =20 > 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 |=3D SKBFL_PURE_ZEROCOPY; > + zc =3D true; > + } > + } > } > =20 > + if (!zc) > + zc =3D skb_zcopy_pure(skb); > + > skb->len +=3D copy; > skb->data_len +=3D copy; > - skb->truesize +=3D copy; > - sk_wmem_queued_add(ssk, copy); > - sk_mem_charge(ssk, copy); > + truesize =3D (!can_coalesce && zc) ? PAGE_SIZE : copy; > + skb->truesize +=3D 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) !=3D !!dfrag->ubuf) prevents subsequent zerocopy dfrags from collapsing into the skb while allowing a subsequent non-zerocopy dfrag (dfrag->ubuf =3D=3D NULL) to collapse into it. [ ... ] > @@ -2113,27 +2149,125 @@ static void mptcp_rps_record_subflows(const stru= ct mptcp_sock *msk) > } > } > =20 > +static ssize_t mptcp_sendmsg_zerocopy_iter(struct sock *sk, struct msghd= r *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 >=3D 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 =3D 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 =3D 0; > =20 > - ret =3D 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 =3D 0; > + zc =3D false; > + } > + > + ret =3D 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 =3D 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()? --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796019473.gi= t.tanggeliang@kylinos.cn?part=3D3