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 5/6] tcp: set TCP_LINGER2 locklessly
Date: Fri, 4 Aug 2023 11:53:23 -0400 [thread overview]
Message-ID: <CACSApvZjQrgZhYj+2=r7YRABCCAi41oxtvLw+KAUS-zu6LV5Yg@mail.gmail.com> (raw)
In-Reply-To: <20230804144616.3938718-6-edumazet@google.com>
On Fri, Aug 4, 2023 at 10:46 AM Eric Dumazet <edumazet@google.com> wrote:
>
> tp->linger2 can be set locklessly as long as readers
> use READ_ONCE().
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
> ---
> net/ipv4/tcp.c | 19 +++++++++----------
> net/ipv4/tcp_input.c | 2 +-
> net/ipv4/tcp_timer.c | 2 +-
> 3 files changed, 11 insertions(+), 12 deletions(-)
>
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index e74a9593283c91aa23fe23fdd125d4ba680a542c..5c71b4fe11d1c34456976d60eb8742641111dd62 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -2865,7 +2865,7 @@ void __tcp_close(struct sock *sk, long timeout)
>
> if (sk->sk_state == TCP_FIN_WAIT2) {
> struct tcp_sock *tp = tcp_sk(sk);
> - if (tp->linger2 < 0) {
> + if (READ_ONCE(tp->linger2) < 0) {
> tcp_set_state(sk, TCP_CLOSE);
> tcp_send_active_reset(sk, GFP_ATOMIC);
> __NET_INC_STATS(sock_net(sk),
> @@ -3471,6 +3471,14 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname,
> return tcp_sock_set_keepintvl(sk, val);
> case TCP_KEEPCNT:
> return tcp_sock_set_keepcnt(sk, val);
> + case TCP_LINGER2:
> + if (val < 0)
> + WRITE_ONCE(tp->linger2, -1);
> + else if (val > TCP_FIN_TIMEOUT_MAX / HZ)
> + WRITE_ONCE(tp->linger2, TCP_FIN_TIMEOUT_MAX);
> + else
> + WRITE_ONCE(tp->linger2, val * HZ);
> + return 0;
> }
>
> sockopt_lock_sock(sk);
> @@ -3576,15 +3584,6 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname,
> tp->save_syn = val;
> break;
>
> - case TCP_LINGER2:
> - if (val < 0)
> - WRITE_ONCE(tp->linger2, -1);
> - else if (val > TCP_FIN_TIMEOUT_MAX / HZ)
> - WRITE_ONCE(tp->linger2, TCP_FIN_TIMEOUT_MAX);
> - else
> - WRITE_ONCE(tp->linger2, val * HZ);
> - break;
> -
> case TCP_DEFER_ACCEPT:
> /* Translate value in seconds to number of retransmits */
> WRITE_ONCE(icsk->icsk_accept_queue.rskq_defer_accept,
> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index 670c3dab24f2b4d3ab4af84a2715a134cd22b443..f445f5a7c0ebf5f7ab2b2402357f3749d954c0e8 100644
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
> @@ -6625,7 +6625,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)
> break;
> }
>
> - if (tp->linger2 < 0) {
> + if (READ_ONCE(tp->linger2) < 0) {
> tcp_done(sk);
> NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONDATA);
> return 1;
> diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
> index f99e2d06ae7cae72efcafe2bd664545fac8f3fee..d45c96c7f5a4473628bd76366c1b5694a2904aec 100644
> --- a/net/ipv4/tcp_timer.c
> +++ b/net/ipv4/tcp_timer.c
> @@ -714,7 +714,7 @@ static void tcp_keepalive_timer (struct timer_list *t)
>
> tcp_mstamp_refresh(tp);
> if (sk->sk_state == TCP_FIN_WAIT2 && sock_flag(sk, SOCK_DEAD)) {
> - if (tp->linger2 >= 0) {
> + if (READ_ONCE(tp->linger2) >= 0) {
> const int tmo = tcp_fin_time(sk) - TCP_TIMEWAIT_LEN;
>
> if (tmo > 0) {
> --
> 2.41.0.640.ga95def55d0-goog
>
next prev parent reply other threads:[~2023-08-04 15:54 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
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 [this message]
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='CACSApvZjQrgZhYj+2=r7YRABCCAi41oxtvLw+KAUS-zu6LV5Yg@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).