History

net: watchdog: add net device refcount tracker

Add a netdevice_tracker inside struct net_device, to track the self reference when a device has an active watchdog timer.

Eric Dumazet committed 4 years ago

Commit f12bf6f1 parent b2dcdc72 files · +8 −4Browse files

Unified · Split

2 files
  1. include/linux/netdevice.h +2 −0
  2. net/sched/sch_generic.c +6 −4
include/linux/netdevice.h+2−0
@@ -1951,6 +1951,7 @@ enum netdev_ml_priv_type { · 1950 unmodified lines
19511951 *
19521952 * @dev_addr_shadow: Copy of @dev_addr to catch direct writes.
19531953 * @linkwatch_dev_tracker: refcount tracker used by linkwatch.
1954+ * @watchdog_dev_tracker: refcount tracker used by watchdog.
19541955 *
19551956 * FIXME: cleanup struct net_device such that network protocol info
19561957 * moves out.
@@ -2282,6 +2283,7 @@ struct net_device { · 325 unmodified lines
22822283
22832284 u8 dev_addr_shadow[MAX_ADDR_LEN];
22842285 netdevice_tracker linkwatch_dev_tracker;
2286+ netdevice_tracker watchdog_dev_tracker;
22852287 };
22862288 #define to_net_dev(d) container_of(d, struct net_device, dev)
22872289
net/sched/sch_generic.c+6−4
@@ -499,6 +499,7 @@ EXPORT_SYMBOL(netif_tx_unlock); · 498 unmodified lines
499499 static void dev_watchdog(struct timer_list *t)
500500 {
501501 struct net_device *dev = from_timer(dev, t, watchdog_timer);
502+ bool release = true;
502503
503504 spin_lock(&dev->tx_global_lock);
504505 if (!qdisc_tx_is_noop(dev)) {
@@ -534,12 +535,13 @@ static void dev_watchdog(struct timer_list *t) · 29 unmodified lines
534535 if (!mod_timer(&dev->watchdog_timer,
535536 round_jiffies(jiffies +
536537 dev->watchdog_timeo)))
537− dev_hold(dev);
538+ release = false;
538539 }
539540 }
540541 spin_unlock(&dev->tx_global_lock);
541542
542− dev_put(dev);
543+ if (release)
544+ dev_put_track(dev, &dev->watchdog_dev_tracker);
543545 }
544546
545547 void __netdev_watchdog_up(struct net_device *dev)
@@ -549,7 +551,7 @@ void __netdev_watchdog_up(struct net_device *dev) · 3 unmodified lines
549551 dev->watchdog_timeo = 5*HZ;
550552 if (!mod_timer(&dev->watchdog_timer,
551553 round_jiffies(jiffies + dev->watchdog_timeo)))
552− dev_hold(dev);
554+ dev_hold_track(dev, &dev->watchdog_dev_tracker, GFP_ATOMIC);
553555 }
554556 }
555557 EXPORT_SYMBOL_GPL(__netdev_watchdog_up);
@@ -563,7 +565,7 @@ static void dev_watchdog_down(struct net_device *dev) · 7 unmodified lines
563565 {
564566 netif_tx_lock_bh(dev);
565567 if (del_timer(&dev->watchdog_timer))
566− dev_put(dev);
568+ dev_put_track(dev, &dev->watchdog_dev_tracker);
567569 netif_tx_unlock_bh(dev);
568570 }
569571