Commit 6f54c27651df94b564dec0d66954ed190c8ef811

Authored by Wei Liu
Committed by Greg Kroah-Hartman
1 parent 1527a1e413

xen-netback: use jiffies_64 value to calculate credit timeout

[ Upstream commit 059dfa6a93b779516321e5112db9d7621b1367ba ]

time_after_eq() only works if the delta is < MAX_ULONG/2.

For a 32bit Dom0, if netfront sends packets at a very low rate, the time
between subsequent calls to tx_credit_exceeded() may exceed MAX_ULONG/2
and the test for timer_after_eq() will be incorrect. Credit will not be
replenished and the guest may become unable to send packets (e.g., if
prior to the long gap, all credit was exhausted).

Use jiffies_64 variant to mitigate this problem for 32bit Dom0.

Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: David Vrabel <david.vrabel@citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Jason Luan <jianhai.luan@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 3 changed files with 7 additions and 7 deletions Side-by-side Diff

drivers/net/xen-netback/common.h
... ... @@ -92,6 +92,7 @@
92 92 unsigned long credit_usec;
93 93 unsigned long remaining_credit;
94 94 struct timer_list credit_timeout;
  95 + u64 credit_window_start;
95 96  
96 97 /* Statistics */
97 98 unsigned long rx_gso_checksum_fixup;
drivers/net/xen-netback/interface.c
... ... @@ -297,8 +297,7 @@
297 297 vif->credit_bytes = vif->remaining_credit = ~0UL;
298 298 vif->credit_usec = 0UL;
299 299 init_timer(&vif->credit_timeout);
300   - /* Initialize 'expires' now: it's used to track the credit window. */
301   - vif->credit_timeout.expires = jiffies;
  300 + vif->credit_window_start = get_jiffies_64();
302 301  
303 302 dev->netdev_ops = &xenvif_netdev_ops;
304 303 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO;
drivers/net/xen-netback/netback.c
... ... @@ -1430,9 +1430,8 @@
1430 1430  
1431 1431 static bool tx_credit_exceeded(struct xenvif *vif, unsigned size)
1432 1432 {
1433   - unsigned long now = jiffies;
1434   - unsigned long next_credit =
1435   - vif->credit_timeout.expires +
  1433 + u64 now = get_jiffies_64();
  1434 + u64 next_credit = vif->credit_window_start +
1436 1435 msecs_to_jiffies(vif->credit_usec / 1000);
1437 1436  
1438 1437 /* Timer could already be pending in rare cases. */
... ... @@ -1440,8 +1439,8 @@
1440 1439 return true;
1441 1440  
1442 1441 /* Passed the point where we can replenish credit? */
1443   - if (time_after_eq(now, next_credit)) {
1444   - vif->credit_timeout.expires = now;
  1442 + if (time_after_eq64(now, next_credit)) {
  1443 + vif->credit_window_start = now;
1445 1444 tx_add_credit(vif);
1446 1445 }
1447 1446  
... ... @@ -1453,6 +1452,7 @@
1453 1452 tx_credit_callback;
1454 1453 mod_timer(&vif->credit_timeout,
1455 1454 next_credit);
  1455 + vif->credit_window_start = next_credit;
1456 1456  
1457 1457 return true;
1458 1458 }