Commit d4011239 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

tcp: guarantee forward progress in tcp_sendmsg()

Under high rx pressure, it is possible tcp_sendmsg() never has a
chance to allocate an skb and loop forever as sk_flush_backlog()
would always return true.

Fix this by calling sk_flush_backlog() only if one skb had been
allocated and filled before last backlog check.

Fixes: d41a69f1 ("tcp: make tcp_sendmsg() aware of socket backlog")
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Acked-by: default avatarSoheil Hassas Yeganeh <soheil@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent cba65321
...@@ -1084,6 +1084,7 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) ...@@ -1084,6 +1084,7 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
struct sockcm_cookie sockc; struct sockcm_cookie sockc;
int flags, err, copied = 0; int flags, err, copied = 0;
int mss_now = 0, size_goal, copied_syn = 0; int mss_now = 0, size_goal, copied_syn = 0;
bool process_backlog = false;
bool sg; bool sg;
long timeo; long timeo;
...@@ -1167,9 +1168,10 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) ...@@ -1167,9 +1168,10 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
if (!sk_stream_memory_free(sk)) if (!sk_stream_memory_free(sk))
goto wait_for_sndbuf; goto wait_for_sndbuf;
if (sk_flush_backlog(sk)) if (process_backlog && sk_flush_backlog(sk)) {
process_backlog = false;
goto restart; goto restart;
}
skb = sk_stream_alloc_skb(sk, skb = sk_stream_alloc_skb(sk,
select_size(sk, sg), select_size(sk, sg),
sk->sk_allocation, sk->sk_allocation,
...@@ -1177,6 +1179,7 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) ...@@ -1177,6 +1179,7 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
if (!skb) if (!skb)
goto wait_for_memory; goto wait_for_memory;
process_backlog = true;
/* /*
* Check whether we can use HW checksum. * Check whether we can use HW checksum.
*/ */
......
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