Commit a81722dd authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

tcp: set TCP_LINGER2 locklessly

tp->linger2 can be set locklessly as long as readers
use READ_ONCE().
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Acked-by: default avatarSoheil Hassas Yeganeh <soheil@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 84485080
...@@ -2865,7 +2865,7 @@ void __tcp_close(struct sock *sk, long timeout) ...@@ -2865,7 +2865,7 @@ void __tcp_close(struct sock *sk, long timeout)
if (sk->sk_state == TCP_FIN_WAIT2) { if (sk->sk_state == TCP_FIN_WAIT2) {
struct tcp_sock *tp = tcp_sk(sk); struct tcp_sock *tp = tcp_sk(sk);
if (tp->linger2 < 0) { if (READ_ONCE(tp->linger2) < 0) {
tcp_set_state(sk, TCP_CLOSE); tcp_set_state(sk, TCP_CLOSE);
tcp_send_active_reset(sk, GFP_ATOMIC); tcp_send_active_reset(sk, GFP_ATOMIC);
__NET_INC_STATS(sock_net(sk), __NET_INC_STATS(sock_net(sk),
...@@ -3471,6 +3471,14 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname, ...@@ -3471,6 +3471,14 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname,
return tcp_sock_set_keepintvl(sk, val); return tcp_sock_set_keepintvl(sk, val);
case TCP_KEEPCNT: case TCP_KEEPCNT:
return tcp_sock_set_keepcnt(sk, val); 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); sockopt_lock_sock(sk);
...@@ -3576,15 +3584,6 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname, ...@@ -3576,15 +3584,6 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname,
tp->save_syn = val; tp->save_syn = val;
break; 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: case TCP_DEFER_ACCEPT:
/* Translate value in seconds to number of retransmits */ /* Translate value in seconds to number of retransmits */
WRITE_ONCE(icsk->icsk_accept_queue.rskq_defer_accept, WRITE_ONCE(icsk->icsk_accept_queue.rskq_defer_accept,
......
...@@ -6624,7 +6624,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) ...@@ -6624,7 +6624,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)
break; break;
} }
if (tp->linger2 < 0) { if (READ_ONCE(tp->linger2) < 0) {
tcp_done(sk); tcp_done(sk);
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONDATA); NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONDATA);
return 1; return 1;
......
...@@ -714,7 +714,7 @@ static void tcp_keepalive_timer (struct timer_list *t) ...@@ -714,7 +714,7 @@ static void tcp_keepalive_timer (struct timer_list *t)
tcp_mstamp_refresh(tp); tcp_mstamp_refresh(tp);
if (sk->sk_state == TCP_FIN_WAIT2 && sock_flag(sk, SOCK_DEAD)) { 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; const int tmo = tcp_fin_time(sk) - TCP_TIMEWAIT_LEN;
if (tmo > 0) { if (tmo > 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment