@@ -1751,4 +1751,21 @@ static inline void skb_set_tcp_pure_ack(struct sk_buff *skb)
skb->truesize = 2;
}
+/* Convert msecs to jiffies, ensuring that the return value is always at least
+ * 2 jiffies.
+ * This can be used when setting tick-based timers to guarantee that they won't
+ * expire right away.
+ */
+static inline unsigned long tcp_safe_msecs_to_jiffies(const unsigned int m)
+{
+ if (__builtin_constant_p(m)) {
+ if (m * HZ > MSEC_PER_SEC)
+ return msecs_to_jiffies(m);
+
+ return 2;
+ }
+
+ return max_t(u32, 2, msecs_to_jiffies(m));
+}
+
#endif /* _TCP_H */
@@ -2207,7 +2207,7 @@ bool tcp_schedule_loss_probe(struct sock *sk)
if (tp->packets_out == 1)
timeout = max_t(u32, timeout,
(rtt + (rtt >> 1) + TCP_DELACK_MAX));
- timeout = max_t(u32, timeout, msecs_to_jiffies(10));
+ timeout = max_t(u32, timeout, tcp_safe_msecs_to_jiffies(10));
/* If RTO is shorter, just schedule TLP in its place. */
tlp_time_stamp = tcp_time_stamp + timeout;