From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.198 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796362900; b=tCpLYn9IT9PYnWc0dMZtDXGpGHZ5Xu7IAODoHZnMboUXc4RAv9oVG+pTTjXJDXfIMICU mazuQzaGt7tSP7h+SIcRMaY6ZfU/c6WGGKSDOBAOUfHhjwFCawFNoBKeHuz2DQHHV7iPa ycGlPWLIuY93uOILIPiO5N1hCAwRAqB736DtbrT9UgbpYUmYRRgjfxWOeiGtHlpevsYTT SgAd5maKtPo7Sv/IT6CquCcRFDJhUJPoBuIuwGuh3eg1cJUfpf1z7VZ2VGjFV6hKd1npk 4MrJrymf2KqRTiPe8JBb/IzEMVSGgA5SPljsJ1mg7EJt5EGreyQswuRL0rJJ8sFVHaw== 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-Gm-Message-State:X-Received:Date:In-Reply-To:Mime-Version: References:X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=F7pm921D666YBl7R7Z2yhF7ItU4ybFPUL9TRXAcuRmU=; b=kdqhMPDMzqZKOeuoB2/h3vx3aokPAWmKZjH1Rv2RgPVx0F+WcbhYM1Q1+jHRX4lqP/yk m5uihs9eS+RZKkhomN9RwmiKbteomJko8/fsK34uu4QvY5sLWG9T0y8WViE00EFloIqGq H/nchX4RealuzlWCTpEuEDZhAO/SeMtDXnIyXlDGvLDFsTgh9seEI3Mm1+eirczPRqvC1 CV8J6oqXur+EdOPTbP9KSy3RcHIRYCHr0cZ0nQzNQ+6I1YSiMJb7NcpXuMbonmnFgtpgu FExE75dJtWHTUANKljL2UTxCs/BqePo5719MIQEr0rGlgBp/203CuczXaNKbDuZWg6g== 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=WSLQNE0T; arc=none smtp.remote-ip=209.85.210.198 Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.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 3B8A9606A6A4 for ; Fri, 4 Dec 2026 05:41:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3B8A9606A6A4 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=WSLQNE0T Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-8b60129a46eso683147b3a.1 for ; Thu, 03 Dec 2026 21:41:38 -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=F7pm921D666YBl7R7Z2yhF7ItU4ybFPUL9TRXAcuRmU=; b=WSLQNE0TXKns16hMNX5PU8UpMrCUV5qfc38u4X3nlGlDdv5xVsim2hMKPtibUT89kt 0C1JKLKHCcth1hmc3gnMfHZ6iMekbOUjM6bc2DzZ7O03cUgPvJ78kKxlvhZKV5bxGBFd Rwhu7rEwocNM5RqdWkB863WEB2uD++iLzigSypD0zLaJJ/PdMNqF/hH2fKBi9oqC/TCj hrmyAbhfu+sRtBqPm0abzpyiQlwfuJyBsLuD7xbNsogP5dU1IAjPKKV2gKA9y/i/oCpn d41RzyrRH14poqOGitK+gv1AZSf4MyCYVqvAZ9xSI43++ArEvMjmutPrx3Bu4a+RBIK5 NkQA== 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=F7pm921D666YBl7R7Z2yhF7ItU4ybFPUL9TRXAcuRmU=; b=LFpvO8JJylhhHjjnN/FZTYca4PCjNRSXQFld2AqA+R4NoerxlfN3PTZhBgB7vPNI42 sYHhPtLCF9cEmXb99BQInHNKzQ644vtKtAxAd80RrXLOH+QjQTozQ2HgL5xY966C+FCa 36CPBpFyq39qGR1FrAOsX3X9OtoRGd8+sHTPwqmhDrukb6klvdf65rxLgao6k+lluDS7 A4IZ02DJhieLa0In9vtHpIOaSmjbgQjKwdB3E9aTL7BQ8Ql58cgoLs6LyXpdvrMhNlHX 0tjXgPvU5zY+7Kr0cPJj7qf/cgAPRMgV7zaQ+7EMLsEG+836JkeJ1TJrRFKgj5JggrV+ Autg== X-Gm-Message-State: APuU4Z82Wrk87GjDYLNDg5CtqWbb8NimZ96Ms4Xkice8RIrNiy+ycl2Z E4Pd4cDXUJewc5dEGU6it0Yn9mHd5rBuPLVCdrxd81bkY3G3s5AqcBkFJC2N5+lFpZqaaxNnsnq J0fdKNHESUYgqH+Yo4tmtz+NRNvTJT8VrP8rSE+xneXfAvxLKn21qFERot5W47bQ4W1YfMsYlnk HlPE6ZmMGvqIguwMmHaaRmwEipPvDIrmc= X-Received: from pjuy22.prod.google.com ([2002:a17:90a:d716:b0:3b4:1cd2:f6a]) (user=tavip job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4a48:b0:3ac:4291:f569 with SMTP id 98e67ed59e1d1-3b5e053b0bcmr801832a91.8.1796362897158; Thu, 03 Dec 2026 21:41:37 -0800 (PST) Date: Fri, 4 Dec 2026 05:41:06 +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-3-tavip@google.com> Subject: [PATCH net 2/3] tcp: set exact recv_skip_hint on mid-frag 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(), when copied_seq lands in the middle of a page frag (offset_frag != 0), the loop breaks with zc->recv_skip_hint still set to skb->len - offset, the entire remaining length of the skb. For multi-frag skbs (such as GRO or BIG TCP skbs), this overstates the number of unmappable bytes: after skipping only the remainder of the current frag (and any subsequent unmappable frags), the remaining full page frags in the same skb are mappable. Returning skb->len - offset causes callers to read() the whole skb instead of realigning to the next mappable frag, and causes tcp_zc_handle_leftover() to over-copy past the frag boundary when copybuf_len exceeds the remaining bytes of the frag. Call tcp_zerocopy_set_hint_for_skb() before breaking when offset_frag is non-zero so zc->recv_skip_hint covers only the bytes up to the next mappable frag. Discovered by code inspection while investigating low TCP receive zerocopy rates with BIG TCP and copybuf enabled. Reproduced on an unmodified kernel with the new tcp_zerocopy_receive selftest added in this series, and tested against it and tcp_mmap. Fixes: 0c3936d32f75 ("net-zerocopy: Set zerocopy hint when data is copied") Assisted-by: LLM Signed-off-by: Octavian Purdila --- net/ipv4/tcp.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index b94d5b2d77daf..bc9548c4212b7 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2291,8 +2291,13 @@ static int tcp_zerocopy_receive(struct sock *sk, } zc->recv_skip_hint = skb->len - offset; frags = skb_advance_to_frag(skb, offset, &offset_frag); - if (!frags || offset_frag) + if (!frags) break; + if (offset_frag) { + tcp_zerocopy_set_hint_for_skb(sk, zc, skb, + offset); + break; + } } mappable_offset = find_next_mappable_frag(frags, -- 2.56.1.915.g69d5ec7298-goog