tcp_tso_should_defer() last step tries to check if the probable
next ACK packet is coming in less than half rtt.

Problem is that the head->tstamp might be in the future,
so we need to use signed arithmetics to avoid overflows.

Signed-off-by: Eric Dumazet <eduma...@google.com>
Acked-by: Soheil Hassas Yeganeh <soh...@google.com>
---
 net/ipv4/tcp_output.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 
35feadf480300cd061411d65257f06ee658daa3c..78a56cef7e397c65ad18897d550f3800e8fe8f41
 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -1907,10 +1907,11 @@ static bool tcp_tso_should_defer(struct sock *sk, 
struct sk_buff *skb,
                                 bool *is_cwnd_limited, u32 max_segs)
 {
        const struct inet_connection_sock *icsk = inet_csk(sk);
-       u32 age, send_win, cong_win, limit, in_flight;
+       u32 send_win, cong_win, limit, in_flight;
        struct tcp_sock *tp = tcp_sk(sk);
        struct sk_buff *head;
        int win_divisor;
+       s64 delta;
 
        if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)
                goto send_now;
@@ -1972,9 +1973,9 @@ static bool tcp_tso_should_defer(struct sock *sk, struct 
sk_buff *skb,
        head = tcp_rtx_queue_head(sk);
        if (!head)
                goto send_now;
-       age = tcp_stamp_us_delta(tp->tcp_mstamp, tcp_skb_timestamp_us(head));
+       delta = tp->tcp_clock_cache - head->tstamp;
        /* If next ACK is likely to come too late (half srtt), do not defer */
-       if (age < (tp->srtt_us >> 4))
+       if ((s64)(delta - (u64)NSEC_PER_USEC * (tp->srtt_us >> 4)) < 0)
                goto send_now;
 
        /* Ok, it looks like it is advisable to defer. */
-- 
2.19.1.930.g4563a0d9d0-goog

Reply via email to