提交 4f3df7f1 编写于 作者: E Eric Dumazet 提交者: Greg Kroah-Hartman

net: use skb_queue_empty_lockless() in busy poll contexts

[ Upstream commit 3f926af3f4d688e2e11e7f8ed04e277a14d4d4a4 ]

Busy polling usually runs without locks.
Let's use skb_queue_empty_lockless() instead of skb_queue_empty()

Also uses READ_ONCE() in __skb_try_recv_datagram() to address
a similar potential problem.
Signed-off-by: NEric Dumazet <edumazet@google.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 eaf548fe
...@@ -1716,7 +1716,7 @@ int chtls_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, ...@@ -1716,7 +1716,7 @@ int chtls_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
return peekmsg(sk, msg, len, nonblock, flags); return peekmsg(sk, msg, len, nonblock, flags);
if (sk_can_busy_loop(sk) && if (sk_can_busy_loop(sk) &&
skb_queue_empty(&sk->sk_receive_queue) && skb_queue_empty_lockless(&sk->sk_receive_queue) &&
sk->sk_state == TCP_ESTABLISHED) sk->sk_state == TCP_ESTABLISHED)
sk_busy_loop(sk, nonblock); sk_busy_loop(sk, nonblock);
......
...@@ -279,7 +279,7 @@ struct sk_buff *__skb_try_recv_datagram(struct sock *sk, unsigned int flags, ...@@ -279,7 +279,7 @@ struct sk_buff *__skb_try_recv_datagram(struct sock *sk, unsigned int flags,
break; break;
sk_busy_loop(sk, flags & MSG_DONTWAIT); sk_busy_loop(sk, flags & MSG_DONTWAIT);
} while (sk->sk_receive_queue.prev != *last); } while (READ_ONCE(sk->sk_receive_queue.prev) != *last);
error = -EAGAIN; error = -EAGAIN;
......
...@@ -3483,7 +3483,7 @@ bool sk_busy_loop_end(void *p, unsigned long start_time) ...@@ -3483,7 +3483,7 @@ bool sk_busy_loop_end(void *p, unsigned long start_time)
{ {
struct sock *sk = p; struct sock *sk = p;
return !skb_queue_empty(&sk->sk_receive_queue) || return !skb_queue_empty_lockless(&sk->sk_receive_queue) ||
sk_busy_loop_timeout(sk, start_time); sk_busy_loop_timeout(sk, start_time);
} }
EXPORT_SYMBOL(sk_busy_loop_end); EXPORT_SYMBOL(sk_busy_loop_end);
......
...@@ -1948,7 +1948,7 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonblock, ...@@ -1948,7 +1948,7 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonblock,
if (unlikely(flags & MSG_ERRQUEUE)) if (unlikely(flags & MSG_ERRQUEUE))
return inet_recv_error(sk, msg, len, addr_len); return inet_recv_error(sk, msg, len, addr_len);
if (sk_can_busy_loop(sk) && skb_queue_empty(&sk->sk_receive_queue) && if (sk_can_busy_loop(sk) && skb_queue_empty_lockless(&sk->sk_receive_queue) &&
(sk->sk_state == TCP_ESTABLISHED)) (sk->sk_state == TCP_ESTABLISHED))
sk_busy_loop(sk, nonblock); sk_busy_loop(sk, nonblock);
......
...@@ -8334,7 +8334,7 @@ struct sk_buff *sctp_skb_recv_datagram(struct sock *sk, int flags, ...@@ -8334,7 +8334,7 @@ struct sk_buff *sctp_skb_recv_datagram(struct sock *sk, int flags,
if (sk_can_busy_loop(sk)) { if (sk_can_busy_loop(sk)) {
sk_busy_loop(sk, noblock); sk_busy_loop(sk, noblock);
if (!skb_queue_empty(&sk->sk_receive_queue)) if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
continue; continue;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册