[PATCH net 0/3] tcp: fix zerocopy leftover copy and mid-frag recv_skip_hint

From: Octavian Purdila

Date: Fri Dec 04 2026 - 00:41:59 EST


When TCP receive zerocopy is used with copybuf enabled on skbs larger
than the caller's mapping buffer (such as GRO, coalesced, or BIG TCP
skbs), two bugs in tcp_zerocopy_receive() cause sustained fallback from
zerocopy to copying:

1. After the mapping loop fills zc->length while >= PAGE_SIZE bytes
remain in the current skb, tcp_zc_handle_leftover() still runs using
zc->recv_skip_hint (the remaining skb length) and copies copybuf_len
bytes out of the next mappable page, misaligning copied_seq mid-frag.

2. When copied_seq is mid-frag (offset_frag != 0), tcp_zerocopy_receive()
breaks with zc->recv_skip_hint left as skb->len - offset instead of
computing the exact bytes to the next mappable frag, forcing callers
or copybuf to copy the remainder of the skb instead of realigning at
the next page boundary.

Patch 1 skips tcp_zc_handle_leftover() when length == zc->length and at
least PAGE_SIZE bytes remain in the skb, preserving sub-page tail
straggler copying. Patch 2 calls tcp_zerocopy_set_hint_for_skb() when
offset_frag is non-zero. Patch 3 adds a kselftest covering both fixes
and sub-page tail straggler copying for IPv4 and IPv6.

Octavian Purdila (3):
tcp: avoid spurious leftover copy in tcp_zerocopy_receive()
tcp: set exact recv_skip_hint on mid-frag in tcp_zerocopy_receive()
selftests: net: add TCP_ZEROCOPY_RECEIVE leftover and hint tests

net/ipv4/tcp.c | 9 +-
tools/testing/selftests/net/.gitignore | 1 +
tools/testing/selftests/net/Makefile | 1 +
.../selftests/net/tcp_zerocopy_receive.c | 428 ++++++++++++++++++
4 files changed, 437 insertions(+), 2 deletions(-)
create mode 100644 tools/testing/selftests/net/tcp_zerocopy_receive.c


base-commit: 90ae4042bd9f35a9098d14b1a12a43df9b326e2b
--
2.56.1.915.g69d5ec7298-goog