mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-22 23:04:43 +00:00
tcp: ensure proper barriers in lockless contexts
Some functions access TCP sockets without holding a lock and might output non consistent data, depending on compiler and or architecture. tcp_diag_get_info(), tcp_get_info(), tcp_poll(), get_tcp4_sock() ... Introduce sk_state_load() and sk_state_store() to fix the issues, and more clearly document where this lack of locking is happening. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
5883d9c6d7
commit
00fd38d938
6 changed files with 62 additions and 23 deletions
|
@ -2158,6 +2158,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i)
|
|||
__u16 destp = ntohs(inet->inet_dport);
|
||||
__u16 srcp = ntohs(inet->inet_sport);
|
||||
int rx_queue;
|
||||
int state;
|
||||
|
||||
if (icsk->icsk_pending == ICSK_TIME_RETRANS ||
|
||||
icsk->icsk_pending == ICSK_TIME_EARLY_RETRANS ||
|
||||
|
@ -2175,17 +2176,18 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i)
|
|||
timer_expires = jiffies;
|
||||
}
|
||||
|
||||
if (sk->sk_state == TCP_LISTEN)
|
||||
state = sk_state_load(sk);
|
||||
if (state == TCP_LISTEN)
|
||||
rx_queue = sk->sk_ack_backlog;
|
||||
else
|
||||
/*
|
||||
* because we dont lock socket, we might find a transient negative value
|
||||
/* Because we don't lock the socket,
|
||||
* we might find a transient negative value.
|
||||
*/
|
||||
rx_queue = max_t(int, tp->rcv_nxt - tp->copied_seq, 0);
|
||||
|
||||
seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
|
||||
"%08X %5u %8d %lu %d %pK %lu %lu %u %u %d",
|
||||
i, src, srcp, dest, destp, sk->sk_state,
|
||||
i, src, srcp, dest, destp, state,
|
||||
tp->write_seq - tp->snd_una,
|
||||
rx_queue,
|
||||
timer_active,
|
||||
|
@ -2199,8 +2201,8 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i)
|
|||
jiffies_to_clock_t(icsk->icsk_ack.ato),
|
||||
(icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
|
||||
tp->snd_cwnd,
|
||||
sk->sk_state == TCP_LISTEN ?
|
||||
(fastopenq ? fastopenq->max_qlen : 0) :
|
||||
state == TCP_LISTEN ?
|
||||
fastopenq->max_qlen :
|
||||
(tcp_in_initial_slowstart(tp) ? -1 : tp->snd_ssthresh));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue