From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.198 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796362899; b=IkM0t4HqElKHK3ws1rZdfexXdQ5XPSfD/+KCEKHr2rYXnxLXoTTdsBmLQZGGFG6FtKTw sEySo6qQT+o7c0Lnw58nIWjkvtUIK5D0HT8ji7994gwLxNw3S6gAsGKwJrDt2cJ8zUhIU 3T5bDLdyBal2Pcyr7/ftSyusv028IG85R8sMzVOhAZ013He/Z+e8yHTJDTV7L3Qo9/BrH JpSHOcJFUWtw2GztbfvEMU8QJ5m7Lz+c0CM7auWV6K8Iv8JWs9zOxNqcE/RZoyryRJX9R oqVHij4tjjob+sH2qq4OlAi3TGHStd99P+6+KTuOSerMqQ25V8fqYbqlVkzKCE/Xqvw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796362899; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted: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=Z8l5gE51ouxxsxO/bcjOTPFFtSKfu3C6mQP+M0bPfp6utD3s7Zri1luzSYVAnERumbYD 8yfXvjMmvV3GF91CE7+HEZNzuwNvfAc46jj3Iul3TgtF1Ew6c0ucNeQSTo4FM4jiS44En 0s4hsyLDjIT6vbw3nVNYhZU1Hdetrd4tKAF6mxhnYGJgWYU+NSrkdHTKGkfWjfU6nyFTq AG2xhtVmLKN+xavXCv3hXk09+je5LXjnA3Q9Qwg3RuSvbqv2l05LbYgKaPquP88BOVuZf 0sFQnrQxdPL0FJ9SqjqdEaYftDnmic+1Xa5sBf8D20OPLAAqeKQL4IqOT0jSwWqsjgQ== 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.198 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (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 7CB88606A69B for ; Fri, 4 Dec 2026 05:41:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7CB88606A69B 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) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=eYaj8wZ6 Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-cd3b9e70f88so783279a12.0 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=QPBqLW05J7cKBRNow2zIBnGIXF1cO7Dhnn+oz23zhmhvKq4+zqIZmspEStdzSWuGou nOIMGFkIcDoFNyh3/ov8ccG6/yRM4eFr/11Xli2VQpT+f92PDlIUKGJ/4k8Y+8QPs+6z LdhHwXgJzyibet1ZZiH9ph/oKHdyHLKD4fCqNzcPx+bKyAYMbT+8/8QjM2opHPeZ/4f/ wd54q8coXu1jsGrAQAvm2HwHUbt6bje+8gKsb8OmRnbv1JunOI7Qem2GEAb2QftKyFL5 SZY8oDqtkohzz3I0L0hEd6fPgr5doC2sD57Hpulzf+36IhL9ZXK6HKdyNiL/8WmbYO2Q ZQSQ== X-Forwarded-Encrypted: i=1; AL+hErHuJIs33tpHj80ssEpNtPkviOP7/N1+gWgyZB0snIXWb0zK29pnpohbaUIEGBtoE3LDT1VzW8R1Yf0zkP84dk4=@vger.kernel.org X-Gm-Message-State: APuU4Z9u8+ZhD6CZdFbFXUshcMB0CKMG3Dvt+BXhCeMx69aAnEfeeXdx QVN4jDyCmukBTaoJJzvlhaP93FCBNRGUDxadV9cNBulQc55JF/IyW6bm2kbK9f+aQ3o0WCqNP1b lMA== 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: linux-kselftest@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