aboutsummaryrefslogtreecommitdiffstats
path: root/net/unix
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@redhat.com>2009-07-08 08:09:13 -0400
committerDavid S. Miller <davem@davemloft.net>2009-07-09 20:06:57 -0400
commita57de0b4336e48db2811a2030bb68dba8dd09d88 (patch)
treea01c189d5fd55c69c9e2e842241e84b46728bc60 /net/unix
parent1b614fb9a00e97b1eab54d4e442d405229c059dd (diff)
net: adding memory barrier to the poll and receive callbacks
Adding memory barrier after the poll_wait function, paired with receive callbacks. Adding fuctions sock_poll_wait and sk_has_sleeper to wrap the memory barrier. Without the memory barrier, following race can happen. The race fires, when following code paths meet, and the tp->rcv_nxt and __add_wait_queue updates stay in CPU caches. CPU1 CPU2 sys_select receive packet ... ... __add_wait_queue update tp->rcv_nxt ... ... tp->rcv_nxt check sock_def_readable ... { schedule ... if (sk->sk_sleep && waitqueue_active(sk->sk_sleep)) wake_up_interruptible(sk->sk_sleep) ... } If there was no cache the code would work ok, since the wait_queue and rcv_nxt are opposit to each other. Meaning that once tp->rcv_nxt is updated by CPU2, the CPU1 either already passed the tp->rcv_nxt check and sleeps, or will get the new value for tp->rcv_nxt and will return with new data mask. In both cases the process (CPU1) is being added to the wait queue, so the waitqueue_active (CPU2) call cannot miss and will wake up CPU1. The bad case is when the __add_wait_queue changes done by CPU1 stay in its cache, and so does the tp->rcv_nxt update on CPU2 side. The CPU1 will then endup calling schedule and sleep forever if there are no more data on the socket. Calls to poll_wait in following modules were ommited: net/bluetooth/af_bluetooth.c net/irda/af_irda.c net/irda/irnet/irnet_ppp.c net/mac80211/rc80211_pid_debugfs.c net/phonet/socket.c net/rds/af_rds.c net/rfkill/core.c net/sunrpc/cache.c net/sunrpc/rpc_pipe.c net/tipc/socket.c Signed-off-by: Jiri Olsa <jolsa@redhat.com> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/unix')
-rw-r--r--net/unix/af_unix.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 36d4e44d6233..fc3ebb906911 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -315,7 +315,7 @@ static void unix_write_space(struct sock *sk)
315{ 315{
316 read_lock(&sk->sk_callback_lock); 316 read_lock(&sk->sk_callback_lock);
317 if (unix_writable(sk)) { 317 if (unix_writable(sk)) {
318 if (sk->sk_sleep && waitqueue_active(sk->sk_sleep)) 318 if (sk_has_sleeper(sk))
319 wake_up_interruptible_sync(sk->sk_sleep); 319 wake_up_interruptible_sync(sk->sk_sleep);
320 sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT); 320 sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);
321 } 321 }
@@ -1985,7 +1985,7 @@ static unsigned int unix_poll(struct file *file, struct socket *sock, poll_table
1985 struct sock *sk = sock->sk; 1985 struct sock *sk = sock->sk;
1986 unsigned int mask; 1986 unsigned int mask;
1987 1987
1988 poll_wait(file, sk->sk_sleep, wait); 1988 sock_poll_wait(file, sk->sk_sleep, wait);
1989 mask = 0; 1989 mask = 0;
1990 1990
1991 /* exceptional events? */ 1991 /* exceptional events? */
@@ -2022,7 +2022,7 @@ static unsigned int unix_dgram_poll(struct file *file, struct socket *sock,
2022 struct sock *sk = sock->sk, *other; 2022 struct sock *sk = sock->sk, *other;
2023 unsigned int mask, writable; 2023 unsigned int mask, writable;
2024 2024
2025 poll_wait(file, sk->sk_sleep, wait); 2025 sock_poll_wait(file, sk->sk_sleep, wait);
2026 mask = 0; 2026 mask = 0;
2027 2027
2028 /* exceptional events? */ 2028 /* exceptional events? */
@@ -2053,7 +2053,7 @@ static unsigned int unix_dgram_poll(struct file *file, struct socket *sock,
2053 other = unix_peer_get(sk); 2053 other = unix_peer_get(sk);
2054 if (other) { 2054 if (other) {
2055 if (unix_peer(other) != sk) { 2055 if (unix_peer(other) != sk) {
2056 poll_wait(file, &unix_sk(other)->peer_wait, 2056 sock_poll_wait(file, &unix_sk(other)->peer_wait,
2057 wait); 2057 wait);
2058 if (unix_recvq_full(other)) 2058 if (unix_recvq_full(other))
2059 writable = 0; 2059 writable = 0;