Netdev List
 help / color / mirror / Atom feed
From: Octavian Purdila <tavip@google.com>
To: netdev@vger.kernel.org, Eric Dumazet <edumazet@kernel.org>,
	 "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	 Willem de Bruijn <willemb@google.com>
Cc: Neal Cardwell <ncardwell@google.com>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	 Simon Horman <horms@kernel.org>, Arjun Roy <arjunroy@google.com>,
	 Soheil Hassas Yeganeh <soheil@google.com>,
	Shuah Khan <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org,  linux-kernel@vger.kernel.org,
	Octavian Purdila <tavip@google.com>
Subject: [PATCH net 0/3] tcp: fix zerocopy leftover copy and mid-frag recv_skip_hint
Date: Fri,  4 Dec 2026 05:41:04 +0000	[thread overview]
Message-ID: <20261204054107.96092-1-tavip@google.com> (raw)

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


             reply	other threads:[~2026-12-04  5:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  5:41 Octavian Purdila [this message]
2026-12-04  5:41 ` [PATCH net 1/3] tcp: avoid spurious leftover copy in tcp_zerocopy_receive() Octavian Purdila
2026-12-04  5:41 ` [PATCH net 2/3] tcp: set exact recv_skip_hint on mid-frag " Octavian Purdila
2026-12-04  5:41 ` [PATCH net 3/3] selftests: net: add TCP_ZEROCOPY_RECEIVE leftover and hint tests Octavian Purdila

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204054107.96092-1-tavip@google.com \
    --to=tavip@google.com \
    --cc=arjunroy@google.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    --cc=soheil@google.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox