1SK_HAS_SLEEPER(9) Linux Networking SK_HAS_SLEEPER(9)
2
3
4
6 sk_has_sleeper - check if there are any waiting processes
7
9 int sk_has_sleeper(struct sock * sk);
10
12 sk
13 socket
14
16 Returns true if socket has waiting processes
17
18 The purpose of the sk_has_sleeper and sock_poll_wait is to wrap the
19 memory barrier call. They were added due to the race found within the
20 tcp code.
21
23 CPU1 CPU2
24
25 sys_select receive packet ... ... __add_wait_queue update tp->rcv_nxt
26 ... ... tp->rcv_nxt check sock_def_readable ... { schedule ... if
27 (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
28 wake_up_interruptible(sk->sk_sleep) ... }
29
30 The race for tcp fires when the __add_wait_queue changes done by CPU1
31 stay in its cache, and so does the tp->rcv_nxt update on CPU2 side. The
32 CPU1 could then endup calling schedule and sleep forever if there are
33 no more data on the socket.
34
35 The sk_has_sleeper is always called right after a call to read_lock, so
36 we can use smp_mb__after_lock barrier.
37
39Kernel Hackers Manual 2.6. June 2019 SK_HAS_SLEEPER(9)