netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] tcp: user_mss and TCP_MAXSEG series
@ 2025-08-21 14:18 Eric Dumazet
  2025-08-21 14:19 ` [PATCH net-next 1/2] tcp: annotate data-races around tp->rx_opt.user_mss Eric Dumazet
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Eric Dumazet @ 2025-08-21 14:18 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni, Neal Cardwell
  Cc: Simon Horman, Kuniyuki Iwashima, Willem de Bruijn, netdev,
	eric.dumazet, Eric Dumazet

Annotate data-races around tp->rx_opt.user_mss and make
TCP_MAXSEG lockless.

Eric Dumazet (2):
  tcp: annotate data-races around tp->rx_opt.user_mss
  tcp: lockless TCP_MAXSEG option

 .../chelsio/inline_crypto/chtls/chtls_cm.c         |  6 ++++--
 .../chelsio/inline_crypto/chtls/chtls_cm.h         |  2 +-
 net/ipv4/tcp.c                                     | 14 +++++++-------
 net/ipv4/tcp_input.c                               |  8 ++++----
 net/ipv4/tcp_output.c                              |  6 ++++--
 5 files changed, 20 insertions(+), 16 deletions(-)

-- 
2.51.0.rc1.193.gad69d77794-goog


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net-next 1/2] tcp: annotate data-races around tp->rx_opt.user_mss
  2025-08-21 14:18 [PATCH net-next 0/2] tcp: user_mss and TCP_MAXSEG series Eric Dumazet
@ 2025-08-21 14:19 ` Eric Dumazet
  2025-08-21 14:28   ` Neal Cardwell
  2025-08-21 14:19 ` [PATCH net-next 2/2] tcp: lockless TCP_MAXSEG option Eric Dumazet
  2025-08-22 23:40 ` [PATCH net-next 0/2] tcp: user_mss and TCP_MAXSEG series patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2025-08-21 14:19 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni, Neal Cardwell
  Cc: Simon Horman, Kuniyuki Iwashima, Willem de Bruijn, netdev,
	eric.dumazet, Eric Dumazet

This field is already read locklessly for listeners,
next patch will make setsockopt(TCP_MAXSEG) lockless.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 .../net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c   | 6 ++++--
 .../net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.h   | 2 +-
 net/ipv4/tcp.c                                            | 8 +++++---
 net/ipv4/tcp_input.c                                      | 8 ++++----
 net/ipv4/tcp_output.c                                     | 6 ++++--
 5 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c b/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c
index 2e7c2691a1933e5c8d9dc71ec99a5d92970ad7cd..000116e47e38d90802c5dd676c0659fab19bcff3 100644
--- a/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c
+++ b/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c
@@ -951,6 +951,7 @@ static unsigned int chtls_select_mss(const struct chtls_sock *csk,
 	struct tcp_sock *tp;
 	unsigned int mss;
 	struct sock *sk;
+	u16 user_mss;
 
 	mss = ntohs(req->tcpopt.mss);
 	sk = csk->sk;
@@ -969,8 +970,9 @@ static unsigned int chtls_select_mss(const struct chtls_sock *csk,
 		tcpoptsz += round_up(TCPOLEN_TIMESTAMP, 4);
 
 	tp->advmss = dst_metric_advmss(dst);
-	if (USER_MSS(tp) && tp->advmss > USER_MSS(tp))
-		tp->advmss = USER_MSS(tp);
+	user_mss = USER_MSS(tp);
+	if (user_mss && tp->advmss > user_mss)
+		tp->advmss = user_mss;
 	if (tp->advmss > pmtu - iphdrsz)
 		tp->advmss = pmtu - iphdrsz;
 	if (mss && tp->advmss > mss)
diff --git a/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.h b/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.h
index 2285cf2df251db9ec84d305d5ffa012279f6c43f..667effc2a23cb78901d65da2712a7e8a66ec81b4 100644
--- a/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.h
+++ b/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.h
@@ -90,7 +90,7 @@ struct deferred_skb_cb {
 
 #define SND_WSCALE(tp) ((tp)->rx_opt.snd_wscale)
 #define RCV_WSCALE(tp) ((tp)->rx_opt.rcv_wscale)
-#define USER_MSS(tp) ((tp)->rx_opt.user_mss)
+#define USER_MSS(tp) (READ_ONCE((tp)->rx_opt.user_mss))
 #define TS_RECENT_STAMP(tp) ((tp)->rx_opt.ts_recent_stamp)
 #define WSCALE_OK(tp) ((tp)->rx_opt.wscale_ok)
 #define TSTAMP_OK(tp) ((tp)->rx_opt.tstamp_ok)
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 71a956fbfc5533224ee00e792de2cfdccd4d40aa..a12d81e01b3f2fb964227881c2f779741cc06e58 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -3760,7 +3760,7 @@ int tcp_sock_set_maxseg(struct sock *sk, int val)
 	if (val && (val < TCP_MIN_MSS || val > MAX_TCP_WINDOW))
 		return -EINVAL;
 
-	tcp_sk(sk)->rx_opt.user_mss = val;
+	WRITE_ONCE(tcp_sk(sk)->rx_opt.user_mss, val);
 	return 0;
 }
 
@@ -4383,6 +4383,7 @@ int do_tcp_getsockopt(struct sock *sk, int level,
 	struct inet_connection_sock *icsk = inet_csk(sk);
 	struct tcp_sock *tp = tcp_sk(sk);
 	struct net *net = sock_net(sk);
+	int user_mss;
 	int val, len;
 
 	if (copy_from_sockptr(&len, optlen, sizeof(int)))
@@ -4396,9 +4397,10 @@ int do_tcp_getsockopt(struct sock *sk, int level,
 	switch (optname) {
 	case TCP_MAXSEG:
 		val = tp->mss_cache;
-		if (tp->rx_opt.user_mss &&
+		user_mss = READ_ONCE(tp->rx_opt.user_mss);
+		if (user_mss &&
 		    ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)))
-			val = tp->rx_opt.user_mss;
+			val = user_mss;
 		if (tp->repair)
 			val = tp->rx_opt.mss_clamp;
 		break;
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 71b76e98371a667b6e8263b32c242363672d7c5a..7b537978dfe6b436c723815f1ce64f05f9c1ae61 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -6297,7 +6297,7 @@ static bool tcp_rcv_fastopen_synack(struct sock *sk, struct sk_buff *synack,
 	u16 mss = tp->rx_opt.mss_clamp, try_exp = 0;
 	bool syn_drop = false;
 
-	if (mss == tp->rx_opt.user_mss) {
+	if (mss == READ_ONCE(tp->rx_opt.user_mss)) {
 		struct tcp_options_received opt;
 
 		/* Get original SYNACK MSS value if user MSS sets mss_clamp */
@@ -7117,7 +7117,7 @@ u16 tcp_get_syncookie_mss(struct request_sock_ops *rsk_ops,
 		return 0;
 	}
 
-	mss = tcp_parse_mss_option(th, tp->rx_opt.user_mss);
+	mss = tcp_parse_mss_option(th, READ_ONCE(tp->rx_opt.user_mss));
 	if (!mss)
 		mss = af_ops->mss_clamp;
 
@@ -7131,7 +7131,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
 {
 	struct tcp_fastopen_cookie foc = { .len = -1 };
 	struct tcp_options_received tmp_opt;
-	struct tcp_sock *tp = tcp_sk(sk);
+	const struct tcp_sock *tp = tcp_sk(sk);
 	struct net *net = sock_net(sk);
 	struct sock *fastopen_sk = NULL;
 	struct request_sock *req;
@@ -7182,7 +7182,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
 
 	tcp_clear_options(&tmp_opt);
 	tmp_opt.mss_clamp = af_ops->mss_clamp;
-	tmp_opt.user_mss  = tp->rx_opt.user_mss;
+	tmp_opt.user_mss  = READ_ONCE(tp->rx_opt.user_mss);
 	tcp_parse_options(sock_net(sk), skb, &tmp_opt, 0,
 			  want_cookie ? NULL : &foc);
 
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index dfbac0876d96ee6b556fff5b6c9ec8fe2e04aa05..86892c8672ed49a49b85530b648d695ed171a3c8 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -3890,6 +3890,7 @@ static void tcp_connect_init(struct sock *sk)
 	const struct dst_entry *dst = __sk_dst_get(sk);
 	struct tcp_sock *tp = tcp_sk(sk);
 	__u8 rcv_wscale;
+	u16 user_mss;
 	u32 rcv_wnd;
 
 	/* We'll fix this up when we get a response from the other end.
@@ -3902,8 +3903,9 @@ static void tcp_connect_init(struct sock *sk)
 	tcp_ao_connect_init(sk);
 
 	/* If user gave his TCP_MAXSEG, record it to clamp */
-	if (tp->rx_opt.user_mss)
-		tp->rx_opt.mss_clamp = tp->rx_opt.user_mss;
+	user_mss = READ_ONCE(tp->rx_opt.user_mss);
+	if (user_mss)
+		tp->rx_opt.mss_clamp = user_mss;
 	tp->max_window = 0;
 	tcp_mtup_init(sk);
 	tcp_sync_mss(sk, dst_mtu(dst));
-- 
2.51.0.rc1.193.gad69d77794-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next 2/2] tcp: lockless TCP_MAXSEG option
  2025-08-21 14:18 [PATCH net-next 0/2] tcp: user_mss and TCP_MAXSEG series Eric Dumazet
  2025-08-21 14:19 ` [PATCH net-next 1/2] tcp: annotate data-races around tp->rx_opt.user_mss Eric Dumazet
@ 2025-08-21 14:19 ` Eric Dumazet
  2025-08-21 14:28   ` Neal Cardwell
  2025-08-22 23:40 ` [PATCH net-next 0/2] tcp: user_mss and TCP_MAXSEG series patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2025-08-21 14:19 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni, Neal Cardwell
  Cc: Simon Horman, Kuniyuki Iwashima, Willem de Bruijn, netdev,
	eric.dumazet, Eric Dumazet

setsockopt(TCP_MAXSEG) writes over a field that does not need
socket lock protection anymore.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/ipv4/tcp.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index a12d81e01b3f2fb964227881c2f779741cc06e58..99232903b03c99d263cce59314fd369cfd33af6f 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -3890,15 +3890,13 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname,
 		WRITE_ONCE(inet_csk(sk)->icsk_delack_max, delack_max);
 		return 0;
 	}
+	case TCP_MAXSEG:
+		return tcp_sock_set_maxseg(sk, val);
 	}
 
 	sockopt_lock_sock(sk);
 
 	switch (optname) {
-	case TCP_MAXSEG:
-		err = tcp_sock_set_maxseg(sk, val);
-		break;
-
 	case TCP_NODELAY:
 		__tcp_sock_set_nodelay(sk, val);
 		break;
-- 
2.51.0.rc1.193.gad69d77794-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next 1/2] tcp: annotate data-races around tp->rx_opt.user_mss
  2025-08-21 14:19 ` [PATCH net-next 1/2] tcp: annotate data-races around tp->rx_opt.user_mss Eric Dumazet
@ 2025-08-21 14:28   ` Neal Cardwell
  0 siblings, 0 replies; 6+ messages in thread
From: Neal Cardwell @ 2025-08-21 14:28 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Kuniyuki Iwashima, Willem de Bruijn, netdev, eric.dumazet

On Thu, Aug 21, 2025 at 10:19 AM Eric Dumazet <edumazet@google.com> wrote:
>
> This field is already read locklessly for listeners,
> next patch will make setsockopt(TCP_MAXSEG) lockless.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> ---

Reviewed-by: Neal Cardwell <ncardwell@google.com>

Thanks, Eric!

neal

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next 2/2] tcp: lockless TCP_MAXSEG option
  2025-08-21 14:19 ` [PATCH net-next 2/2] tcp: lockless TCP_MAXSEG option Eric Dumazet
@ 2025-08-21 14:28   ` Neal Cardwell
  0 siblings, 0 replies; 6+ messages in thread
From: Neal Cardwell @ 2025-08-21 14:28 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Kuniyuki Iwashima, Willem de Bruijn, netdev, eric.dumazet

On Thu, Aug 21, 2025 at 10:19 AM Eric Dumazet <edumazet@google.com> wrote:
>
> setsockopt(TCP_MAXSEG) writes over a field that does not need
> socket lock protection anymore.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> ---

Reviewed-by: Neal Cardwell <ncardwell@google.com>

Thanks, Eric!

neal

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next 0/2] tcp: user_mss and TCP_MAXSEG series
  2025-08-21 14:18 [PATCH net-next 0/2] tcp: user_mss and TCP_MAXSEG series Eric Dumazet
  2025-08-21 14:19 ` [PATCH net-next 1/2] tcp: annotate data-races around tp->rx_opt.user_mss Eric Dumazet
  2025-08-21 14:19 ` [PATCH net-next 2/2] tcp: lockless TCP_MAXSEG option Eric Dumazet
@ 2025-08-22 23:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-08-22 23:40 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: davem, kuba, pabeni, ncardwell, horms, kuniyu, willemb, netdev,
	eric.dumazet

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 21 Aug 2025 14:18:59 +0000 you wrote:
> Annotate data-races around tp->rx_opt.user_mss and make
> TCP_MAXSEG lockless.
> 
> Eric Dumazet (2):
>   tcp: annotate data-races around tp->rx_opt.user_mss
>   tcp: lockless TCP_MAXSEG option
> 
> [...]

Here is the summary with links:
  - [net-next,1/2] tcp: annotate data-races around tp->rx_opt.user_mss
    https://git.kernel.org/netdev/net-next/c/d5ffba0f254d
  - [net-next,2/2] tcp: lockless TCP_MAXSEG option
    https://git.kernel.org/netdev/net-next/c/9217146fee49

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-08-22 23:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-21 14:18 [PATCH net-next 0/2] tcp: user_mss and TCP_MAXSEG series Eric Dumazet
2025-08-21 14:19 ` [PATCH net-next 1/2] tcp: annotate data-races around tp->rx_opt.user_mss Eric Dumazet
2025-08-21 14:28   ` Neal Cardwell
2025-08-21 14:19 ` [PATCH net-next 2/2] tcp: lockless TCP_MAXSEG option Eric Dumazet
2025-08-21 14:28   ` Neal Cardwell
2025-08-22 23:40 ` [PATCH net-next 0/2] tcp: user_mss and TCP_MAXSEG series patchwork-bot+netdevbpf

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).