netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: lei lei <llleigoing@outlook.com>
To: "netdev@vger.kernel.org" <netdev@vger.kernel.org>
Cc: "mptcp@lists.linux.dev" <mptcp@lists.linux.dev>,
	"edumazet@kernel.org" <edumazet@kernel.org>,
	"ncardwell@google.com" <ncardwell@google.com>,
	"kuniyu@google.com" <kuniyu@google.com>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"kuba@kernel.org" <kuba@kernel.org>,
	"pabeni@redhat.com" <pabeni@redhat.com>,
	"horms@kernel.org" <horms@kernel.org>,
	"matttbe@kernel.org" <matttbe@kernel.org>,
	"martineau@kernel.org" <martineau@kernel.org>,
	"geliang@kernel.org" <geliang@kernel.org>
Subject: [PATCH net 1/3] tcp: saturate window-to-memory conversions at INT_MAX
Date: Tue, 17 Nov 2026 05:22:01 +0000	[thread overview]
Message-ID: <20261117052200.1507847-2-llleigoing@outlook.com> (raw)
In-Reply-To: <20261117052200.1507847-1-llleigoing@outlook.com>

__tcp_space_from_win() computes a receive-memory requirement in u64 but
returns int. A result above INT_MAX can therefore become negative or
wrap to a smaller positive value before the caller compares or limits it.

TCP and MPTCP SO_RCVLOWAT handling compare this result with sk_rcvbuf.
They can accept a large low watermark without increasing the receive
budget because the truncated requirement appears smaller than the
existing buffer. Receive autotuning uses the same conversion helper.

Saturate the u64 result at INT_MAX before returning it. This matches the
int type of sk_rcvbuf and preserves the value and rounding of every
representable result.

TCP and MPTCP loopback tests with tcp_rmem[2]=INT_MAX and
SO_RCVLOWAT=INT_MAX/2 reproduce the missed update after learning a
scaling ratio below 128. With this change, both budgets reach INT_MAX.

Fixes: dfa2f0483360 ("tcp: get rid of sysctl_tcp_adv_win_scale")
Signed-off-by: lllei <llleigoing@outlook.com>
---
 include/net/tcp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/net/tcp.h b/include/net/tcp.h
index 5c9203aae..09827f1ae 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1799,7 +1799,7 @@ static inline int __tcp_space_from_win(u8 scaling_ratio, int win)
 	u64 val = (u64)win << TCP_RMEM_TO_WIN_SCALE;
 
 	do_div(val, scaling_ratio);
-	return val;
+	return min_t(u64, val, INT_MAX);
 }
 
 static inline int tcp_space_from_win(const struct sock *sk, int win)
-- 
2.43.0


  reply	other threads:[~2026-11-17  5:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  5:22 [PATCH net 0/3] tcp, mptcp: fix receive buffer sizing and peek accounting lei lei
2026-11-17  5:22 ` lei lei [this message]
2026-11-19  7:54   ` [PATCH net 1/3] tcp: saturate window-to-memory conversions at INT_MAX Eric Dumazet
2026-11-17  5:22 ` [PATCH net 2/3] net: bound receive window predictions before narrowing lei lei
2026-11-19  7:56   ` Eric Dumazet
2026-11-17  5:22 ` [PATCH net 3/3] mptcp: exclude MSG_PEEK from receive buffer autotuning lei lei
2026-11-19  7:59   ` Eric Dumazet
2026-11-19 18:33     ` Matthieu Baerts

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261117052200.1507847-2-llleigoing@outlook.com \
    --to=llleigoing@outlook.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=geliang@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=martineau@kernel.org \
    --cc=matttbe@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).