Commit 70f360dd authored by Eric Dumazet's avatar Eric Dumazet Committed by Jakub Kicinski

tcp: annotate data-races around fastopenq.max_qlen

This field can be read locklessly.

Fixes: 1536e285 ("tcp: Add a TCP_FASTOPEN socket option to get a max backlog on its listner")
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/20230719212857.3943972-12-edumazet@google.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 26023e91
...@@ -513,7 +513,7 @@ static inline void fastopen_queue_tune(struct sock *sk, int backlog) ...@@ -513,7 +513,7 @@ static inline void fastopen_queue_tune(struct sock *sk, int backlog)
struct request_sock_queue *queue = &inet_csk(sk)->icsk_accept_queue; struct request_sock_queue *queue = &inet_csk(sk)->icsk_accept_queue;
int somaxconn = READ_ONCE(sock_net(sk)->core.sysctl_somaxconn); int somaxconn = READ_ONCE(sock_net(sk)->core.sysctl_somaxconn);
queue->fastopenq.max_qlen = min_t(unsigned int, backlog, somaxconn); WRITE_ONCE(queue->fastopenq.max_qlen, min_t(unsigned int, backlog, somaxconn));
} }
static inline void tcp_move_syn(struct tcp_sock *tp, static inline void tcp_move_syn(struct tcp_sock *tp,
......
...@@ -4145,7 +4145,7 @@ int do_tcp_getsockopt(struct sock *sk, int level, ...@@ -4145,7 +4145,7 @@ int do_tcp_getsockopt(struct sock *sk, int level,
break; break;
case TCP_FASTOPEN: case TCP_FASTOPEN:
val = icsk->icsk_accept_queue.fastopenq.max_qlen; val = READ_ONCE(icsk->icsk_accept_queue.fastopenq.max_qlen);
break; break;
case TCP_FASTOPEN_CONNECT: case TCP_FASTOPEN_CONNECT:
......
...@@ -296,6 +296,7 @@ static struct sock *tcp_fastopen_create_child(struct sock *sk, ...@@ -296,6 +296,7 @@ static struct sock *tcp_fastopen_create_child(struct sock *sk,
static bool tcp_fastopen_queue_check(struct sock *sk) static bool tcp_fastopen_queue_check(struct sock *sk)
{ {
struct fastopen_queue *fastopenq; struct fastopen_queue *fastopenq;
int max_qlen;
/* Make sure the listener has enabled fastopen, and we don't /* Make sure the listener has enabled fastopen, and we don't
* exceed the max # of pending TFO requests allowed before trying * exceed the max # of pending TFO requests allowed before trying
...@@ -308,10 +309,11 @@ static bool tcp_fastopen_queue_check(struct sock *sk) ...@@ -308,10 +309,11 @@ static bool tcp_fastopen_queue_check(struct sock *sk)
* temporarily vs a server not supporting Fast Open at all. * temporarily vs a server not supporting Fast Open at all.
*/ */
fastopenq = &inet_csk(sk)->icsk_accept_queue.fastopenq; fastopenq = &inet_csk(sk)->icsk_accept_queue.fastopenq;
if (fastopenq->max_qlen == 0) max_qlen = READ_ONCE(fastopenq->max_qlen);
if (max_qlen == 0)
return false; return false;
if (fastopenq->qlen >= fastopenq->max_qlen) { if (fastopenq->qlen >= max_qlen) {
struct request_sock *req1; struct request_sock *req1;
spin_lock(&fastopenq->lock); spin_lock(&fastopenq->lock);
req1 = fastopenq->rskq_rst_head; req1 = fastopenq->rskq_rst_head;
......
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