net: add preliminary netdev refcount tracking
Subsystems (11)
v2 cover net: add preliminary netdev refcount tracking
From: Eric Dumazet <[email protected]>
Two first patches add a generic infrastructure, that will be used to get tracking of refcount increments/decrements.
The general idea is to be able to precisely pair each decrement with a corresponding prior increment. Both share a cookie, basically a pointer to private data storing stack traces.
The third place adds dev_hold_track() and dev_put_track() helpers (CONFIG_NET_DEV_REFCNT_TRACKER)
Then a series of 20 patches converts some dev_hold()/dev_put() pairs to new hepers : dev_hold_track() and dev_put_track().
Hopefully this will be used by developpers and syzbot to root cause bugs that cause netdevice dismantles freezes.
With CONFIG_PCPU_DEV_REFCNT=n option, we were able to detect some class of bugs, but too late (when too many dev_put() were happening).
v2: added four additional patches,
added netdev_tracker_alloc() and netdev_tracker_free() addressed build error (kernel bots),
use GFP_ATOMIC in test_ref_tracker_timer_func()
Eric Dumazet (23):
lib: add reference counting tracking infrastructure
lib: add tests for reference tracker
net: add dev_hold_track() and dev_put_track() helpers
net: add net device refcount tracker to struct netdev_rx_queue
net: add net device refcount tracker to struct netdev_queue
net: add net device refcount tracker to ethtool_phys_id()
net: add net device refcount tracker to dev_ifsioc()
drop_monitor: add net device refcount tracker
net: dst: add net device refcount tracking to dst_entry
ipv6: add net device refcount tracker to rt6_probe_deferred()
sit: add net device refcount tracking to ip_tunnel
ipv6: add net device refcount tracker to struct ip6_tnl
net: add net device refcount tracker to struct neighbour
net: add net device refcount tracker to struct pneigh_entry
net: add net device refcount tracker to struct neigh_parms
net: add net device refcount tracker to struct netdev_adjacent
ipv6: add net device refcount tracker to struct inet6_dev
ipv4: add net device refcount tracker to struct in_device net/sched: add net device refcount tracker to struct Qdisc
net: linkwatch: add net device refcount tracker
net: failover: add net device refcount tracker
ipmr, ip6mr: add net device refcount tracker to struct vif_device
netpoll: add net device refcount tracker to struct netpoll
drivers/net/netconsole.c | 2 +- include/linux/inetdevice.h | 2 + include/linux/mroute_base.h | 1 + include/linux/netdevice.h | 66 +++++++++++++++++ include/linux/netpoll.h | 1 + include/linux/ref_tracker.h | 73 +++++++++++++++++++ include/net/devlink.h | 3 + include/net/dst.h | 1 + include/net/failover.h | 1 + include/net/if_inet6.h | 1 + include/net/ip6_tunnel.h | 1 + include/net/ip_tunnels.h | 3 + include/net/neighbour.h | 3 + include/net/sch_generic.h | 2 +- lib/Kconfig | 5 ++ lib/Kconfig.debug | 10 +++ lib/Makefile | 4 +- lib/ref_tracker.c | 140 ++++++++++++++++++++++++++++++++++++ lib/test_ref_tracker.c | 115 +++++++++++++++++++++++++++++ net/Kconfig | 8 +++ net/core/dev.c | 10 ++- net/core/dev_ioctl.c | 5 +- net/core/drop_monitor.c | 6 +- net/core/dst.c | 8 +-- net/core/failover.c | 4 +- net/core/link_watch.c | 4 +- net/core/neighbour.c | 18 ++--- net/core/net-sysfs.c | 8 +-- net/core/netpoll.c | 4 +- net/ethtool/ioctl.c | 5 +- net/ipv4/devinet.c | 4 +- net/ipv4/ipmr.c | 3 +- net/ipv4/route.c | 7 +- net/ipv6/addrconf.c | 4 +- net/ipv6/addrconf_core.c | 2 +- net/ipv6/ip6_gre.c | 8 +-- net/ipv6/ip6_tunnel.c | 4 +- net/ipv6/ip6_vti.c | 4 +- net/ipv6/ip6mr.c | 3 +- net/ipv6/route.c | 10 +-- net/ipv6/sit.c | 4 +- net/sched/sch_generic.c | 4 +- 42 files changed, 509 insertions(+), 62 deletions(-) create mode 100644 include/linux/ref_tracker.h create mode 100644 lib/ref_tracker.c create mode 100644 lib/test_ref_tracker.c
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 1/23 lib: add reference counting tracking infrastructure
From: Eric Dumazet <[email protected]>
It can be hard to track where references are taken and released.
In networking, we have annoying issues at device or netns dismantles, and we had various proposals to ease root causing them.
This patch adds new infrastructure pairing refcount increases and decreases. This will self document code, because programmers will have to associate increments/decrements.
This is controled by CONFIG_REF_TRACKER which can be selected by users of this feature.
This adds both cpu and memory costs, and thus should probably be used with care.
--- include/linux/ref_tracker.h | 73 +++++++++++++++++++ lib/Kconfig | 5 ++ lib/Makefile | 2 + lib/ref_tracker.c | 140 ++++++++++++++++++++++++++++++++++++ 4 files changed, 220 insertions(+) create mode 100644 include/linux/ref_tracker.h create mode 100644 lib/ref_tracker.c
include/linux/ref_tracker.h new file +73 -0
@@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef _LINUX_REF_TRACKER_H +#define _LINUX_REF_TRACKER_H +#include <linux/refcount.h> +#include <linux/types.h> +#include <linux/spinlock.h> + +struct ref_tracker ; + +struct ref_tracker_dir { +#ifdef CONFIG_REF_TRACKER +spinlock_t lock; +unsigned int quarantine_avail; +refcount_t untracked; +struct list_head list;/* List of active trackers */ +struct list_head quarantine;/* List of dead trackers */ +#endif +}; + +#ifdef CONFIG_REF_TRACKER +static inline void ref_tracker_dir_init (struct ref_tracker_dir *dir, +unsigned int quarantine_count) +{ +INIT_LIST_HEAD (&dir->list); +INIT_LIST_HEAD (&dir->quarantine); +spin_lock_init (&dir->lock); + dir->quarantine_avail = quarantine_count; +refcount_set (&dir->untracked,1 ); +} + +void ref_tracker_dir_exit (struct ref_tracker_dir *dir); + +void ref_tracker_dir_print (struct ref_tracker_dir *dir, +unsigned int display_limit); + +int ref_tracker_alloc (struct ref_tracker_dir *dir, +struct ref_tracker **trackerp,gfp_t gfp); + +int ref_tracker_free (struct ref_tracker_dir *dir, +struct ref_tracker **trackerp); + +#else /* CONFIG_REF_TRACKER */ + +static inline void ref_tracker_dir_init (struct ref_tracker_dir *dir, +unsigned int quarantine_count) +{ +} + +static inline void ref_tracker_dir_exit (struct ref_tracker_dir *dir) +{ +} + +static inline void ref_tracker_dir_print (struct ref_tracker_dir *dir, +unsigned int display_limit) +{ +} + +static inline int ref_tracker_alloc (struct ref_tracker_dir *dir, +struct ref_tracker **trackerp, +gfp_t gfp) +{ +return 0 ; +} + +static inline int ref_tracker_free (struct ref_tracker_dir *dir, +struct ref_tracker **trackerp) +{ +return 0 ; +} + +#endif + +#endif /* _LINUX_REF_TRACKER_H */
lib/Kconfig +5 -0
@@ -680,6 +680,11 @@ config STACK_HASH_ORDER Select the hash size as a power of 2 for the stackdepot hash table. Choose a lower value to reduce the memory impact. +config REF_TRACKER + bool + depends on STACKTRACE_SUPPORT + select STACKDEPOT + config SBITMAP bool
lib/Makefile +2 -0
@@ -270,6 +270,8 @@ obj-$(CONFIG_STACKDEPOT) += stackdepot.o KASAN_SANITIZE_stackdepot.o := n KCOV_INSTRUMENT_stackdepot.o := n +obj-$(CONFIG_REF_TRACKER) += ref_tracker.o + libfdt_files = fdt.o fdt_ro.o fdt_wip.o fdt_rw.o fdt_sw.o fdt_strerror.o \ fdt_empty_tree.o fdt_addresses.o $(foreach file, $(libfdt_files), \
lib/ref_tracker.c new file +140 -0
140 lines not on this page · raw message
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 2/23 lib: add tests for reference tracker
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
This module uses reference tracker, forcing two issues.
1) Double free of a tracker
2) leak of two trackers, one being allocated from softirq context.
"modprobe test_ref_tracker" would emit the following traces. (Use scripts/decode_stacktrace.sh if necessary)
[ 171.648681] reference already released. [ 171.653213] allocated in: [ 171.656523] alloctest_ref_tracker_alloc2+0x1c/0x20 [test_ref_tracker] [ 171.656526] init_module+0x86/0x1000 [test_ref_tracker] [ 171.656528] do_one_initcall+0x9c/0x220 [ 171.656532] do_init_module+0x60/0x240 [ 171.656536] load_module+0x32b5/0x3610 [ 171.656538] __do_sys_init_module+0x148/0x1a0 [ 171.656540] __x64_sys_init_module+0x1d/0x20 [ 171.656542] do_syscall_64+0x4a/0xb0 [ 171.656546] entry_SYSCALL_64_after_hwframe+0x44/0xae [ 171.656549] freed in: [ 171.659520] alloctest_ref_tracker_free+0x13/0x20 [test_ref_tracker] [ 171.659522] init_module+0xec/0x1000 [test_ref_tracker] [ 171.659523] do_one_initcall+0x9c/0x220 [ 171.659525] do_init_module+0x60/0x240 [ 171.659527] load_module+0x32b5/0x3610 [ 171.659529] __do_sys_init_module+0x148/0x1a0 [ 171.659532] __x64_sys_init_module+0x1d/0x20 [ 171.659534] do_syscall_64+0x4a/0xb0 [ 171.659536] entry_SYSCALL_64_after_hwframe+0x44/0xae [ 171.659575] ------------[ cut here ]------------ [ 171.659576] WARNING: CPU: 5 PID: 13016 at lib/ref_tracker.c:112 ref_tracker_free+0x224/0x270 [ 171.659581] Modules linked in: test_ref_tracker(+) [ 171.659591] CPU: 5 PID: 13016 Comm: modprobe Tainted: G S 5.16.0-smp-DEV #290 [ 171.659595] RIP: 0010:ref_tracker_free+0x224/0x270 [ 171.659599] Code: 5e 41 5f 5d c3 48 c7 c7 04 9c 74 a6 31 c0 e8 62 ee 67 00 83 7b 14 00 75 1a 83 7b 18 00 75 30 4c 89 ff 4c 89 f6 e8 9c 00 69 00 <0f> 0b bb ea ff ff ff eb ae 48 c7 c7 3a 0a 77 a6 31 c0 e8 34 ee 67 [ 171.659601] RSP: 0018:ffff89058ba0bbd0 EFLAGS: 00010286 [ 171.659603] RAX: 0000000000000029 RBX: ffff890586b19780 RCX: 08895bff57c7d100 [ 171.659604] RDX: c0000000ffff7fff RSI: 0000000000000282 RDI: ffffffffc0407000 [ 171.659606] RBP: ffff89058ba0bc88 R08: 0000000000000000 R09: ffffffffa6f342e0 [ 171.659607] R10: 00000000ffff7fff R11: 0000000000000000 R12: 000000008f000000 [ 171.659608] R13: 0000000000000014 R14: 0000000000000282 R15: ffffffffc0407000 [ 171.659609] FS: 00007f97ea29d740(0000) GS:ffff8923ff940000(0000) knlGS:0000000000000000 [ 171.659611] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 171.659613] CR2: 00007f97ea299000 CR3: 0000000186b4a004 CR4: 00000000001706e0 [ 171.659614] Call Trace: [ 171.659615] <TASK> [ 171.659631] ? alloctest_ref_tracker_free+0x13/0x20 [test_ref_tracker] [ 171.659633] ? init_module+0x105/0x1000 [test_ref_tracker] [ 171.659636] ? do_one_initcall+0x9c/0x220 [ 171.659638] ? do_init_module+0x60/0x240 [ 171.659641] ? load_module+0x32b5/0x3610 [ 171.659644] ? __do_sys_init_module+0x148/0x1a0 [ 171.659646] ? __x64_sys_init_module+0x1d/0x20 [ 171.659649] ? do_syscall_64+0x4a/0xb0 [ 171.659652] ? entry_SYSCALL_64_after_hwframe+0x44/0xae [ 171.659656] ? 0xffffffffc040a000 [ 171.659658] alloctest_ref_tracker_free+0x13/0x20 [test_ref_tracker] [ 171.659660] init_module+0x105/0x1000 [test_ref_tracker] [ 171.659663] do_one_initcall+0x9c/0x220 [ 171.659666] do_init_module+0x60/0x240 [ 171.659669] load_module+0x32b5/0x3610 [ 171.659672] __do_sys_init_module+0x148/0x1a0 [ 171.659676] __x64_sys_init_module+0x1d/0x20 [ 171.659678] do_syscall_64+0x4a/0xb0 [ 171.659694] ? exc_page_fault+0x6e/0x140 [ 171.659696] entry_SYSCALL_64_after_hwframe+0x44/0xae [ 171.659698] RIP: 0033:0x7f97ea3dbe7a [ 171.659700] Code: 48 8b 0d 61 8d 06 00 f7 d8 64 89 01 48 83 c8 ff c3 cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc 49 89 ca b8 af 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 2e 8d 06 00 f7 d8 64 89 01 48 [ 171.659701] RSP: 002b:00007ffea67ce608 EFLAGS: 00000246 ORIG_RAX: 00000000000000af [ 171.659703] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f97ea3dbe7a [ 171.659704] RDX: 00000000013a0ba0 RSI: 0000000000002808 RDI: 00007f97ea299000 [ 171.659705] RBP: 00007ffea67ce670 R08: 0000000000000003 R09: 0000000000000000 [ 171.659706] R10: 0000000000000000 R11: 0000000000000246 R12: 00000000013a1048 [ 171.659707] R13: 00000000013a0ba0 R14: 0000000001399930 R15: 00000000013a1030 [ 171.659709] </TASK> [ 171.659710] ---[ end trace f5dbd6afa41e60a9 ]--- [ 171.659712] leaked reference. [ 171.663393] alloctest_ref_tracker_alloc0+0x1c/0x20 [test_ref_tracker] [ 171.663395] test_ref_tracker_timer_func+0x9/0x20 [test_ref_tracker] [ 171.663397] call_timer_fn+0x31/0x140 [ 171.663401] expire_timers+0x46/0x110 [ 171.663403] __run_timers+0x16f/0x1b0 [ 171.663404] run_timer_softirq+0x1d/0x40 [ 171.663406] __do_softirq+0x148/0x2d3 [ 171.663408] leaked reference. [ 171.667101] alloctest_ref_tracker_alloc1+0x1c/0x20 [test_ref_tracker] [ 171.667103] init_module+0x81/0x1000 [test_ref_tracker] [ 171.667104] do_one_initcall+0x9c/0x220 [ 171.667106] do_init_module+0x60/0x240 [ 171.667108] load_module+0x32b5/0x3610 [ 171.667111] __do_sys_init_module+0x148/0x1a0 [ 171.667113] __x64_sys_init_module+0x1d/0x20 [ 171.667115] do_syscall_64+0x4a/0xb0 [ 171.667117] entry_SYSCALL_64_after_hwframe+0x44/0xae [ 171.667131] ------------[ cut here ]------------ [ 171.667132] WARNING: CPU: 5 PID: 13016 at lib/ref_tracker.c:30 ref_tracker_dir_exit+0x104/0x130 [ 171.667136] Modules linked in: test_ref_tracker(+) [ 171.667144] CPU: 5 PID: 13016 Comm: modprobe Tainted: G S W 5.16.0-smp-DEV #290 [ 171.667147] RIP: 0010:ref_tracker_dir_exit+0x104/0x130 [ 171.667150] Code: 01 00 00 00 00 ad de 48 89 03 4c 89 63 08 48 89 df e8 20 a0 d5 ff 4c 89 f3 4d 39 ee 75 a8 4c 89 ff 48 8b 75 d0 e8 7c 05 69 00 <0f> 0b eb 0c 4c 89 ff 48 8b 75 d0 e8 6c 05 69 00 41 8b 47 08 83 f8 [ 171.667151] RSP: 0018:ffff89058ba0bc68 EFLAGS: 00010286 [ 171.667154] RAX: 08895bff57c7d100 RBX: ffffffffc0407010 RCX: 000000000000003b [ 171.667156] RDX: 000000000000003c RSI: 0000000000000282 RDI: ffffffffc0407000 [ 171.667157] RBP: ffff89058ba0bc98 R08: 0000000000000000 R09: ffffffffa6f342e0 [ 171.667159] R10: 00000000ffff7fff R11: 0000000000000000 R12: dead000000000122 [ 171.667160] R13: ffffffffc0407010 R14: ffffffffc0407010 R15: ffffffffc0407000 [ 171.667162] FS: 00007f97ea29d740(0000) GS:ffff8923ff940000(0000) knlGS:0000000000000000 [ 171.667164] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 171.667166] CR2: 00007f97ea299000 CR3: 0000000186b4a004 CR4: 00000000001706e0 [ 171.667169] Call Trace: [ 171.667170] <TASK> [ 171.667171] ? 0xffffffffc040a000 [ 171.667173] init_module+0x126/0x1000 [test_ref_tracker] [ 171.667175] do_one_initcall+0x9c/0x220 [ 171.667179] do_init_module+0x60/0x240 [ 171.667182] load_module+0x32b5/0x3610 [ 171.667186] __do_sys_init_module+0x148/0x1a0 [ 171.667189] __x64_sys_init_module+0x1d/0x20 [ 171.667192] do_syscall_64+0x4a/0xb0 [ 171.667194] ? exc_page_fault+0x6e/0x140 [ 171.667196] entry_SYSCALL_64_after_hwframe+0x44/0xae [ 171.667199] RIP: 0033:0x7f97ea3dbe7a [ 171.667200] Code: 48 8b 0d 61 8d 06 00 f7 d8 64 89 01 48 83 c8 ff c3 cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc 49 89 ca b8 af 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 2e 8d 06 00 f7 d8 64 89 01 48 [ 171.667201] RSP: 002b:00007ffea67ce608 EFLAGS: 00000246 ORIG_RAX: 00000000000000af [ 171.667203] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f97ea3dbe7a [ 171.667204] RDX: 00000000013a0ba0 RSI: 0000000000002808 RDI: 00007f97ea299000 [ 171.667205] RBP: 00007ffea67ce670 R08: 0000000000000003 R09: 0000000000000000 [ 171.667206] R10: 0000000000000000 R11: 0000000000000246 R12: 00000000013a1048 [ 171.667207] R13: 00000000013a0ba0 R14: 0000000001399930 R15: 00000000013a1030 [ 171.667209] </TASK> [ 171.667210] ---[ end trace f5dbd6afa41e60aa ]---
--- lib/Kconfig.debug | 10 ++++ lib/Makefile | 2 +- lib/test_ref_tracker.c | 115 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 lib/test_ref_tracker.c
lib/Kconfig.debug +10 -0
@@ -2106,6 +2106,16 @@ config BACKTRACE_SELF_TEST Say N if you are unsure. +config TEST_REF_TRACKER + tristate "Self test for reference tracker" + depends on DEBUG_KERNEL + select REF_TRACKER + help + This option provides a kernel module performing tests + using reference tracker infrastructure. + + Say N if you are unsure. + config RBTREE_TEST tristate "Red-Black tree test" depends on DEBUG_KERNEL
lib/Makefile +1 -1
@@ -101,7 +101,7 @@ obj-$(CONFIG_TEST_LOCKUP) += test_lockup.o obj-$(CONFIG_TEST_HMM) += test_hmm.o obj-$(CONFIG_TEST_FREE_PAGES) += test_free_pages.o obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o - +obj-$(CONFIG_TEST_REF_TRACKER) += test_ref_tracker.o # # CFLAGS for compiling floating point code inside the kernel. x86/Makefile turns # off the generation of FPU/SSE* instructions for kernel proper but FPU_FLAGS
lib/test_ref_tracker.c new file +115 -0
115 lines not on this page · raw message
Signature · 1 line
2.34.1.400.ga245620fadb-goog
kernel test robot
build botRe: [PATCH v2 net-next 02/23] lib: add tests for reference tracker
I love your patch! Yet something to improve:
Hi Eric,
I love your patch! Yet something to improve:
[auto build test ERROR on net-next/master]
url: https://github.com/0day-ci/linux/commits/Eric-Dumazet/net-add-preliminary-netdev-refcount-tracking/20211203-104930 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git fc993be36f9ea7fc286d84d8471a1a20e871aad4 config: nios2-allyesconfig (https://download.01.org/0day-ci/archive/20211205/202112050729.hISLa0oF-lkp(a)intel.com/config) compiler: nios2-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/98ad7e89138f4176a549203b6e23c2dc1cb9581d
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Eric-Dumazet/net-add-preliminary-netdev-refcount-tracking/20211203-104930 git checkout 98ad7e89138f4176a549203b6e23c2dc1cb9581d
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=nios2 SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
lib/ref_tracker.c: In function 'ref_tracker_alloc':
>> lib/ref_tracker.c:80:22: error: implicit declaration of function 'stack_trace_save'; did you mean 'stack_depot_save'? [-Werror=implicit-function-declaration]
80 | nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 1);
| ^~~~~~~~~~~~~~~~
| stack_depot_save
>> lib/ref_tracker.c:81:22: error: implicit declaration of function 'filter_irq_stacks' [-Werror=implicit-function-declaration]
81 | nr_entries = filter_irq_stacks(entries, nr_entries);
| ^~~~~~~~~~~~~~~~~cc1: some warnings being treated as errors
Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for REF_TRACKER Depends on STACKTRACE_SUPPORT
Selected by
- TEST_REF_TRACKER && RUNTIME_TESTING_MENU && DEBUG_KERNEL
vim +80 lib/ref_tracker.c
fc2d884275133c Eric Dumazet 2021-12-02 64
fc2d884275133c Eric Dumazet 2021-12-02 65 int ref_tracker_alloc(struct ref_tracker_dir *dir,
fc2d884275133c Eric Dumazet 2021-12-02 66 struct ref_tracker **trackerp,
fc2d884275133c Eric Dumazet 2021-12-02 67 gfp_t gfp)
fc2d884275133c Eric Dumazet 2021-12-02 68 {
fc2d884275133c Eric Dumazet 2021-12-02 69 unsigned long entries[REF_TRACKER_STACK_ENTRIES];
fc2d884275133c Eric Dumazet 2021-12-02 70 struct ref_tracker *tracker;
fc2d884275133c Eric Dumazet 2021-12-02 71 unsigned int nr_entries;
fc2d884275133c Eric Dumazet 2021-12-02 72 unsigned long flags;
fc2d884275133c Eric Dumazet 2021-12-02 73
fc2d884275133c Eric Dumazet 2021-12-02 74 *trackerp = tracker = kzalloc(sizeof(*tracker), gfp | __GFP_NOFAIL);
fc2d884275133c Eric Dumazet 2021-12-02 75 if (unlikely(!tracker)) {
fc2d884275133c Eric Dumazet 2021-12-02 76 pr_err_once("memory allocation failure, unreliable refcount tracker.\n");
fc2d884275133c Eric Dumazet 2021-12-02 77 refcount_inc(&dir->untracked);
fc2d884275133c Eric Dumazet 2021-12-02 78 return -ENOMEM;
fc2d884275133c Eric Dumazet 2021-12-02 79 }
fc2d884275133c Eric Dumazet 2021-12-02 @80 nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 1);
fc2d884275133c Eric Dumazet 2021-12-02 @81 nr_entries = filter_irq_stacks(entries, nr_entries);
fc2d884275133c Eric Dumazet 2021-12-02 82 tracker->alloc_stack_handle = stack_depot_save(entries, nr_entries, gfp);
fc2d884275133c Eric Dumazet 2021-12-02 83
fc2d884275133c Eric Dumazet 2021-12-02 84 spin_lock_irqsave(&dir->lock, flags);
fc2d884275133c Eric Dumazet 2021-12-02 85 list_add(&tracker->head, &dir->list);
fc2d884275133c Eric Dumazet 2021-12-02 86 spin_unlock_irqrestore(&dir->lock, flags);
fc2d884275133c Eric Dumazet 2021-12-02 87 return 0;
fc2d884275133c Eric Dumazet 2021-12-02 88 }
fc2d884275133c Eric Dumazet 2021-12-02 89 EXPORT_SYMBOL_GPL(ref_tracker_alloc);
fc2d884275133c Eric Dumazet 2021-12-02 90 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v2 net-next 02/23] lib: add tests for reference tracker
Quoted 11 lines · kernel test robot
Hi Eric,
I love your patch! Yet something to improve:
[auto build test ERROR on net-next/master]
url: https://github.com/0day-ci/linux/commits/Eric-Dumazet/net-add-preliminary-netdev-refcount-tracking/20211203-104930 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git fc993be36f9ea7fc286d84d8471a1a20e871aad4 config: nios2-allyesconfig (https://download.01.org/0day-ci/archive/20211205/202112050729.hISLa0oF-lkp(a)intel.com/config) compiler: nios2-linux-gcc (GCC) 11.2.0
Quoted 11 lines
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/98ad7e89138f4176a549203b6e23c2dc1cb9581d
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Eric-Dumazet/net-add-preliminary-netdev-refcount-tracking/20211203-104930 git checkout98ad7e89138f4176a549203b6e23c2dc1cb9581d
# save the config file to linux build tree
mkdirbuild_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=nios2 SHELL=/bin/bash
I tried following these instructions, but this failed on my laptop.
Quoted 13 lines
If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>All errors (new ones prefixed by >>):
lib/ref_tracker.c: In function 'ref_tracker_alloc':Quoted 1 line
Quoted 1 line
lib/ref_tracker.c:80:22: error: implicit declaration of function 'stack_trace_save'; did you mean 'stack_depot_save'? [-Werror=implicit-function-declaration]80 | nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 1); | ^~~~~~~~~~~~~~~~ | stack_depot_saveQuoted 1 line
Quoted 1 line
lib/ref_tracker.c:81:22: error: implicit declaration of function 'filter_irq_stacks' [-Werror=implicit-function-declaration]81 | nr_entries = filter_irq_stacks(entries, nr_entries); | ^~~~~~~~~~~~~~~~~
Quoted 8 lines
cc1: some warnings being treated as errors
Kconfigwarnings: (for reference only)
WARNING: unmet direct dependencies detected forREF_TRACKERDepends onSTACKTRACE_SUPPORT
Selected by
-TEST_REF_TRACKER&&RUNTIME_TESTING_MENU&&DEBUG_KERNEL
This seems to be a bug unrelated to this patch series.
Re: [PATCH v2 net-next 02/23] lib: add tests for reference tracker
Quoted 43 lines · Eric Dumazet
Quoted 11 lines · kernel test robot
Hi Eric,
I love your patch! Yet something to improve:
[auto build test ERROR on net-next/master]
url: https://github.com/0day-ci/linux/commits/Eric-Dumazet/net-add-preliminary-netdev-refcount-tracking/20211203-104930 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git fc993be36f9ea7fc286d84d8471a1a20e871aad4 config: nios2-allyesconfig (https://download.01.org/0day-ci/archive/20211205/202112050729.hISLa0oF-lkp(a)intel.com/config) compiler: nios2-linux-gcc (GCC) 11.2.0Quoted 11 lines
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/98ad7e89138f4176a549203b6e23c2dc1cb9581d
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Eric-Dumazet/net-add-preliminary-netdev-refcount-tracking/20211203-104930 git checkout98ad7e89138f4176a549203b6e23c2dc1cb9581d
# save the config file to linux build tree
mkdirbuild_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=nios2 SHELL=/bin/bashI tried following these instructions, but this failed on my laptop.
Quoted 15 lines
If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>All errors (new ones prefixed by >>):
lib/ref_tracker.c: In function 'ref_tracker_alloc':Quoted 1 line
Quoted 1 line
lib/ref_tracker.c:80:22: error: implicit declaration of function 'stack_trace_save'; did you mean 'stack_depot_save'? [-Werror=implicit-function-declaration]80 | nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 1); | ^~~~~~~~~~~~~~~~ | stack_depot_saveQuoted 1 line
Quoted 1 line
lib/ref_tracker.c:81:22: error: implicit declaration of function 'filter_irq_stacks' [-Werror=implicit-function-declaration]81 | nr_entries = filter_irq_stacks(entries, nr_entries); | ^~~~~~~~~~~~~~~~~cc1: some warnings being treated as errors
Quoted 8 lines
Quoted 6 lines
Kconfigwarnings: (for reference only)
WARNING: unmet direct dependencies detected forREF_TRACKERDepends onSTACKTRACE_SUPPORT
Selected by
-TEST_REF_TRACKER&&RUNTIME_TESTING_MENU&&DEBUG_KERNELThis seems to be a bug unrelated to this patch series.
Ah... maybe I got the Kconfig thing wrong.
This is hard to believe we will have to duplicate " depends on STACKTRACE_SUPPORT" for all trackers
will intend to have (I have a series for netns refcount tracking)
net/Kconfig +0 -0
100644
net/Kconfig +1 -0
@@ -255,6 +255,7 @@ config PCPU_DEV_REFCNT config NET_DEV_REFCNT_TRACKER bool "Enable tracking in dev_put_track() and dev_hold_track()" + depends on STACKTRACE_SUPPORT select REF_TRACKER default n help
I thought that having the dependency centralized in REF_TRACKER would be enough really ?
config REF_TRACKER
bool
depends on STACKTRACE_SUPPORT
select STACKDEPOT
PATCH v2 3/23 net: add dev_hold_track() and dev_put_track() helpers
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
They should replace dev_hold() and dev_put().
To use these helpers, each data structure owning a refcount should also use a "netdevice_tracker" to pair the hold and put.
Whenever a leak happens, we will get precise stack traces of the point dev_hold_track() happened, at device dismantle phase.
--- include/linux/netdevice.h | 44 +++++++++++++++++++++++++++++++++++++++ net/Kconfig | 8 +++++++ net/core/dev.c | 3 +++ 3 files changed, 55 insertions(+)
include/linux/netdevice.h +44 -0
@@ -48,6 +48,7 @@#include <uapi/linux/pkt_cls.h> #include <linux/hashtable.h> #include <linux/rbtree.h> +#include <linux/ref_tracker.h> struct netpoll_info ;struct device ;
@@ -300,6 +301,12 @@ enum netdev_state_t { }; +#ifdef CONFIG_NET_DEV_REFCNT_TRACKER +typedef struct ref_tracker *netdevice_tracker ; +#else +typedef struct {}netdevice_tracker ; +#endif +struct gro_list {struct list_head list;int count;
@@ -2178,6 +2185,7 @@ struct net_device {#else refcount_t dev_refcnt;#endif +struct ref_tracker_dir refcnt_tracker;struct list_head link_watch_list;
@@ -3805,6 +3813,7 @@ void netdev_run_todo(void);* @dev: network device * * Release reference to device to allow it to be freed. +* Try using dev_put_track() instead. */ static inline void dev_put (struct net_device *dev) {
@@ -3822,6 +3831,7 @@ static inline void dev_put(struct net_device *dev)* @dev: network device * * Hold reference to device to keep it from being freed. +* Try using dev_hold_track() instead. */ static inline void dev_hold (struct net_device *dev) {
@@ -3834,6 +3844,40 @@ static inline void dev_hold(struct net_device *dev) } } +static inline void netdev_tracker_alloc (struct net_device *dev, +netdevice_tracker *tracker,gfp_t gfp) +{ +#ifdef CONFIG_NET_DEV_REFCNT_TRACKER +ref_tracker_alloc (&dev->refcnt_tracker, tracker, gfp); +#endif +} + +static inline void netdev_tracker_free (struct net_device *dev, +netdevice_tracker *tracker) +{ +#ifdef CONFIG_NET_DEV_REFCNT_TRACKER +ref_tracker_free (&dev->refcnt_tracker, tracker); +#endif +} + +static inline void dev_hold_track (struct net_device *dev, +netdevice_tracker *tracker,gfp_t gfp) +{ +if (dev) { +dev_hold (dev); +netdev_tracker_alloc (dev, tracker, gfp); + } +} + +static inline void dev_put_track (struct net_device *dev, +netdevice_tracker *tracker) +{ +if (dev) { +netdev_tracker_free (dev, tracker); +dev_put (dev); + } +} +/* Carrier loss detection, dial on demand. The functions netif_carrier_on * and _off may be called from IRQ context, but it is caller * who is responsible for serialization of these calls.
net/Kconfig +8 -0
@@ -253,6 +253,14 @@ config PCPU_DEV_REFCNT network device refcount are using per cpu variables if this option is set. This can be forced to N to detect underflows (with a performance drop). +config NET_DEV_REFCNT_TRACKER + bool "Enable tracking in dev_put_track() and dev_hold_track()" + select REF_TRACKER + default n + help + Enable debugging feature to track leaked device references. + This adds memory and cpu costs. + config RPS bool depends on SMP && SYSFS
net/core/dev.c +3 -0
@@ -9864,6 +9864,7 @@ static void netdev_wait_allrefs(struct net_device *dev) netdev_unregister_timeout_secs * HZ)) {pr_emerg ("unregister_netdevice: waiting for %s to become free. Usage count = %d\n" , dev->name, refcnt); +ref_tracker_dir_print (&dev->refcnt_tracker,10 ); warning_time = jiffies; } }
@@ -10154,6 +10155,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, dev =PTR_ALIGN (p,NETDEV_ALIGN ); dev->padded = (char *)dev - (char *)p; +ref_tracker_dir_init (&dev->refcnt_tracker,128 );#ifdef CONFIG_PCPU_DEV_REFCNT dev->pcpu_refcnt =alloc_percpu (int);if (!dev->pcpu_refcnt)
@@ -10270,6 +10272,7 @@ void free_netdev(struct net_device *dev)list_for_each_entry_safe (p, n, &dev->napi_list, dev_list)netif_napi_del (p); +ref_tracker_dir_exit (&dev->refcnt_tracker);#ifdef CONFIG_PCPU_DEV_REFCNT free_percpu (dev->pcpu_refcnt); dev->pcpu_refcnt =NULL ;
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 4/23 net: add net device refcount tracker to struct netdev_rx_queue
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
This helps debugging net device refcount leaks.
--- include/linux/netdevice.h | 2 ++ net/core/net-sysfs.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-)
include/linux/netdevice.h +2 -0
@@ -741,6 +741,8 @@ struct netdev_rx_queue {#endif struct kobject kobj;struct net_device *dev; +netdevice_tracker dev_tracker; +#ifdef CONFIG_XDP_SOCKETS struct xsk_buff_pool *pool;#endif
net/core/net-sysfs.c +2 -2
@@ -1004,7 +1004,7 @@ static void rx_queue_release(struct kobject *kobj)#endif memset (kobj,0 ,sizeof (*kobj)); -dev_put (queue->dev); +dev_put_track (queue->dev, &queue->dev_tracker); }static const void *rx_queue_namespace (struct kobject *kobj)
@@ -1044,7 +1044,7 @@ static int rx_queue_add_kobject(struct net_device *dev, int index)/* Kobject_put later will trigger rx_queue_release call which * decreases dev refcount: Take that reference here */ -dev_hold (queue->dev); +dev_hold_track (queue->dev, &queue->dev_tracker,GFP_KERNEL ); kobj->kset = dev->queues_kset; error = kobject_init_and_add(kobj, &rx_queue_ktype, NULL,
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 5/23 net: add net device refcount tracker to struct netdev_queue
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
This will help debugging pesky netdev reference leaks.
--- include/linux/netdevice.h | 2 ++ net/core/net-sysfs.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-)
include/linux/netdevice.h +2 -0
@@ -586,6 +586,8 @@ struct netdev_queue {* read-mostly part */ struct net_device *dev; +netdevice_tracker dev_tracker; +struct Qdisc __rcu *qdisc;struct Qdisc *qdisc_sleeping;#ifdef CONFIG_SYSFS
net/core/net-sysfs.c +2 -2
@@ -1607,7 +1607,7 @@ static void netdev_queue_release(struct kobject *kobj)struct netdev_queue *queue =to_netdev_queue (kobj);memset (kobj,0 ,sizeof (*kobj)); -dev_put (queue->dev); +dev_put_track (queue->dev, &queue->dev_tracker); }static const void *netdev_queue_namespace (struct kobject *kobj)
@@ -1647,7 +1647,7 @@ static int netdev_queue_add_kobject(struct net_device *dev, int index)/* Kobject_put later will trigger netdev_queue_release call * which decreases dev refcount: Take that reference here */ -dev_hold (queue->dev); +dev_hold_track (queue->dev, &queue->dev_tracker,GFP_KERNEL ); kobj->kset = dev->queues_kset; error = kobject_init_and_add(kobj, &netdev_queue_ktype, NULL,
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 6/23 net: add net device refcount tracker to ethtool_phys_id()
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
This helper might hold a netdev reference for a long time, lets add reference tracking.
--- net/ethtool/ioctl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/ethtool/ioctl.c +3 -2
@@ -1989,6 +1989,7 @@ static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)struct ethtool_value id;static bool busy;const struct ethtool_ops *ops = dev->ethtool_ops; +netdevice_tracker dev_tracker;int rc;if (!ops->set_phys_id)
@@ -2008,7 +2009,7 @@ static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)* removal of the device. */ busy = true; -dev_hold (dev); +dev_hold_track (dev, &dev_tracker,GFP_KERNEL );rtnl_unlock ();if (rc ==0 ) {
@@ -2032,7 +2033,7 @@ static int ethtool_phys_id(struct net_device *dev, void __user *useraddr) }rtnl_lock (); -dev_put (dev); +dev_put_track (dev, &dev_tracker); busy = false; (void ) ops->set_phys_id (dev,ETHTOOL_ID_INACTIVE );
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 7/23 net: add net device refcount tracker to dev_ifsioc()
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
--- net/core/dev_ioctl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/core/dev_ioctl.c +3 -2
@@ -313,6 +313,7 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, void __user *data,int err;struct net_device *dev =__dev_get_by_name (net, ifr->ifr_name);const struct net_device_ops *ops; +netdevice_tracker dev_tracker;if (!dev)return -ENODEV ;
@@ -381,10 +382,10 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, void __user *data,return -ENODEV ;if (!netif_is_bridge_master (dev))return -EOPNOTSUPP ; -dev_hold (dev); +dev_hold_track (dev, &dev_tracker,GFP_KERNEL );rtnl_unlock (); err =br_ioctl_call (net,netdev_priv (dev), cmd, ifr,NULL ); -dev_put (dev); +dev_put_track (dev, &dev_tracker);rtnl_lock ();return err;
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 8/23 drop_monitor: add net device refcount tracker
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
We want to track all dev_hold()/dev_put() to ease leak hunting.
--- include/net/devlink.h | 3 +++ net/core/drop_monitor.c | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-)
include/net/devlink.h +3 -0
@@ -670,7 +670,10 @@ struct devlink_health_reporter_ops {struct devlink_trap_metadata {const char *trap_name;const char *trap_group_name; +struct net_device *input_dev; +netdevice_tracker dev_tracker; +const struct flow_action_cookie *fa_cookie;enum devlink_trap_type trap_type; };
net/core/drop_monitor.c +3 -3
@@ -850,7 +850,7 @@ net_dm_hw_metadata_copy(const struct devlink_trap_metadata *metadata) } hw_metadata->input_dev = metadata->input_dev; -dev_hold (hw_metadata->input_dev); +dev_hold_track (hw_metadata->input_dev, &hw_metadata->dev_tracker,GFP_ATOMIC );return hw_metadata;
@@ -864,9 +864,9 @@ net_dm_hw_metadata_copy(const struct devlink_trap_metadata *metadata) }static void -net_dm_hw_metadata_free (const struct devlink_trap_metadata *hw_metadata) +net_dm_hw_metadata_free (struct devlink_trap_metadata *hw_metadata) { -dev_put (hw_metadata->input_dev); +dev_put_track (hw_metadata->input_dev, &hw_metadata->dev_tracker);kfree (hw_metadata->fa_cookie);kfree (hw_metadata->trap_name);kfree (hw_metadata->trap_group_name);
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 9/23 net: dst: add net device refcount tracking to dst_entry
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
We want to track all dev_hold()/dev_put() to ease leak hunting.
--- include/linux/netdevice.h | 17 +++++++++++++++++ include/net/dst.h | 1 + net/core/dst.c | 8 ++++---- net/ipv4/route.c | 7 ++++--- net/ipv6/route.c | 5 +++-- 5 files changed, 29 insertions(+), 9 deletions(-)
include/linux/netdevice.h +17 -0
@@ -3882,6 +3882,23 @@ static inline void dev_put_track(struct net_device *dev, } } +static inline void dev_replace_track (struct net_device *odev, +struct net_device *ndev, +netdevice_tracker *tracker, +gfp_t gfp) +{ +#ifdef CONFIG_NET_DEV_REFCNT_TRACKER +if (odev) +ref_tracker_free (&odev->refcnt_tracker, tracker); +#endif +dev_hold (ndev); +dev_put (odev); +#ifdef CONFIG_NET_DEV_REFCNT_TRACKER +if (ndev) +ref_tracker_alloc (&ndev->refcnt_tracker, tracker, gfp); +#endif +} +/* Carrier loss detection, dial on demand. The functions netif_carrier_on * and _off may be called from IRQ context, but it is caller * who is responsible for serialization of these calls.
include/net/dst.h +1 -0
@@ -77,6 +77,7 @@ struct dst_entry {#ifndef CONFIG_64BIT atomic_t __refcnt;/* 32-bit offset 64 */ #endif +netdevice_tracker dev_tracker; };struct dst_metrics {
net/core/dst.c +4 -4
@@ -49,7 +49,7 @@ void dst_init(struct dst_entry *dst, struct dst_ops *ops, unsigned short flags) { dst->dev = dev; -dev_hold (dev); +dev_hold_track (dev, &dst->dev_tracker,GFP_ATOMIC ); dst->ops = ops;dst_init_metrics (dst, dst_default_metrics.metrics, true); dst->expires =0UL ;
@@ -117,7 +117,7 @@ struct dst_entry *dst_destroy(struct dst_entry * dst)if (dst->ops->destroy) dst->ops->destroy (dst); -dev_put (dst->dev); +dev_put_track (dst->dev, &dst->dev_tracker);lwtstate_put (dst->lwtstate);
@@ -159,8 +159,8 @@ void dst_dev_put(struct dst_entry *dst) dst->input = dst_discard; dst->output = dst_discard_out; dst->dev = blackhole_netdev; -dev_hold (dst->dev); -dev_put (dev); +dev_replace_track (dev, blackhole_netdev, &dst->dev_tracker, +GFP_ATOMIC ); }EXPORT_SYMBOL (dst_dev_put);
net/ipv4/route.c +4 -3
@@ -1531,8 +1531,9 @@ void rt_flush_dev(struct net_device *dev)if (rt->dst.dev != dev)continue ; rt->dst.dev = blackhole_netdev; -dev_hold (rt->dst.dev); -dev_put (dev); +dev_replace_track (dev, blackhole_netdev, + &rt->dst.dev_tracker, +GFP_ATOMIC ); }spin_unlock_bh (&ul->lock); }
@@ -2819,7 +2820,7 @@ struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_or new->output = dst_discard_out; new->dev = net->loopback_dev; -dev_hold (new->dev); +dev_hold_track (new->dev, &new->dev_tracker,GFP_ATOMIC ); rt->rt_is_input = ort->rt_is_input; rt->rt_iif = ort->rt_iif;
net/ipv6/route.c +3 -2
@@ -182,8 +182,9 @@ static void rt6_uncached_list_flush_dev(struct net *net, struct net_device *dev)if (rt_dev == dev) { rt->dst.dev = blackhole_netdev; -dev_hold (rt->dst.dev); -dev_put (rt_dev); +dev_replace_track (rt_dev, blackhole_netdev, + &rt->dst.dev_tracker, +GFP_ATOMIC ); } }spin_unlock_bh (&ul->lock);
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 10/23 ipv6: add net device refcount tracker to rt6_probe_deferred()
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
--- net/ipv6/route.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/ipv6/route.c +3 -2
@@ -593,6 +593,7 @@ struct __rt6_probe_work {struct work_struct work;struct in6_addr target;struct net_device *dev; +netdevice_tracker dev_tracker; };static void rt6_probe_deferred (struct work_struct *w)
@@ -603,7 +604,7 @@ static void rt6_probe_deferred(struct work_struct *w)addrconf_addr_solict_mult (&work->target, &mcaddr);ndisc_send_ns (work->dev, &work->target, &mcaddr,NULL ,0 ); -dev_put (work->dev); +dev_put_track (work->dev, &work->dev_tracker);kfree (work); }
@@ -657,7 +658,7 @@ static void rt6_probe(struct fib6_nh *fib6_nh) }else {INIT_WORK (&work->work, rt6_probe_deferred); work->target = *nh_gw; -dev_hold (dev); +dev_hold_track (dev, &work->dev_tracker,GFP_KERNEL ); work->dev = dev;schedule_work (&work->work); }
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 11/23 sit: add net device refcount tracking to ip_tunnel
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
Note that other ip_tunnel users do not seem to hold a reference on tunnel->dev. Probably needs some investigations.
--- include/net/ip_tunnels.h | 3 +++ net/ipv6/sit.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-)
include/net/ip_tunnels.h +3 -0
@@ -104,7 +104,10 @@ struct metadata_dst;struct ip_tunnel {struct ip_tunnel __rcu *next;struct hlist_node hash_node; +struct net_device *dev; +netdevice_tracker dev_tracker; +struct net *net;/* netns for packet i/o */ unsigned long err_time;/* Time when the last ICMP error
net/ipv6/sit.c +2 -2
@@ -521,7 +521,7 @@ static void ipip6_tunnel_uninit(struct net_device *dev)ipip6_tunnel_del_prl (tunnel,NULL ); }dst_cache_reset (&tunnel->dst_cache); -dev_put (dev); +dev_put_track (dev, &tunnel->dev_tracker); }static int ipip6_err (struct sk_buff *skb,u32 info)
@@ -1463,7 +1463,7 @@ static int ipip6_tunnel_init(struct net_device *dev) dev->tstats =NULL ;return err; } -dev_hold (dev); +dev_hold_track (dev, &tunnel->dev_tracker,GFP_KERNEL );return 0 ; }
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 12/23 ipv6: add net device refcount tracker to struct ip6_tnl
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
--- include/net/ip6_tunnel.h | 1 + net/ipv6/ip6_gre.c | 8 ++++---- net/ipv6/ip6_tunnel.c | 4 ++-- net/ipv6/ip6_vti.c | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-)
include/net/ip6_tunnel.h +1 -0
@@ -46,6 +46,7 @@ struct __ip6_tnl_parm {struct ip6_tnl {struct ip6_tnl __rcu *next;/* next tunnel in list */ struct net_device *dev;/* virtual device associated with tunnel */ +netdevice_tracker dev_tracker;struct net *net;/* netns for packet i/o */ struct __ip6_tnl_parm parms;/* tunnel configuration parameters */ struct flowi fl;/* flowi template for xmit */
net/ipv6/ip6_gre.c +4 -4
@@ -403,7 +403,7 @@ static void ip6erspan_tunnel_uninit(struct net_device *dev)ip6erspan_tunnel_unlink_md (ign, t);ip6gre_tunnel_unlink (ign, t);dst_cache_reset (&t->dst_cache); -dev_put (dev); +dev_put_track (dev, &t->dev_tracker); }static void ip6gre_tunnel_uninit (struct net_device *dev)
@@ -416,7 +416,7 @@ static void ip6gre_tunnel_uninit(struct net_device *dev)if (ign->fb_tunnel_dev == dev)WRITE_ONCE (ign->fb_tunnel_dev,NULL );dst_cache_reset (&t->dst_cache); -dev_put (dev); +dev_put_track (dev, &t->dev_tracker); }
@@ -1496,7 +1496,7 @@ static int ip6gre_tunnel_init_common(struct net_device *dev) }ip6gre_tnl_init_features (dev); -dev_hold (dev); +dev_hold_track (dev, &tunnel->dev_tracker,GFP_KERNEL );return 0 ; cleanup_dst_cache_init:
@@ -1888,7 +1888,7 @@ static int ip6erspan_tap_init(struct net_device *dev) dev->priv_flags |=IFF_LIVE_ADDR_CHANGE ;ip6erspan_tnl_link_config (tunnel,1 ); -dev_hold (dev); +dev_hold_track (dev, &tunnel->dev_tracker,GFP_KERNEL );return 0 ; cleanup_dst_cache_init:
net/ipv6/ip6_tunnel.c +2 -2
@@ -383,7 +383,7 @@ ip6_tnl_dev_uninit(struct net_device *dev)else ip6_tnl_unlink (ip6n, t);dst_cache_reset (&t->dst_cache); -dev_put (dev); +dev_put_track (dev, &t->dev_tracker); }/**
@@ -1883,7 +1883,7 @@ ip6_tnl_dev_init_gen(struct net_device *dev) dev->min_mtu =ETH_MIN_MTU ; dev->max_mtu =IP6_MAX_MTU - dev->hard_header_len; -dev_hold (dev); +dev_hold_track (dev, &t->dev_tracker,GFP_KERNEL );return 0 ; destroy_dst:
net/ipv6/ip6_vti.c +2 -2
@@ -293,7 +293,7 @@ static void vti6_dev_uninit(struct net_device *dev)RCU_INIT_POINTER (ip6n->tnls_wc[0 ],NULL ); elsevti6_tnl_unlink (ip6n ,t ); -dev_put (dev); +dev_put_track (dev, &t->dev_tracker); } static int vti6_input_proto(struct sk_buff *skb, int nexthdr, __be32 spi,
@@ -934,7 +934,7 @@ static inline int vti6_dev_init_gen(struct net_device *dev) dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);if (!dev->tstats)return -ENOMEM ; -dev_hold (dev); +dev_hold_track (dev, &t->dev_tracker,GFP_KERNEL );return 0 ; }
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 13/23 net: add net device refcount tracker to struct neighbour
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
--- include/net/neighbour.h | 1 + net/core/neighbour.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-)
include/net/neighbour.h +1 -0
@@ -158,6 +158,7 @@ struct neighbour {struct list_head managed_list;struct rcu_head rcu;struct net_device *dev; +netdevice_tracker dev_tracker;u8 primary_key[0 ]; } __randomize_layout;
net/core/neighbour.c +2 -2
@@ -624,7 +624,7 @@ ___neigh_create(struct neigh_table *tbl, const void *pkey,memcpy (n->primary_key, pkey, key_len); n->dev = dev; -dev_hold (dev); +dev_hold_track (dev, &n->dev_tracker,GFP_ATOMIC );/* Protocol specific setup. */ if (tbl->constructor && (error = tbl->constructor (n)) <0 ) {
@@ -880,7 +880,7 @@ void neigh_destroy(struct neighbour *neigh)if (dev->netdev_ops->ndo_neigh_destroy) dev->netdev_ops->ndo_neigh_destroy (dev, neigh); -dev_put (dev); +dev_put_track (dev, &neigh->dev_tracker);neigh_parms_put (neigh->parms);neigh_dbg (2 ,"neigh %p is destroyed\n" , neigh);
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 14/23 net: add net device refcount tracker to struct pneigh_entry
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
--- include/net/neighbour.h | 1 + net/core/neighbour.c | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-)
include/net/neighbour.h +1 -0
@@ -174,6 +174,7 @@ struct pneigh_entry {struct pneigh_entry *next;possible_net_t net;struct net_device *dev; +netdevice_tracker dev_tracker;u32 flags;u8 protocol;u8 key[];
net/core/neighbour.c +4 -4
@@ -771,10 +771,10 @@ struct pneigh_entry * pneigh_lookup(struct neigh_table *tbl,write_pnet (&n->net, net);memcpy (n->key, pkey, key_len); n->dev = dev; -dev_hold (dev); +dev_hold_track (dev, &n->dev_tracker,GFP_KERNEL );if (tbl->pconstructor && tbl->pconstructor (n)) { -dev_put (dev); +dev_put_track (dev, &n->dev_tracker);kfree (n); n =NULL ; goto out;
@@ -806,7 +806,7 @@ int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *pkey,write_unlock_bh (&tbl->lock);if (tbl->pdestructor) tbl->pdestructor (n); -dev_put (n->dev); +dev_put_track (n->dev, &n->dev_tracker);kfree (n);return 0 ; }
@@ -839,7 +839,7 @@ static int pneigh_ifdown_and_unlock(struct neigh_table *tbl, n->next =NULL ;if (tbl->pdestructor) tbl->pdestructor (n); -dev_put (n->dev); +dev_put_track (n->dev, &n->dev_tracker);kfree (n); }return -ENOENT ;
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 15/23 net: add net device refcount tracker to struct neigh_parms
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
--- include/net/neighbour.h | 1 + net/core/neighbour.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-)
include/net/neighbour.h +1 -0
@@ -70,6 +70,7 @@ enum {struct neigh_parms {possible_net_t net;struct net_device *dev; +netdevice_tracker dev_tracker;struct list_head list;int (*neigh_setup)(struct neighbour *);struct neigh_table *tbl;
net/core/neighbour.c +3 -3
@@ -1666,13 +1666,13 @@ struct neigh_parms *neigh_parms_alloc(struct net_device *dev,refcount_set (&p->refcnt,1 ); p->reachable_time =neigh_rand_reach_time (NEIGH_VAR (p,BASE_REACHABLE_TIME )); -dev_hold (dev); +dev_hold_track (dev, &p->dev_tracker,GFP_KERNEL ); p->dev = dev;write_pnet (&p->net, net); p->sysctl_table =NULL ;if (ops->ndo_neigh_setup && ops->ndo_neigh_setup (dev, p)) { -dev_put (dev); +dev_put_track (dev, &p->dev_tracker);kfree (p);return NULL ; }
@@ -1703,7 +1703,7 @@ void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms)list_del (&parms->list); parms->dead =1 ;write_unlock_bh (&tbl->lock); -dev_put (parms->dev); +dev_put_track (parms->dev, &parms->dev_tracker);call_rcu (&parms->rcu_head, neigh_rcu_free_parms); }EXPORT_SYMBOL (neigh_parms_release);
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 16/23 net: add net device refcount tracker to struct netdev_adjacent
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
--- net/core/dev.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/core/dev.c +4 -3
@@ -6537,6 +6537,7 @@ static __latent_entropy void net_rx_action(struct softirq_action *h)struct netdev_adjacent {struct net_device *dev; +netdevice_tracker dev_tracker;/* upper master flag, there can only be one master device per list */ bool master;
@@ -7301,7 +7302,7 @@ static int __netdev_adjacent_dev_insert(struct net_device *dev, adj->ref_nr =1 ; adj->private = private; adj->ignore = false; -dev_hold (adj_dev); +dev_hold_track (adj_dev, &adj->dev_tracker,GFP_KERNEL );pr_debug ("Insert adjacency: dev %s adj_dev %s adj->ref_nr %d; dev_hold on %s\n" , dev->name, adj_dev->name, adj->ref_nr, adj_dev->name);
@@ -7330,8 +7331,8 @@ static int __netdev_adjacent_dev_insert(struct net_device *dev,if (netdev_adjacent_is_neigh_list (dev, adj_dev, dev_list))netdev_adjacent_sysfs_del (dev, adj_dev->name, dev_list); free_adj: +dev_put_track (adj_dev, &adj->dev_tracker);kfree (adj); -dev_put (adj_dev);return ret; }
@@ -7372,7 +7373,7 @@ static void __netdev_adjacent_dev_remove(struct net_device *dev,list_del_rcu (&adj->list);pr_debug ("adjacency: dev_put for %s, because link removed from %s to %s\n" , adj_dev->name, dev->name, adj_dev->name); -dev_put (adj_dev); +dev_put_track (adj_dev, &adj->dev_tracker);kfree_rcu (adj, rcu); }
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 17/23 ipv6: add net device refcount tracker to struct inet6_dev
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
--- include/net/if_inet6.h | 1 + net/ipv6/addrconf.c | 4 ++-- net/ipv6/addrconf_core.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-)
include/net/if_inet6.h +1 -0
@@ -160,6 +160,7 @@ struct ipv6_devstat {struct inet6_dev {struct net_device *dev; +netdevice_tracker dev_tracker;struct list_head addr_list;
net/ipv6/addrconf.c +2 -2
@@ -405,13 +405,13 @@ static struct inet6_dev *ipv6_add_dev(struct net_device *dev)if (ndev->cnf.forwarding)dev_disable_lro (dev);/* We refer to the device */ -dev_hold (dev); +dev_hold_track (dev, &ndev->dev_tracker,GFP_KERNEL );if (snmp6_alloc_dev (ndev) <0 ) {netdev_dbg (dev,"%s: cannot allocate memory for statistics\n" , __func__);neigh_parms_release (&nd_tbl, ndev->nd_parms); -dev_put (dev); +dev_put_track (dev, &ndev->dev_tracker);kfree (ndev);return ERR_PTR (err); }
net/ipv6/addrconf_core.c +1 -1
@@ -263,7 +263,7 @@ void in6_dev_finish_destroy(struct inet6_dev *idev)#ifdef NET_REFCNT_DEBUG pr_debug ("%s: %s\n" , __func__, dev ? dev->name :"NIL" );#endif -dev_put (dev); +dev_put_track (dev, &idev->dev_tracker);if (!idev->dead) {pr_warn ("Freeing alive inet6 device %p\n" , idev);return ;
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 18/23 ipv4: add net device refcount tracker to struct in_device
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
--- include/linux/inetdevice.h | 2 ++ net/ipv4/devinet.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-)
include/linux/inetdevice.h +2 -0
@@ -24,6 +24,8 @@ struct ipv4_devconf {struct in_device {struct net_device *dev; +netdevice_tracker dev_tracker; +refcount_t refcnt;int dead;struct in_ifaddr __rcu *ifa_list;/* IP ifaddr chain */
net/ipv4/devinet.c +2 -2
@@ -243,7 +243,7 @@ void in_dev_finish_destroy(struct in_device *idev)#ifdef NET_REFCNT_DEBUG pr_debug ("%s: %p=%s\n" , __func__, idev, dev ? dev->name :"NIL" );#endif -dev_put (dev); +dev_put_track (dev, &idev->dev_tracker);if (!idev->dead)pr_err ("Freeing alive in_device %p\n" , idev);else
@@ -271,7 +271,7 @@ static struct in_device *inetdev_init(struct net_device *dev)if (IPV4_DEVCONF (in_dev->cnf,FORWARDING ))dev_disable_lro (dev);/* Reference in_dev->dev */ -dev_hold (dev); +dev_hold_track (dev, &in_dev->dev_tracker,GFP_KERNEL );/* Account for reference dev->ip_ptr (below) */ refcount_set (&in_dev->refcnt,1 );
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 19/23 net/sched: add net device refcount tracker to struct Qdisc
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
--- include/net/sch_generic.h | 2 +- net/sched/sch_generic.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
include/net/sch_generic.h +1 -1
@@ -125,7 +125,7 @@ struct Qdisc {spinlock_t seqlock;struct rcu_head rcu; - +netdevice_tracker dev_tracker;/* private data */ long privdata[]____cacheline_aligned ; };
net/sched/sch_generic.c +2 -2
@@ -973,7 +973,7 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue, sch->enqueue = ops->enqueue; sch->dequeue = ops->dequeue; sch->dev_queue = dev_queue; -dev_hold (dev); +dev_hold_track (dev, &sch->dev_tracker,GFP_KERNEL );refcount_set (&sch->refcnt,1 );return sch;
@@ -1073,7 +1073,7 @@ static void qdisc_destroy(struct Qdisc *qdisc) ops->destroy (qdisc);module_put (ops->owner); -dev_put (qdisc_dev (qdisc)); +dev_put_track (qdisc_dev (qdisc), &qdisc->dev_tracker);trace_qdisc_destroy (qdisc);
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 20/23 net: linkwatch: add net device refcount tracker
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
Add a netdevice_tracker inside struct net_device, to track the self reference when a device is in lweventlist.
--- include/linux/netdevice.h | 1 + net/core/link_watch.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-)
include/linux/netdevice.h +1 -0
@@ -2279,6 +2279,7 @@ struct net_device {struct bpf_xdp_entity xdp_state[__MAX_XDP_MODE];u8 dev_addr_shadow[MAX_ADDR_LEN ]; +netdevice_tracker linkwatch_dev_tracker; };#define to_net_dev (d) container_of(d, struct net_device, dev)
net/core/link_watch.c +2 -2
@@ -109,7 +109,7 @@ static void linkwatch_add_event(struct net_device *dev)spin_lock_irqsave (&lweventlist_lock, flags);if (list_empty (&dev->link_watch_list)) {list_add_tail (&dev->link_watch_list, &lweventlist); -dev_hold (dev); +dev_hold_track (dev, &dev->linkwatch_dev_tracker,GFP_ATOMIC ); }spin_unlock_irqrestore (&lweventlist_lock, flags); }
@@ -166,7 +166,7 @@ static void linkwatch_do_dev(struct net_device *dev)netdev_state_change (dev); } -dev_put (dev); +dev_put_track (dev, &dev->linkwatch_dev_tracker); }static void __linkwatch_run_queue (int urgent_only)
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 21/23 net: failover: add net device refcount tracker
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
--- include/net/failover.h | 1 + net/core/failover.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-)
include/net/failover.h +1 -0
@@ -25,6 +25,7 @@ struct failover_ops {struct failover {struct list_head list;struct net_device __rcu *failover_dev; +netdevice_tracker dev_tracker;struct failover_ops __rcu *ops; };
net/core/failover.c +2 -2
@@ -252,7 +252,7 @@ struct failover *failover_register(struct net_device *dev,return ERR_PTR (-ENOMEM );rcu_assign_pointer (failover->ops, ops); -dev_hold (dev); +dev_hold_track (dev, &failover->dev_tracker,GFP_KERNEL ); dev->priv_flags |=IFF_FAILOVER ;rcu_assign_pointer (failover->failover_dev, dev);
@@ -285,7 +285,7 @@ void failover_unregister(struct failover *failover) failover_dev->name); failover_dev->priv_flags &= ~IFF_FAILOVER ; -dev_put (failover_dev); +dev_put_track (failover_dev, &failover->dev_tracker);spin_lock (&failover_lock);list_del (&failover->list);
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 22/23 ipmr, ip6mr: add net device refcount tracker to struct vif_device
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
--- include/linux/mroute_base.h | 1 + net/ipv4/ipmr.c | 3 ++- net/ipv6/ip6mr.c | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-)
include/linux/mroute_base.h +1 -0
@@ -26,6 +26,7 @@*/ struct vif_device {struct net_device *dev; +netdevice_tracker dev_tracker;unsigned long bytes_in, bytes_out;unsigned long pkt_in, pkt_out;unsigned long rate_limit;
net/ipv4/ipmr.c +2 -1
@@ -696,7 +696,7 @@ static int vif_delete(struct mr_table *mrt, int vifi, int notify,if (v->flags & (VIFF_TUNNEL |VIFF_REGISTER ) && !notify)unregister_netdevice_queue (dev, head); -dev_put (dev); +dev_put_track (dev, &v->dev_tracker);return 0 ; }
@@ -896,6 +896,7 @@ static int vif_add(struct net *net, struct mr_table *mrt,/* And finish update writing critical data */ write_lock_bh (&mrt_lock); v->dev = dev; +netdev_tracker_alloc (dev, &v->dev_tracker,GFP_ATOMIC );if (v->flags &VIFF_REGISTER ) mrt->mroute_reg_vif_num = vifi;if (vifi+1 > mrt->maxvif)
net/ipv6/ip6mr.c +2 -1
@@ -746,7 +746,7 @@ static int mif6_delete(struct mr_table *mrt, int vifi, int notify,if ((v->flags &MIFF_REGISTER ) && !notify)unregister_netdevice_queue (dev, head); -dev_put (dev); +dev_put_track (dev, &v->dev_tracker);return 0 ; }
@@ -919,6 +919,7 @@ static int mif6_add(struct net *net, struct mr_table *mrt,/* And finish update writing critical data */ write_lock_bh (&mrt_lock); v->dev = dev; +netdev_tracker_alloc (dev, &v->dev_tracker,GFP_ATOMIC );#ifdef CONFIG_IPV6_PIMSM_V2 if (v->flags &MIFF_REGISTER ) mrt->mroute_reg_vif_num = vifi;
Signature · 1 line
2.34.1.400.ga245620fadb-goog
PATCH v2 23/23 netpoll: add net device refcount tracker to struct netpoll
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
--- drivers/net/netconsole.c | 2 +- include/linux/netpoll.h | 1 + net/core/netpoll.c | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-)
drivers/net/netconsole.c +1 -1
@@ -721,7 +721,7 @@ static int netconsole_netdev_event(struct notifier_block *this,__netpoll_cleanup (&nt->np);spin_lock_irqsave (&target_list_lock, flags); -dev_put (nt->np.dev); +dev_put_track (nt->np.dev, &nt->np.dev_tracker); nt->np.dev =NULL ; nt->enabled = false; stopped = true;
include/linux/netpoll.h +1 -0
@@ -24,6 +24,7 @@ union inet_addr {struct netpoll {struct net_device *dev; +netdevice_tracker dev_tracker;char dev_name[IFNAMSIZ ];const char *name;
net/core/netpoll.c +2 -2
@@ -776,7 +776,7 @@ int netpoll_setup(struct netpoll *np) err =__netpoll_setup (np, ndev);if (err) goto put; - +netdev_tracker_alloc (ndev, &np->dev_tracker,GFP_KERNEL );rtnl_unlock ();return 0 ;
@@ -853,7 +853,7 @@ void netpoll_cleanup(struct netpoll *np)if (!np->dev) goto out;__netpoll_cleanup (np); -dev_put (np->dev); +dev_put_track (np->dev, &np->dev_tracker); np->dev =NULL ; out:rtnl_unlock ();
Signature · 1 line
2.34.1.400.ga245620fadb-goog
Jakub Kicinski
maintainerQuoted 13 lines · On Thu, 2 Dec 2021 18:46:17 -0800 Eric Dumazet wrote:
Two first patches add a generic infrastructure, that will be used to get tracking of refcount increments/decrements.
The general idea is to be able to precisely pair each decrement with a corresponding prior increment. Both share a cookie, basically a pointer to private data storing stack traces.
The third place adds
dev_hold_track()anddev_put_track()helpers (CONFIG_NET_DEV_REFCNT_TRACKER)Then a series of 20 patches converts some dev_hold()/dev_put() pairs to new hepers :
dev_hold_track()anddev_put_track().
Quoted 6 lines
Hopefully this will be used by developpers and syzbot to root cause bugs that cause netdevice dismantles freezes.
With
CONFIG_PCPU_DEV_REFCNT=noption, we were able to detect some class of bugs, but too late (when too manydev_put()were happening).
Hi Eric, there's a handful of kdoc warnings added here:
include/linux/netdevice.h:2278: warning: Function parameter or member 'refcnt_tracker' not described in 'net_device' include/net/devlink.h:679: warning: Function parameter or member 'dev_tracker' not described in 'devlink_trap_metadata' include/linux/netdevice.h:2283: warning: Function parameter or member 'refcnt_tracker' not described in 'net_device' include/linux/mroute_base.h:40: warning: Function parameter or member 'dev_tracker' not described in 'vif_device'
Would you mind following up? likely not worth re-spinning just for that.
Quoted 22 lines · Jakub Kicinski
Quoted 13 lines · On Thu, 2 Dec 2021 18:46:17 -0800 Eric Dumazet wrote:
Two first patches add a generic infrastructure, that will be used to get tracking of refcount increments/decrements.
The general idea is to be able to precisely pair each decrement with a corresponding prior increment. Both share a cookie, basically a pointer to private data storing stack traces.
The third place adds
dev_hold_track()anddev_put_track()helpers (CONFIG_NET_DEV_REFCNT_TRACKER)Then a series of 20 patches converts some dev_hold()/dev_put() pairs to new hepers :
dev_hold_track()anddev_put_track().Quoted 6 lines
Hopefully this will be used by developpers and syzbot to root cause bugs that cause netdevice dismantles freezes.
With
CONFIG_PCPU_DEV_REFCNT=noption, we were able to detect some class of bugs, but too late (when too manydev_put()were happening).
Quoted 8 lines
Hi Eric, there's a handful of kdoc warnings added here:
include/linux/netdevice.h:2278: warning: Function parameter or member 'refcnt_tracker' not described in 'net_device'include/net/devlink.h:679: warning: Function parameter or member 'dev_tracker' not described in 'devlink_trap_metadata'include/linux/netdevice.h:2283: warning: Function parameter or member 'refcnt_tracker' not described in 'net_device'include/linux/mroute_base.h:40: warning: Function parameter or member 'dev_tracker' not described in 'vif_device'Would you mind following up? likely not worth re-spinning just for that.
Sure thing, I will insert a patch to fix this in the next round.
Thanks !