diff options
author | Eric Dumazet <edumazet@google.com> | 2023-08-04 14:46:11 +0000 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2023-08-06 08:24:55 +0100 |
commit | d44fd4a767b3755899f8ad1df3e8eca3961ba708 (patch) | |
tree | 9a3f8e02c87025cd2a6ac2d79a6e3a211de0b7e8 /net/ipv4/tcp.c | |
parent | 81083076a007d3af3f2216ad9be1374de0687d49 (diff) |
tcp: set TCP_SYNCNT locklessly
icsk->icsk_syn_retries can safely be set without locking the socket.
We have to add READ_ONCE() annotations in tcp_fastopen_synack_timer()
and tcp_write_timeout().
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/tcp.c')
-rw-r--r-- | net/ipv4/tcp.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index aca5620cf3ba..bcbb33a8c152 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3291,9 +3291,7 @@ int tcp_sock_set_syncnt(struct sock *sk, int val) if (val < 1 || val > MAX_TCP_SYNCNT) return -EINVAL; - lock_sock(sk); WRITE_ONCE(inet_csk(sk)->icsk_syn_retries, val); - release_sock(sk); return 0; } EXPORT_SYMBOL(tcp_sock_set_syncnt); @@ -3462,6 +3460,12 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname, if (copy_from_sockptr(&val, optval, sizeof(val))) return -EFAULT; + /* Handle options that can be set without locking the socket. */ + switch (optname) { + case TCP_SYNCNT: + return tcp_sock_set_syncnt(sk, val); + } + sockopt_lock_sock(sk); switch (optname) { @@ -3569,13 +3573,6 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname, else WRITE_ONCE(tp->keepalive_probes, val); break; - case TCP_SYNCNT: - if (val < 1 || val > MAX_TCP_SYNCNT) - err = -EINVAL; - else - WRITE_ONCE(icsk->icsk_syn_retries, val); - break; - case TCP_SAVE_SYN: /* 0: disable, 1: enable, 2: start from ether_header */ if (val < 0 || val > 2) |