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=1796362901; b=tlBUvCxcflMrRT/sqXrjcWW3NE0XcJyk5TQ8g1DDCS4BvyQ3b/H2PhHTv7rwSZ7zNes7 oFfAQqBI2dAU16lLoETK19iyGNgbU6+cyuWAbBPV00diqid1gCjvhUBbiVUr45HZ2nCMr M0gnlHwUFCbRf7IjhsDpR+b2IFeG1093gm7ZyLixoTjI2d0d1MasJuNBu6C4ptddGr29m ZSJQa+MJUNAxC0UpJ9HB7zSRuGtR2qtes7laAQtb+gc+RsQHF9arT7J5tY7frZco47G9t a7VtS8H3z1xSFR3ivq73fjmr+tmJD0kYpxiXIdX6+9OV/WlWktbBklVkZI35OQ9egwg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796362901; 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=F7pm921D666YBl7R7Z2yhF7ItU4ybFPUL9TRXAcuRmU=; b=1+ouNASbc6Wi7OGdDZuB4aq0iy1bREFNLJXlbvi9UxJbO6kQRQzpJcn9LijAGj54VAuF A8OldXtC8e0eEcH2BOMDte3W7BRawfIZra3zV37ZUvu/oZ8Zzbuz6eETPC0JZ4RlfL2Jg 20GjK/5QfEwZGfgjfdE9B2Xa9BRL8SzLSHt5Dzsp4e5+rrC7cSrZ+IWYVdvDc51zH5LDZ xpttcUobGgU1zkxfgtTF7i6wxTopRZ0KIJ8XjYqZN/tupu2BBwT5FJDkGmsj2UD0DEYmP xK27jhCNbf46yH6teVkv2Zlk+18YaALJT03oamWelLhdX5xJp48IARJfRa0i5C9gq/A== 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.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 259BA606A33A for ; Fri, 4 Dec 2026 05:41:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 259BA606A33A 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-pg1-f198.google.com with SMTP id 41be03b00d2f7-cd3b9e70f88so783290a12.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=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=eHnDueEnHadUPhRQ3AGEoV4iQAC9xPF57N7k48+lUl2GXDmB5NjwwKqmtHOAHyzGLo uiCypWfovhDNKMV/QpoLgmQ/m5KTUDM1us30ui36jdJ8RmQUqFI1ac5pQ6IVVJaAp5Tt DBGSwNUh4FBtOnzxvBjKjlel2eWusW4TH26QHXEue8jsOaV1eZz4OEhX4L6J6ChwgOuz 4ZskR+lX8HN8dFM68d7TcB0ErvyKcNKVdx9vMCxKk6TrFGDzKCYlb96cD7slfHuDUPfE AhBEjHbTmXsOwt+gJM0q8Ay2hB6yEitxeawdrmOQotXK2BsBaoa+AEGFXoESl8csLK4m OTwg== X-Forwarded-Encrypted: i=1; AL+hErHhx/qOX2K7QNl9YTq5Pwh1ZfT2+AkBbk8j2Q6MHujyuJgnNNEE7P9+Bog7SK6MjPRkCiYF65KYN9QnP6Fm8X4=@vger.kernel.org X-Gm-Message-State: APuU4Z+WjRRsWjEBo4OtF/6P00DRm+TpOIiujoQD33x05K3t18bEV1JK uyG0SfxP9Ss1KRJZzSdI9hC1xCR2rBq/Ia4EFxB3VnV45EOpE7MSkWp7slnDE7A45MKFROJNxbg 3Zw== 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: 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-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