From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.72 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796362899; b=vJDpuy1l65iS7Eyi24bZxcrfbNVr6Euj7plIotF/qTNBrCs+6jS9f4fuYX+ZhXprV/Ou Oiz/O+MiNh7k5vD4+g7VwkI+Oko5NwjL25QU0gVciyoYXzAAxABYZRoP9AUrbfolbCJNo zR8Sk8l0O/9uhtuXQIydRp76oGZIzUuCyr0a+UW3JJKS6qTtGty885s4gpx1Fac9dVLIp iVsj2AGa+2EMVfEV6GbaweKCwswil78ZYgJcbZXZNFeDdJ3Lq4f+EC3RZaM/+b+yE11r+ 2/FYx/Vl83lg+YA92W/NALwJIj4A5PRfG48q1FPD22xm5enrvgyOPiWhz6M6x73ea6g== 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=F7pm921D666YBl7R7Z2yhF7ItU4ybFPUL9TRXAcuRmU=; b=5Ipy9ecvM26606VGDMmi4CMp9eehnnf5oc9WKf2AYtdnFQf/FECd+CRZfym5u0wxLGGa pnEYUQzkYx+Pim8DsFQDXm0OH4J7atQKQsR9mF6RPstCKU2R5qkxE/9Zt2wkPP6iYXrx3 bK0/fPZR6e+a1iG5SNzD/cisjpqsH/DMuoHUdoFACGzYqUUFj6v4kgMU9DD32nPE28Hgr SYFeEynuNQcmUi3V8mAxMQlTi5DR23mJb3v29Ky1TFJrmP95Ri8TeM276HRvqXAEHMvPB xL9GnqNn+3zRbaC98v+dApIKfXYXiOU4M+ZCR91UjBLQPYXd9mIawri/8ADH6l/FWzw== 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.216.72 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (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 1B0AC606A6A1 for ; Fri, 4 Dec 2026 05:41:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1B0AC606A6A1 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-pj1-f72.google.com with SMTP id 98e67ed59e1d1-3b0a7cbf164so655445a91.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=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=DWGuL0ukk2/5opWxG+mB7tWdtDm1rPLJh0J8d2cMqgAcatGJXPUJluw3GwAq8LfDeS Fi4iazcacH5wTIkUh04ajQdPohfaHXyhEq1jUJ52CPe/hGFxA1fbVW/2YWWZ1WHSsjzq tLEUqfVZuBYgu1j50bXCpLyNc1kEGajJhHscvVa75W8ifX5XzN2+UWPorYZa15sPqkhD s3oLnfWLSQG7Fl/X9prud3/cwiUVwwGiHudTUiIcEYMas3q4TMLdZmoalwCS0x3PO5m1 QdNyGaoOwFPYYu1M3MwvI5/2bROWwwT0Qt2u8fGihWjwKOqx1zlau+Ov0+uWny8LuBdJ qyQQ== X-Forwarded-Encrypted: i=1; AL+hErGZA3tr+VjiTrbXU+6GU+3SjOjq0SPjXg5gR+k2vFGnj3qqZgXeh1bX4VaW85kNfQPZkIfu4Rp+7cpAtyQ=@vger.kernel.org X-Gm-Message-State: APuU4Z+Gdjh1fETasBEJfU5CkfvmDkkmritW1vEkewg6IZ+FlrgfXUgl KVH9pL/mMKYTidSAIskHRMAXFyxoPQxi9EvqheYN/eylN95SzrwdizeER3Jzq5scaspo4T3ZUpU OQA== 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-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-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