On Wed, May 15, 2024 at 07:10:49PM -0400, Jon Maloy wrote: > > > On 2024-05-15 16:24, Stefano Brivio wrote: > > On Wed, 15 May 2024 11:34:29 -0400 > > Jon Maloy wrote: > > > > > A bug in kernel TCP may lead to a deadlock where a zero window is sent > > > from the peer, while it is unable to send out window updates even after > > > reads have freed up enough buffer space to permit a larger window. > > > In this situation, new window advertisemnts from the peer can only be > > > triggered by packets arriving from this side. > > > > > > However, such packets are never sent, because the zero-window condition > > > currently prevents this side from sending out any packets whatsoever > > > to the peer. > > > > > > We notice that the above bug is triggered *only* after the peer has > > > dropped an arriving packet because of severe memory squeeze, and that we > > > hence always enter a retransmission situation when this occurs. This > > > also means that it goes against the RFC 9293 recommendation that a > > > previously advertised window never should shrink. > > > > > > RFC 9293 gives the solution to this situation. In chapter 3.6.1 we find > > > the following statement: > > > "A TCP receiver SHOULD NOT shrink the window, i.e., move the right > > > window edge to the left (SHLD-14). However, a sending TCP peer MUST > > > be robust against window shrinking, which may cause the > > > "usable window" (see Section 3.8.6.2.1) to become negative (MUST-34). > > > > > > If this happens, the sender SHOULD NOT send new data (SHLD-15), but > > > SHOULD retransmit normally the old unacknowledged data between SND.UNA > > > and SND.UNA+SND.WND (SHLD-16). The sender MAY also retransmit old data > > > beyond SND.UNA+SND.WND (MAY-7)" > > > > > > We never see the window become negative, but we interpret this as a > > > recommendation to use the previously available window during > > > retransmission even when the currently advertised window is zero. > > > > > > We use the above mechanism only at timer-induced retransmits. > > > In the case we receive duplicate ack and a zero window, but > > > still know we have outstanding data acks waiting, we send out an > > > empty "fast probe" instead of doing fast retransmit. This averts > > > the risk of overwhelming a memory squeezed peer with retransmits, > > > while still forcing it to send out a new window update when the > > > probe is received. This entails a theoretical risk of redundant > > > retransmits from the peer, but that is a risk worth taking. > > > > > > In case of a zero-window non-retransmission situation where there > > > is no new data to be sent, we also add a simple zero-window probing > > > feature. By sending an empty packet at regular timeout events we > > > resolve the situation described above, since the peer receives the > > > necessary trigger to advertise its window once it becomes non-zero > > > again. > > > > > > It should be noted that although this solves the problem we have at > > > hand, it is not a genuine solution to the kernel bug. There may well > > > be TCP stacks around in other OS-es which don't do this, nor have > > > keep-alive probing as an alternatve way to solve the situation. > > > > > > Signed-off-by: Jon Maloy > > > > > > --- > > > v2: - Using previously advertised window during retransmission, instead > > > highest send sequencece number in the cycle. > > > v3: - Rebased to newest code > > > - Changes based on feedback from PASST team > > > - Sending out empty probe message at timer expiration when > > > we are not in retransmit situation. > > > v4: - Some small changes based on feedback from PASST team. > > > - Replaced fast retransmit with a one-time 'fast probe' when > > > window is zero. > > > --- > > > tcp.c | 32 +++++++++++++++++++++++++++----- > > > tcp_conn.h | 2 ++ > > > 2 files changed, 29 insertions(+), 5 deletions(-) > > > > > > diff --git a/tcp.c b/tcp.c > > > index 4163bf9..a33f494 100644 > > > --- a/tcp.c > > > +++ b/tcp.c > > > @@ -1761,9 +1761,15 @@ static void tcp_get_tap_ws(struct tcp_tap_conn *conn, > > > */ > > > static void tcp_tap_window_update(struct tcp_tap_conn *conn, unsigned wnd) > > > { > > > + uint32_t wnd_edge; > > > + > > > wnd = MIN(MAX_WINDOW, wnd << conn->ws_from_tap); > > > conn->wnd_from_tap = MIN(wnd >> conn->ws_from_tap, USHRT_MAX); > > > + wnd_edge = conn->seq_ack_from_tap + wnd; > > > + if (wnd && SEQ_GT(wnd_edge, conn->seq_wnd_edge_from_tap)) > > Here, cppcheck ('make cppcheck') says: > > > > tcp.c:1770:6: style: Condition 'wnd' is always true [knownConditionTrueFalse] > > if (wnd && SEQ_GT(wnd_edge, conn->seq_wnd_edge_from_tap)) > > ^ > > tcp.c:1766:8: note: Assignment 'wnd=((1<<(16+8))<(wnd<ws_from_tap))?(1<<(16+8)):(wnd<ws_from_tap)', assigned value is less than 1 > > wnd = MIN(MAX_WINDOW, wnd << conn->ws_from_tap); > > ^ > > tcp.c:1770:6: note: Condition 'wnd' is always true > > if (wnd && SEQ_GT(wnd_edge, conn->seq_wnd_edge_from_tap)) > > ^ > > > > See the comment in tcp_update_seqack_wnd() and related suppression. > > > > It's clearly a false positive (if you omit the MIN() macro, it goes > > away), so we need that same suppression here. > Ok. I'll change it. Still a little annoying when our tools are causing us > extra job because they aren't up to the task. Yeah, it's frustrating, particularly the fact that this was reported ages ago and there's no sign of motion on fixing it. But, I'm pretty sure cppcheck has caught considerably more than two bugs for me that might have taken a while to catch otherwise, so I still think it's worth using on balance. -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson