net: make unregister netdev warning timeout configurable
authorDmitry Vyukov <dvyukov@google.com>
Tue, 23 Mar 2021 06:49:23 +0000 (07:49 +0100)
committerDavid S. Miller <davem@davemloft.net>
Wed, 24 Mar 2021 00:22:50 +0000 (17:22 -0700)
netdev_wait_allrefs() issues a warning if refcount does not drop to 0
after 10 seconds. While 10 second wait generally should not happen
under normal workload in normal environment, it seems to fire falsely
very often during fuzzing and/or in qemu emulation (~10x slower).
At least it's not possible to understand if it's really a false
positive or not. Automated testing generally bumps all timeouts
to very high values to avoid flake failures.
Add net.core.netdev_unregister_timeout_secs sysctl to make
the timeout configurable for automated testing systems.
Lowering the timeout may also be useful for e.g. manual bisection.
The default value matches the current behavior.

Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=211877
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: David S. Miller <davem@davemloft.net>
Documentation/admin-guide/sysctl/net.rst
include/linux/netdevice.h
net/core/dev.c
net/core/sysctl_net_core.c

index f2ab8a5..2090bfc 100644 (file)
@@ -311,6 +311,17 @@ permit to distribute the load on several cpus.
 If set to 1 (default), timestamps are sampled as soon as possible, before
 queueing.
 
+netdev_unregister_timeout_secs
+------------------------------
+
+Unregister network device timeout in seconds.
+This option controls the timeout (in seconds) used to issue a warning while
+waiting for a network device refcount to drop to 0 during device
+unregistration. A lower value may be useful during bisection to detect
+a leaked reference faster. A larger value may be useful to prevent false
+warnings on slow/loaded systems.
+Default value is 10, minimum 0, maximum 3600.
+
 optmem_max
 ----------
 
index 7005ad8..5fa66db 100644 (file)
@@ -4661,6 +4661,7 @@ void dev_get_tstats64(struct net_device *dev, struct rtnl_link_stats64 *s);
 
 extern int             netdev_max_backlog;
 extern int             netdev_tstamp_prequeue;
+extern int             netdev_unregister_timeout_secs;
 extern int             weight_p;
 extern int             dev_weight_rx_bias;
 extern int             dev_weight_tx_bias;
index c9a496f..5153095 100644 (file)
@@ -10322,6 +10322,8 @@ int netdev_refcnt_read(const struct net_device *dev)
 }
 EXPORT_SYMBOL(netdev_refcnt_read);
 
+int netdev_unregister_timeout_secs __read_mostly = 10;
+
 #define WAIT_REFS_MIN_MSECS 1
 #define WAIT_REFS_MAX_MSECS 250
 /**
@@ -10383,7 +10385,9 @@ static void netdev_wait_allrefs(struct net_device *dev)
 
                refcnt = netdev_refcnt_read(dev);
 
-               if (refcnt != 1 && time_after(jiffies, warning_time + 10 * HZ)) {
+               if (refcnt &&
+                   time_after(jiffies, warning_time +
+                              netdev_unregister_timeout_secs * HZ)) {
                        pr_emerg("unregister_netdevice: waiting for %s to become free. Usage count = %d\n",
                                 dev->name, refcnt);
                        warning_time = jiffies;
index 4567de5..d84c8a1 100644 (file)
@@ -24,6 +24,7 @@
 
 static int two = 2;
 static int three = 3;
+static int int_3600 = 3600;
 static int min_sndbuf = SOCK_MIN_SNDBUF;
 static int min_rcvbuf = SOCK_MIN_RCVBUF;
 static int max_skb_frags = MAX_SKB_FRAGS;
@@ -570,6 +571,15 @@ static struct ctl_table net_core_table[] = {
                .proc_handler   = proc_dointvec_minmax,
                .extra1         = SYSCTL_ONE,
        },
+       {
+               .procname       = "netdev_unregister_timeout_secs",
+               .data           = &netdev_unregister_timeout_secs,
+               .maxlen         = sizeof(unsigned int),
+               .mode           = 0644,
+               .proc_handler   = proc_dointvec_minmax,
+               .extra1         = SYSCTL_ZERO,
+               .extra2         = &int_3600,
+       },
        { }
 };