]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tcp: update window_clamp when SO_RCVBUF is set
authorJakub Kicinski <kuba@kernel.org>
Wed, 8 Apr 2026 00:14:38 +0000 (17:14 -0700)
committerPaolo Abeni <pabeni@redhat.com>
Mon, 13 Apr 2026 13:32:35 +0000 (15:32 +0200)
Commit under Fixes moved recomputing the window clamp to
tcp_measure_rcv_mss() (when scaling_ratio changes).
I suspect it missed the fact that we don't recompute the clamp
when rcvbuf is set. Until scaling_ratio changes we are
stuck with the old window clamp which may be based on
the small initial buffer. scaling_ratio may never change.

Inspired by Eric's recent commit d1361840f8c5 ("tcp: fix
SO_RCVLOWAT and RCVBUF autotuning") plumb the user action
thru to TCP and have it update the clamp.

A smaller fix would be to just have tcp_rcvbuf_grow()
adjust the clamp even if SOCK_RCVBUF_LOCK is set.
But IIUC this is what we were trying to get away from
in the first place.

Fixes: a2cbb1603943 ("tcp: Update window clamping condition")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Eric Dumazet <edumaze@google.com>
Link: https://patch.msgid.link/20260408001438.129165-1-kuba@kernel.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
include/linux/net.h
include/net/tcp.h
net/core/sock.c
net/ipv4/af_inet.c
net/ipv4/tcp.c
net/ipv6/af_inet6.c

index a8e818de95b3345351bee3e8f4089962b942492b..ca6a7bc5c9ae1119d8ade7a14bd6bcfcbecddd45 100644 (file)
@@ -223,6 +223,7 @@ struct proto_ops {
        int             (*sendmsg_locked)(struct sock *sk, struct msghdr *msg,
                                          size_t size);
        int             (*set_rcvlowat)(struct sock *sk, int val);
+       void            (*set_rcvbuf)(struct sock *sk, int val);
 };
 
 #define DECLARE_SOCKADDR(type, dst, src)       \
index 0f09429ff4cba1484ede374e969f13eb561b12ab..dfa52ceefd23b7a25ed725e3a7fde3bd7e442e4e 100644 (file)
@@ -516,6 +516,7 @@ void tcp_syn_ack_timeout(const struct request_sock *req);
 int tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
                int flags);
 int tcp_set_rcvlowat(struct sock *sk, int val);
+void tcp_set_rcvbuf(struct sock *sk, int val);
 int tcp_set_window_clamp(struct sock *sk, int val);
 
 static inline void
index 367fd7bad4ac2e6557dc73519ac0c04debb43cb3..b37b664b6eb92f375d6708a5a609f35f07ee2897 100644 (file)
@@ -966,6 +966,8 @@ EXPORT_SYMBOL(sock_set_keepalive);
 
 static void __sock_set_rcvbuf(struct sock *sk, int val)
 {
+       struct socket *sock = sk->sk_socket;
+
        /* Ensure val * 2 fits into an int, to prevent max_t() from treating it
         * as a negative value.
         */
@@ -983,6 +985,13 @@ static void __sock_set_rcvbuf(struct sock *sk, int val)
         * we actually used in getsockopt is the most desirable behavior.
         */
        WRITE_ONCE(sk->sk_rcvbuf, max_t(int, val * 2, SOCK_MIN_RCVBUF));
+
+       if (sock) {
+               const struct proto_ops *ops = READ_ONCE(sock->ops);
+
+               if (ops->set_rcvbuf)
+                       ops->set_rcvbuf(sk, sk->sk_rcvbuf);
+       }
 }
 
 void sock_set_rcvbuf(struct sock *sk, int val)
index f98e46ae3e301fc3849c5ada0a321732f0d5aea2..0e62032e76b19b3b5616110bf49194d3afe62f92 100644 (file)
@@ -1091,6 +1091,7 @@ const struct proto_ops inet_stream_ops = {
        .compat_ioctl      = inet_compat_ioctl,
 #endif
        .set_rcvlowat      = tcp_set_rcvlowat,
+       .set_rcvbuf        = tcp_set_rcvbuf,
 };
 EXPORT_SYMBOL(inet_stream_ops);
 
index e57eaffc007a02d1265df097e0f66d09a44a971a..1a494d18c5fd130c2a7bb4c425eda8e4ddcdf612 100644 (file)
@@ -1858,6 +1858,11 @@ int tcp_set_rcvlowat(struct sock *sk, int val)
        return 0;
 }
 
+void tcp_set_rcvbuf(struct sock *sk, int val)
+{
+       tcp_set_window_clamp(sk, tcp_win_from_space(sk, val));
+}
+
 #ifdef CONFIG_MMU
 static const struct vm_operations_struct tcp_vm_ops = {
 };
index ee341a8254bffafcb1dab1fd0dfb4e599f25d6a1..0a88b376141d70217d96976b7230fd4a34519d43 100644 (file)
@@ -690,6 +690,7 @@ const struct proto_ops inet6_stream_ops = {
        .compat_ioctl      = inet6_compat_ioctl,
 #endif
        .set_rcvlowat      = tcp_set_rcvlowat,
+       .set_rcvbuf        = tcp_set_rcvbuf,
 };
 EXPORT_SYMBOL_GPL(inet6_stream_ops);