Patch "tcp: fix SO_RCVLOWAT related hangs under mem pressure" has been added to the 5.4-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    tcp: fix SO_RCVLOWAT related hangs under mem pressure

to the 5.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     tcp-fix-so_rcvlowat-related-hangs-under-mem-pressure.patch
and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit d2a42973008a8853cabbcc316fb34d8f47503218
Author: Eric Dumazet <edumazet@xxxxxxxxxx>
Date:   Fri Feb 12 15:22:13 2021 -0800

    tcp: fix SO_RCVLOWAT related hangs under mem pressure
    
    [ Upstream commit f969dc5a885736842c3511ecdea240fbb02d25d9 ]
    
    While commit 24adbc1676af ("tcp: fix SO_RCVLOWAT hangs with fat skbs")
    fixed an issue vs too small sk_rcvbuf for given sk_rcvlowat constraint,
    it missed to address issue caused by memory pressure.
    
    1) If we are under memory pressure and socket receive queue is empty.
    First incoming packet is allowed to be queued, after commit
    76dfa6082032 ("tcp: allow one skb to be received per socket under memory pressure")
    
    But we do not send EPOLLIN yet, in case tcp_data_ready() sees sk_rcvlowat
    is bigger than skb length.
    
    2) Then, when next packet comes, it is dropped, and we directly
    call sk->sk_data_ready().
    
    3) If application is using poll(), tcp_poll() will then use
    tcp_stream_is_readable() and decide the socket receive queue is
    not yet filled, so nothing will happen.
    
    Even when sender retransmits packets, phases 2) & 3) repeat
    and flow is effectively frozen, until memory pressure is off.
    
    Fix is to consider tcp_under_memory_pressure() to take care
    of global memory pressure or memcg pressure.
    
    Fixes: 24adbc1676af ("tcp: fix SO_RCVLOWAT hangs with fat skbs")
    Signed-off-by: Eric Dumazet <edumazet@xxxxxxxxxx>
    Reported-by: Arjun Roy <arjunroy@xxxxxxxxxx>
    Suggested-by: Wei Wang <weiwan@xxxxxxxxxx>
    Reviewed-by: Wei Wang <weiwan@xxxxxxxxxx>
    Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/include/net/tcp.h b/include/net/tcp.h
index 37b51456784f8..b914959cd2c67 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1409,8 +1409,13 @@ static inline int tcp_full_space(const struct sock *sk)
  */
 static inline bool tcp_rmem_pressure(const struct sock *sk)
 {
-	int rcvbuf = READ_ONCE(sk->sk_rcvbuf);
-	int threshold = rcvbuf - (rcvbuf >> 3);
+	int rcvbuf, threshold;
+
+	if (tcp_under_memory_pressure(sk))
+		return true;
+
+	rcvbuf = READ_ONCE(sk->sk_rcvbuf);
+	threshold = rcvbuf - (rcvbuf >> 3);
 
 	return atomic_read(&sk->sk_rmem_alloc) > threshold;
 }



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux