tcp: add memory barriers to write space paths
authorjbaron@akamai.com <jbaron@akamai.com>
Mon, 20 Apr 2015 20:05:07 +0000 (20:05 +0000)
committerDavid S. Miller <davem@davemloft.net>
Tue, 21 Apr 2015 19:57:34 +0000 (15:57 -0400)
Ensure that we either see that the buffer has write space
in tcp_poll() or that we perform a wakeup from the input
side. Did not run into any actual problem here, but thought
that we should make things explicit.

Signed-off-by: Jason Baron <jbaron@akamai.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/tcp.c
net/ipv4/tcp_input.c

index 59c8a027721b2d7dcd8b8631a1ed686b530b4241..8c5cd9efebbcfa877fedb49dda67e3d098ccbbc1 100644 (file)
@@ -520,8 +520,10 @@ unsigned int tcp_poll(struct file *file, struct socket *sock, poll_table *wait)
 
                                /* Race breaker. If space is freed after
                                 * wspace test but before the flags are set,
-                                * IO signal will be lost.
+                                * IO signal will be lost. Memory barrier
+                                * pairs with the input side.
                                 */
+                               smp_mb__after_atomic();
                                if (sk_stream_is_writeable(sk))
                                        mask |= POLLOUT | POLLWRNORM;
                        }
index a7ef679dd3ea434e5b3bda48d391e1a872ed2478..3a4d9b34bed44a2f6b77b2be0e753867bad32292 100644 (file)
@@ -4845,6 +4845,8 @@ static void tcp_check_space(struct sock *sk)
 {
        if (sock_flag(sk, SOCK_QUEUE_SHRUNK)) {
                sock_reset_flag(sk, SOCK_QUEUE_SHRUNK);
+               /* pairs with tcp_poll() */
+               smp_mb__after_atomic();
                if (sk->sk_socket &&
                    test_bit(SOCK_NOSPACE, &sk->sk_socket->flags))
                        tcp_new_space(sk);