From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796362897; b=c8ui+xhEZ920zUYuG/l4pXDcSty9awfeWiaMzfYtgCoZrXOCmrdEOtC4fqxxhS7Y1D8y GSTdYZw15TtELqy//3ZMHdHa7sBK+rE1TXm+PTxRAzjTg4y4CU0/DsR6JV84GRmURNZha lMhbAF4QDIMNAqwQk9Ey2p4uOc6tmBb+uopWRRU7jPGNgOh0iWFZ8UicsnMMiBT6/NXYf Ddloq2t5eJmNeXOfWL7MPHvyjiKSR64Tcw+9pROYIF99A4XteF5RlAgStxn8IeW0ZJQNf oUlpkopmSqCEr7qkaBVTAYRMqGrNcNe2BgoYlk0XCZIDoWpuXj+LBUZrW6Qvy3eF8tg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796362897; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Received:Date:In-Reply-To:Mime-Version: References:X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=7QE3PI7ldvblkBeQtqOOXltFfhnUn6Vc4WKsYN0oEQc=; b=CUjnqfcnQjJVGAAzqWHPL99Dn+zKXXE6caUFOu2kTfI8dTn+OwkNkc1LBkqjN9h2vtO+ VxKMie4kg7ykKhysfTj7k459X/P+FACObkpDLOeFjSyYXFYC/9+yVeDugz+sJHLetEVLu EXH2/meKkxslpRGhiaGt8tCCIMOb8reJ/Kh73wIYMEqk/CgSjnFDDF8dID2aOA1XDTyuc OFRFoSt8sJ7yQ9DThtKwH0HBuLFF31imHECAksC+f6YIXCeq7o6quhWnm8lJy55ZBgaYj kZHvmfgtoKYxQABCeZO5p7IFQKuyEHCV1Pj1ri1VonOdhZ8YrDbQOyFJJY0LSeaDFNw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--tavip.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=eYaj8wZ6; arc=none smtp.remote-ip=209.85.215.197 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66555606A69A for ; Fri, 4 Dec 2026 05:41:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 66555606A69A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tavip.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=eYaj8wZ6 Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-cdb45b4ed6bso625459a12.3 for ; Thu, 03 Dec 2026 21:41:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796362897; x=1796967697; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=7QE3PI7ldvblkBeQtqOOXltFfhnUn6Vc4WKsYN0oEQc=; b=eYaj8wZ62f47rN9IqptUwFmdW+oynicp8NwHKhrs2jPoVZn11FnBbVeoKEHI30u3NM etFvPE/JUXo9/NIn5mRsTR3s48h9T+13imlN1seNgdVbMk1nIxjk+Rv4Cdh27BuX3fsP wlqOq3L078acGrXiqXwHc44WRkoUPAss4TLvZ/jj5ncYIl6oK6ErNPYSVBPg0xgUAy68 ztER7FwhhTZEbWOYirxDcdcJ1aq1Pxzkr5E7C9kPNZkxz20UU2hjBNyaFUxp21MDXsSw 9kFw+M0Vf5fShnjtmakxUH5BjkbB5JrksDYY4M+tBYVPQBO1+3oWtBMJ2yKvt5Idm7aS VnXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796362897; x=1796967697; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=7QE3PI7ldvblkBeQtqOOXltFfhnUn6Vc4WKsYN0oEQc=; b=Mzms96P4BGYP5mwT6DyYmLerWytEskJ3O6Q0mSC/fHmNXwdSL7w6QUIqlLo9YevChw LS4V3eXCuqb1KHBqksuoFzJTLEh09I6N+q6zSRr1ARf7Sj/5aqEk/BrsbcjcbsQIUjSB cJkEiFqtZVpTuvzgocFvS5liamV1IVjXOwfz1x6h6/RrreS9YQTQ+ACXI8/kUrNxjUd6 KWsGzdTJSZjprtrm5KxfCpj8Xvbv8btwKum08KrHea57ZEJip5y+pXXWiykg6N2I7lc4 RRME+XZLFL4EELh9Z7FDEiDK1HoVtNzXApF6ZQOsxmQp529Fs/GEbpmOn9FwQ8UCHQdz zTyg== X-Gm-Message-State: APuU4Z+U48puGWYVnVTbp95qkiKYgkatjdiKBWOIt1ftqC0tIn04Bdwu hrGUZvTbUkm87Vb3WiB68wa06RW7rYmYpz3Y0TdTy1DMqcHsVbJ9SpQ5PS0c0oc+lXKdVtCZqP1 Res2kXaq98cfUORhG6Tt39Ejx3SrXrrqVBty21FjrAHCBRAbdoWx2nSvyE2BYXuAn9h6/JXz/V6 gP8c5f+ScP87iGk8NbaFbcyTMDSTcZQ2g= X-Received: from pgfd20-n2.prod.google.com ([2002:a05:6a02:6554:20b0:cd8:c4be:4fc3]) (user=tavip job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:6a1b:b0:3fa:f23f:a1d2 with SMTP id adf61e73a8af0-41562128a55mr1119178637.37.1796362896501; Thu, 03 Dec 2026 21:41:36 -0800 (PST) Date: Fri, 4 Dec 2026 05:41:05 +0000 In-Reply-To: <20261204054107.96092-1-tavip@google.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261204054107.96092-1-tavip@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261204054107.96092-2-tavip@google.com> Subject: [PATCH net 1/3] tcp: avoid spurious leftover copy in tcp_zerocopy_receive() From: Octavian Purdila To: netdev@vger.kernel.org, Eric Dumazet , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Willem de Bruijn Cc: Neal Cardwell , Kuniyuki Iwashima , Simon Horman , Arjun Roy , Soheil Hassas Yeganeh , Shuah Khan , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Octavian Purdila Content-Type: text/plain; charset="UTF-8" In tcp_zerocopy_receive(), zc->recv_skip_hint tracks the remaining unread bytes in the current skb while mapping pages into the user VMA. When the mapping loop finishes because length reached zc->length while at least PAGE_SIZE bytes remain in the current skb, zc->recv_skip_hint still holds those remaining bytes rather than an unmappable skip length. Because tcp_zc_handle_leftover() runs before zc->recv_skip_hint is cleared for length == zc->length, a caller that supplies a copybuf gets copybuf_len bytes copied out of the next mappable page. That advances copied_seq into the middle of a page frag, forcing subsequent TCP_ZEROCOPY_RECEIVE calls on the same skb to fall back to copying. This commonly triggers when GRO, coalescing, or BIG TCP produces skbs larger than the user's receive mapping buffer. Skip tcp_zc_handle_leftover() when the requested mapping length was filled and at least PAGE_SIZE bytes remain in the skb, while preserving sub-page tail straggler copying when fewer than PAGE_SIZE bytes remain. Observed while investigating low TCP receive zerocopy rates in throughput benchmarks with BIG TCP and copybuf enabled, and confirmed via code inspection. Reproduced on an unmodified kernel with a BIG TCP loopback reproducer and the new tcp_zerocopy_receive selftest added in this series, and tested against both as well as tcp_mmap. Fixes: 18fb76ed5386 ("net-zerocopy: Copy straggler unaligned data for TCP Rx. zerocopy.") Assisted-by: LLM Signed-off-by: Octavian Purdila --- net/ipv4/tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 80de376a9d2ef..b94d5b2d77daf 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2333,7 +2333,7 @@ static int tcp_zerocopy_receive(struct sock *sk, out: vma_end_read(vma); /* Try to copy straggler data. */ - if (!ret) + if (!ret && (length != zc->length || zc->recv_skip_hint < PAGE_SIZE)) copylen = tcp_zc_handle_leftover(zc, sk, skb, &seq, copybuf_len, tss); if (length + copylen) { -- 2.56.1.915.g69d5ec7298-goog