From: Soheil Hassas Yeganeh <soheil@google.com>
To: Eric Dumazet <edumazet@google.com>
Cc: "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, eric.dumazet@gmail.com
Subject: Re: [PATCH net-next 1/6] tcp: set TCP_SYNCNT locklessly
Date: Fri, 4 Aug 2023 10:55:37 -0400 [thread overview]
Message-ID: <CACSApvaDR4-PSWfwigW5X3simF9gWsY7hVbUKuU4=1i87yk0SQ@mail.gmail.com> (raw)
In-Reply-To: <20230804144616.3938718-2-edumazet@google.com>
On Fri, Aug 4, 2023 at 10:46 AM Eric Dumazet <edumazet@google.com> wrote:
>
> 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>
Acked by: Soheil Hassas Yeganeh <soheil@google.com>
> ---
> net/ipv4/tcp.c | 15 ++++++---------
> net/ipv4/tcp_timer.c | 9 ++++++---
> 2 files changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index aca5620cf3ba20be38d81b1b526c22623b145ff7..bcbb33a8c152abe2a060abd644689b54bcca1daa 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)
> diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
> index 470f581eedd438b3bbd6ae4973c7a6f01ee1724f..66040ab457d46ffa2fac62f875b636f567157793 100644
> --- a/net/ipv4/tcp_timer.c
> +++ b/net/ipv4/tcp_timer.c
> @@ -239,7 +239,8 @@ static int tcp_write_timeout(struct sock *sk)
> if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) {
> if (icsk->icsk_retransmits)
> __dst_negative_advice(sk);
> - retry_until = icsk->icsk_syn_retries ? :
> + /* Paired with WRITE_ONCE() in tcp_sock_set_syncnt() */
> + retry_until = READ_ONCE(icsk->icsk_syn_retries) ? :
> READ_ONCE(net->ipv4.sysctl_tcp_syn_retries);
>
> max_retransmits = retry_until;
> @@ -421,8 +422,10 @@ static void tcp_fastopen_synack_timer(struct sock *sk, struct request_sock *req)
>
> req->rsk_ops->syn_ack_timeout(req);
>
> - /* add one more retry for fastopen */
> - max_retries = icsk->icsk_syn_retries ? :
> + /* Add one more retry for fastopen.
> + * Paired with WRITE_ONCE() in tcp_sock_set_syncnt()
> + */
> + max_retries = READ_ONCE(icsk->icsk_syn_retries) ? :
> READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_synack_retries) + 1;
>
> if (req->num_timeout >= max_retries) {
> --
> 2.41.0.640.ga95def55d0-goog
>
next prev parent reply other threads:[~2023-08-04 14:56 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-04 14:46 [PATCH net-next 0/6] tcp: set few options locklessly Eric Dumazet
2023-08-04 14:46 ` [PATCH net-next 1/6] tcp: set TCP_SYNCNT locklessly Eric Dumazet
2023-08-04 14:55 ` Soheil Hassas Yeganeh [this message]
2023-08-04 14:46 ` [PATCH net-next 2/6] tcp: set TCP_USER_TIMEOUT locklessly Eric Dumazet
2023-08-04 15:49 ` Soheil Hassas Yeganeh
2023-08-04 14:46 ` [PATCH net-next 3/6] tcp: set TCP_KEEPINTVL locklessly Eric Dumazet
2023-08-04 15:50 ` Soheil Hassas Yeganeh
2023-08-04 14:46 ` [PATCH net-next 4/6] tcp: set TCP_KEEPCNT locklessly Eric Dumazet
2023-08-04 15:50 ` Soheil Hassas Yeganeh
2023-08-04 14:46 ` [PATCH net-next 5/6] tcp: set TCP_LINGER2 locklessly Eric Dumazet
2023-08-04 15:53 ` Soheil Hassas Yeganeh
2023-08-04 14:46 ` [PATCH net-next 6/6] tcp: set TCP_DEFER_ACCEPT locklessly Eric Dumazet
2023-08-04 18:14 ` Soheil Hassas Yeganeh
2023-08-06 7:30 ` [PATCH net-next 0/6] tcp: set few options locklessly patchwork-bot+netdevbpf
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='CACSApvaDR4-PSWfwigW5X3simF9gWsY7hVbUKuU4=1i87yk0SQ@mail.gmail.com' \
--to=soheil@google.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=eric.dumazet@gmail.com \
--cc=kuba@kernel.org \
--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).