Skip to content

Commit 5aa3afe

Browse files
dvyukovdavem330
authored andcommitted
net: make unregister netdev warning timeout configurable
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 <[email protected]> Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=211877 Cc: [email protected] Cc: [email protected] Signed-off-by: David S. Miller <[email protected]>
1 parent 4c94fe8 commit 5aa3afe

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

Documentation/admin-guide/sysctl/net.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,17 @@ permit to distribute the load on several cpus.
311311
If set to 1 (default), timestamps are sampled as soon as possible, before
312312
queueing.
313313

314+
netdev_unregister_timeout_secs
315+
------------------------------
316+
317+
Unregister network device timeout in seconds.
318+
This option controls the timeout (in seconds) used to issue a warning while
319+
waiting for a network device refcount to drop to 0 during device
320+
unregistration. A lower value may be useful during bisection to detect
321+
a leaked reference faster. A larger value may be useful to prevent false
322+
warnings on slow/loaded systems.
323+
Default value is 10, minimum 0, maximum 3600.
324+
314325
optmem_max
315326
----------
316327

include/linux/netdevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4661,6 +4661,7 @@ void dev_get_tstats64(struct net_device *dev, struct rtnl_link_stats64 *s);
46614661

46624662
extern int netdev_max_backlog;
46634663
extern int netdev_tstamp_prequeue;
4664+
extern int netdev_unregister_timeout_secs;
46644665
extern int weight_p;
46654666
extern int dev_weight_rx_bias;
46664667
extern int dev_weight_tx_bias;

net/core/dev.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10322,6 +10322,8 @@ int netdev_refcnt_read(const struct net_device *dev)
1032210322
}
1032310323
EXPORT_SYMBOL(netdev_refcnt_read);
1032410324

10325+
int netdev_unregister_timeout_secs __read_mostly = 10;
10326+
1032510327
#define WAIT_REFS_MIN_MSECS 1
1032610328
#define WAIT_REFS_MAX_MSECS 250
1032710329
/**
@@ -10383,7 +10385,9 @@ static void netdev_wait_allrefs(struct net_device *dev)
1038310385

1038410386
refcnt = netdev_refcnt_read(dev);
1038510387

10386-
if (refcnt != 1 && time_after(jiffies, warning_time + 10 * HZ)) {
10388+
if (refcnt &&
10389+
time_after(jiffies, warning_time +
10390+
netdev_unregister_timeout_secs * HZ)) {
1038710391
pr_emerg("unregister_netdevice: waiting for %s to become free. Usage count = %d\n",
1038810392
dev->name, refcnt);
1038910393
warning_time = jiffies;

net/core/sysctl_net_core.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
static int two = 2;
2626
static int three = 3;
27+
static int int_3600 = 3600;
2728
static int min_sndbuf = SOCK_MIN_SNDBUF;
2829
static int min_rcvbuf = SOCK_MIN_RCVBUF;
2930
static int max_skb_frags = MAX_SKB_FRAGS;
@@ -570,6 +571,15 @@ static struct ctl_table net_core_table[] = {
570571
.proc_handler = proc_dointvec_minmax,
571572
.extra1 = SYSCTL_ONE,
572573
},
574+
{
575+
.procname = "netdev_unregister_timeout_secs",
576+
.data = &netdev_unregister_timeout_secs,
577+
.maxlen = sizeof(unsigned int),
578+
.mode = 0644,
579+
.proc_handler = proc_dointvec_minmax,
580+
.extra1 = SYSCTL_ZERO,
581+
.extra2 = &int_3600,
582+
},
573583
{ }
574584
};
575585

0 commit comments

Comments
 (0)