Commit 95774e38 authored by Eric Dumazet's avatar Eric Dumazet Committed by Kleber Sacilotto de Souza

tcp: make sure EPOLLOUT wont be missed

BugLink: https://bugs.launchpad.net/bugs/1845036

[ Upstream commit ef8d8ccd ]

As Jason Baron explained in commit 790ba456 ("tcp: set SOCK_NOSPACE
under memory pressure"), it is crucial we properly set SOCK_NOSPACE
when needed.

However, Jason patch had a bug, because the 'nonblocking' status
as far as sk_stream_wait_memory() is concerned is governed
by MSG_DONTWAIT flag passed at sendmsg() time :

    long timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT);

So it is very possible that tcp sendmsg() calls sk_stream_wait_memory(),
and that sk_stream_wait_memory() returns -EAGAIN with SOCK_NOSPACE
cleared, if sk->sk_sndtimeo has been set to a small (but not zero)
value.

This patch removes the 'noblock' variable since we must always
set SOCK_NOSPACE if -EAGAIN is returned.

It also renames the do_nonblock label since we might reach this
code path even if we were in blocking mode.

Fixes: 790ba456 ("tcp: set SOCK_NOSPACE under memory pressure")
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Cc: Jason Baron <jbaron@akamai.com>
Reported-by: default avatarVladimir Rutsky  <rutsky@google.com>
Acked-by: default avatarSoheil Hassas Yeganeh <soheil@google.com>
Acked-by: default avatarNeal Cardwell <ncardwell@google.com>
Acked-by: default avatarJason Baron <jbaron@akamai.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarConnor Kuehl <connor.kuehl@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent f88a55f9
...@@ -119,7 +119,6 @@ int sk_stream_wait_memory(struct sock *sk, long *timeo_p) ...@@ -119,7 +119,6 @@ int sk_stream_wait_memory(struct sock *sk, long *timeo_p)
int err = 0; int err = 0;
long vm_wait = 0; long vm_wait = 0;
long current_timeo = *timeo_p; long current_timeo = *timeo_p;
bool noblock = (*timeo_p ? false : true);
DEFINE_WAIT(wait); DEFINE_WAIT(wait);
if (sk_stream_memory_free(sk)) if (sk_stream_memory_free(sk))
...@@ -132,11 +131,8 @@ int sk_stream_wait_memory(struct sock *sk, long *timeo_p) ...@@ -132,11 +131,8 @@ int sk_stream_wait_memory(struct sock *sk, long *timeo_p)
if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)) if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN))
goto do_error; goto do_error;
if (!*timeo_p) { if (!*timeo_p)
if (noblock) goto do_eagain;
set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
goto do_nonblock;
}
if (signal_pending(current)) if (signal_pending(current))
goto do_interrupted; goto do_interrupted;
sk_clear_bit(SOCKWQ_ASYNC_NOSPACE, sk); sk_clear_bit(SOCKWQ_ASYNC_NOSPACE, sk);
...@@ -168,7 +164,13 @@ int sk_stream_wait_memory(struct sock *sk, long *timeo_p) ...@@ -168,7 +164,13 @@ int sk_stream_wait_memory(struct sock *sk, long *timeo_p)
do_error: do_error:
err = -EPIPE; err = -EPIPE;
goto out; goto out;
do_nonblock: do_eagain:
/* Make sure that whenever EAGAIN is returned, EPOLLOUT event can
* be generated later.
* When TCP receives ACK packets that make room, tcp_check_space()
* only calls tcp_new_space() if SOCK_NOSPACE is set.
*/
set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
err = -EAGAIN; err = -EAGAIN;
goto out; goto out;
do_interrupted: do_interrupted:
......
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