All of lore.kernel.org
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: geliang@kernel.org
Cc: mptcp@lists.linux.dev, kuba@kernel.org
Subject: Re: [PATCH mptcp-next v9 4/7] mptcp: handle SO_ZEROCOPY in setsockopt
Date: Thu, 26 Nov 2026 20:44:03 +0000	[thread overview]
Message-ID: <179572584314.3133.7930166357274276359@kernel.org> (raw)
In-Reply-To: <aaf330d9dbfe6e4f8b15542106d5e687e719a8cf.1795591278.git.tanggeliang@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] This patch adds mptcp_setsockopt_sol_socket_zerocopy()
  (net/mptcp/sockopt.c), the first way to set SOCK_ZEROCOPY on an MPTCP…

--

mptcp: handle SO_ZEROCOPY in setsockopt

Until now MPTCP setsockopt() rejected SO_ZEROCOPY with -EOPNOTSUPP, so on
MPTCP sockets MSG_ZEROCOPY quietly fell back to copying. This patch adds
mptcp_setsockopt_sol_socket_zerocopy(), which checks that val is 0 or 1,
sets or clears SOCK_ZEROCOPY on the msk and pushes the flag to every
subflow. sync_socket_options() also copies the flag to new subflows.

> diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
> index 922f6ae5c80cb..3391f7a9d9834 100644
> --- a/net/mptcp/sockopt.c
> +++ b/net/mptcp/sockopt.c
> @@ -184,6 +184,31 @@ static int mptcp_setsockopt_sol_socket_tstamp(struct mptcp_sock *msk, int optnam
>  	return 0;
>  }
>  
> +static int mptcp_setsockopt_sol_socket_zerocopy(struct mptcp_sock *msk, int val)
> +{
> +	struct mptcp_subflow_context *subflow;
> +	struct sock *sk = (struct sock *)msk;
> +
> +	if (val != 0 && val != 1)
> +		return -EINVAL;
> +
> +	lock_sock(sk);
> +	sock_valbool_flag(sk, SOCK_ZEROCOPY, val);

[Severity: Medium]
This is the first way to set SOCK_ZEROCOPY on an msk. That means
unprivileged userspace can now reach the ubuf dfrag path in
mptcp_sendmsg_frag(), which the earlier patch in this series, "mptcp: add
MSG_ZEROCOPY support", added. Does that path handle memory pressure
correctly?

In net/mptcp/protocol.c:mptcp_sendmsg_frag(), every dfrag goes through
tcp_wmem_schedule(), including pure zero-copy ones. The early exit is then
skipped for ubuf dfrags:

net/mptcp/protocol.c:mptcp_sendmsg_frag() {
    ...
	avail = tcp_wmem_schedule(ssk, copy);
	if (!dfrag->ubuf && avail <= 0) {
		tcp_remove_empty_skb(ssk);
		return -ENOMEM;
	}
	copy = avail;
    ...
}

tcp_wmem_schedule() can return 0 in two cases: when sk_wmem_schedule()
fails with sk_forward_alloc at 0, and when the subflow already has at least
tcp_wmem[0] queued.

Plain TCP avoids this by skipping the schedule for pure zero-copy skbs, and
by treating 0 as wait_for_space:

net/ipv4/tcp.c:tcp_sendmsg_locked() {
    ...
			if (!skb_zcopy_pure(skb)) {
				copy = tcp_wmem_schedule(sk, copy);
				if (!copy)
					goto wait_for_space;
			}
    ...
}

When copy is 0 on the MPTCP side, mptcp_sendmsg_frag() still does this:

		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);
			skb_shinfo(skb)->flags |= SKBFL_PURE_ZEROCOPY;
		}

So a zero-size frag is added, and page and uarg references are taken for
zero bytes.

On the alloc_skb path, __mptcp_alloc_tx_skb() has already called
tcp_skb_entail(), so the skb is on the subflow write queue. The function
then writes the mapping:

	mpext->data_len = copy;
	mpext->use_map = 1;

and returns 0 without calling tcp_remove_empty_skb(). RFC 8684 reserves
data_len 0 for the infinite mapping.

The other two early returns in this function call tcp_remove_empty_skb()
to avoid exactly this state. __subflow_push_pending() treats ret <= 0 as
"stop pushing" and does not remove the skb.

Could mptcp_push_release()->tcp_push() then send a zero-length data
segment carrying a data_len 0 DSS mapping? That segment would also be
counted in packets_out and could be retransmitted by RTO.

The triggering sequence would be:

setsockopt(SOL_SOCKET, SO_ZEROCOPY, 1)
sendmsg(MSG_ZEROCOPY)
  mptcp_sendmsg_zerocopy_iter()  /* dfrag->ubuf != NULL */
  __mptcp_push_pending()
    mptcp_sendmsg_frag()

This needs tcp_wmem[0] or more queued on the subflow, sk_forward_alloc at
0, and __sk_mem_schedule() failing. The last condition can happen under
global TCP memory pressure above tcp_mem[2], or with a tight memcg.

On the reuse path with !can_coalesce, the same thing appends a zero-size
frag to an existing skb. If sk_forward_alloc could go negative here, copy =
avail would also wrap to a huge size_t value. I couldn't confirm that
sk_forward_alloc goes negative on this path, though.

The code is still the same at the end of the series.

Would it make sense to fix the ubuf handling in mptcp_sendmsg_frag() before
exposing SO_ZEROCOPY? For example, skip tcp_wmem_schedule() for pure
zero-copy dfrags as TCP does, or handle a 0 result with
tcp_remove_empty_skb().

> +	sockopt_seq_inc(msk);
> +
> +	mptcp_for_each_subflow(msk, subflow) {

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795591278.git.tanggeliang%40kylinos.cn

  parent reply	other threads:[~2026-11-26 20:44 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  7:22 [PATCH mptcp-next v9 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
2026-11-25  7:22 ` [PATCH mptcp-next v9 1/7] mptcp: use local variable tp in sendmsg_frag Geliang Tang
2026-11-26 20:44   ` netdev-bot+sashiko
2026-11-25  7:23 ` [PATCH mptcp-next v9 2/7] mptcp: remove redundant orig_offset in carve_data_frag Geliang Tang
2026-11-26 20:44   ` netdev-bot+sashiko
2026-11-25  7:23 ` [PATCH mptcp-next v9 3/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
2026-11-25  7:52   ` sashiko-bot
2026-11-26 20:44   ` netdev-bot+sashiko
2026-11-25  7:23 ` [PATCH mptcp-next v9 4/7] mptcp: handle SO_ZEROCOPY in setsockopt Geliang Tang
2026-11-25  7:44   ` sashiko-bot
2026-11-26 20:44   ` netdev-bot+sashiko [this message]
2026-11-25  7:23 ` [PATCH mptcp-next v9 5/7] Documentation: msg_zerocopy: add MPTCP support Geliang Tang
2026-11-26 20:44   ` netdev-bot+sashiko
2026-11-25  7:23 ` [PATCH mptcp-next v9 6/7] selftests: net: " Geliang Tang
2026-11-26 20:44   ` netdev-bot+sashiko
2026-11-25  7:23 ` [PATCH mptcp-next v9 7/7] selftests: mptcp: cover msg_zerocopy test Geliang Tang
2026-11-25  7:34   ` sashiko-bot
2026-11-26 20:44   ` netdev-bot+sashiko
2026-11-25  9:39 ` [PATCH mptcp-next v9 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=179572584314.3133.7930166357274276359@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=geliang@kernel.org \
    --cc=kuba@kernel.org \
    --cc=mptcp@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.