From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796362900; b=XEa8UonHFnyulTTgSC+N4sBc5EWoUAOAX5AGpdE1DeJrAmbqsnjMzsWXTWlOcL0Ki6pa 9utRSOZ6Ss3GgCHe7qIFWpQvATzuu9ZhlgdNiNB0+oH3awqLk1VQhehLdyEpd5GzwjBI0 5E9TqiDrrcg0keSHnKYOsm7lqqT2sEXZQz2rZvS4MbzR9pwOQMAm9G4U8PB9/y85Ae0ni Gg7lNrWohVC5+mczx6vpSdA28SzKBgjPisez4VD+79S3Qlitq/EDgRslR6lXqaU6RLebo XZO68XC5zU4vDjaapYeQ1NAB3f7sDalyOzz6lI+cXyMFwhpBwhRS9TBlzz6BOwM9MEQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796362900; 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=dHl4/Efo27tWqzs8zLVwnZx8Sv1UZbTqlM41NG6FA3XuDpkOjYil0dPRe1w+3mn1ErGr levV4P1VExO1fxmzjDTZSZiqj83ydg7Hm7OuYi96Zry9782P64fGU8box1tzfjbM/F8c7 M3MhUBnU5Fuoo3OI7YoOsLBu74xn6/7ygObColsWBtBcQVobnzAJTPuzLTNnC2TcAGUg9 15EBsVPqdejSYcMqtzCTpSVSpszs0fI2IWcn+AtGOpAhNq8dJJFtfUumf9PF2ZgVuKvXB 8wTNc0wM/fDBMXlC5FcSEbTytKVpWZRrnuLac46n23TFOTzeN4vGuRZGpr2B+Nk5eVA== 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.199 Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) (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 7BF3F606A692 for ; Fri, 4 Dec 2026 05:41:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7BF3F606A692 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-f199.google.com with SMTP id 41be03b00d2f7-cc73895c7d5so741095a12.1 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=ZpwdC/qt1cMKUs+X4h3QxSYDXPud2RLYll+FnFCGCxA8T2oLBBbNP/QbDzAyOdTJCt HX9cr9SXWtg8N7SCY5AO8EDCA4fDjIuFRAW6MlNwtqPKzFCbLS0bwYcjx2pf6YkW3h0C vr3dkkx+YvlVFBTqx2H4aDa8f5aRz9wQ0DtZ3d/RWDPqgm0J8KOR0xLV6LN5rqInzPHR eYItbLVmD7nC+MAqhnlrQOrGg1HeC57+rxFlkTsF5ZijrC/5SPtDewt9aa+pe7zKXKBv A+HZGIf+b6IpbEyRC/NAxDk2MSQ2+cG7Pph1pQPdwrCDvgqXM6+80NOXgvDEg6GsQpeS CcBQ== X-Forwarded-Encrypted: i=1; AL+hErFJRprRC1oDnyjqfFmApPIDAVLwbisVfciEcQbIB4iaUKnVlyHhW8XBkFsU+t7zQ3nnVkSFfR3iDDWF60k=@vger.kernel.org X-Gm-Message-State: APuU4Z+Wdce06OrZUF+/scoJu1tgLeXwgEyoSYWhvwzmSLg+roIfD3MQ tf368OlwyAmG0x33yoLOen0a0m7+fVRh/pwNCoJ5ISXH1VNngWcHjIZgCS9BMd9gE/sqPuxU/rx HdA== 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-kernel@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