All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH mptcp-next v12 0/7] mptcp: add MSG_ZEROCOPY support
@ 2026-11-30  6:25 Geliang Tang
  2026-11-30  6:25 ` [PATCH mptcp-next v12 1/7] mptcp: use local variable tp in sendmsg_frag Geliang Tang
                   ` (7 more replies)
  0 siblings, 8 replies; 18+ messages in thread
From: Geliang Tang @ 2026-11-30  6:25 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang

From: Geliang Tang <tanggeliang@kylinos.cn>

This series adds MSG_ZEROCOPY support for MPTCP sockets, allowing
userspace to transmit data without intermediate kernel copies, and
provides corresponding selftests to exercise the new path.

v12:
 - patch 3:
   Add 'truesize' variable to unify skb memory accounting - use PAGE_SIZE
   only for new zerocopy frags, otherwise use copy length.
   Moved tcp_wmem_schedule() inside 'if (!dfrag->ubuf)' block, eliminating
   the zerocopy fallback clearing path.
   Changed skb_zcopy_set() to unconditional call; PURE_ZEROCOPY flag and
   zc set only when NETIF_F_SG is supported.
   Added sk_wmem_schedule() check in mptcp_sendmsg_zerocopy_iter() to
   prevent memory limit bypass.
   Extended MSG_FASTOPEN condition with inet_test_bit(DEFER_CONNECT) to
   cover deferred connect path.
 - patch 6:
   Split MPTCP capability probe into separate IPv4 and IPv6 checks with
   individual SKIP messages.
 - patch 7:
   Simplified msg_zerocopy.sh wrapper by removing local capability check.

v11:
- patch 3:
  Simplified tcp_wmem_schedule handling by calling it only for non-zerocopy
  dfrags, eliminating the NETIF_F_SG fallback path that cleared zerocopy
  via uarg_to_msgzc()->zerocopy = 0.
  Pass zc ? ubuf : NULL to mptcp_sendmsg_fastopen instead of always passing
  ubuf.
- patch 7:
  Added MPTCP zerocopy support check to msg_zerocopy.sh wrapper script
  before executing the net selftest.
  Added ../msg_zerocopy.sh to TEST_INCLUDES for out-of-tree builds.
  Added CONFIG_DUMMY=y to config file.
- https://patchwork.kernel.org/project/mptcp/cover/cover.1795783388.git.tanggeliang@kylinos.cn/

v10:
- patch 3:
  Refactored tcp_wmem_schedule error handling to eliminate duplicate
  tcp_remove_empty_skb() calls by consolidating the error path.
  Added NETIF_F_SG capability check to disable zerocopy when scatter-gather
  is not supported.
  Added PAGE_SIZE > U16_MAX + 1 check to disable zerocopy on large-page
  architectures.
  Changed memory accounting to use a local zc flag instead of calling
  skb_zcopy_pure() directly.
  Removed sk_wmem_schedule check for zerocopy dfrag allocation path.
- patch 5:
  Added MPTCP mentions in additional documentation sections (error format
  and loopback implementation).
- patch 6:
  Added check_mptcp_support() helper to probe MPTCP and zerocopy support
  before running tests.
  Added "check" test option for capability detection.
  Improved shell script to conditionally run MPTCP tests based on support
  detection.
  Reordered protocol list in usage message.
- patch 7:
  Changed msg_zerocopy.sh from a symlink to a proper script that sources
  mptcp_lib.sh and calls mptcp_lib_check_mptcp before executing the net
  selftest.
  Added CONFIG_DUMMY=y to config file.
  Changed Makefile to use $(LINK.c) instead of $(CC) for proper linking.
- https://patchwork.kernel.org/project/mptcp/cover/cover.1795753727.git.tanggeliang@kylinos.cn/

v9:
- drop "ipv4: fix uninitialized memory in zerocopy cmsg".
- patch 3:
  The dfrag memory accounting now uses PAGE_SIZE for zerocopy dfrags
  instead of the actual data length, and sk_wmem_schedule checks are
  skipped for zerocopy paths.
  A page reference leak was fixed when iov_iter_get_pages2 returns zero.
  mptcp_sendmsg_fastopen helper now accepts and forwards the ubuf
  parameter.
  Error handling has been improved by using uarg_to_msgzc()->zerocopy = 0
  instead of net_zcopy_put_abort, and the success path now checks ubuf
  directly rather than the zc flag.
  Additionally, MSG_FASTOPEN flag clearing is handled separately from the
  SOCK_ZEROCOPY check.
- patch 4:
  mptcp_setsockopt_sol_socket_zerocopy helper now increments the setsockopt
  sequence counter and iterates through all subflows, setting SOCK_ZEROCOPY
  on each one and updating their setsockopt_seq values.
  Additionally, sync_socket_options has been updated to synchronize the
  SOCK_ZEROCOPY flag to keep subflows consistent with the msk.
- patch 5:
  Documentation has been updated to reflect MPTCP support in the
  msg_zerocopy guide.
- patch 6:
  add mptcp support for selftests msg_zerocopy.c.
- https://patchwork.kernel.org/project/mptcp/cover/cover.1795591278.git.tanggeliang@kylinos.cn/

v8:
- Add pg_off + pg_len overflow check in mptcp_sendmsg_zerocopy_iter() to
  cap the sum at U16_MAX, preventing silent wraparound in dfrag->offset
  during partial ACK processing.
- Reorder kzalloc_obj() before sk_wmem_schedule() to eliminate erroneous
  sk_forward_alloc_add() on allocation failure path.
- Update caller to handle -EAGAIN/-ENOMEM by jumping to wait_for_memory,
  preserving blocking socket semantics.
- Refactor wait_for_completions_zc() to use clock_gettime(CLOCK_MONOTONIC)
  instead of loop counter, preventing premature exit when poll() returns
  immediately after shut_wr().
- Add retry loop in do_sendmsg_zc() to handle short writes from
  sendmsg(MSG_ZEROCOPY).
- Skip wait_for_completions_zc() when size is 0 to avoid 5-second stall on
  MPTFO transfers.
- https://patchwork.kernel.org/project/mptcp/cover/cover.1795421388.git.tanggeliang@kylinos.cn/

v7:
- Add the pg_len / pg_off defensive truncation directly inside
  mptcp_sendmsg_zerocopy_iter() (the new helper in patch 5). When
  iov_iter_get_pages2() returns more than U16_MAX bytes, the excess
  is reverted from the iov_iter so the next iteration picks it up
  cleanly. When the page offset exceeds U16_MAX (on 256KB-page
  kernels like PowerPC and Hexagon), the call returns -EFAULT
  instead of silently truncating. The non-zerocopy path is left
  untouched.
- Refactor mptcp_sendmsg_zerocopy_iter() to return the per-iteration
  byte count as ssize_t so the caller can simply accumulate via
  copied += ret; this drops a ssize_t *copied out-parameter.
- Clean up and fix the zerocopy completion path in mptcp_connect.c
- https://patchwork.kernel.org/project/mptcp/cover/cover.1784260668.git.tanggeliang@kylinos.cn/

v6:
- Add patch 2 to widen offset field in struct mptcp_data_frag from u16 to
  u32 to support page sizes up to 4GB on architectures with large page
  sizes (256KB on PowerPC and Hexagon). This prevents offset wrap-around
  when page fragment offset exceeds 65535.
- Add patch 5 to fix uninitialized memory leak in IPv4 error queue
  handling for zerocopy completion notifications. Add early check for
  SO_EE_ORIGIN_ZEROCOPY in ipv4_datagram_support_cmsg() to prevent
  reading uninitialized memory from ip_hdr(skb)->saddr.
- Refactor zerocopy completion notification draining logic in selftests.
  Extract process_zc_cmsg() helper to process individual control messages.
  Extract drain_errqueue() helper to handle error queue draining.
  Simplify wait_for_zc_completions() main loop from 6 levels to 3 levels.
  Move variables to their actual usage scope for better maintainability.
- Use batched polling (200ms intervals with 5s total timeout) to drain
  completion notifications for large transfers that may generate multiple
  completion events.
- Parse error queue messages to verify all sent data has been ACKed before
  breaking the completion loop.
- Reset msg_controllen each iteration of the inner reap loop to prevent
  truncation of control messages.
- Use >= instead of > in the MPTFO size adjustment so file_size reaches 0
  when the whole file is sent via fast open.
- https://patchwork.kernel.org/project/mptcp/cover/cover.1784188064.git.tanggeliang@kylinos.cn/

v5:
- A new patch to align struct mptcp_data_frag to 8 bytes on 32-bit.
- Prevent coalescing of dfrags with different ubuf instances into the same
  subflow skb to avoid premature completion notifications.
- Return -EFAULT instead of -EAGAIN when iov_iter_get_pages2() returns 0
  to properly signal iterator exhaustion.
- Account for dfrag metadata overhead in sk_wmem_queued_add() to prevent
  bypassing socket memory limits.
- Widen data_len field from u16 to u32 to prevent truncation on 64KB-page
  kernels (ARM64, PPC64).
- In selftests, use batched polling (200ms intervals with 5s total timeout)
  to drain completion notifications for large transfers that may generate
  multiple completion events.
- https://patchwork.kernel.org/project/mptcp/cover/cover.1784113088.git.tanggeliang@kylinos.cn/

v4:
- two more cleanups, patch 2 and patch 7.
- net/mptcp/protocol.c, mptcp_sendmsg_frag(): pull the type-mismatch
  check out of the if (can_coalesce) block and use the standard
  skb_zcopy_pure() helper; mptcp_sendmsg_zerocopy_iter() now
  calls iov_iter_revert() before put_page() in the kzalloc failure
  path so a retry starts from the same iterator offset.
- tools/testing/selftests/net/mptcp/mptcp_connect.c, copyfd_io_zc():
  reset msg_controllen each iteration of the inner reap loop using a
  do {} while block; use >= instead of > in the MPTFO size
  adjustment so file_size reaches 0 when the whole file is sent via
  fast open.
- https://patchwork.kernel.org/project/mptcp/cover/cover.1783992745.git.tanggeliang@kylinos.cn/

v3:
- Force fresh skb when mixing zerocopy and kernel-copy fragments.
- Simplify zero-copy availability check by using SOCK_ZEROCOPY flag
  directly.
- Validate SO_ZEROCOPY value in setsockopt and avoid affecting
  fallback subflow.
- In selftests, drain MPTFO partial data, use poll+recvmsg for completion
  notifications with timeout, and verify getsockopt round-trip.
- https://patchwork.kernel.org/project/mptcp/cover/cover.1783913332.git.tanggeliang@kylinos.cn/

v2:
- patch 2, never mix PURE_ZEROCOPY frags with kernel-copy frags in the
  same skb; handle fallback, return values.
- patch 3, a new patch to handle SO_ZEROCOPY in setsockopt.
- patch 4, set SO_ZEROCOPY, handle listen_mode, error queue.
- https://patchwork.kernel.org/project/mptcp/cover/cover.1783821830.git.tanggeliang@kylinos.cn/

v1:
- https://patchwork.kernel.org/project/mptcp/cover/cover.1783774784.git.tanggeliang@kylinos.cn/

Geliang Tang (7):
  mptcp: use local variable tp in sendmsg_frag
  mptcp: remove redundant orig_offset in carve_data_frag
  mptcp: add MSG_ZEROCOPY support
  mptcp: handle SO_ZEROCOPY in setsockopt
  Documentation: msg_zerocopy: add MPTCP support
  selftests: net: msg_zerocopy: add MPTCP support
  selftests: mptcp: cover msg_zerocopy test

 Documentation/networking/msg_zerocopy.rst     |   8 +-
 net/mptcp/protocol.c                          | 207 ++++++++++++++++--
 net/mptcp/protocol.h                          |   1 +
 net/mptcp/sockopt.c                           |  30 ++-
 tools/testing/selftests/net/mptcp/.gitignore  |   1 +
 tools/testing/selftests/net/mptcp/Makefile    |   7 +-
 tools/testing/selftests/net/mptcp/config      |   1 +
 .../selftests/net/mptcp/msg_zerocopy.sh       |   8 +
 tools/testing/selftests/net/msg_zerocopy.c    |  27 +++
 tools/testing/selftests/net/msg_zerocopy.sh   |  18 +-
 10 files changed, 275 insertions(+), 33 deletions(-)
 create mode 100755 tools/testing/selftests/net/mptcp/msg_zerocopy.sh

-- 
2.55.0


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH mptcp-next v12 1/7] mptcp: use local variable tp in sendmsg_frag
  2026-11-30  6:25 [PATCH mptcp-next v12 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
@ 2026-11-30  6:25 ` Geliang Tang
  2026-11-30  6:29   ` sashiko-bot
  2026-12-01 20:14   ` netdev-bot+sashiko
  2026-11-30  6:25 ` [PATCH mptcp-next v12 2/7] mptcp: remove redundant orig_offset in carve_data_frag Geliang Tang
                   ` (6 subsequent siblings)
  7 siblings, 2 replies; 18+ messages in thread
From: Geliang Tang @ 2026-11-30  6:25 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang, Paolo Abeni

From: Geliang Tang <tanggeliang@kylinos.cn>

In mptcp_sendmsg_frag(), tcp_sk(ssk) is called multiple times.
Introduce a local variable 'tp' to hold the tcp_sock pointer and
use it throughout the function. This improves code readability,
with no functional change.

Suggested-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 net/mptcp/protocol.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index b9c6e5a615c8..58cb11b25253 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1456,6 +1456,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 	u64 data_seq = dfrag->data_seq + info->sent;
 	int offset = dfrag->offset + info->sent;
 	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct tcp_sock *tp = tcp_sk(ssk);
 	bool zero_window_probe = false;
 	struct mptcp_ext *mpext = NULL;
 	bool can_coalesce = false;
@@ -1505,14 +1506,14 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 		mpext = mptcp_get_ext(skb);
 		if (!mptcp_skb_can_collapse_to(data_seq, skb, mpext)) {
 			TCP_SKB_CB(skb)->eor = 1;
-			tcp_mark_push(tcp_sk(ssk), skb);
+			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)) {
-			tcp_mark_push(tcp_sk(ssk), skb);
+			tcp_mark_push(tp, skb);
 			goto alloc_skb;
 		}
 
@@ -1590,7 +1591,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 	skb->truesize += copy;
 	sk_wmem_queued_add(ssk, copy);
 	sk_mem_charge(ssk, copy);
-	WRITE_ONCE(tcp_sk(ssk)->write_seq, tcp_sk(ssk)->write_seq + copy);
+	WRITE_ONCE(tp->write_seq, tp->write_seq + copy);
 	TCP_SKB_CB(skb)->end_seq += copy;
 	tcp_skb_pcount_set(skb, 0);
 
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH mptcp-next v12 2/7] mptcp: remove redundant orig_offset in carve_data_frag
  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:25 ` Geliang Tang
  2026-11-30  6:25 ` [PATCH mptcp-next v12 3/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 18+ messages in thread
From: Geliang Tang @ 2026-11-30  6:25 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang

From: Geliang Tang <tanggeliang@kylinos.cn>

mptcp_carve_data_frag() already receives struct page_frag via its 'pfrag'
parameter, making the separate 'orig_offset' parameter redundant since it
merely duplicates pfrag->offset.

Simplify the function signature by removing this unnecessary parameter
and directly accessing the offset from struct pfrag internally.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 net/mptcp/protocol.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 58cb11b25253..ab86f8ee1f03 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1310,9 +1310,9 @@ static bool mptcp_page_frag_refill(struct sock *sk, struct page_frag *pfrag)
 }
 
 static struct mptcp_data_frag *
-mptcp_carve_data_frag(const struct mptcp_sock *msk, struct page_frag *pfrag,
-		      int orig_offset)
+mptcp_carve_data_frag(const struct mptcp_sock *msk, struct page_frag *pfrag)
 {
+	int orig_offset = pfrag->offset;
 	int offset = ALIGN(orig_offset, sizeof(long));
 	struct mptcp_data_frag *dfrag;
 
@@ -2176,7 +2176,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 			if (!mptcp_page_frag_refill(sk, pfrag))
 				goto wait_for_memory;
 
-			dfrag = mptcp_carve_data_frag(msk, pfrag, pfrag->offset);
+			dfrag = mptcp_carve_data_frag(msk, pfrag);
 			frag_truesize = dfrag->overhead;
 		}
 
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH mptcp-next v12 3/7] mptcp: add MSG_ZEROCOPY support
  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:25 ` [PATCH mptcp-next v12 2/7] mptcp: remove redundant orig_offset in carve_data_frag Geliang Tang
@ 2026-11-30  6:25 ` Geliang Tang
  2026-11-30  6:56   ` sashiko-bot
  2026-12-01 20:14   ` netdev-bot+sashiko
  2026-11-30  6:25 ` [PATCH mptcp-next v12 4/7] mptcp: handle SO_ZEROCOPY in setsockopt Geliang Tang
                   ` (4 subsequent siblings)
  7 siblings, 2 replies; 18+ messages in thread
From: Geliang Tang @ 2026-11-30  6:25 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang

From: Geliang Tang <tanggeliang@kylinos.cn>

This patch enables MSG_ZEROCOPY support for MPTCP sockets, allowing
user-space to transmit data without intermediate kernel copies.

The implementation follows the same lifecycle model as TCP:

A single ubuf_info_msgzc is allocated per sendmsg via
msg_zerocopy_realloc(). Its reference count consists of three parts:
one 'caller' reference held until sendmsg returns, one reference per
MPTCP dfrag in the retransmission queue (released when the dfrag is
acked and cleared), and one reference per subflow skb that consumes
dfrag bytes (released by TCP's skb_zcopy_clear() when the skb is
acked). Completion is reported only after all bytes are acknowledged
at both MPTCP and subflow levels.

User pages are pinned via iov_iter_get_pages2() and stored directly
in a newly allocated mptcp_data_frag. Subflow skbs take additional
page references via get_page() and are marked with skb_zcopy_set()
and SKBFL_PURE_ZEROCOPY.

The feature silently downgrades to regular copy when MSG_FASTOPEN is
set or the application has not opted in via setsockopt(SO_ZEROCOPY).

To prevent premature completion notifications, dfrags with different
ubuf instances cannot be coalesced into the same subflow skb. The new
mptcp_sendmsg_zerocopy_iter() helper handles page pinning and ensures
offsets stay within u16 limits.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 net/mptcp/protocol.c | 194 +++++++++++++++++++++++++++++++++++++++----
 net/mptcp/protocol.h |   1 +
 2 files changed, 177 insertions(+), 18 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index ab86f8ee1f03..3009d54eb3d9 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1194,18 +1194,27 @@ static bool mptcp_frag_can_collapse_to(const struct mptcp_sock *msk,
 		df->data_seq + df->data_len == msk->write_seq;
 }
 
-static void dfrag_uncharge(struct sock *sk, int len)
+static void dfrag_uncharge(struct sock *sk, int len,
+			   struct mptcp_data_frag *dfrag)
 {
-	sk_mem_uncharge(sk, len);
+	if (!dfrag->ubuf)
+		sk_mem_uncharge(sk, len);
 	sk_wmem_queued_add(sk, -len);
 }
 
 static void dfrag_clear(struct sock *sk, struct mptcp_data_frag *dfrag)
 {
-	int len = dfrag->data_len + dfrag->overhead;
+	int len = dfrag->ubuf ? PAGE_SIZE + dfrag->overhead :
+				dfrag->data_len + dfrag->overhead;
 
 	list_del(&dfrag->list);
-	dfrag_uncharge(sk, len);
+	dfrag_uncharge(sk, len, dfrag);
+	if (dfrag->ubuf) {
+		net_zcopy_put(dfrag->ubuf);
+		put_page(dfrag->page);
+		kfree(dfrag);
+		return;
+	}
 	put_page(dfrag->page);
 }
 
@@ -1250,7 +1259,8 @@ static void __mptcp_clean_una(struct sock *sk)
 		dfrag->data_len -= delta;
 		dfrag->already_sent -= delta;
 
-		dfrag_uncharge(sk, delta);
+		if (!dfrag->ubuf)
+			dfrag_uncharge(sk, delta, dfrag);
 	}
 
 	/* all retransmitted data acked, recovery completed */
@@ -1324,6 +1334,7 @@ mptcp_carve_data_frag(const struct mptcp_sock *msk, struct page_frag *pfrag)
 	dfrag->already_sent = 0;
 	dfrag->page = pfrag->page;
 	dfrag->eor = 0;
+	dfrag->ubuf = NULL;
 
 	return dfrag;
 }
@@ -1462,6 +1473,8 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 	bool can_coalesce = false;
 	bool reuse_skb = true;
 	struct sk_buff *skb;
+	bool zc = false;
+	size_t truesize;
 	size_t copy;
 	int avail;
 	int i;
@@ -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);
 		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);
 	WRITE_ONCE(tp->write_seq, tp->write_seq + copy);
 	TCP_SKB_CB(skb)->end_seq += copy;
 	tcp_skb_pcount_set(skb, 0);
@@ -1991,7 +2026,8 @@ static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk, bool
 static int mptcp_disconnect(struct sock *sk, int flags);
 
 static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
-				  size_t len, int *copied_syn)
+				  size_t len, int *copied_syn,
+				  struct ubuf_info *ubuf)
 {
 	unsigned int saved_flags = msg->msg_flags;
 	struct mptcp_sock *msk = mptcp_sk(sk);
@@ -2028,7 +2064,7 @@ static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
 
 	msg->msg_flags |= MSG_DONTWAIT;
 	msk->fastopening = 1;
-	ret = tcp_sendmsg_fastopen(ssk, msg, copied_syn, len, NULL);
+	ret = tcp_sendmsg_fastopen(ssk, msg, copied_syn, len, ubuf);
 	msk->fastopening = 0;
 	msg->msg_flags = saved_flags;
 	release_sock(ssk);
@@ -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)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct mptcp_data_frag *dfrag;
+	struct page *pages[1] = {};
+	size_t pg_off = 0;
+	ssize_t pg_len;
+
+	pg_len = iov_iter_get_pages2(&msg->msg_iter, pages,
+				     copy_limit, 1, &pg_off);
+	if (pg_len < 0)
+		return pg_len;
+	if (pg_len == 0) {
+		if (pages[0])
+			put_page(pages[0]);
+		return -EFAULT;
+	}
+
+	if (pg_len > U16_MAX) {
+		iov_iter_revert(&msg->msg_iter, pg_len - U16_MAX);
+		pg_len = U16_MAX;
+	}
+
+	if (pg_off > U16_MAX) {
+		iov_iter_revert(&msg->msg_iter, pg_len);
+		put_page(pages[0]);
+		return -EFAULT;
+	}
+
+	if (pg_off + pg_len > U16_MAX + 1) {
+		size_t len = U16_MAX + 1 - pg_off;
+
+		iov_iter_revert(&msg->msg_iter, pg_len - len);
+		pg_len = len;
+	}
+
+	dfrag = kzalloc_obj(*dfrag, GFP_KERNEL_ACCOUNT);
+	if (!dfrag) {
+		iov_iter_revert(&msg->msg_iter, pg_len);
+		put_page(pages[0]);
+		return -ENOMEM;
+	}
+
+	dfrag->data_len = pg_len;
+	dfrag->data_seq = msk->write_seq;
+	dfrag->offset = pg_off;
+	dfrag->page = pages[0];
+	dfrag->ubuf = ubuf;
+	dfrag->overhead = sizeof(struct mptcp_data_frag);
+
+	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);
+
+	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)
 {
 	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct ubuf_info *ubuf = NULL;
 	struct page_frag *pfrag;
 	size_t copied = 0;
+	bool zc = false;
 	int ret = 0;
 	long timeo;
 
 	/* silently ignore everything else */
 	msg->msg_flags &= MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL |
-			  MSG_FASTOPEN | MSG_EOR;
+			  MSG_FASTOPEN | MSG_EOR | MSG_ZEROCOPY;
 
 	lock_sock(sk);
 
 	mptcp_rps_record_subflows(msk);
 
+	if (!sock_flag(sk, SOCK_ZEROCOPY))
+		msg->msg_flags &= ~MSG_ZEROCOPY;
+
+	if ((msg->msg_flags & MSG_ZEROCOPY) && len) {
+		ubuf = msg_zerocopy_realloc(sk, len, NULL, false);
+		if (!ubuf) {
+			ret = -ENOBUFS;
+			goto do_error;
+		}
+		zc = true;
+	}
+
+	if (zc && PAGE_SIZE > U16_MAX + 1) {
+		uarg_to_msgzc(ubuf)->zerocopy = 0;
+		zc = false;
+	}
+
 	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);
 		copied += copied_syn;
 		if (ret == -EINPROGRESS && copied_syn > 0)
 			goto out;
@@ -2167,6 +2301,24 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 		if (!copy_limit)
 			goto wait_for_memory;
 
+		if (zc) {
+			ret = mptcp_sendmsg_zerocopy_iter(sk, msg, ubuf,
+							  copy_limit);
+			if (ret == -EAGAIN || ret == -ENOMEM)
+				goto wait_for_memory;
+			if (ret == -EFAULT) {
+				if (copied)
+					goto do_error;
+				uarg_to_msgzc(ubuf)->zerocopy = 0;
+				zc = false;
+			} else if (ret < 0) {
+				goto do_error;
+			} else {
+				copied += ret;
+				continue;
+			}
+		}
+
 		/* reuse tail pfrag, if possible, or carve a new one from the
 		 * page allocator
 		 */
@@ -2242,6 +2394,8 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	}
 
 out:
+	if (ubuf)
+		net_zcopy_put(ubuf);
 	release_sock(sk);
 	return copied;
 
@@ -2252,6 +2406,10 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	}
 
 	copied = sk_stream_error(sk, msg->msg_flags, ret);
+	if (ubuf) {
+		net_zcopy_put_abort(ubuf, true);
+		ubuf = NULL;
+	}
 	goto out;
 }
 
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 7cdd0a7e8296..e06f77d58f2c 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -287,6 +287,7 @@ struct mptcp_data_frag {
 	u8 eor;			/* currently using 1 bit */
 	u16 already_sent;
 	struct page *page;
+	struct ubuf_info *ubuf;
 };
 
 /* Arbitrary compromise between as low as possible to react timely to subflow
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH mptcp-next v12 4/7] mptcp: handle SO_ZEROCOPY in setsockopt
  2026-11-30  6:25 [PATCH mptcp-next v12 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
                   ` (2 preceding siblings ...)
  2026-11-30  6:25 ` [PATCH mptcp-next v12 3/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
@ 2026-11-30  6:25 ` Geliang Tang
  2026-12-01 20:14   ` netdev-bot+sashiko
  2026-11-30  6:25 ` [PATCH mptcp-next v12 5/7] Documentation: msg_zerocopy: add MPTCP support Geliang Tang
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 18+ messages in thread
From: Geliang Tang @ 2026-11-30  6:25 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang

From: Geliang Tang <tanggeliang@kylinos.cn>

SO_ZEROCOPY is currently rejected by MPTCP setsockopt with -EOPNOTSUPP,
even though the matching MSG_ZEROCOPY path in mptcp_sendmsg() is wired up.
As a result MSG_ZEROCOPY silently falls back to a copy on MPTCP sockets
because the opt-in flag is never set.

Expose SO_ZEROCOPY through the SOL_SOCKET setsockopt dispatcher. The new
mptcp_setsockopt_sol_socket_zerocopy() helper validates that val is 0 or 1
(matching standard TCP sk_setsockopt), flips SOCK_ZEROCOPY on the msk, and
propagates it to all subflows. sync_socket_options() also synchronizes the
flag to keep subflows consistent.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 net/mptcp/sockopt.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
index 922f6ae5c80c..3391f7a9d983 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);
+	sockopt_seq_inc(msk);
+
+	mptcp_for_each_subflow(msk, subflow) {
+		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+		bool slow = lock_sock_fast(ssk);
+
+		sock_valbool_flag(ssk, SOCK_ZEROCOPY, val);
+		subflow->setsockopt_seq = msk->setsockopt_seq;
+		unlock_sock_fast(ssk, slow);
+	}
+
+	release_sock(sk);
+	return 0;
+}
+
 static int mptcp_setsockopt_sol_socket_int(struct mptcp_sock *msk, int optname,
 					   sockptr_t optval,
 					   unsigned int optlen)
@@ -212,6 +237,8 @@ static int mptcp_setsockopt_sol_socket_int(struct mptcp_sock *msk, int optname,
 	case SO_TIMESTAMPNS_OLD:
 	case SO_TIMESTAMPNS_NEW:
 		return mptcp_setsockopt_sol_socket_tstamp(msk, optname, val);
+	case SO_ZEROCOPY:
+		return mptcp_setsockopt_sol_socket_zerocopy(msk, val);
 	}
 
 	return -ENOPROTOOPT;
@@ -351,6 +378,7 @@ static int mptcp_setsockopt_sol_socket(struct mptcp_sock *msk, int optname,
 	case SO_TIMESTAMP_NEW:
 	case SO_TIMESTAMPNS_OLD:
 	case SO_TIMESTAMPNS_NEW:
+	case SO_ZEROCOPY:
 		return mptcp_setsockopt_sol_socket_int(msk, optname, optval,
 						       optlen);
 	case SO_TIMESTAMPING_OLD:
@@ -396,7 +424,6 @@ static int mptcp_setsockopt_sol_socket(struct mptcp_sock *msk, int optname,
 	 * SO_CNX_ADVICE is currently unsupported, could possibly be relevant,
 	 * but likely needs careful design
 	 *
-	 * SO_ZEROCOPY is currently unsupported, TODO in sndmsg
 	 * SO_TXTIME is currently unsupported
 	 */
 
@@ -1682,6 +1709,7 @@ static void sync_socket_options(struct mptcp_sock *msk, struct sock *ssk)
 	}
 
 	sock_valbool_flag(ssk, SOCK_DBG, sock_flag(sk, SOCK_DBG));
+	sock_valbool_flag(ssk, SOCK_ZEROCOPY, sock_flag(sk, SOCK_ZEROCOPY));
 
 	if (inet_csk(sk)->icsk_ca_ops != inet_csk(ssk)->icsk_ca_ops)
 		tcp_set_congestion_control(ssk, msk->ca_name, false, true);
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH mptcp-next v12 5/7] Documentation: msg_zerocopy: add MPTCP support
  2026-11-30  6:25 [PATCH mptcp-next v12 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
                   ` (3 preceding siblings ...)
  2026-11-30  6:25 ` [PATCH mptcp-next v12 4/7] mptcp: handle SO_ZEROCOPY in setsockopt Geliang Tang
@ 2026-11-30  6:25 ` Geliang Tang
  2026-12-01 20:14   ` netdev-bot+sashiko
  2026-11-30  6:25 ` [PATCH mptcp-next v12 6/7] selftests: net: " Geliang Tang
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 18+ messages in thread
From: Geliang Tang @ 2026-11-30  6:25 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang

From: Geliang Tang <tanggeliang@kylinos.cn>

Update the MSG_ZEROCOPY documentation to list MPTCP as one of the
protocols that support this feature, alongside TCP, UDP and VSOCK.
Also mention MPTCP in the notification error queue and Loopback
sections.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 Documentation/networking/msg_zerocopy.rst | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/Documentation/networking/msg_zerocopy.rst b/Documentation/networking/msg_zerocopy.rst
index 78fb70e748b7..a06055f1243a 100644
--- a/Documentation/networking/msg_zerocopy.rst
+++ b/Documentation/networking/msg_zerocopy.rst
@@ -7,8 +7,8 @@ Intro
 =====
 
 The MSG_ZEROCOPY flag enables copy avoidance for socket send calls.
-The feature is currently implemented for TCP, UDP and VSOCK (with
-virtio transport) sockets.
+The feature is currently implemented for TCP, MPTCP, UDP and VSOCK
+(with virtio transport) sockets.
 
 
 Opportunity and Caveats
@@ -175,7 +175,7 @@ read_notification() call in the previous snippet. A notification
 is encoded in the standard error format, sock_extended_err.
 
 The level and type fields in the control data are protocol family
-specific, IP_RECVERR or IPV6_RECVERR (for TCP or UDP socket).
+specific, IP_RECVERR or IPV6_RECVERR (for TCP, MPTCP or UDP socket).
 For VSOCK socket, cmsg_level will be SOL_VSOCK and cmsg_type will be
 VSOCK_RECVERR.
 
@@ -238,7 +238,7 @@ Implementation
 Loopback
 --------
 
-For TCP and UDP:
+For TCP, MPTCP and UDP:
 Data sent to local sockets can be queued indefinitely if the receive
 process does not read its socket. Unbound notification latency is not
 acceptable. For this reason all packets generated with MSG_ZEROCOPY
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH mptcp-next v12 6/7] selftests: net: msg_zerocopy: add MPTCP support
  2026-11-30  6:25 [PATCH mptcp-next v12 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
                   ` (4 preceding siblings ...)
  2026-11-30  6:25 ` [PATCH mptcp-next v12 5/7] Documentation: msg_zerocopy: add MPTCP support Geliang Tang
@ 2026-11-30  6:25 ` Geliang Tang
  2026-12-01 20:14   ` netdev-bot+sashiko
  2026-11-30  6:25 ` [PATCH mptcp-next v12 7/7] selftests: mptcp: cover msg_zerocopy test Geliang Tang
  2026-11-30  7:30 ` [PATCH mptcp-next v12 0/7] mptcp: add MSG_ZEROCOPY support MPTCP CI
  7 siblings, 1 reply; 18+ messages in thread
From: Geliang Tang @ 2026-11-30  6:25 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang

From: Geliang Tang <tanggeliang@kylinos.cn>

Add support for testing MSG_ZEROCOPY over MPTCP sockets. This enables
the existing msg_zerocopy test to exercise the zerocopy send path on
MPTCP connections by specifying "mptcp" as the test mode. A new
"check" mode is also added to verify that MPTCP and its zerocopy
support are available before running the tests.

A fallback definition for IPPROTO_MPTCP (262) is provided for systems
with older headers that do not include it.

Usage example:
    ./msg_zerocopy -4 -t 1 -D 127.0.0.1 mptcp
    ./msg_zerocopy -4 -t 1 -D 127.0.0.1 -z mptcp

msg_zerocopy.sh is updated to run IPv4 and IPv6 MPTCP tests in the
default test suite, skipping them if MPTCP is not supported.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/net/msg_zerocopy.c  | 27 +++++++++++++++++++++
 tools/testing/selftests/net/msg_zerocopy.sh | 18 +++++++++++---
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/net/msg_zerocopy.c b/tools/testing/selftests/net/msg_zerocopy.c
index 1d5d3c4e7e87..8c7567c79198 100644
--- a/tools/testing/selftests/net/msg_zerocopy.c
+++ b/tools/testing/selftests/net/msg_zerocopy.c
@@ -5,6 +5,7 @@
  *
  * PF_INET/PF_INET6
  * - SOCK_STREAM
+ * - SOCK_STREAM with IPPROTO_MPTCP
  * - SOCK_DGRAM
  * - SOCK_DGRAM with UDP_CORK
  * - SOCK_RAW
@@ -74,6 +75,10 @@
 #define MSG_ZEROCOPY	0x4000000
 #endif
 
+#ifndef IPPROTO_MPTCP
+#define IPPROTO_MPTCP	262
+#endif
+
 static int  cfg_cork;
 static bool cfg_cork_mixed;
 static int  cfg_cpu		= -1;		/* default: pin to last cpu */
@@ -798,6 +803,24 @@ static void parse_opts(int argc, char **argv)
 		usage(argv[0]);
 }
 
+static void check_mptcp_support(int family, bool zerocopy)
+{
+	int fd = socket(family, SOCK_STREAM, IPPROTO_MPTCP);
+	int val = 1;
+
+	if (fd == -1)
+		exit(1);
+	if (zerocopy) {
+		if (setsockopt(fd, SOL_SOCKET, SO_ZEROCOPY,
+			       &val, sizeof(val))) {
+			close(fd);
+			exit(1);
+		}
+	}
+	close(fd);
+	exit(0);
+}
+
 int main(int argc, char **argv)
 {
 	const char *cfg_test;
@@ -820,6 +843,10 @@ int main(int argc, char **argv)
 		do_test(cfg_family, SOCK_DGRAM, 0);
 	else if (!strcmp(cfg_test, "rds"))
 		do_test(PF_RDS, SOCK_SEQPACKET, 0);
+	else if (!strcmp(cfg_test, "check"))
+		check_mptcp_support(cfg_family, cfg_zerocopy);
+	else if (!strcmp(cfg_test, "mptcp"))
+		do_test(cfg_family, SOCK_STREAM, IPPROTO_MPTCP);
 	else
 		error(1, 0, "unknown cfg_test %s", cfg_test);
 
diff --git a/tools/testing/selftests/net/msg_zerocopy.sh b/tools/testing/selftests/net/msg_zerocopy.sh
index 28178a38a4e7..1dd471e3781b 100755
--- a/tools/testing/selftests/net/msg_zerocopy.sh
+++ b/tools/testing/selftests/net/msg_zerocopy.sh
@@ -32,13 +32,25 @@ if [[ "$#" -eq "0" ]]; then
 	$0 4 udp -t 1 || ret=1
 	$0 6 udp -t 1 || ret=1
 
+	if ${BIN} -4 -t 1 check && ${BIN} -4 -t 1 -z check; then
+		$0 4 mptcp -t 1 || ret=1
+	else
+		echo "SKIP: MPTCP IPv4 tests (not supported)"
+	fi
+
+	if ${BIN} -6 -t 1 check && ${BIN} -6 -t 1 -z check; then
+		$0 6 mptcp -t 1 || ret=1
+	else
+		echo "SKIP: MPTCP IPv6 tests (not supported)"
+	fi
+
 	[[ "$ret" == "0" ]] && echo "OK. All tests passed"
 	exit $ret
 fi
 
 # Argument parsing
 if [[ "$#" -lt "2" ]]; then
-	echo "Usage: $0 [4|6] [tcp|udp|raw|raw_hdrincl|packet|packet_dgram] <args>"
+	echo "Usage: $0 [4|6] [tcp|mptcp|udp|raw|raw_hdrincl|packet|packet_dgram] <args>"
 	exit 1
 fi
 
@@ -143,8 +155,8 @@ do_test() {
 		-S "${SADDR}" -D "${DADDR}" ${ARGS} "${TXMODE}" -Z 0 || ret=1
 	wait
 
-	# next test is unconnected tx to dummy0, cannot exercise with tcp
-	[[ "${TXMODE}" == "tcp" ]] && return
+	# next test is unconnected tx to dummy0, cannot exercise with tcp/mptcp
+	[[ "${TXMODE}" == "tcp" || "${TXMODE}" == "mptcp" ]] && return
 
 	# tx-only test: send out dummy0
 	# packets leaving the host are not copied,
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH mptcp-next v12 7/7] selftests: mptcp: cover msg_zerocopy test
  2026-11-30  6:25 [PATCH mptcp-next v12 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
                   ` (5 preceding siblings ...)
  2026-11-30  6:25 ` [PATCH mptcp-next v12 6/7] selftests: net: " Geliang Tang
@ 2026-11-30  6:25 ` Geliang Tang
  2026-11-30  6:40   ` sashiko-bot
  2026-12-01 20:14   ` netdev-bot+sashiko
  2026-11-30  7:30 ` [PATCH mptcp-next v12 0/7] mptcp: add MSG_ZEROCOPY support MPTCP CI
  7 siblings, 2 replies; 18+ messages in thread
From: Geliang Tang @ 2026-11-30  6:25 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang

From: Geliang Tang <tanggeliang@kylinos.cn>

Add the msg_zerocopy test to the MPTCP selftest suite by creating a
wrapper script that checks for MPTCP zerocopy support before executing
the existing msg_zerocopy.sh script in the net selftests directory.

Update the Makefile to add msg_zerocopy.sh to TEST_PROGS, add
msg_zerocopy binary to TEST_GEN_FILES, add build rule to compile
msg_zerocopy from ../msg_zerocopy.c, and add ../msg_zerocopy.sh to
TEST_INCLUDES for out-of-tree builds. Also add msg_zerocopy binary
to .gitignore and CONFIG_DUMMY=y to the config file.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/net/mptcp/.gitignore      | 1 +
 tools/testing/selftests/net/mptcp/Makefile        | 7 ++++++-
 tools/testing/selftests/net/mptcp/config          | 1 +
 tools/testing/selftests/net/mptcp/msg_zerocopy.sh | 8 ++++++++
 4 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/net/mptcp/msg_zerocopy.sh

diff --git a/tools/testing/selftests/net/mptcp/.gitignore b/tools/testing/selftests/net/mptcp/.gitignore
index 833279fb34e2..1f318a297f70 100644
--- a/tools/testing/selftests/net/mptcp/.gitignore
+++ b/tools/testing/selftests/net/mptcp/.gitignore
@@ -3,5 +3,6 @@ mptcp_connect
 mptcp_diag
 mptcp_inq
 mptcp_sockopt
+msg_zerocopy
 pm_nl_ctl
 *.pcap
diff --git a/tools/testing/selftests/net/mptcp/Makefile b/tools/testing/selftests/net/mptcp/Makefile
index 22ba0da2adb8..c23e36482194 100644
--- a/tools/testing/selftests/net/mptcp/Makefile
+++ b/tools/testing/selftests/net/mptcp/Makefile
@@ -14,6 +14,7 @@ TEST_PROGS := \
 	mptcp_connect_splice.sh \
 	mptcp_join.sh \
 	mptcp_sockopt.sh \
+	msg_zerocopy.sh \
 	pm_netlink.sh \
 	simult_flows.sh \
 	userspace_pm.sh \
@@ -24,6 +25,7 @@ TEST_GEN_FILES := \
 	mptcp_diag \
 	mptcp_inq \
 	mptcp_sockopt \
+	msg_zerocopy \
 	pm_nl_ctl \
 # end of TEST_GEN_FILES
 
@@ -32,8 +34,11 @@ TEST_FILES := \
 	settings \
 # end of TEST_FILES
 
-TEST_INCLUDES := ../lib.sh $(wildcard ../lib/sh/*.sh)
+TEST_INCLUDES := ../lib.sh ../msg_zerocopy.sh $(wildcard ../lib/sh/*.sh)
 
 EXTRA_CLEAN := *.pcap
 
 include ../../lib.mk
+
+$(OUTPUT)/msg_zerocopy: ../msg_zerocopy.c
+	$(LINK.c) $^ $(LDLIBS) -o $@
diff --git a/tools/testing/selftests/net/mptcp/config b/tools/testing/selftests/net/mptcp/config
index 6a96cfbbc461..b44358c178af 100644
--- a/tools/testing/selftests/net/mptcp/config
+++ b/tools/testing/selftests/net/mptcp/config
@@ -1,3 +1,4 @@
+CONFIG_DUMMY=y
 CONFIG_INET_DIAG=m
 CONFIG_INET_MPTCP_DIAG=m
 CONFIG_IP_ADVANCED_ROUTER=y
diff --git a/tools/testing/selftests/net/mptcp/msg_zerocopy.sh b/tools/testing/selftests/net/mptcp/msg_zerocopy.sh
new file mode 100755
index 000000000000..118fff27dc5c
--- /dev/null
+++ b/tools/testing/selftests/net/mptcp/msg_zerocopy.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+. "$(dirname "${0}")/mptcp_lib.sh"
+
+mptcp_lib_check_mptcp
+
+exec "$(dirname "${0}")/../msg_zerocopy.sh" "$@"
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH mptcp-next v12 1/7] mptcp: use local variable tp in sendmsg_frag
  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-12-01 20:14   ` netdev-bot+sashiko
  1 sibling, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-11-30  6:29 UTC (permalink / raw)
  To: Geliang Tang, mptcp

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] mptcp: incomplete conversion to local variable tp in
  mptcp_sendmsg_frag()
--

commit e1a0fc5eae2c7cc5e3f3690ee2878f7fadb4d91b
Author: Geliang Tang <geliang@kernel.org>

mptcp: use local variable tp in sendmsg_frag

This commit introduces a local variable tp for tcp_sk(ssk) in
mptcp_sendmsg_frag() and replaces repeated tcp_sk(ssk) calls with it.

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index b9c6e5a615c8b..58cb11b25253d 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -1456,6 +1456,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
>  	u64 data_seq = dfrag->data_seq + info->sent;
>  	int offset = dfrag->offset + info->sent;
>  	struct mptcp_sock *msk = mptcp_sk(sk);
> +	struct tcp_sock *tp = tcp_sk(ssk);
>  	bool zero_window_probe = false;
>  	struct mptcp_ext *mpext = NULL;
>  	bool can_coalesce = false;
> @@ -1505,14 +1506,14 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
>  		mpext = mptcp_get_ext(skb);
>  		if (!mptcp_skb_can_collapse_to(data_seq, skb, mpext)) {
>  			TCP_SKB_CB(skb)->eor = 1;
> -			tcp_mark_push(tcp_sk(ssk), skb);
> +			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)) {
> -			tcp_mark_push(tcp_sk(ssk), skb);
> +			tcp_mark_push(tp, skb);
>  			goto alloc_skb;
>  		}
>  
> @@ -1590,7 +1591,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
>  	skb->truesize += copy;
>  	sk_wmem_queued_add(ssk, copy);
>  	sk_mem_charge(ssk, copy);
> -	WRITE_ONCE(tcp_sk(ssk)->write_seq, tcp_sk(ssk)->write_seq + copy);
> +	WRITE_ONCE(tp->write_seq, tp->write_seq + copy);
>  	TCP_SKB_CB(skb)->end_seq += copy;
>  	tcp_skb_pcount_set(skb, 0);
>  

[Severity: Low]
This isn't a bug, but two other tcp_sk(ssk) calls remain in
mptcp_sendmsg_frag() and could also use tp:

net/mptcp/protocol.c:mptcp_sendmsg_frag() {
    ...
	if (unlikely(before64(data_seq, msk->snd_nxt) &&
		     !test_bit(MPTCP_JOINED, &msk->flags) &&
		     after(tcp_sk(ssk)->snd_una, subflow->opt_ack_seq))) {
    ...
	if (unlikely(before64(data_seq, msk->snd_nxt))) {
		mptcp_subflow_ctx(ssk)->old_data_end = tcp_sk(ssk)->write_seq;
		mptcp_subflow_ctx(ssk)->old_data_pending = 1;
	}
    ...
}

Converting those as well would avoid the remaining tcp_sk(ssk) evaluations
(including the redundant WARN_ON() check under CONFIG_DEBUG_NET).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796019473.git.tanggeliang@kylinos.cn?part=1

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH mptcp-next v12 7/7] selftests: mptcp: cover msg_zerocopy test
  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-12-01 20:14   ` netdev-bot+sashiko
  1 sibling, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-11-30  6:40 UTC (permalink / raw)
  To: Geliang Tang, mptcp

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] selftests: mptcp: missing zerocopy check in msg_zerocopy.sh
  wrapper
- [Medium] mptcp: unscheduled sk_mem_charge() without SG in
  mptcp_sendmsg_frag()
- [Medium] mptcp: zc cleared before mptcp_sendmsg_fastopen() in
  mptcp_sendmsg()
--

commit 1852c1fd7d811fa5bc6531df5e7b0dad74715d8f
Author: Geliang Tang <geliang@kernel.org>

selftests: mptcp: cover msg_zerocopy test

This commit adds a wrapper script and build rules to run the msg_zerocopy
test as part of the MPTCP selftest suite.

> diff --git a/tools/testing/selftests/net/mptcp/msg_zerocopy.sh b/tools/testing/selftests/net/mptcp/msg_zerocopy.sh
> new file mode 100755
> index 0000000000000..118fff27dc5cd
> --- /dev/null
> +++ b/tools/testing/selftests/net/mptcp/msg_zerocopy.sh
> @@ -0,0 +1,8 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +
> +. "$(dirname "${0}")/mptcp_lib.sh"
> +
> +mptcp_lib_check_mptcp
> +
> +exec "$(dirname "${0}")/../msg_zerocopy.sh" "$@"

[Severity: Medium]
Does this wrapper actually check for MPTCP zerocopy support before running
../msg_zerocopy.sh?

mptcp_lib_check_mptcp() only checks that /proc/sys/net/mptcp/enabled exists.
On a kernel with MPTCP enabled but without MPTCP zerocopy support, running
this script executes the TCP and UDP zerocopy tests in ../msg_zerocopy.sh,
prints skip messages for the MPTCP subtests, and exits 0 (KSFT_PASS) instead
of KSFT_SKIP, while also bypassing SELFTESTS_MPTCP_LIB_EXPECT_ALL_FEATURES=1.
Checking for the feature symbol via mptcp_lib_kallsyms_has() (for example
"mptcp_sendmsg_zerocopy_iter$") before execing ../msg_zerocopy.sh would avoid
this.

[Severity: Medium]
In commit "mptcp: add MSG_ZEROCOPY support", can mptcp_sendmsg_frag() call
sk_mem_charge() without prior memory scheduling when the subflow route lacks
NETIF_F_SG?

net/mptcp/protocol.c:mptcp_sendmsg_frag() {
	...
		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;
		}
	...
	if (!dfrag->ubuf) {
		/* like TCP, allow some progress up to tcp_wmem[0] */
		avail = tcp_wmem_schedule(ssk, 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);
	...
	if (!zc)
		sk_mem_charge(ssk, copy);
}

tcp_wmem_schedule() is skipped whenever dfrag->ubuf is set, but
SKBFL_PURE_ZEROCOPY and zc = true are only set when NETIF_F_SG is present on
the subflow route.  Without NETIF_F_SG, zc stays false, so sk_mem_charge()
charges unscheduled bytes against ssk->sk_forward_alloc (driving it negative),
and the next mptcp_sendmsg_frag() call fails skb_zcopy_pure(skb) !=
!!dfrag->ubuf and allocates a new skb for every fragment.

[Severity: Medium]
In commit "mptcp: add MSG_ZEROCOPY support", does mptcp_sendmsg() always pass
NULL instead of ubuf to mptcp_sendmsg_fastopen()?

net/mptcp/protocol.c:mptcp_sendmsg() {
	...
	if (unlikely(inet_test_bit(DEFER_CONNECT, sk) ||
		     msg->msg_flags & MSG_FASTOPEN)) {
		int copied_syn = 0;

		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);
}

Because zc is cleared to false right before the call, zc ? ubuf : NULL always
evaluates to NULL.  tcp_send_syn_data() never attaches ubuf to the SYN+DATA
skb via skb_zcopy_set(), and when mptcp_sendmsg_fastopen() returns
-EINPROGRESS with copied_syn > 0, mptcp_sendmsg() jumps to out and calls
net_zcopy_put(ubuf), completing the zerocopy notification before the SYN data
is sent or acknowledged.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796019473.git.tanggeliang@kylinos.cn?part=7

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH mptcp-next v12 3/7] mptcp: add MSG_ZEROCOPY support
  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
  2026-12-01 20:14   ` netdev-bot+sashiko
  1 sibling, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-11-30  6:56 UTC (permalink / raw)
  To: Geliang Tang, mptcp

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH mptcp-next v12 0/7] mptcp: add MSG_ZEROCOPY support
  2026-11-30  6:25 [PATCH mptcp-next v12 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
                   ` (6 preceding siblings ...)
  2026-11-30  6:25 ` [PATCH mptcp-next v12 7/7] selftests: mptcp: cover msg_zerocopy test Geliang Tang
@ 2026-11-30  7:30 ` MPTCP CI
  7 siblings, 0 replies; 18+ messages in thread
From: MPTCP CI @ 2026-11-30  7:30 UTC (permalink / raw)
  To: Geliang Tang; +Cc: mptcp

Hi Geliang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal (except selftest_mptcp_join): Unstable: 1 failed test(s): packetdrill_regressions ⚠️ 
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Success! ✅
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Perf: Unstable: 1 failed test(s): regression:sched-baseline(3) ⚠️  (15 new outliers to review) | Unstable: 1 failed test(s): validation:sched-loss ⚠️  (21 new outliers to review) | Unstable: 3 failed test(s): regression:sched-bbr(3) regression:sched-serverlim(2) regression:sched-weak-secondary(3) ⚠️  (4 improvements, 10 new outliers to review) | Success! ✅ (7 new outliers to review)
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/46368645246

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/5c22958a8dcc
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1226343


If there are some issues, you can reproduce them using the same environment as
the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

    https://github.com/multipath-tcp/mptcp-upstream-virtme-docker


Please note that despite all the efforts that have been already done to have a
stable tests suite when executed on a public CI like here, it is possible some
reported issues are not due to your modifications. Still, do not hesitate to
help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH mptcp-next v12 1/7] mptcp: use local variable tp in sendmsg_frag
  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-12-01 20:14   ` netdev-bot+sashiko
  1 sibling, 0 replies; 18+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 20:14 UTC (permalink / raw)
  To: geliang; +Cc: mptcp, tanggeliang, kuba

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message for mptcp_sendmsg_frag() in
  net/mptcp/protocol.c says the new local 'tp' is used "throughout the…
- [Low] The commit author identity (Geliang Tang <geliang@kernel.org>)
  does not match the only Signed-off-by trailer (Geliang Tang…

--

mptcp: use local variable tp in sendmsg_frag

This patch adds a local tcp_sock pointer named tp in
mptcp_sendmsg_frag() and uses it in place of some of the repeated
tcp_sk(ssk) calls. It is meant as a readability cleanup with no
functional change.

> Suggested-by: Paolo Abeni <pabeni@redhat.com>
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>

[Severity: Low]
This isn't a bug, but the author address (geliang@kernel.org) does not
match the only Signed-off-by address (tanggeliang@kylinos.cn).
checkpatch warns about this as a From:/Signed-off-by: email address
mismatch.

Could you add an in-body From: line with the kylinos.cn address, or sign
off with the kernel.org address instead?

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index b9c6e5a615c8b..58cb11b25253d 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -1456,6 +1456,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
>  	u64 data_seq = dfrag->data_seq + info->sent;
>  	int offset = dfrag->offset + info->sent;
>  	struct mptcp_sock *msk = mptcp_sk(sk);
> +	struct tcp_sock *tp = tcp_sk(ssk);
>  	bool zero_window_probe = false;
>  	struct mptcp_ext *mpext = NULL;
>  	bool can_coalesce = false;

[ ... ]

> @@ -1590,7 +1591,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
>  	skb->truesize += copy;
>  	sk_wmem_queued_add(ssk, copy);
>  	sk_mem_charge(ssk, copy);
> -	WRITE_ONCE(tcp_sk(ssk)->write_seq, tcp_sk(ssk)->write_seq + copy);
> +	WRITE_ONCE(tp->write_seq, tp->write_seq + copy);

[Severity: Low]
This isn't a bug, but the commit message says tp is used "throughout the
function". Two open-coded tcp_sk(ssk) dereferences are still left in
mptcp_sendmsg_frag().

The middlebox fallback check still has:

	if (unlikely(before64(data_seq, msk->snd_nxt) &&
		     !test_bit(MPTCP_JOINED, &msk->flags) &&
		     after(tcp_sk(ssk)->snd_una, subflow->opt_ack_seq))) {

A few lines below this hunk, the same write_seq field is still read
through tcp_sk(ssk):

	if (unlikely(before64(data_seq, msk->snd_nxt))) {
		mptcp_subflow_ctx(ssk)->old_data_end = tcp_sk(ssk)->write_seq;
		mptcp_subflow_ctx(ssk)->old_data_pending = 1;
	}

So tp->write_seq and tcp_sk(ssk)->write_seq now appear next to each
other. The later patches in the series do not convert these two sites
either.

Should these two sites use tp as well, or should the commit message be
reworded?

[ ... ]

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH mptcp-next v12 3/7] mptcp: add MSG_ZEROCOPY support
  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
@ 2026-12-01 20:14   ` netdev-bot+sashiko
  1 sibling, 0 replies; 18+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 20:14 UTC (permalink / raw)
  To: geliang; +Cc: mptcp, tanggeliang, kuba

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

Critical: 0 · High: 0 · Medium: 2 · Low: 4

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] mptcp_sendmsg_frag() (net/mptcp/protocol.c) mishandles
  zerocopy dfrags on a subflow whose route lacks NETIF_F_SG.
- [Medium] mptcp: broken zcopy coalescing via skb_can_coalesce() in
  mptcp_sendmsg_frag()
- [Low] At this commit, nothing can set SOCK_ZEROCOPY on an MPTCP socket.
- [Low] In mptcp_sendmsg(), the code inside the `if
  (unlikely(inet_test_bit(DEFER_CONNECT, sk) || msg->msg_flags &…
- [Low] Two behaviours are not mentioned in the commit message.
- [Low] mptcp_sendmsg_zerocopy_iter() calls `sk_wmem_schedule(sk,
  PAGE_SIZE + dfrag->overhead)` but never uses the reservation: no…

--

mptcp: add MSG_ZEROCOPY support

This patch adds MSG_ZEROCOPY support to MPTCP sockets. User pages are
pinned with iov_iter_get_pages2(), stored in a separately allocated
mptcp_data_frag that holds a ubuf_info reference, and attached to subflow
skbs marked with skb_zcopy_set() and SKBFL_PURE_ZEROCOPY. The feature
silently falls back to copying in some cases, such as MSG_FASTOPEN.

> 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

[ ... ]

> @@ -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: Medium]
Can can_coalesce ever be true for a zerocopy dfrag here?

skb_can_coalesce() goes through skb_can_coalesce_netmem(), which
returns early for any zerocopy skb:

include/linux/skbuff.h:skb_can_coalesce_netmem() {
	if (skb_zcopy(skb))
		return false;
    ...
}

A freshly allocated skb has i == 0, so skb_can_coalesce() returns false
there as well. Once the first slice of a zerocopy dfrag is attached,
skb_zcopy_set() has made skb_zcopy(skb) non-NULL. Every later reuse of
that tail skb by a dfrag with the same ubuf then also gets
can_coalesce == false, even when the new slice is contiguous with the
last frag on the same page.

That makes the can_coalesce half of the new truesize expression dead
for zerocopy skbs. Each slice takes the else branch instead, which
means:

    - another get_page()
    - another skb_frag_t slot
    - a full PAGE_SIZE added to skb->truesize and ssk->sk_wmem_queued

Contiguous slices of one page can land on the same skb in several
cases:

    - a dfrag is split across calls by info->limit, the send window
      or the size goal
    - copy_limit makes two iov_iter_get_pages2() calls on one page
    - on 64K-page kernels, the U16_MAX clamp in
      mptcp_sendmsg_zerocopy_iter() splits a page into two dfrags

In those cases the subflow send budget is overcharged by about a page
per slice. The frags array also fills faster, so the
sysctl_max_skb_frags check forces new skbs and DSS mappings sooner.

TCP does not hit this because its zerocopy path does not rely on
skb_can_coalesce(). __zerocopy_sg_from_iter() compares the new page
and offset against the last frag itself and extends that frag.

Should mptcp_sendmsg_frag() do the same for zerocopy skbs with a
matching ubuf, by open-coding the last-frag page/offset comparison
instead of calling skb_can_coalesce()? Or is there another way you
would prefer to account truesize for zerocopy slices?

[Severity: Medium]
What happens here when the subflow route lacks NETIF_F_SG? This can occur
with IPsec without offload, or when sk_gso_disabled is set.

The tcp_wmem_schedule() call is skipped because dfrag->ubuf is set. But zc
stays false, since the NETIF_F_SG branch is not taken and the skb is not
pure. So sk_mem_charge(ssk, copy) charges memory that was never reserved,
and sk_forward_alloc can go negative until the next schedule or free.

TCP handles the same case in tcp_sendmsg_locked() by falling back to a copy
and clearing the zerocopy indicator:

net/ipv4/tcp.c:tcp_sendmsg_locked() {
    ...
			if (sk->sk_route_caps & NETIF_F_SG)
				zc = MSG_ZEROCOPY;
			else
				uarg_to_msgzc(uarg)->zerocopy = 0;
    ...
}

Here uarg->zerocopy is never cleared. The completion therefore does not
report SO_EE_CODE_ZEROCOPY_COPIED, even though the non-SG path will copy
the frags.

The skb is also zerocopy but not pure. Because of that, the new reuse check
earlier in mptcp_sendmsg_frag():

    if (skb_zcopy_pure(skb) != !!dfrag->ubuf ||

forces a new skb and DSS mapping for every later zerocopy dfrag on that
subflow.

Should mptcp_sendmsg_frag() check NETIF_F_SG the same way TCP does?

[ ... ]

> @@ -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 (pg_len > U16_MAX) {
> +		iov_iter_revert(&msg->msg_iter, pg_len - U16_MAX);
> +		pg_len = U16_MAX;
> +	}

[Severity: Low]
On 64K-page kernels, does this clamp split a full, aligned user page into
two dfrags?

The first call gets pg_len 65536 and clamps it to 65535. The next call gets
pg_off 65535 and pg_len 1. That passes both the pg_off > U16_MAX check and
the pg_off + pg_len > U16_MAX + 1 check.

Each dfrag then runs:

    sk_wmem_queued_add(sk, PAGE_SIZE + dfrag->overhead);

So 64K of user data uses about 128K of the msk send budget.
mptcp_send_limit() compares sk_wmem_queued with sk_sndbuf, so zerocopy gets
about half the in-flight data that copy mode gets on these systems.

On kernels with pages larger than 64K, this check in mptcp_sendmsg() turns
MSG_ZEROCOPY into a plain copy:

    if (zc && PAGE_SIZE > U16_MAX + 1) {
        uarg_to_msgzc(ubuf)->zerocopy = 0;
        zc = false;
    }

Neither behaviour is mentioned in the commit message. Could it describe
them?

[ ... ]

> +	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;
> +	}

[Severity: Low]
Is this reservation ever used? No sk_mem_charge() or sk_forward_alloc_add()
follows it.

The other side matches this. dfrag_uncharge() skips sk_mem_uncharge() for
ubuf dfrags, and __mptcp_clean_una() skips the partial-ack uncharge for
them.

Since sk_forward_alloc is never reduced, later calls mostly return true
without reserving anything. The check does not limit how many zerocopy
dfrags get queued. Its only effect is forward-alloc memory that sits
unused. Because sk_mem_uncharge() is skipped, sk_mem_reclaim() is also not
triggered on this path.

The only real bound left is the sk_wmem_queued vs. sk_sndbuf test in
mptcp_send_limit().

Unlike page-frag-carved dfrags in the copy path, the kmalloc'd dfrags are
charged to memcg via GFP_KERNEL_ACCOUNT but are not counted in protocol
memory_allocated.

[ ... ]

>  	lock_sock(sk);
>
>  	mptcp_rps_record_subflows(msk);
>
> +	if (!sock_flag(sk, SOCK_ZEROCOPY))
> +		msg->msg_flags &= ~MSG_ZEROCOPY;

[Severity: Low]
Can SOCK_ZEROCOPY be set on an MPTCP socket at this commit?
mptcp_setsockopt_sol_socket() still rejects SO_ZEROCOPY with -EOPNOTSUPP,
and its comment in net/mptcp/sockopt.c still says:

    * SO_ZEROCOPY is currently unsupported, TODO in sndmsg

As a result, this check always clears MSG_ZEROCOPY, and none of the new
zerocopy code can run yet.

The next patch in the series, "mptcp: handle SO_ZEROCOPY in setsockopt",
adds the setsockopt handling, removes the stale comment, and syncs
SOCK_ZEROCOPY to subflows in sync_socket_options(). So this only affects
bisection at this point in the series.

[ ... ]

>  	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]
Inside this block, the inner condition reduces to just zc. Doesn't that
mean zc is always cleared, so mptcp_sendmsg_fastopen() always receives
NULL?

If so, the new ubuf parameter of mptcp_sendmsg_fastopen(), and its
forwarding to tcp_sendmsg_fastopen(), never carry a value. They could be
dropped.

The commit message also seems incomplete here:

    The feature silently downgrades to regular copy when MSG_FASTOPEN is
    set or the application has not opted in via setsockopt(SO_ZEROCOPY).

The code also falls back to copying without notice in these cases:

    - DEFER_CONNECT is set (TCP_FASTOPEN_CONNECT)
    - PAGE_SIZE > 64K
    - page pinning returns -EFAULT on the first chunk

The new memory accounting rules for zerocopy dfrags are not described
either.

[ ... ]

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH mptcp-next v12 4/7] mptcp: handle SO_ZEROCOPY in setsockopt
  2026-11-30  6:25 ` [PATCH mptcp-next v12 4/7] mptcp: handle SO_ZEROCOPY in setsockopt Geliang Tang
@ 2026-12-01 20:14   ` netdev-bot+sashiko
  0 siblings, 0 replies; 18+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 20:14 UTC (permalink / raw)
  To: geliang; +Cc: mptcp, tanggeliang, kuba

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 makes SO_ZEROCOPY settable on MPTCP sockets, which
  makes the MSG_ZEROCOPY transmit path from commit "mptcp: add…

--

mptcp: handle SO_ZEROCOPY in setsockopt

With this patch, MPTCP's SOL_SOCKET setsockopt dispatcher accepts
SO_ZEROCOPY instead of returning -EOPNOTSUPP. A new helper sets
SOCK_ZEROCOPY on the msk and all its subflows, and
sync_socket_options() 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]
Once this flag is set, mptcp_sendmsg() no longer clears MSG_ZEROCOPY.
That makes the MPTCP zerocopy send path reachable from userspace for the
first time. When the subflow route lacks NETIF_F_SG, does that path
charge subflow memory that was never reserved?

In mptcp_sendmsg_frag() in net/mptcp/protocol.c, the reservation is
skipped for every zerocopy dfrag:

	if (!dfrag->ubuf) {
		/* like TCP, allow some progress up to tcp_wmem[0] */
		avail = tcp_wmem_schedule(ssk, copy);
		...
	}

The skb is only marked pure when the route has SG:

		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)
		sk_mem_charge(ssk, copy);

Without NETIF_F_SG, zc stays false and skb_zcopy_pure(skb) is also
false. In that case sk_mem_charge() takes copy bytes out of
ssk->sk_forward_alloc, but no sk_wmem_schedule() call ever reserved them.

Can sk_forward_alloc go negative here? The proto memory_allocated and
memcg counters also look under-counted by those bytes for as long as the
skb sits in the write and retransmit queues. Those bytes would then
bypass the tcp_mem and memcg limits. The counters only balance again
when tcp_wmem_free_skb() uncharges skb->truesize.

For comparison, tcp_sendmsg_locked() only uses zerocopy when SG is
present:

		if (sk->sk_route_caps & NETIF_F_SG)
			zc = MSG_ZEROCOPY;
		else
			uarg_to_msgzc(uarg)->zerocopy = 0;

Even on its zerocopy path, TCP still calls tcp_wmem_schedule() for any
skb that is not pure zerocopy.

sk_setup_caps() does not force NETIF_F_SG for non-offloaded xfrm routes,
or when sk_gso_disabled is set. That means a subflow running over IPsec
without offload, on a device with SG turned off, looks able to reach
this path.

The commit message of "mptcp: add MSG_ZEROCOPY support" says subflow
skbs are always marked SKBFL_PURE_ZEROCOPY. That does not seem to hold
in the no-SG case.

Later patches in this series don't touch net/, so this still appears to
be present at the end of the series.

Should MPTCP fall back to copying when the subflow has no SG? Or should
it reserve memory for non-pure zerocopy skbs, the way TCP does?

> +	sockopt_seq_inc(msk);
> +

[ ... ]

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH mptcp-next v12 5/7] Documentation: msg_zerocopy: add MPTCP support
  2026-11-30  6:25 ` [PATCH mptcp-next v12 5/7] Documentation: msg_zerocopy: add MPTCP support Geliang Tang
@ 2026-12-01 20:14   ` netdev-bot+sashiko
  0 siblings, 0 replies; 18+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 20:14 UTC (permalink / raw)
  To: geliang; +Cc: mptcp, tanggeliang, kuba

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 to the MSG_ZEROCOPY documentation
  alongside TCP.

--

Documentation: msg_zerocopy: add MPTCP support

This commit updates Documentation/networking/msg_zerocopy.rst to list
MPTCP as a protocol that supports MSG_ZEROCOPY, alongside TCP, UDP and
VSOCK. It also mentions MPTCP in the notification error queue and
Loopback sections.

> diff --git a/Documentation/networking/msg_zerocopy.rst b/Documentation/networking/msg_zerocopy.rst
> index 78fb70e748b77..a06055f1243ad 100644
> --- a/Documentation/networking/msg_zerocopy.rst
> +++ b/Documentation/networking/msg_zerocopy.rst
> @@ -7,8 +7,8 @@ Intro
>  =====
>  
>  The MSG_ZEROCOPY flag enables copy avoidance for socket send calls.
> -The feature is currently implemented for TCP, UDP and VSOCK (with
> -virtio transport) sockets.
> +The feature is currently implemented for TCP, MPTCP, UDP and VSOCK
> +(with virtio transport) sockets.

[Severity: Medium]

With MPTCP listed here, the "Deferred copies" section of this file now
covers MPTCP too:

  reason, the kernel signals if data was completed with a copy, by
  setting flag SO_EE_CODE_ZEROCOPY_COPIED in field ee_code on return.

Does MPTCP report SO_EE_CODE_ZEROCOPY_COPIED when a subflow route lacks
NETIF_F_SG?

In mptcp_sendmsg_frag() in net/mptcp/protocol.c, the ubuf is attached
whether or not the route has SG. The NETIF_F_SG check only decides
whether SKBFL_PURE_ZEROCOPY is set:

	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;
		}
	}

mptcp_sendmsg() clears uarg_to_msgzc(ubuf)->zerocopy in only three
cases:

  - PAGE_SIZE > U16_MAX + 1
  - MSG_FASTOPEN or DEFER_CONNECT
  - -EFAULT on the first chunk

By contrast, tcp_sendmsg_locked() in net/ipv4/tcp.c handles the non-SG
case directly:

	if (sk->sk_route_caps & NETIF_F_SG)
		zc = MSG_ZEROCOPY;
	else
		uarg_to_msgzc(uarg)->zerocopy = 0;

On a non-SG MPTCP subflow, the user pages are copied later in the
stack. Examples are __skb_linearize() called from validate_xmit_skb(),
or ESP's skb_cow_data().

msg_zerocopy_alloc() always sets SKBFL_DONT_ORPHAN. Because of that,
skb_orphan_frags() returns 0 and skb_copy_ubufs() never runs, so
uarg->zerocopy stays 1. __msg_zerocopy_callback() then sends the
completion without the flag:

	if (!is_zerocopy)
		serr->ee.ee_code |= SO_EE_CODE_ZEROCOPY_COPIED;

Would MPTCP applications then never get the documented signal to stop
using MSG_ZEROCOPY? This could happen with IPsec without hardware
offload, with sk_gso_disabled set, or on a device without SG. It would
also happen when only some subflows of a connection lack SG.

Should the MPTCP code clear ->zerocopy for non-SG subflows, as TCP
does, before this document lists MPTCP alongside TCP?

[ ... ]

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH mptcp-next v12 6/7] selftests: net: msg_zerocopy: add MPTCP support
  2026-11-30  6:25 ` [PATCH mptcp-next v12 6/7] selftests: net: " Geliang Tang
@ 2026-12-01 20:14   ` netdev-bot+sashiko
  0 siblings, 0 replies; 18+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 20:14 UTC (permalink / raw)
  To: geliang; +Cc: mptcp, tanggeliang, kuba

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] In `tools/testing/selftests/net/msg_zerocopy.sh`, the default
  run (no arguments, lines 35-45) only runs the MPTCP tests if two…

--

selftests: net: msg_zerocopy: add MPTCP support

This adds an "mptcp" test mode to msg_zerocopy, so the zerocopy send path
also runs over IPPROTO_MPTCP sockets. It also adds a "check" mode that
probes whether MPTCP sockets, and SO_ZEROCOPY on them, are available.
msg_zerocopy.sh now runs the IPv4 and IPv6 MPTCP tests by default and
skips them when the probe fails.

> diff --git a/tools/testing/selftests/net/msg_zerocopy.c b/tools/testing/selftests/net/msg_zerocopy.c
> index 1d5d3c4e7e872..8c7567c79198b 100644
> --- a/tools/testing/selftests/net/msg_zerocopy.c
> +++ b/tools/testing/selftests/net/msg_zerocopy.c

[ ... ]

> @@ -798,6 +803,24 @@ static void parse_opts(int argc, char **argv)
>  		usage(argv[0]);
>  }
>  
> +static void check_mptcp_support(int family, bool zerocopy)
> +{
> +	int fd = socket(family, SOCK_STREAM, IPPROTO_MPTCP);
> +	int val = 1;
> +
> +	if (fd == -1)
> +		exit(1);
> +	if (zerocopy) {
> +		if (setsockopt(fd, SOL_SOCKET, SO_ZEROCOPY,
> +			       &val, sizeof(val))) {
> +			close(fd);
> +			exit(1);
> +		}
> +	}
> +	close(fd);
> +	exit(0);
> +}
> +

[ ... ]

> diff --git a/tools/testing/selftests/net/msg_zerocopy.sh b/tools/testing/selftests/net/msg_zerocopy.sh
> index 28178a38a4e7b..1dd471e3781b7 100755
> --- a/tools/testing/selftests/net/msg_zerocopy.sh
> +++ b/tools/testing/selftests/net/msg_zerocopy.sh
> @@ -32,13 +32,25 @@ if [[ "$#" -eq "0" ]]; then
>  	$0 4 udp -t 1 || ret=1
>  	$0 6 udp -t 1 || ret=1
>  
> +	if ${BIN} -4 -t 1 check && ${BIN} -4 -t 1 -z check; then
> +		$0 4 mptcp -t 1 || ret=1
> +	else
> +		echo "SKIP: MPTCP IPv4 tests (not supported)"
> +	fi
> +
> +	if ${BIN} -6 -t 1 check && ${BIN} -6 -t 1 -z check; then
> +		$0 6 mptcp -t 1 || ret=1
> +	else
> +		echo "SKIP: MPTCP IPv6 tests (not supported)"
> +	fi
> +
>  	[[ "$ret" == "0" ]] && echo "OK. All tests passed"
>  	exit $ret
>  fi

[Severity: Medium]
Can this hide a regression in the very feature the test is meant to cover?

check_mptcp_support() exits 1 if either socket(..., IPPROTO_MPTCP) or
setsockopt(SO_ZEROCOPY) fails. The script then only prints the SKIP
message. It leaves ret at 0, prints "OK. All tests passed" and exits 0.
There is no KSFT_SKIP or failure status.

This series adds SO_ZEROCOPY support for MPTCP sockets in "mptcp: handle
SO_ZEROCOPY in setsockopt". Suppose that handling regresses, for example
by returning -EOPNOTSUPP again. The MPTCP cases would then be skipped
quietly and the run would still pass.

tools/testing/selftests/net/config sets CONFIG_MPTCP=y. On a kernel built
for selftests, a failed probe is therefore more likely a regression than
missing support.

The wrapper added later in the series by "selftests: mptcp: cover
msg_zerocopy test" does not appear to change this:

tools/testing/selftests/net/mptcp/msg_zerocopy.sh:
    mptcp_lib_check_mptcp

    exec "$(dirname "${0}")/../msg_zerocopy.sh" "$@"

mptcp_lib_check_mptcp() only checks that /proc/sys/net/mptcp/enabled
exists. The wrapper runs the net script with no arguments, so it takes
this same path.

The internal SKIP also bypasses SELFTESTS_MPTCP_LIB_EXPECT_ALL_FEATURES
and mptcp_lib_fail_if_expected_feature(). Those exist to turn
missing-feature skips into failures in MPTCP CI.

The probes also run in the caller's network namespace. All the real tx/rx
runs happen inside NS1/NS2, and net.mptcp.enabled is a per-netns setting:

net/mptcp/protocol.c:mptcp_init_sock() {
    ...
	if (!mptcp_is_enabled(net))
		return -ENOPROTOOPT;
    ...
}

mptcp_pernet_set_defaults() enables MPTCP in new namespaces. If MPTCP is
disabled in the caller's namespace, the tests are skipped even though
they would work in NS1/NS2.

Every failure prints the same "not supported" message: socket creation
failing, IPv6 being unavailable, or SO_ZEROCOPY being rejected. The
reason for a skip is not visible.

Could the probe run inside the test namespaces, after they are set up? And
should a failed -z probe, after the plain check has passed, count as a
failure instead of a silent skip?

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH mptcp-next v12 7/7] selftests: mptcp: cover msg_zerocopy test
  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-12-01 20:14   ` netdev-bot+sashiko
  1 sibling, 0 replies; 18+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 20:14 UTC (permalink / raw)
  To: geliang; +Cc: mptcp, tanggeliang, kuba

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

Critical: 0 · High: 0 · Medium: 2 · Low: 2

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] The commit message says the new wrapper
  tools/testing/selftests/net/mptcp/msg_zerocopy.sh "checks for MPTCP…
- [Medium] mptcp: unscheduled sk_mem_charge() without SG in
  mptcp_sendmsg_frag()
- [Low] tools/testing/selftests/net/mptcp/msg_zerocopy.sh runs
  ../msg_zerocopy.sh with no arguments under run_kselftest, so the MPTCP…
- [Low] The commit author is "Geliang Tang <geliang@kernel.org>", but the
  only Signed-off-by is "Geliang Tang <tanggeliang@kylinos.cn>".

--

selftests: mptcp: cover msg_zerocopy test

This commit adds a wrapper script to the MPTCP selftest directory. The
wrapper runs the existing net/msg_zerocopy.sh after checking that MPTCP
is available. It also updates the Makefile to build msg_zerocopy from
../msg_zerocopy.c and install ../msg_zerocopy.sh via TEST_INCLUDES, and
adds CONFIG_DUMMY=y to the mptcp config.

> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>

[Severity: Low]
This isn't a bug, but the author address is geliang@kernel.org and the
only Signed-off-by address is tanggeliang@kylinos.cn. checkpatch.pl
reports this as FROM_SIGN_OFF_MISMATCH.

Could a sign-off for geliang@kernel.org be added, or the From: address
changed to match? The other commits in the series seem to have the same
mismatch.

[ ... ]

> diff --git a/tools/testing/selftests/net/mptcp/msg_zerocopy.sh b/tools/testing/selftests/net/mptcp/msg_zerocopy.sh
> new file mode 100755
> index 0000000000000..118fff27dc5cd
> --- /dev/null
> +++ b/tools/testing/selftests/net/mptcp/msg_zerocopy.sh
> @@ -0,0 +1,8 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +
> +. "$(dirname "${0}")/mptcp_lib.sh"
> +
> +mptcp_lib_check_mptcp
> +
> +exec "$(dirname "${0}")/../msg_zerocopy.sh" "$@"

[Severity: Medium]
This problem is in the earlier patch that adds MPTCP zerocopy support,
not in this test. This test is what exercises that code, so I am
raising it here.

In mptcp_sendmsg_frag(), tcp_wmem_schedule(ssk, copy) is skipped
whenever dfrag->ubuf is set. dfrag->page is then attached to the
subflow skb unconditionally, and skb_zcopy_set() is called. However,
SKBFL_PURE_ZEROCOPY and zc = true are only set when ssk->sk_route_caps
has NETIF_F_SG.

Suppose the subflow is routed over a device without NETIF_F_SG. Then
zc stays false, and the later zc = skb_zcopy_pure(skb) is also false.
The tail of the function then does sk_mem_charge(ssk, copy) for bytes
that were never scheduled.

Wouldn't that let an unprivileged sender using SO_ZEROCOPY and
MSG_ZEROCOPY drive ssk->sk_forward_alloc negative?

It also seems to defeat coalescing on such a subflow. On the next call,
this check is true:

	if (skb_zcopy_pure(skb) != !!dfrag->ubuf || ...)

The tail skb is not marked pure zerocopy, but dfrag->ubuf is set. So
every fragment goes to alloc_skb and gets its own skb.

What is the intended behaviour when the subflow lacks SG? One option is
to schedule memory with tcp_wmem_schedule() as the copy path does.
Another is to decouple the pure zerocopy marking and accounting from
NETIF_F_SG, since the user page is attached either way.

As far as I can tell, net/msg_zerocopy.sh runs over veth, which
advertises SG, so this test would not hit the non-SG case. Would it
make sense to add a variant that turns sg off on the veth pair?

[Severity: Medium]
The commit message says the wrapper "checks for MPTCP zerocopy support
before executing" the net script. Is that accurate?

mptcp_lib_check_mptcp() only checks that /proc/sys/net/mptcp/enabled
exists:

tools/testing/selftests/net/mptcp/mptcp_lib.sh:mptcp_lib_check_mptcp() {
	if ! mptcp_lib_has_file "/proc/sys/net/mptcp/enabled"; then
		mptcp_lib_pr_skip "MPTCP support is not available"
		exit ${KSFT_SKIP}
	fi
}

The actual MPTCP plus SO_ZEROCOPY check is in the no-argument branch of
net/msg_zerocopy.sh:

	if ${BIN} -4 -t 1 check && ${BIN} -4 -t 1 -z check; then
		$0 4 mptcp -t 1 || ret=1
	else
		echo "SKIP: MPTCP IPv4 tests (not supported)"
	fi

check_mptcp_support() in msg_zerocopy.c calls exit(1) when
socket(IPPROTO_MPTCP) or setsockopt(SO_ZEROCOPY) fails. The else branch
only prints SKIP and leaves ret at 0. The IPv6 block works the same way.

Suppose MPTCP sockets don't support SO_ZEROCOPY on the running kernel.
That can happen with newer selftests on an older or stable kernel, or
after a regression that brings back -EOPNOTSUPP. In that case, wouldn't
this wrapper exit 0 and be reported as ok, even though no MPTCP traffic
was sent?

It never returns KSFT_SKIP. It also skips
mptcp_lib_fail_if_expected_feature(), so setting
SELFTESTS_MPTCP_LIB_EXPECT_ALL_FEATURES cannot turn a missing feature
into a failure.

A smaller point: the commit message says ../msg_zerocopy.sh is added to
TEST_INCLUDES "for out-of-tree builds". In lib.mk, INSTALL_INCLUDES uses
TEST_INCLUDES to install files from other selftest directories. Could
the wording be updated?

[Severity: Low]
run_kselftest calls this wrapper with no arguments, so
net/msg_zerocopy.sh takes its automated branch:

	$0 4 tcp -t 1 || ret=1
	$0 6 tcp -t 1 || ret=1
	$0 4 udp -t 1 || ret=1
	$0 6 udp -t 1 || ret=1

Doesn't that make the MPTCP suite run all the TCP and UDP zerocopy
cases before the MPTCP ones, including the UDP tx-only test over
dummy0?

net/msg_zerocopy.sh is already in TEST_PROGS for the net collection, so
a full kselftest run would run these cases twice. A TCP or UDP failure
would also be reported as an MPTCP selftest failure.

The CONFIG_DUMMY=y added to the mptcp config looks like it is only
needed for the UDP tx-only test. do_test() returns early for tcp and
mptcp before it reaches the dummy0 part.

Would it match the stated goal better if the wrapper ran only the MPTCP
modes? For example, it could run "../msg_zerocopy.sh 4 mptcp -t 1" and
"../msg_zerocopy.sh 6 mptcp -t 1" after an MPTCP-style feature check.

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2026-12-01 20:14 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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-12-01 20:14   ` netdev-bot+sashiko
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
2026-12-01 20:14   ` netdev-bot+sashiko
2026-11-30  6:25 ` [PATCH mptcp-next v12 4/7] mptcp: handle SO_ZEROCOPY in setsockopt Geliang Tang
2026-12-01 20:14   ` netdev-bot+sashiko
2026-11-30  6:25 ` [PATCH mptcp-next v12 5/7] Documentation: msg_zerocopy: add MPTCP support Geliang Tang
2026-12-01 20:14   ` netdev-bot+sashiko
2026-11-30  6:25 ` [PATCH mptcp-next v12 6/7] selftests: net: " Geliang Tang
2026-12-01 20:14   ` netdev-bot+sashiko
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-12-01 20:14   ` netdev-bot+sashiko
2026-11-30  7:30 ` [PATCH mptcp-next v12 0/7] mptcp: add MSG_ZEROCOPY support MPTCP CI

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.