* [PATCH mptcp-next v9 0/7] mptcp: add MSG_ZEROCOPY support
@ 2026-11-25 7:22 Geliang Tang
2026-11-25 7:22 ` [PATCH mptcp-next v9 1/7] mptcp: use local variable tp in sendmsg_frag Geliang Tang
` (7 more replies)
0 siblings, 8 replies; 12+ messages in thread
From: Geliang Tang @ 2026-11-25 7:22 UTC (permalink / raw)
To: mptcp
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.
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.
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 | 4 +-
net/mptcp/protocol.c | 173 ++++++++++++++++--
net/mptcp/protocol.h | 1 +
net/mptcp/sockopt.c | 30 ++-
tools/testing/selftests/net/mptcp/.gitignore | 1 +
tools/testing/selftests/net/mptcp/Makefile | 5 +
.../selftests/net/mptcp/msg_zerocopy.sh | 1 +
tools/testing/selftests/net/msg_zerocopy.c | 6 +
tools/testing/selftests/net/msg_zerocopy.sh | 8 +-
9 files changed, 206 insertions(+), 23 deletions(-)
create mode 120000 tools/testing/selftests/net/mptcp/msg_zerocopy.sh
--
2.55.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH mptcp-next v9 1/7] mptcp: use local variable tp in sendmsg_frag
2026-11-25 7:22 [PATCH mptcp-next v9 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
@ 2026-11-25 7:22 ` Geliang Tang
2026-11-25 7:23 ` [PATCH mptcp-next v9 2/7] mptcp: remove redundant orig_offset in carve_data_frag Geliang Tang
` (6 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Geliang Tang @ 2026-11-25 7:22 UTC (permalink / raw)
To: mptcp
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 d64e04245963..b9ae52caf47e 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1447,6 +1447,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;
@@ -1483,14 +1484,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;
}
@@ -1548,7 +1549,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] 12+ messages in thread
* [PATCH mptcp-next v9 2/7] mptcp: remove redundant orig_offset in carve_data_frag
2026-11-25 7:22 [PATCH mptcp-next v9 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
2026-11-25 7:22 ` [PATCH mptcp-next v9 1/7] mptcp: use local variable tp in sendmsg_frag Geliang Tang
@ 2026-11-25 7:23 ` Geliang Tang
2026-11-25 7:23 ` [PATCH mptcp-next v9 3/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
` (5 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Geliang Tang @ 2026-11-25 7:23 UTC (permalink / raw)
To: mptcp
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 b9ae52caf47e..504d0b196d84 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1302,9 +1302,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;
@@ -2111,7 +2111,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] 12+ messages in thread
* [PATCH mptcp-next v9 3/7] mptcp: add MSG_ZEROCOPY support
2026-11-25 7:22 [PATCH mptcp-next v9 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
2026-11-25 7:22 ` [PATCH mptcp-next v9 1/7] mptcp: use local variable tp in sendmsg_frag Geliang Tang
2026-11-25 7:23 ` [PATCH mptcp-next v9 2/7] mptcp: remove redundant orig_offset in carve_data_frag Geliang Tang
@ 2026-11-25 7:23 ` Geliang Tang
2026-11-25 7:52 ` sashiko-bot
2026-11-25 7:23 ` [PATCH mptcp-next v9 4/7] mptcp: handle SO_ZEROCOPY in setsockopt Geliang Tang
` (4 subsequent siblings)
7 siblings, 1 reply; 12+ messages in thread
From: Geliang Tang @ 2026-11-25 7:23 UTC (permalink / raw)
To: mptcp
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 | 160 ++++++++++++++++++++++++++++++++++++++++---
net/mptcp/protocol.h | 1 +
2 files changed, 150 insertions(+), 11 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 504d0b196d84..6bd10a4e1e93 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1186,18 +1186,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);
}
@@ -1242,7 +1251,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 */
@@ -1316,6 +1326,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;
}
@@ -1488,6 +1499,16 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
goto alloc_skb;
}
+ if (skb_zcopy_pure(skb) != !!dfrag->ubuf) {
+ tcp_mark_push(tp, skb);
+ goto alloc_skb;
+ }
+ if (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)) {
@@ -1531,7 +1552,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
/* like TCP, allow some progress up to tcp_wmem[0] */
avail = tcp_wmem_schedule(ssk, copy);
- if (avail <= 0) {
+ if (!dfrag->ubuf && avail <= 0) {
tcp_remove_empty_skb(ssk);
return -ENOMEM;
}
@@ -1542,13 +1563,19 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
} else {
get_page(dfrag->page);
skb_fill_page_desc(skb, i, dfrag->page, offset, copy);
+
+ if (dfrag->ubuf && !skb_zcopy(skb)) {
+ skb_zcopy_set(skb, dfrag->ubuf, NULL);
+ skb_shinfo(skb)->flags |= SKBFL_PURE_ZEROCOPY;
+ }
}
skb->len += copy;
skb->data_len += copy;
skb->truesize += copy;
sk_wmem_queued_add(ssk, copy);
- sk_mem_charge(ssk, copy);
+ if (!skb_zcopy_pure(skb))
+ 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);
@@ -1940,7 +1967,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);
@@ -1966,7 +1994,7 @@ static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
lock_sock(ssk);
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);
@@ -2048,27 +2076,113 @@ 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;
+ }
+
+ if (!ubuf && !sk_wmem_schedule(sk, pg_len + sizeof(*dfrag))) {
+ kfree(dfrag);
+ iov_iter_revert(&msg->msg_iter, pg_len);
+ put_page(pages[0]);
+ return -EAGAIN;
+ }
+
+ 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);
+
+ /* 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 (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);
+ ret = mptcp_sendmsg_fastopen(sk, msg, len, &copied_syn, ubuf);
copied += copied_syn;
if (ret == -EINPROGRESS && copied_syn > 0)
goto out;
@@ -2102,6 +2216,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
*/
@@ -2177,6 +2309,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;
@@ -2187,6 +2321,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 2c9a442dacd6..5378321ae58a 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -285,6 +285,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] 12+ messages in thread
* [PATCH mptcp-next v9 4/7] mptcp: handle SO_ZEROCOPY in setsockopt
2026-11-25 7:22 [PATCH mptcp-next v9 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
` (2 preceding siblings ...)
2026-11-25 7:23 ` [PATCH mptcp-next v9 3/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
@ 2026-11-25 7:23 ` Geliang Tang
2026-11-25 7:44 ` sashiko-bot
2026-11-25 7:23 ` [PATCH mptcp-next v9 5/7] Documentation: msg_zerocopy: add MPTCP support Geliang Tang
` (3 subsequent siblings)
7 siblings, 1 reply; 12+ messages in thread
From: Geliang Tang @ 2026-11-25 7:23 UTC (permalink / raw)
To: mptcp
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] 12+ messages in thread
* [PATCH mptcp-next v9 5/7] Documentation: msg_zerocopy: add MPTCP support
2026-11-25 7:22 [PATCH mptcp-next v9 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
` (3 preceding siblings ...)
2026-11-25 7:23 ` [PATCH mptcp-next v9 4/7] mptcp: handle SO_ZEROCOPY in setsockopt Geliang Tang
@ 2026-11-25 7:23 ` Geliang Tang
2026-11-25 7:23 ` [PATCH mptcp-next v9 6/7] selftests: net: " Geliang Tang
` (2 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Geliang Tang @ 2026-11-25 7:23 UTC (permalink / raw)
To: mptcp
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.
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
Documentation/networking/msg_zerocopy.rst | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Documentation/networking/msg_zerocopy.rst b/Documentation/networking/msg_zerocopy.rst
index 78fb70e748b7..0b91beb2f5be 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
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH mptcp-next v9 6/7] selftests: net: msg_zerocopy: add MPTCP support
2026-11-25 7:22 [PATCH mptcp-next v9 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
` (4 preceding siblings ...)
2026-11-25 7:23 ` [PATCH mptcp-next v9 5/7] Documentation: msg_zerocopy: add MPTCP support Geliang Tang
@ 2026-11-25 7:23 ` Geliang Tang
2026-11-25 7:23 ` [PATCH mptcp-next v9 7/7] selftests: mptcp: cover msg_zerocopy test Geliang Tang
2026-11-25 9:39 ` [PATCH mptcp-next v9 0/7] mptcp: add MSG_ZEROCOPY support MPTCP CI
7 siblings, 0 replies; 12+ messages in thread
From: Geliang Tang @ 2026-11-25 7:23 UTC (permalink / raw)
To: mptcp
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 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 script is also updated to automatically run IPv4 and IPv6
MPTCP tests in the default test suite.
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
tools/testing/selftests/net/msg_zerocopy.c | 6 ++++++
tools/testing/selftests/net/msg_zerocopy.sh | 8 +++++---
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/net/msg_zerocopy.c b/tools/testing/selftests/net/msg_zerocopy.c
index 1d5d3c4e7e87..3a130f80d662 100644
--- a/tools/testing/selftests/net/msg_zerocopy.c
+++ b/tools/testing/selftests/net/msg_zerocopy.c
@@ -74,6 +74,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 */
@@ -816,6 +820,8 @@ int main(int argc, char **argv)
do_test(cfg_family, SOCK_RAW, IPPROTO_RAW);
else if (!strcmp(cfg_test, "tcp"))
do_test(cfg_family, SOCK_STREAM, 0);
+ else if (!strcmp(cfg_test, "mptcp"))
+ do_test(cfg_family, SOCK_STREAM, IPPROTO_MPTCP);
else if (!strcmp(cfg_test, "udp"))
do_test(cfg_family, SOCK_DGRAM, 0);
else if (!strcmp(cfg_test, "rds"))
diff --git a/tools/testing/selftests/net/msg_zerocopy.sh b/tools/testing/selftests/net/msg_zerocopy.sh
index 28178a38a4e7..83424758c452 100755
--- a/tools/testing/selftests/net/msg_zerocopy.sh
+++ b/tools/testing/selftests/net/msg_zerocopy.sh
@@ -31,6 +31,8 @@ if [[ "$#" -eq "0" ]]; then
$0 6 tcp -t 1 || ret=1
$0 4 udp -t 1 || ret=1
$0 6 udp -t 1 || ret=1
+ $0 4 mptcp -t 1 || ret=1
+ $0 6 mptcp -t 1 || ret=1
[[ "$ret" == "0" ]] && echo "OK. All tests passed"
exit $ret
@@ -38,7 +40,7 @@ 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|udp|mptcp|raw|raw_hdrincl|packet|packet_dgram] <args>"
exit 1
fi
@@ -143,8 +145,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] 12+ messages in thread
* [PATCH mptcp-next v9 7/7] selftests: mptcp: cover msg_zerocopy test
2026-11-25 7:22 [PATCH mptcp-next v9 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
` (5 preceding siblings ...)
2026-11-25 7:23 ` [PATCH mptcp-next v9 6/7] selftests: net: " Geliang Tang
@ 2026-11-25 7:23 ` Geliang Tang
2026-11-25 7:34 ` sashiko-bot
2026-11-25 9:39 ` [PATCH mptcp-next v9 0/7] mptcp: add MSG_ZEROCOPY support MPTCP CI
7 siblings, 1 reply; 12+ messages in thread
From: Geliang Tang @ 2026-11-25 7:23 UTC (permalink / raw)
To: mptcp
From: Geliang Tang <tanggeliang@kylinos.cn>
Add the msg_zerocopy test to the MPTCP selftest suite by creating a
symlink to 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, and add build rule to compile
msg_zerocopy from ../msg_zerocopy.c. Also add msg_zerocopy binary
to .gitignore.
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
tools/testing/selftests/net/mptcp/.gitignore | 1 +
tools/testing/selftests/net/mptcp/Makefile | 5 +++++
tools/testing/selftests/net/mptcp/msg_zerocopy.sh | 1 +
3 files changed, 7 insertions(+)
create mode 120000 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..17d0d1051165 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
@@ -37,3 +39,6 @@ TEST_INCLUDES := ../lib.sh $(wildcard ../lib/sh/*.sh)
EXTRA_CLEAN := *.pcap
include ../../lib.mk
+
+$(OUTPUT)/msg_zerocopy: ../msg_zerocopy.c
+ $(CC) $< $(CFLAGS) $(CPPFLAGS) -o $@
diff --git a/tools/testing/selftests/net/mptcp/msg_zerocopy.sh b/tools/testing/selftests/net/mptcp/msg_zerocopy.sh
new file mode 120000
index 000000000000..b2f82b8fa5f2
--- /dev/null
+++ b/tools/testing/selftests/net/mptcp/msg_zerocopy.sh
@@ -0,0 +1 @@
+../msg_zerocopy.sh
\ No newline at end of file
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH mptcp-next v9 7/7] selftests: mptcp: cover msg_zerocopy test
2026-11-25 7:23 ` [PATCH mptcp-next v9 7/7] selftests: mptcp: cover msg_zerocopy test Geliang Tang
@ 2026-11-25 7:34 ` sashiko-bot
0 siblings, 0 replies; 12+ messages in thread
From: sashiko-bot @ 2026-11-25 7:34 UTC (permalink / raw)
To: Geliang Tang, mptcp
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] selftests: mptcp: missing CONFIG_DUMMY in config for
msg_zerocopy.sh
--
commit 5b3ee281d765d4c4bfa0409eafb89f384c870ea5
Author: Geliang Tang <geliang@kernel.org>
selftests: mptcp: cover msg_zerocopy test
This commit adds the msg_zerocopy test to the MPTCP selftest suite by
symlinking ../msg_zerocopy.sh and building msg_zerocopy from
../msg_zerocopy.c.
> diff --git a/tools/testing/selftests/net/mptcp/Makefile b/tools/testing/selftests/net/mptcp/Makefile
> index 22ba0da2adb85..17d0d1051165c 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 \
[Severity: Medium]
Does tools/testing/selftests/net/mptcp/config also need CONFIG_DUMMY=y?
msg_zerocopy.sh runs under set -e and unconditionally creates a dummy
network device with "ip link add ... type dummy" for every subtest.
Unlike tools/testing/selftests/net/config, the mptcp config only enables
CONFIG_VETH=y and omits CONFIG_DUMMY, so running the mptcp selftests on a
kernel built from tools/testing/selftests/net/mptcp/config will fail when
msg_zerocopy.sh tries to create dummy0.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795591278.git.tanggeliang@kylinos.cn?part=7
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH mptcp-next v9 4/7] mptcp: handle SO_ZEROCOPY in setsockopt
2026-11-25 7:23 ` [PATCH mptcp-next v9 4/7] mptcp: handle SO_ZEROCOPY in setsockopt Geliang Tang
@ 2026-11-25 7:44 ` sashiko-bot
0 siblings, 0 replies; 12+ messages in thread
From: sashiko-bot @ 2026-11-25 7:44 UTC (permalink / raw)
To: Geliang Tang, mptcp
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mptcp: 0-length skb queued in mptcp_sendmsg_frag() on
zerocopy wmem failure
--
commit c40bf75d2e840f9a30a3c937060e37a47f1aa32c
Author: Geliang Tang <geliang@kernel.org>
mptcp: handle SO_ZEROCOPY in setsockopt
This commit enables SO_ZEROCOPY in MPTCP setsockopt by setting
SOCK_ZEROCOPY on the MPTCP socket and propagating it to all 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]
Can enabling SOCK_ZEROCOPY cause mptcp_sendmsg_frag() to leave a 0-length
skb on ssk->sk_write_queue when tcp_wmem_schedule() returns 0?
With SOCK_ZEROCOPY set, mptcp_sendmsg() queues mptcp_data_frag entries
with dfrag->ubuf set. When __subflow_push_pending() pushes such a
fragment under subflow wmem pressure, mptcp_sendmsg_frag() skips the
avail <= 0 check but still overwrites copy with avail:
net/mptcp/protocol.c:mptcp_sendmsg_frag() {
...
avail = tcp_wmem_schedule(ssk, copy);
if (!dfrag->ubuf && avail <= 0) {
tcp_remove_empty_skb(ssk);
return -ENOMEM;
}
copy = avail;
...
}
When tcp_wmem_schedule() returns 0 on a newly allocated skb, execution
continues with copy == 0, attaches a 0-byte page fragment and a
dfrag->ubuf reference via skb_zcopy_set(), and leaves the empty skb
(end_seq == seq) on ssk->sk_write_queue. Once a non-coalescing skb is
queued behind it, tcp_write_xmit() stalls at tcp_send_head(ssk), wedging
transmission on the subflow and holding the ubuf reference until the
subflow is closed.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795591278.git.tanggeliang@kylinos.cn?part=4
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH mptcp-next v9 3/7] mptcp: add MSG_ZEROCOPY support
2026-11-25 7:23 ` [PATCH mptcp-next v9 3/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
@ 2026-11-25 7:52 ` sashiko-bot
0 siblings, 0 replies; 12+ messages in thread
From: sashiko-bot @ 2026-11-25 7:52 UTC (permalink / raw)
To: Geliang Tang, mptcp
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] mptcp: corrupted copy length and wmem accounting in
mptcp_sendmsg_frag()
- [Medium] mptcp: missing zerocopy downgrade on fastopen in
mptcp_sendmsg()
- [Low] mptcp: dead !ubuf check before net_zcopy_get() in
mptcp_sendmsg_zerocopy_iter()
--
commit 5139e983df0c81d1f761fa0ac9e35eeb08cfa459
Author: Geliang Tang <geliang@kernel.org>
mptcp: add MSG_ZEROCOPY support
This commit adds MSG_ZEROCOPY support for MPTCP sockets by pinning user
pages into mptcp_data_frag structures and tracking completion across
both the MPTCP retransmission queue and subflow skbs via ubuf_info_msgzc.
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 504d0b196d84b..6bd10a4e1e938 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
[ ... ]
> @@ -1531,7 +1552,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
>
> /* like TCP, allow some progress up to tcp_wmem[0] */
> avail = tcp_wmem_schedule(ssk, copy);
> - if (avail <= 0) {
> + if (!dfrag->ubuf && avail <= 0) {
> tcp_remove_empty_skb(ssk);
> return -ENOMEM;
> }
> @@ -1542,13 +1563,19 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
> } else {
> get_page(dfrag->page);
> skb_fill_page_desc(skb, i, dfrag->page, offset, copy);
> +
> + if (dfrag->ubuf && !skb_zcopy(skb)) {
> + skb_zcopy_set(skb, dfrag->ubuf, NULL);
> + skb_shinfo(skb)->flags |= SKBFL_PURE_ZEROCOPY;
> + }
> }
>
> skb->len += copy;
> skb->data_len += copy;
> skb->truesize += copy;
> sk_wmem_queued_add(ssk, copy);
> - sk_mem_charge(ssk, copy);
> + if (!skb_zcopy_pure(skb))
> + 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);
[Severity: High]
Should tcp_wmem_schedule(ssk, copy) and copy = avail be skipped entirely
when dfrag->ubuf is non-NULL, matching tcp_sendmsg_locked()?
Right now tcp_wmem_schedule(ssk, copy) and copy = avail still run for
zerocopy dfrags while only the avail <= 0 error return and
sk_mem_charge(ssk, copy) are skipped. When tcp_wmem_schedule() succeeds,
it raises ssk->sk_forward_alloc without a matching sk_mem_charge() or
payload uncharge in tcp_wmem_free_skb(). When ssk hits write memory
pressure and tcp_wmem_schedule() returns avail == 0 (or avail < 0 if
ssk->sk_forward_alloc is negative), copy is overwritten with 0 (or wraps
to a large size_t), leaving an empty 0-length skb on ssk->sk_write_queue
that stalls tcp_write_xmit() or corrupting the skb lengths and sequence
numbers.
[ ... ]
> @@ -2048,27 +2076,113 @@ 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)
> +{
[ ... ]
> + dfrag = kzalloc_obj(*dfrag, GFP_KERNEL_ACCOUNT);
> + if (!dfrag) {
> + iov_iter_revert(&msg->msg_iter, pg_len);
> + put_page(pages[0]);
> + return -ENOMEM;
> + }
> +
> + if (!ubuf && !sk_wmem_schedule(sk, pg_len + sizeof(*dfrag))) {
> + kfree(dfrag);
> + iov_iter_revert(&msg->msg_iter, pg_len);
> + put_page(pages[0]);
> + return -EAGAIN;
> + }
> +
> + 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);
> +
> + /* one ref for the dfrag; released in dfrag_clear */
> + net_zcopy_get(ubuf);
[Severity: Low]
Is the !ubuf check in mptcp_sendmsg_zerocopy_iter() dead code?
mptcp_sendmsg() only calls this helper when zc is true (so ubuf is
non-NULL), and net_zcopy_get(ubuf) unconditionally dereferences ubuf a
few lines below.
> +
> + 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 (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);
> + ret = mptcp_sendmsg_fastopen(sk, msg, len, &copied_syn, ubuf);
[Severity: Medium]
Does the fastopen path miss downgrading ubuf and zc to regular copy?
The commit message notes that MSG_ZEROCOPY silently downgrades to regular
copy when MSG_FASTOPEN is set, and tcp_send_syn_data() copies the SYN
payload into a kernel page_frag via copy_page_from_iter() before calling
skb_zcopy_set(syn_data, fo->uarg, NULL). However, msg_zerocopy_realloc()
initializes uarg_to_msgzc(ubuf)->zerocopy = 1 and mptcp_sendmsg() sets
zc = true before entering the DEFER_CONNECT / MSG_FASTOPEN branch.
Without clearing uarg_to_msgzc(ubuf)->zerocopy = 0 and zc = false here,
completion notifications for the copied SYN data will omit
SO_EE_CODE_ZEROCOPY_COPIED, and any remaining bytes after
mptcp_sendmsg_fastopen() will still take the mptcp_sendmsg_zerocopy_iter()
path.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795591278.git.tanggeliang@kylinos.cn?part=3
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH mptcp-next v9 0/7] mptcp: add MSG_ZEROCOPY support
2026-11-25 7:22 [PATCH mptcp-next v9 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
` (6 preceding siblings ...)
2026-11-25 7:23 ` [PATCH mptcp-next v9 7/7] selftests: mptcp: cover msg_zerocopy test Geliang Tang
@ 2026-11-25 9:39 ` MPTCP CI
7 siblings, 0 replies; 12+ messages in thread
From: MPTCP CI @ 2026-11-25 9:39 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: 2 failed test(s): packetdrill_regressions selftest_msg_zerocopy ⚠️
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Unstable: 1 failed test(s): selftest_msg_zerocopy ⚠️
- 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: 5 failed test(s): regression:sched-baseline(7) regression:sched-bbr(5) regression:sched-clientlim regression:sched-mem-pressure validation:sched-loss(2) ⚠️ (3 improvements, 56 new outliers to review)
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/45570779969
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/95b50a4b8e72
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1221715
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] 12+ messages in thread
end of thread, other threads:[~2026-11-25 9:39 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 7:22 [PATCH mptcp-next v9 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
2026-11-25 7:22 ` [PATCH mptcp-next v9 1/7] mptcp: use local variable tp in sendmsg_frag Geliang Tang
2026-11-25 7:23 ` [PATCH mptcp-next v9 2/7] mptcp: remove redundant orig_offset in carve_data_frag Geliang Tang
2026-11-25 7:23 ` [PATCH mptcp-next v9 3/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
2026-11-25 7:52 ` sashiko-bot
2026-11-25 7:23 ` [PATCH mptcp-next v9 4/7] mptcp: handle SO_ZEROCOPY in setsockopt Geliang Tang
2026-11-25 7:44 ` sashiko-bot
2026-11-25 7:23 ` [PATCH mptcp-next v9 5/7] Documentation: msg_zerocopy: add MPTCP support Geliang Tang
2026-11-25 7:23 ` [PATCH mptcp-next v9 6/7] selftests: net: " Geliang Tang
2026-11-25 7:23 ` [PATCH mptcp-next v9 7/7] selftests: mptcp: cover msg_zerocopy test Geliang Tang
2026-11-25 7:34 ` sashiko-bot
2026-11-25 9:39 ` [PATCH mptcp-next v9 0/7] mptcp: add MSG_ZEROCOPY support MPTCP CI
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox