From patchwork Thu Dec 2 03:21:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12651501 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A88E3C433F5 for ; Thu, 2 Dec 2021 03:21:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355169AbhLBDZN (ORCPT ); Wed, 1 Dec 2021 22:25:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355151AbhLBDZM (ORCPT ); Wed, 1 Dec 2021 22:25:12 -0500 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34938C061574 for ; Wed, 1 Dec 2021 19:21:51 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id s37so15974755pga.9 for ; Wed, 01 Dec 2021 19:21:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FgGjzv1NIC92hODa2gbn4h153F1HGBrv6ma2SYdMaOA=; b=HoxiYC9ox6fj/PblhfFjDbk8rjiLgKL3SEdB6V8AbljJxivTguhFa/myqb2/4Uweij EpNVXj8Cqp18V30+DjPOsD4oOnGurfmJMvO4DM4Q7IsjKeulZZmDhMuzmb4KpxfidbCT rHAfbMLCEHX0AMrZlIOVsO1BrLOjf05L2wNAg0qSUJpss6XF7HyYLm6SjdjrSbxAVV+3 gPQrue1dWGCQQk4NmJAQYfYPYmtPeb9h28ZkbrWutkOckGJji/VCmFW0yF9F/ndcjghr SEl5FBm3dPir/DojqEewR0fDoaVVj9K79c2+qFcZGkdoQlhE2HY7O4uOGXxnopYf1D+S vXxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FgGjzv1NIC92hODa2gbn4h153F1HGBrv6ma2SYdMaOA=; b=hrLxdTVYaDewpNcOBaBMUJw/JAubQQeyTBq/3AwBOZjsJd9B08wjkX19Em+BzIYYqW OFs9JY1rtou6TT1TPgPIAu70rYjh38TuhWYIoqU2UYIlxD0t44+YhwR004NeOJXnnJFU yfUFakulVEg/KFcyfkfhgcIgG/UeJQSJR7GItDwAJwF9jnrT/Qp64i+8g+3HpaD/opE6 U+NVf1V67IaXLy5eGJ3nr5yvzE68DSLqaqfFhOUkU+0gi6a/6AflOsdzB139p4jPmNLv VHi0LWy8UYMUa2CpuQ8CyZgcwdD2H6xuRcM/UGq1Zm9YbrVEHbyTo4ZhAfgUZU1MCxUg djUw== X-Gm-Message-State: AOAM533MSrrJINqr2t8aWNTzKUJg2Q+vvoeCczTtgzY/mccRQ6kunM/c Wdg2QuOTISjEqukQnHT8nfw= X-Google-Smtp-Source: ABdhPJzZ5drDOIadDcQDm4vqT/xM4bszAQQtE7o6GU1HLp88fRinyF60h9xCT0rSl1BZX9XNIFOsUg== X-Received: by 2002:a63:e50:: with SMTP id 16mr7716342pgo.619.1638415310705; Wed, 01 Dec 2021 19:21:50 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:e768:caa5:c812:6a1c]) by smtp.gmail.com with ESMTPSA id h5sm1306572pfi.46.2021.12.01.19.21.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 19:21:50 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Dmitry Vyukov , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 01/19] lib: add reference counting tracking infrastructure Date: Wed, 1 Dec 2021 19:21:21 -0800 Message-Id: <20211202032139.3156411-2-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211202032139.3156411-1-eric.dumazet@gmail.com> References: <20211202032139.3156411-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet 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. Signed-off-by: Eric Dumazet Reviewed-by: Dmitry Vyukov --- include/linux/ref_tracker.h | 73 +++++++++++++++++++ lib/Kconfig | 4 ++ lib/Makefile | 2 + lib/ref_tracker.c | 140 ++++++++++++++++++++++++++++++++++++ 4 files changed, 219 insertions(+) create mode 100644 include/linux/ref_tracker.h create mode 100644 lib/ref_tracker.c diff --git a/include/linux/ref_tracker.h b/include/linux/ref_tracker.h new file mode 100644 index 0000000000000000000000000000000000000000..c11c9db5825cf933acf529c83db441a818135f29 --- /dev/null +++ b/include/linux/ref_tracker.h @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef _LINUX_REF_TRACKER_H +#define _LINUX_REF_TRACKER_H +#include +#include +#include + +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 */ diff --git a/lib/Kconfig b/lib/Kconfig index 5e7165e6a346c9bec878b78c8c8c3d175fc98dfd..d01be8e9593992a7d94a46bd1716460bc33c3ae1 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -680,6 +680,10 @@ 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 + select STACKDEPOT + config SBITMAP bool diff --git a/lib/Makefile b/lib/Makefile index 364c23f1557816f73aebd8304c01224a4846ac6c..c1fd9243ddb9cc1ac5252d7eb8009f9290782c4a 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -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), \ diff --git a/lib/ref_tracker.c b/lib/ref_tracker.c new file mode 100644 index 0000000000000000000000000000000000000000..0ae2e66dcf0fdb976f4cb99e747c9448b37f22cc --- /dev/null +++ b/lib/ref_tracker.c @@ -0,0 +1,140 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include +#include +#include +#include +#include + +#define REF_TRACKER_STACK_ENTRIES 16 + +struct ref_tracker { + struct list_head head; /* anchor into dir->list or dir->quarantine */ + bool dead; + depot_stack_handle_t alloc_stack_handle; + depot_stack_handle_t free_stack_handle; +}; + +void ref_tracker_dir_exit(struct ref_tracker_dir *dir) +{ + struct ref_tracker *tracker, *n; + unsigned long flags; + bool leak = false; + + spin_lock_irqsave(&dir->lock, flags); + list_for_each_entry_safe(tracker, n, &dir->quarantine, head) { + list_del(&tracker->head); + kfree(tracker); + dir->quarantine_avail++; + } + list_for_each_entry_safe(tracker, n, &dir->list, head) { + pr_err("leaked reference.\n"); + if (tracker->alloc_stack_handle) + stack_depot_print(tracker->alloc_stack_handle); + leak = true; + list_del(&tracker->head); + kfree(tracker); + } + spin_unlock_irqrestore(&dir->lock, flags); + WARN_ON_ONCE(leak); + WARN_ON_ONCE(refcount_read(&dir->untracked) != 1); +} +EXPORT_SYMBOL(ref_tracker_dir_exit); + +void ref_tracker_dir_print(struct ref_tracker_dir *dir, + unsigned int display_limit) +{ + struct ref_tracker *tracker; + unsigned long flags; + unsigned int i = 0; + + spin_lock_irqsave(&dir->lock, flags); + list_for_each_entry(tracker, &dir->list, head) { + if (i < display_limit) { + pr_err("leaked reference.\n"); + if (tracker->alloc_stack_handle) + stack_depot_print(tracker->alloc_stack_handle); + i++; + } else { + break; + } + } + spin_unlock_irqrestore(&dir->lock, flags); +} +EXPORT_SYMBOL(ref_tracker_dir_print); + +int ref_tracker_alloc(struct ref_tracker_dir *dir, + struct ref_tracker **trackerp, + gfp_t gfp) +{ + unsigned long entries[REF_TRACKER_STACK_ENTRIES]; + struct ref_tracker *tracker; + unsigned int nr_entries; + unsigned long flags; + + *trackerp = tracker = kzalloc(sizeof(*tracker), gfp | __GFP_NOFAIL); + if (unlikely(!tracker)) { + pr_err_once("memory allocation failure, unreliable refcount tracker.\n"); + refcount_inc(&dir->untracked); + return -ENOMEM; + } + nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 1); + nr_entries = filter_irq_stacks(entries, nr_entries); + tracker->alloc_stack_handle = stack_depot_save(entries, nr_entries, gfp); + + spin_lock_irqsave(&dir->lock, flags); + list_add(&tracker->head, &dir->list); + spin_unlock_irqrestore(&dir->lock, flags); + return 0; +} +EXPORT_SYMBOL_GPL(ref_tracker_alloc); + +int ref_tracker_free(struct ref_tracker_dir *dir, + struct ref_tracker **trackerp) +{ + unsigned long entries[REF_TRACKER_STACK_ENTRIES]; + struct ref_tracker *tracker = *trackerp; + depot_stack_handle_t stack_handle; + unsigned int nr_entries; + unsigned long flags; + + if (!tracker) { + refcount_dec(&dir->untracked); + return -EEXIST; + } + nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 1); + nr_entries = filter_irq_stacks(entries, nr_entries); + stack_handle = stack_depot_save(entries, nr_entries, GFP_ATOMIC); + + spin_lock_irqsave(&dir->lock, flags); + if (tracker->dead) { + pr_err("reference already released.\n"); + if (tracker->alloc_stack_handle) { + pr_err("allocated in:\n"); + stack_depot_print(tracker->alloc_stack_handle); + } + if (tracker->free_stack_handle) { + pr_err("freed in:\n"); + stack_depot_print(tracker->free_stack_handle); + } + spin_unlock_irqrestore(&dir->lock, flags); + WARN_ON_ONCE(1); + return -EINVAL; + } + tracker->dead = true; + + tracker->free_stack_handle = stack_handle; + + list_move_tail(&tracker->head, &dir->quarantine); + if (!dir->quarantine_avail) { + tracker = list_first_entry(&dir->quarantine, struct ref_tracker, head); + list_del(&tracker->head); + } else { + dir->quarantine_avail--; + tracker = NULL; + } + spin_unlock_irqrestore(&dir->lock, flags); + + kfree(tracker); + return 0; +} +EXPORT_SYMBOL_GPL(ref_tracker_free); From patchwork Thu Dec 2 03:21:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12651503 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A04FC433EF for ; Thu, 2 Dec 2021 03:21:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355171AbhLBDZT (ORCPT ); Wed, 1 Dec 2021 22:25:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355151AbhLBDZS (ORCPT ); Wed, 1 Dec 2021 22:25:18 -0500 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2801FC061574 for ; Wed, 1 Dec 2021 19:21:57 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id l190so25664786pge.7 for ; Wed, 01 Dec 2021 19:21:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Hdz71BLCH2fNlxnnQDjh3NIu7TqQvsqAxUP3S97Q0zY=; b=N5hRpsqh6Gsljtdh6zThKV96NRTZB0NhL2fCeICs016odQAAK+mNfuvwxSBCfgXACc GGjQ+XwVyfxC0gNffQ8Yr9IFEskMyD+Q+bsrQl+EDLVyagCI7+BYJnnqIVCvW6fPhme2 lD6db+4BF6Fe/U2tzpJrnJX3oEMSkdMPLHnOul6AYpd1EDGG4SjsGBpnCliHAehAXaiI 1zfLjEirYiaDwCcm7CZn65hUnO+JBgvU1g42XpuCck96Lq7z8mbs9qUIHiQjhSav54Dz ALMBQfD+8tJo+XpMAJ8GpBiGEJES0wq8nIyyJkV68cTxx1k3hUWJhQr7F8JrgqGg4yFt br8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Hdz71BLCH2fNlxnnQDjh3NIu7TqQvsqAxUP3S97Q0zY=; b=wgG6pR1nUoAnyXaKCJBPRmh43ht7yrr3gGb6PdxQWS01j3TMAisdavuYW2o8yZAygG bZExZrsioS977cT7RrCoyibSDqHebaQTCVZnPQ/sejaIfNgEyOnLnyeGuiE8Dnmzuxpg rrqcZOv5IvZJAWcfv1z82gnBp4N8zruF91iNoeUIKSonsU/9SpOs9kcK8r66nxmL5gPM rB0qKhDWC0YO9fAv6cs+LRBQ2As9Oo5k0W44PKaT3zNu1KeB9bNw2gIBDuiFAkyDoPg7 2rl1v5dPPMGhggwc95CDuddk8lA1jOPLY370q69YIfJtkTldSUgWbg9vBip2r2amlJt1 Eo0w== X-Gm-Message-State: AOAM5325M8MqWOAZs7Rs8SVQ0rOfJmKWMUsspjLAgTtMJ1Psz1f/3XDy tPOg/sUYpknUnrEcGkGukpDnTzXMErk= X-Google-Smtp-Source: ABdhPJy9U6meyQO72JKRFopOCLsvFqMmSrd+ntzg0/jSlkeCpoFTldLK2ZBmHkYNUzTumFJP6kUxTw== X-Received: by 2002:a63:dc0b:: with SMTP id s11mr7959714pgg.272.1638415316674; Wed, 01 Dec 2021 19:21:56 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:e768:caa5:c812:6a1c]) by smtp.gmail.com with ESMTPSA id h5sm1306572pfi.46.2021.12.01.19.21.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 19:21:56 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Dmitry Vyukov , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 02/19] lib: add tests for reference tracker Date: Wed, 1 Dec 2021 19:21:22 -0800 Message-Id: <20211202032139.3156411-3-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211202032139.3156411-1-eric.dumazet@gmail.com> References: <20211202032139.3156411-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet 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] [ 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] [ 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] [ 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] [ 171.667210] ---[ end trace f5dbd6afa41e60aa ]--- Signed-off-by: Eric Dumazet Reported-by: kernel test robot Reported-by: kernel test robot --- lib/Kconfig.debug | 10 ++++ lib/Makefile | 2 +- lib/test_ref_tracker.c | 116 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 lib/test_ref_tracker.c diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 5c12bde10996cf97b5f075d318089b1be73f71d7..d005f555872147e15d3e0a65d2a03e1a5c44f5f0 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -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 diff --git a/lib/Makefile b/lib/Makefile index c1fd9243ddb9cc1ac5252d7eb8009f9290782c4a..b213a7bbf3fda2eb9f234fb7473b8f1b617bed6b 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -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 diff --git a/lib/test_ref_tracker.c b/lib/test_ref_tracker.c new file mode 100644 index 0000000000000000000000000000000000000000..73bf9255e03790fa50491fe8e5cd411d54827c45 --- /dev/null +++ b/lib/test_ref_tracker.c @@ -0,0 +1,116 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Referrence tracker self test. + * + * Copyright (c) 2021 Eric Dumazet + */ +#include +#include +#include +#include +#include +#include + +static struct ref_tracker_dir ref_dir; +static struct ref_tracker *tracker[20]; + +#define TRT_ALLOC(X) static noinline void \ + alloctest_ref_tracker_alloc##X(struct ref_tracker_dir *dir, \ + struct ref_tracker **trackerp) \ + { \ + ref_tracker_alloc(dir, trackerp, GFP_KERNEL); \ + } + +TRT_ALLOC(0) +TRT_ALLOC(1) +TRT_ALLOC(2) +TRT_ALLOC(3) +TRT_ALLOC(4) +TRT_ALLOC(5) +TRT_ALLOC(6) +TRT_ALLOC(7) +TRT_ALLOC(8) +TRT_ALLOC(9) +TRT_ALLOC(10) +TRT_ALLOC(11) +TRT_ALLOC(12) +TRT_ALLOC(13) +TRT_ALLOC(14) +TRT_ALLOC(15) +TRT_ALLOC(16) +TRT_ALLOC(17) +TRT_ALLOC(18) +TRT_ALLOC(19) + +#undef TRT_ALLOC + +static noinline void +alloctest_ref_tracker_free(struct ref_tracker_dir *dir, + struct ref_tracker **trackerp) +{ + ref_tracker_free(dir, trackerp); +} + + +static struct timer_list test_ref_tracker_timer; +static atomic_t test_ref_timer_done = ATOMIC_INIT(0); + +static void test_ref_tracker_timer_func(struct timer_list *t) +{ + alloctest_ref_tracker_alloc0(&ref_dir, &tracker[0]); + atomic_set(&test_ref_timer_done, 1); +} + +static int __init test_ref_tracker_init(void) +{ + int i; + + ref_tracker_dir_init(&ref_dir, 100); + + timer_setup(&test_ref_tracker_timer, test_ref_tracker_timer_func, 0); + mod_timer(&test_ref_tracker_timer, jiffies + 1); + + alloctest_ref_tracker_alloc1(&ref_dir, &tracker[1]); + alloctest_ref_tracker_alloc2(&ref_dir, &tracker[2]); + alloctest_ref_tracker_alloc3(&ref_dir, &tracker[3]); + alloctest_ref_tracker_alloc4(&ref_dir, &tracker[4]); + alloctest_ref_tracker_alloc5(&ref_dir, &tracker[5]); + alloctest_ref_tracker_alloc6(&ref_dir, &tracker[6]); + alloctest_ref_tracker_alloc7(&ref_dir, &tracker[7]); + alloctest_ref_tracker_alloc8(&ref_dir, &tracker[8]); + alloctest_ref_tracker_alloc9(&ref_dir, &tracker[9]); + alloctest_ref_tracker_alloc10(&ref_dir, &tracker[10]); + alloctest_ref_tracker_alloc11(&ref_dir, &tracker[11]); + alloctest_ref_tracker_alloc12(&ref_dir, &tracker[12]); + alloctest_ref_tracker_alloc13(&ref_dir, &tracker[13]); + alloctest_ref_tracker_alloc14(&ref_dir, &tracker[14]); + alloctest_ref_tracker_alloc15(&ref_dir, &tracker[15]); + alloctest_ref_tracker_alloc16(&ref_dir, &tracker[16]); + alloctest_ref_tracker_alloc17(&ref_dir, &tracker[17]); + alloctest_ref_tracker_alloc18(&ref_dir, &tracker[18]); + alloctest_ref_tracker_alloc19(&ref_dir, &tracker[19]); + + /* free all trackers but first 0 and 1. */ + for (i = 2; i < ARRAY_SIZE(tracker); i++) + alloctest_ref_tracker_free(&ref_dir, &tracker[i]); + + /* Attempt to free an already freed tracker. */ + alloctest_ref_tracker_free(&ref_dir, &tracker[2]); + + while (!atomic_read(&test_ref_timer_done)) + msleep(1); + + /* This should warn about tracker[0] & tracker[1] being not freed. */ + ref_tracker_dir_exit(&ref_dir); + + return 0; +} + +static void __exit test_ref_tracker_exit(void) +{ +} + +module_init(test_ref_tracker_init); +module_exit(test_ref_tracker_exit); + +MODULE_LICENSE("GPL v2"); From patchwork Thu Dec 2 03:21:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12651505 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9007C433EF for ; Thu, 2 Dec 2021 03:22:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355172AbhLBDZ0 (ORCPT ); Wed, 1 Dec 2021 22:25:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355177AbhLBDZY (ORCPT ); Wed, 1 Dec 2021 22:25:24 -0500 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3809BC061574 for ; Wed, 1 Dec 2021 19:22:02 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id r5so25595496pgi.6 for ; Wed, 01 Dec 2021 19:22:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Rq5RcFgLaQiCcb/mMtHlYjRYf8HJlaucDsU2hzr3g04=; b=p27UkZSO9xDngdO+DgvoWKRkH2qf06tpyQSPbs0pzyRXMfAF0GDfx0OQkqUmc1FvuG mqo3+ma0+31QB5xmNywoCMk705A9+LZm90SWxXGv4aXzohn5ICZJv6hPFno6OBT2uxkn cgVV7VFKd8/1XAajQN3BAiwoYqhAH2bJMqMChtFOOfTbnsMS+QD021ZfGNb+YfZrBXx4 NVVCd+6s9xemTVsYPqrin4yJazoqg7+LTTUSLslaxa3enNcc0NENYr9BILfoPth2ty8H Hl8fkv/49bkO4Qyd8iidWI/RPo3NsjxbtgVQlzamYXX3OTmrlZeig+DD9IP0H8Zk8xwD ZIpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Rq5RcFgLaQiCcb/mMtHlYjRYf8HJlaucDsU2hzr3g04=; b=qMa5Gnb+gG7pct5h1wixBm6iq6JtT+ZGzeTQUXLbtzABrkvgEKW2ucWFl9NWXMnopu q8pGaDDCeQm9NcQdbBMsnZB/M7RwSAwo5Rj5vUj2Rr/70pYETvjNWWRfTSxM/rpTqCqP v3Xg7LmneuxFNBgKrVakI0VXqJ928zzueXiM35NC8/IJi3hHB6m3pWCE5rTDyCRTprZs DGSG9Tl3J0+faky2lsmdbRjMYqFK3AjDCPoMXBKyUWbrnDIGXRT2JqNThKOdGdJQqAqk vcafoVY8XTPuhO+QXluOrkQhgSql9OACf4ujLUuoOKGqN738MdZEQSGoVrPAgLPPmBaq b+4Q== X-Gm-Message-State: AOAM531rex7RbxaUYIcc9CKW7MNEjISS6VL2cpjOlfWTZO71YOkXUAPH aA89SGej/rK6lu9Y55J2XPs= X-Google-Smtp-Source: ABdhPJxmuWJ4YPNo7rSxkRtJGRo4KrUvmZVPDVoLPRkzOAakzITvgXUx88ILcT/iR0AjDZBcxIR7DA== X-Received: by 2002:a05:6a00:1944:b0:438:d002:6e35 with SMTP id s4-20020a056a00194400b00438d0026e35mr10154100pfk.20.1638415321784; Wed, 01 Dec 2021 19:22:01 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:e768:caa5:c812:6a1c]) by smtp.gmail.com with ESMTPSA id h5sm1306572pfi.46.2021.12.01.19.22.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 19:22:01 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Dmitry Vyukov , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 03/19] net: add dev_hold_track() and dev_put_track() helpers Date: Wed, 1 Dec 2021 19:21:23 -0800 Message-Id: <20211202032139.3156411-4-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211202032139.3156411-1-eric.dumazet@gmail.com> References: <20211202032139.3156411-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet 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. Signed-off-by: Eric Dumazet --- include/linux/netdevice.h | 32 ++++++++++++++++++++++++++++++++ net/Kconfig | 8 ++++++++ net/core/dev.c | 3 +++ 3 files changed, 43 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index db3bff1ae7fdf5ff0b0546cbd0102b86f04fa144..3ddced0fa20f5c7a4548c340788214ea909a265f 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -48,6 +48,7 @@ #include #include #include +#include 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,28 @@ static inline void dev_hold(struct net_device *dev) } } +static inline void dev_hold_track(struct net_device *dev, + netdevice_tracker *tracker, gfp_t gfp) +{ + if (dev) { + dev_hold(dev); +#ifdef CONFIG_NET_DEV_REFCNT_TRACKER + ref_tracker_alloc(&dev->refcnt_tracker, tracker, gfp); +#endif + } +} + +static inline void dev_put_track(struct net_device *dev, + netdevice_tracker *tracker) +{ + if (dev) { +#ifdef CONFIG_NET_DEV_REFCNT_TRACKER + ref_tracker_free(&dev->refcnt_tracker, tracker); +#endif + 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. diff --git a/net/Kconfig b/net/Kconfig index 8a1f9d0287de3c32040eee03b60114c6e6d150bc..0b665e60b53490f44eeda1e5506d4e125ef4c53a 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -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 diff --git a/net/core/dev.c b/net/core/dev.c index d30adecc2bb2b744b283dbda89d9488b8eb6d47e..bdfbfa4e291858f990f5e2c99c4ce0ee9ed687cd 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -9861,6 +9861,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; } } @@ -10151,6 +10152,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) @@ -10267,6 +10269,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; From patchwork Thu Dec 2 03:21:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12651507 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A541C433EF for ; Thu, 2 Dec 2021 03:22:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355180AbhLBDZg (ORCPT ); Wed, 1 Dec 2021 22:25:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355178AbhLBDZf (ORCPT ); Wed, 1 Dec 2021 22:25:35 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80564C061574 for ; Wed, 1 Dec 2021 19:22:13 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id y14-20020a17090a2b4e00b001a5824f4918so1333811pjc.4 for ; Wed, 01 Dec 2021 19:22:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QonKtI/vol5OMXM6N4aZU6C7EHW8LoX8FZwTRiSZlBY=; b=AHYenBHL206uGy1RRgucpEKd6Qg31J+S4nqd+6c1V2hStumnLg26v/1ChHkY8KiTuK HN6eHfQwwZOWEX5AsFepwfpxIy/k+2hHmO93SHpyvekDBKKAdrrNnd41DBL2SkzUKf+m gkpdaNtKLScNoFRI0RLJxguSqZsvyahCKIbi0oPlEWsZ+mihkydQB9trztaLO5ZbwEFI YQuI13IsVweXnrC+HzdggWNHlRDXBKpLUD2VOLgzaNSM5Z9SYo2XilmsPTFdCvPijMMv rP80Lc/0CPNwrzgtZrseR0EawtEFstQpaT8jh/KW1XiPwCPmFwC8Ku/NPG6+bDb/rxsE lFOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QonKtI/vol5OMXM6N4aZU6C7EHW8LoX8FZwTRiSZlBY=; b=TUrTaiucdlWYsdqbXIpDVYlVZJ/HBegG0o1a1g/eZWxsVWqMHfHqthP0mMOzA63hSn w+kXAoGiDsKwqz10GDyo66XBp2FCfkPpvw8TUnjgB3dyuS9OPcNfJ1ClIibXUGTqnbCL c2C9ONTWgWcRWQQSMwLshxUSYJDUR29j7lKx+1SAqkq0Q+2wjgMJiyPXbBlKFLnqxHB3 XAjaOhm/xtLhmHE4BaW3zaq1ZumRtSySXvMSUtYASakUy2cqIpIw6XeUDgPMEXmA5X9O SbKEWrE+Dmf8x2OZtlTK7gaZ+ijB1kvMVsFAKxukHjauev0otoodEx1NU++qBCqaiszC AV4Q== X-Gm-Message-State: AOAM533IF7Xoy6OSJDW3wIz9RZoyy9Rzj9vKO/Qay+EQcBt7xTRkK3lI 9tGCpFLSlvl8mSXR2IuEOA8= X-Google-Smtp-Source: ABdhPJxx3rNadXZjezw/LnZ/ye14BZHj4xI4z8vpOQYmXo11ZtOL7x4VoGxW1XPxAsz2ex/RmzPH/g== X-Received: by 2002:a17:903:124e:b0:143:a388:a5de with SMTP id u14-20020a170903124e00b00143a388a5demr12441647plh.73.1638415333099; Wed, 01 Dec 2021 19:22:13 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:e768:caa5:c812:6a1c]) by smtp.gmail.com with ESMTPSA id h5sm1306572pfi.46.2021.12.01.19.22.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 19:22:12 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Dmitry Vyukov , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 04/19] net: add net device refcount tracker to struct netdev_rx_queue Date: Wed, 1 Dec 2021 19:21:24 -0800 Message-Id: <20211202032139.3156411-5-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211202032139.3156411-1-eric.dumazet@gmail.com> References: <20211202032139.3156411-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet This helps debugging net device refcount leaks. Signed-off-by: Eric Dumazet --- include/linux/netdevice.h | 2 ++ net/core/net-sysfs.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 3ddced0fa20f5c7a4548c340788214ea909a265f..01006e02f8e66fc3ee16890d3bbdb49e3e7386b6 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -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 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index affe34d71d313498d8fae4a319696250aa3aef0a..27a7ac2e516f65dbfdb2a2319e6faa27c7dd8f31 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -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, From patchwork Thu Dec 2 03:21:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12651509 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD82AC433F5 for ; Thu, 2 Dec 2021 03:22:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355187AbhLBDZs (ORCPT ); Wed, 1 Dec 2021 22:25:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355177AbhLBDZj (ORCPT ); Wed, 1 Dec 2021 22:25:39 -0500 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D5FFC061574 for ; Wed, 1 Dec 2021 19:22:17 -0800 (PST) Received: by mail-pg1-x530.google.com with SMTP id k4so15517181pgb.8 for ; Wed, 01 Dec 2021 19:22:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DwKye74xS/o+/oCC7HHBDHu1NiXUCS13Osw1+37JcqA=; b=qyjxkv+3Xr3R+z6R5+Sn5qdLp3LMsKCKNyjGm8vHecfxo24qxMOI2MSeYN1qqJlKIr WIBL17tNWLjPhIpgaJY0BfLR5HicTUj9K/pPRg4wKeKbt4esnOZBt+83rQO9z2SMv50l gPNm4L3z1AUiptyPAp7rBGkOp5tXZz0EP7NkPDJkyCIh5vw9s/79z/6TP/P7MeELOmbM XqNWMbLD2d336QRrt9+SE/ivh/LNvPvXS8bptQcDG0wrgga2ST2rApHlSTUx1YbqaSmv eNTtYL71UT0b54vzxCtuXN/KgjmCHeNhyRqn4i9CrXleRx/E8REVDnR7Say7J6NwTTA1 E91A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DwKye74xS/o+/oCC7HHBDHu1NiXUCS13Osw1+37JcqA=; b=VNbjNMOu1vjVP2xkR325lx1Q3m8cyauMWT9F9Ak9rFh0c98kBCvfV1sU2whCxs2B2S S1vTEzH+QrDBa7Q/K69IrWH529oEucJhZX/pDqOdMJtsBPKlmf9qNZ6X6TEph+V9inXq ++RP9k9e5i+mU4ALokDCw1h15uBTEMmw5aQinD7VEhGmu4+n+MMxXw9YHHmFu5CzjgVH HltqadaxM5+VquHqbc3BTpaYDS93zMGpqfy5g1EIhQacVkWdVczl4lsb595pQnaAb5Qz lzKLHHDEhVKqp8AId45FgVK3Rpi+7gqhsPJPFKAIVQOLbanNYrJWQljQit/aiTXjEIw6 OG+g== X-Gm-Message-State: AOAM533KBq9Cw5ii60HGTcWQAvzN3EouXJAgqzTJtq10RjCKsrCl3Qs2 MLLkxDk7pasmRzP/A/vEKPw= X-Google-Smtp-Source: ABdhPJxxSmiR2BKDAcDWnQXUf2xOjJuIrHpZEjsesffCNFBKgh7tTcOZjLrOW6KNm9PdU7fWhcWO1Q== X-Received: by 2002:a63:5526:: with SMTP id j38mr7625189pgb.86.1638415336935; Wed, 01 Dec 2021 19:22:16 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:e768:caa5:c812:6a1c]) by smtp.gmail.com with ESMTPSA id h5sm1306572pfi.46.2021.12.01.19.22.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 19:22:16 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Dmitry Vyukov , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 05/19] net: add net device refcount tracker to struct netdev_queue Date: Wed, 1 Dec 2021 19:21:25 -0800 Message-Id: <20211202032139.3156411-6-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211202032139.3156411-1-eric.dumazet@gmail.com> References: <20211202032139.3156411-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet This will help debugging pesky netdev reference leaks. Signed-off-by: Eric Dumazet --- include/linux/netdevice.h | 2 ++ net/core/net-sysfs.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 01006e02f8e66fc3ee16890d3bbdb49e3e7386b6..b43102614696a97c919f601d1337746443d79557 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -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 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 27a7ac2e516f65dbfdb2a2319e6faa27c7dd8f31..3b2cdbbdc858e06fb0a482a9b7fc778e501ba1e0 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -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, From patchwork Thu Dec 2 03:21:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12651511 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAA75C433F5 for ; Thu, 2 Dec 2021 03:22:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355184AbhLBDZ5 (ORCPT ); Wed, 1 Dec 2021 22:25:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355178AbhLBDZp (ORCPT ); Wed, 1 Dec 2021 22:25:45 -0500 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84AECC061574 for ; Wed, 1 Dec 2021 19:22:19 -0800 (PST) Received: by mail-pg1-x536.google.com with SMTP id s37so15975531pga.9 for ; Wed, 01 Dec 2021 19:22:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qij13/EDGcPoDif2lcrCVzSIcywYR2YPGYnVdiAWmgA=; b=CYF8LDLykIVHm4LmTf9aZ8S69jprDNkKGB8uasOEKut2MrPsdjL8luWmintH4k6N4C 3vmNQsKSrQPnAHmNQFdwu+qG35+FzypGNlcq9tfS20716GgE3dcTAYG6r5eXWznOsMFz UxSbXf0axEuyfWkmsJWYJZL39hx+ZPIrKgOGlM1uii1w1+6AtAa84BhOcgtjeU/SAGgE Bb+DutoibTahdLNVx/Dud4ZCQk+4bnoS/TZrz+mf0EGUZ17QjXdCwkCM3kq46lxKXeN1 iJDTKFNkroJDnblroWgyeNoJibL07vh2PkUSHRAsOnB+U/OECYmBTCRQUfXu6PfIp+KM apmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Qij13/EDGcPoDif2lcrCVzSIcywYR2YPGYnVdiAWmgA=; b=WeoB3A0dSTQHGm1z+RXqfgn20mej2YeX0xaKO5+S4y2IFRswODpVSN9ylKjgXCZ0fZ jSJ9VZd9aO/ccDdp8QjQU+hGO4DDc5op0welzJI2KqqicsZBhbzyysSkVBj9/dY29VAd yXk87znmmfCx0gpgABQv0aV+lOtVCtqaE1HojvH4JoaqN28Pb/NQYxkyIW3nD4SOEhGn rKgcnkdEHc+jU7Hg2ffZAd6hfdLbhVS6ebjw+6+ryTIGD0FOz4brf5NJSDmPQr+kL56Q O+utqP0Lzpg2FADMIHvzdIbwTvXGHDBJs4gkdShX4XnNNNM3WR5JqF15fMduajF1zIPa hfyw== X-Gm-Message-State: AOAM530lDRBDG3XonQR7Mpau4HQJvPgYLa8MXtnWBfV/Wx4MNp1Hs2SR zfmWiKy/ZI+aw13Oa0DP3NM= X-Google-Smtp-Source: ABdhPJzqG6orxJGGbvefjjxllddIm9fxm3xc9tieZcmApNECJRPIg8vvYnrSLbbl2GMlSFKGalvg+A== X-Received: by 2002:a62:15d0:0:b0:4a0:2dd5:ee4e with SMTP id 199-20020a6215d0000000b004a02dd5ee4emr10488587pfv.14.1638415339117; Wed, 01 Dec 2021 19:22:19 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:e768:caa5:c812:6a1c]) by smtp.gmail.com with ESMTPSA id h5sm1306572pfi.46.2021.12.01.19.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 19:22:18 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Dmitry Vyukov , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 06/19] net: add net device refcount tracker to ethtool_phys_id() Date: Wed, 1 Dec 2021 19:21:26 -0800 Message-Id: <20211202032139.3156411-7-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211202032139.3156411-1-eric.dumazet@gmail.com> References: <20211202032139.3156411-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet This helper might hold a netdev reference for a long time, lets add reference tracking. Signed-off-by: Eric Dumazet --- net/ethtool/ioctl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index fa8aa5ec19ba1cfff611a159c5b8bcd02f74c5ca..9a113d89352123acf56ec598c191bb75985c6be5 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -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); From patchwork Thu Dec 2 03:21:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12651513 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 418DDC433F5 for ; Thu, 2 Dec 2021 03:22:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355193AbhLBD0G (ORCPT ); Wed, 1 Dec 2021 22:26:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355189AbhLBDZu (ORCPT ); Wed, 1 Dec 2021 22:25:50 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 669B5C061574 for ; Wed, 1 Dec 2021 19:22:28 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id nh10-20020a17090b364a00b001a69adad5ebso3487509pjb.2 for ; Wed, 01 Dec 2021 19:22:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qJ4N3TZkXDp/zFxWJ2xUxDT7iabkYNzhWXo0PGJiX9I=; b=m1JDw9mEk6QQypZVRgDVe3gsMes+dmrI8wVgYgX5QCSHfRBdunsKGQ12uKxqLYBde5 vTwslReDovfQKkRUdeSR/au4Y8v0m9SbGpz3BbWBx/5O2uOnnwkdkTZWMDVeXxSnEBPX g6PpTnMUPYuvr+I0d/ctyOv7lzeugvuZEiyBdtGFs6Tn4b7Byah39Xec50ZwnAB9z/n0 Ksr5tq4/x/Y6DnDbXwygoPzjCGYgUC5lM8UylwMYGPJonoWinPTs3zMjiYKfgaOZSBDv 2WSm3/mfwSdpv/Or5LqfQvv/9nMyJHmuWBbzl64QpXS3uVg5Y5cuSW2id66jw93+heOB X34Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qJ4N3TZkXDp/zFxWJ2xUxDT7iabkYNzhWXo0PGJiX9I=; b=41UdcKFxrh9TGdsnH0ozEW/rExq8f6CWcM2r3OYFo2hdEYpeA7is9aW6RLFjArFxpk JAJlE5dnpXxWgWp20k+ySFIxEJf29H7ennpW+pCfDvn5YKei699SlHjrNbE2TevcgQF+ CrUZ2au11MReJlvhY8PGSZkurWHWo3glg9BC0jhI7hDFL2TNg3v8SmvuLTFXy9lVgvNR 0O7gh9oe6WTSNcJZex/FUZRQuSFVC8I7ZfVcJ+2u7LjpXxzSQcYVQRtA/K2nB4WvbTQf lSwVGziLZcrYNkXyOmdGMzFI+llJPMWOjl8RO1rZJNLjEk2qLpaEJ9GrGYKRp7G6YxIR HjAQ== X-Gm-Message-State: AOAM530akbqWQnsdRZzQb8c+yZ63oIVmVeDn4bky0Gkag3GTf4NWt9Ul djdmPn7KJeoeDxkAnEwRgOs= X-Google-Smtp-Source: ABdhPJxjNhLyP3s/7Wtz9KuLKeDPsTIm+PgbfyRXADen5O80S3J5alrAtGBRnvgZArqlAYmQNohkGw== X-Received: by 2002:a17:90b:224f:: with SMTP id hk15mr2888567pjb.173.1638415347986; Wed, 01 Dec 2021 19:22:27 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:e768:caa5:c812:6a1c]) by smtp.gmail.com with ESMTPSA id h5sm1306572pfi.46.2021.12.01.19.22.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 19:22:27 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Dmitry Vyukov , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 07/19] net: add net device refcount tracker to dev_ifsioc() Date: Wed, 1 Dec 2021 19:21:27 -0800 Message-Id: <20211202032139.3156411-8-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211202032139.3156411-1-eric.dumazet@gmail.com> References: <20211202032139.3156411-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Signed-off-by: Eric Dumazet --- net/core/dev_ioctl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c index cbab5fec64b12df9355b154bdcaa0f48701966e8..1d309a6669325ad26c59892c4e78ca14dec017d9 100644 --- a/net/core/dev_ioctl.c +++ b/net/core/dev_ioctl.c @@ -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; From patchwork Thu Dec 2 03:21:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12651515 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99FDDC433F5 for ; Thu, 2 Dec 2021 03:22:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355178AbhLBD0K (ORCPT ); Wed, 1 Dec 2021 22:26:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355177AbhLBDZy (ORCPT ); Wed, 1 Dec 2021 22:25:54 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5476C061748 for ; Wed, 1 Dec 2021 19:22:31 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id gb13-20020a17090b060d00b001a674e2c4a8so3473057pjb.4 for ; Wed, 01 Dec 2021 19:22:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WK2P6yNg78NxDXxmvRH1elSqJxnqJhGGVYpY4oWpzF4=; b=YOK7bmmMul5XdaGGCIT1Oom1vad/uARTX0TgnQOseNCYenWRcVNGjM5AQchPOzL0ma mWVl/rrzl4CVggVQ/BcTLWRTLrIPJ1kEODydYXsn3zjbZPWD1Y4iCUI9saXvW1MVIq0V qlZz5ABYc3KXw2VWtDuQcWPAxdmPQkFGm+195Lubw0DNqf4uB8g9WMVt+/uDX/8OOUdW JeHuDATafrXort8sX3KhorHAkQEbE7grhJs6Zcb+b6RvbbilXZgl9s5rSBHYXTxhKzcz q+Ps9rU/W1BoAGx0F8L4hFXzs2fTksoJUDUk56LYc1yS4ezPgfVUIkay/3OOXL5DfmSz Lb2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WK2P6yNg78NxDXxmvRH1elSqJxnqJhGGVYpY4oWpzF4=; b=sajENmHhbVREMHVbrklf3+2JDDo7006v4mo3j55pRC/xhnsJmW94jw6StVTy1jFQ0h wM7nXjUJ4ymk48t43Nx75ceelz8XbCH17yjBI0brgAd/dumwztISL+QeWWlrQoMX1jEU U+TJLZhSXgc66k8LfPCIRZzJkGyi9V/gex9VYWAcglCz3w1e57LdXzQ8/KHn2dXKt7DH wwQ0HezLJSic1wTVR1sfJMrSk+jbhMXIGvDNxtE6OZJiaH7rIB794vMVs5DLy0mxSOJZ dDwAlu58Srq7GnqxRW60tLiqNPEQ9627VqinYB7ylfV3MkbEk1PlsrYcLVC3JL9nszxz Q+Uw== X-Gm-Message-State: AOAM531KtjTOieZyUscAzXt3mygV5pQCIdUFv30owQ6ct4mgi18r7NM9 4qglZkxwXaKqwfg5sHvzdPS2Fi7h5VQ= X-Google-Smtp-Source: ABdhPJxP/BNWWonp6UurgNkkSFMzH4oWW160qnQO8rqR+0RJlYt2o8rtXgeQkSxdylLwVYkXIstjgA== X-Received: by 2002:a17:902:7797:b0:143:88c3:7ff1 with SMTP id o23-20020a170902779700b0014388c37ff1mr12315099pll.22.1638415351422; Wed, 01 Dec 2021 19:22:31 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:e768:caa5:c812:6a1c]) by smtp.gmail.com with ESMTPSA id h5sm1306572pfi.46.2021.12.01.19.22.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 19:22:31 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Dmitry Vyukov , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 08/19] drop_monitor: add net device refcount tracker Date: Wed, 1 Dec 2021 19:21:28 -0800 Message-Id: <20211202032139.3156411-9-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211202032139.3156411-1-eric.dumazet@gmail.com> References: <20211202032139.3156411-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet We want to track all dev_hold()/dev_put() to ease leak hunting. Signed-off-by: Eric Dumazet Reported-by: kernel test robot --- include/net/devlink.h | 3 +++ net/core/drop_monitor.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index 043fcec8b0aadf041aba35b8339c93ac9336b551..09b75fdfa74e268aaeb05ec640fd76ec5ba777ac 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -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; }; diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c index 49442cae6f69d5e9d93d00b53ab8f5a0563c1d37..dff13c208c1dafac26c3180a37e6e3be5f8fa744 100644 --- a/net/core/drop_monitor.c +++ b/net/core/drop_monitor.c @@ -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; @@ -866,7 +866,7 @@ 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) { - 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); From patchwork Thu Dec 2 03:21:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12651521 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE84EC433F5 for ; Thu, 2 Dec 2021 03:22:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355177AbhLBD0Q (ORCPT ); Wed, 1 Dec 2021 22:26:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355179AbhLBDZ4 (ORCPT ); Wed, 1 Dec 2021 22:25:56 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D663C06174A for ; Wed, 1 Dec 2021 19:22:34 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id p18so19215209plf.13 for ; Wed, 01 Dec 2021 19:22:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7250yZGq0GXwSYTzvQqtJYpIvKlJXs9zw1bN31JtSgY=; b=N5RpV3YEzqUZHVjeXMp3/6igGPXcXpfrGAyybzt2OuLn1yTnVO4yCMpyTkXkjQ6MM6 2iYBur7tie27sj1PIQMMyYqYHp9eMkF3iPbZyl+JAkMl/kNcZE85vd9hK/J5VYZnxndN WpeKRs4Pzd0Hul1/ZMEe/ZXBn1wtwx9EtnNIq1lnJCMdPg0tjUwAwOwMSeGP3XFJ9X+2 JwpURIXyDCH9XrwXkLZwEyvo3PMPMPx9LBrjlvwmz/xxo6LOPEMwC/BiNE/2/HpHSh5h EmbH0u7k3pLzoHUg2HR5ZA8Lrno5oAR9Qd3G1DMvqBTeerX25aMDmAlhkNx+ye/qKKIH +NUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7250yZGq0GXwSYTzvQqtJYpIvKlJXs9zw1bN31JtSgY=; b=kc9GhhNbSxzBPmpwyuCF6YfPgsIkEvUVLkmkMsgz2sRFgVmY0IVnR4VKGKALz0U5Gy vIh20qecwVMyfyyWxI+rkZ0fMCHsObs4UeZkeWSy+g5dr+MDdXdsRuNIQvCwd4634f28 92x9xaFu83l1qGycquD3lzsmvwg4IXSKflOXzPrF43kRabqR4vcaPAqbKw1GSwy6IBBq Hg52wCaQocEMST42OmsT0YLZQNEMS+E9RVDwPgI6of+m/4U/nzQR8maxi9EgZaIAdQjD 1nGRpSsKgzJHzsZvWJL09kMurnpeSnHzBdvYbe5lQh2cl6I2l0KeGDl5RVr69pFDdtAj yvBw== X-Gm-Message-State: AOAM5327oXPhhg/fw87sV3V8LD0ewh8F+TTMwL2LUFw5KC/P0ro2q51G rJIBgRSwkZMDYBeNiqF4IZc= X-Google-Smtp-Source: ABdhPJyfMAcRhaXLwDbT436IL1xppsBjtn6TBZUiISUS5pA+jLChjQiZOW47ADwLVtbPMMaoC+fYJw== X-Received: by 2002:a17:903:285:b0:142:7a83:6dd2 with SMTP id j5-20020a170903028500b001427a836dd2mr12271666plr.59.1638415353707; Wed, 01 Dec 2021 19:22:33 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:e768:caa5:c812:6a1c]) by smtp.gmail.com with ESMTPSA id h5sm1306572pfi.46.2021.12.01.19.22.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 19:22:33 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Dmitry Vyukov , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 09/19] net: dst: add net device refcount tracking to dst_entry Date: Wed, 1 Dec 2021 19:21:29 -0800 Message-Id: <20211202032139.3156411-10-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211202032139.3156411-1-eric.dumazet@gmail.com> References: <20211202032139.3156411-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet We want to track all dev_hold()/dev_put() to ease leak hunting. Signed-off-by: Eric Dumazet --- 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(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index b43102614696a97c919f601d1337746443d79557..bfbf7c52688396093740c16aeb2e6947eaa9ac9c 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -3870,6 +3870,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. diff --git a/include/net/dst.h b/include/net/dst.h index a057319aabefac52075edb038358439ceec23a60..6aa252c3fc55ccaee58faebf265510469e91d780 100644 --- a/include/net/dst.h +++ b/include/net/dst.h @@ -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 { diff --git a/net/core/dst.c b/net/core/dst.c index 497ef9b3fc6abb5fd9c74e5730c3aedc3277f850..d16c2c9bfebd3dadd4c8dbc4f14836574bb52bbe 100644 --- a/net/core/dst.c +++ b/net/core/dst.c @@ -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); diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 243a0c52be42b60226a38dce980956b33e583d80..843a7a3699feeb24f3b9af5efaff87724214cbce 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -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; diff --git a/net/ipv6/route.c b/net/ipv6/route.c index f0d29fcb20945b5a48097c89dc57daedeed9d177..ba4dc94d76d63c98ff49c41b712231f81eb8af40 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -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); From patchwork Thu Dec 2 03:21:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12651519 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49223C433EF for ; Thu, 2 Dec 2021 03:22:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355197AbhLBD0P (ORCPT ); Wed, 1 Dec 2021 22:26:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355167AbhLBD0E (ORCPT ); Wed, 1 Dec 2021 22:26:04 -0500 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90DBEC061574 for ; Wed, 1 Dec 2021 19:22:42 -0800 (PST) Received: by mail-pf1-x42d.google.com with SMTP id x131so26591651pfc.12 for ; Wed, 01 Dec 2021 19:22:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kOrlKtG87qDx0MrTwJ8e9KliXZ82ErbO04FOjqifzxo=; b=HtLK0pNX4V8dxH3nmzKGzpqe7oPuBC8I+pi+LcTigo5RcTi22J4Y3ezkYvvjtM9Yb2 d+rP4XOZLz1sOBi/j0bg418f9GslFYbnMsCNwFKDgB0Y27PkgBKgeT12PIqFEQFg9r8H /B1Gtm1jw8OLmqNsOF+FwcCAd3xcn6Mpuo4/Ll2zLKTe31GaldchKnqlXwyFhT98sg0i ilf2kqzF7JE1aRbCjIvmIk5ixELg3uFg1SUhEaJGKyBRb54Sq/K6jjlSGtJDn8Xo3W0o oPU84Y+yTRdkRtdgSUBQwyq9aIEp6fSE9LAKtLzGAUorkYnoaHvGhP/FVpgDE3MNmeuU NxGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kOrlKtG87qDx0MrTwJ8e9KliXZ82ErbO04FOjqifzxo=; b=tjZ2NmhhpE7Ukr+pd6sV76GreXGZMP0eArIoS8P1wzGlrB4Z50kX4Z85SBbH0Nz80x 4pdYgZZiM7ZO0Q1Jh2PhKpwVfT1x2yWDZgBGu2vkPlOArc5pVZ9q40/nBEBsibAp8JXq HyGInlTjHNuiq7b7Wmb2hY/x8RFmHesTub9S8fMjMdWBa3LS2K7W8+whu6NEF4Qsezq4 I74zVCGMVG8JPcO/CqcXNl/xNwyRsMjyUkCmG0RAnMWSp+gAHgC23hu2hZjxlnsFJDE7 yiirDtfdLAt/CMgI+JsmVT4vJU5uoovzffasEPNHymeDQxk9HuL+f/7pKr2d0HkbA31d eRVQ== X-Gm-Message-State: AOAM533I1xRRR6wCr8B5UElugZJpdiDmKf+wnW21dQQ2zEelrC8ux3Jb dk/b7oG2Wo3xUHrHgHYCj6I= X-Google-Smtp-Source: ABdhPJxr9RyTR2Y0aW0PzuXY+pMcudj0Nqwv3TUuWTIop66z3/KY4w3VVe+5ED2CCtwE+QYg7B991Q== X-Received: by 2002:a63:e50:: with SMTP id 16mr7718889pgo.619.1638415362175; Wed, 01 Dec 2021 19:22:42 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:e768:caa5:c812:6a1c]) by smtp.gmail.com with ESMTPSA id h5sm1306572pfi.46.2021.12.01.19.22.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 19:22:41 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Dmitry Vyukov , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 10/19] ipv6: add net device refcount tracker to rt6_probe_deferred() Date: Wed, 1 Dec 2021 19:21:30 -0800 Message-Id: <20211202032139.3156411-11-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211202032139.3156411-1-eric.dumazet@gmail.com> References: <20211202032139.3156411-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Signed-off-by: Eric Dumazet --- net/ipv6/route.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index ba4dc94d76d63c98ff49c41b712231f81eb8af40..8d834f901b483edf75c493620d38f979a4bcbf69 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -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); } From patchwork Thu Dec 2 03:21:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12651517 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12E40C433EF for ; Thu, 2 Dec 2021 03:22:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355182AbhLBD0M (ORCPT ); Wed, 1 Dec 2021 22:26:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355170AbhLBD0H (ORCPT ); Wed, 1 Dec 2021 22:26:07 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C48B2C061758 for ; Wed, 1 Dec 2021 19:22:45 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id v19so19229065plo.7 for ; Wed, 01 Dec 2021 19:22:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3AtGaI5Z9dy79c6BymwnVzO55YEIgeVodtM3Ea3/0D8=; b=MShumrO9UeU+aonyjKgYJ2+JJ1SF6XWvMHw+4Itl0I/3INa8QduU5I0qIjbzwCe9Ki gmVHh7oVCi8NnrE2Hhi6tHb4tOXWR1UdjOU/ST4EHsF1j84qkoJgE/7pV9VVgG0ZtP9A xZpodG4DZDQHXaWB3KR2ELZ+zQqfC6Kr/Vu2XpF1UKmIsJPPQbwj+mSBPGScPbYCRfSj GjA+8PyOL42F+mFbJO+0/n44kPfOfdUJJPp2FDkVzhlvGHmk2pHtGsO1hrjY5DPl2eeQ UEmSOf0Xthm5A+Z2mkWzqQKaZw4IG+bbQ7Mkt3t19mp7puboz+h9c1Zj/RAJ7sDfpDbx TvVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3AtGaI5Z9dy79c6BymwnVzO55YEIgeVodtM3Ea3/0D8=; b=IiC4v7Tm0VmXFthez0TyVw5Bomaqs8z1F1DiHFygvOGx1APOXjXqwRGbOB2jqeQpUl Zgwr6ONWYiajLsP480d0nSsmaehGp/Sxo9PinMhj5gV4NIg3X37Fc2ehOoOMO7oysh59 z/+/+SBMuh5SA5cLUk37uwXdZ2WjooirxbU860ELzi/HxNj+5u6gvTxTkURf0LYWOqEq lmICSKT3Hd5KeFDxjNQxcg+64R6q/zTaQvA5iPPC8TNxcfLtFtdGPoPg7lxiah2kcH/H XEJPxfRKu2npJJfTJ5ek7/GPZRFR5uklGiD85iIRqaDolPHFTUUoSzboWcV4i71ivI58 NaTA== X-Gm-Message-State: AOAM531y5souy5B6OlTTQWVYFrAkDrxk8Zra/LNNUSZ6PFZhy+cslw/V LRt3jL3Tuxkvfpyj3/KCLjE= X-Google-Smtp-Source: ABdhPJypXFbKcMDQ/lHMbbNnq3zuBKJh31oAinf7KDlolq6+p59JtSBtt7P/zhWOKnqJuOA3VRRLsg== X-Received: by 2002:a17:903:30cd:b0:141:c6dd:4d03 with SMTP id s13-20020a17090330cd00b00141c6dd4d03mr12551154plc.16.1638415365373; Wed, 01 Dec 2021 19:22:45 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:e768:caa5:c812:6a1c]) by smtp.gmail.com with ESMTPSA id h5sm1306572pfi.46.2021.12.01.19.22.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 19:22:45 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Dmitry Vyukov , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 11/19] sit: add net device refcount tracking to ip_tunnel Date: Wed, 1 Dec 2021 19:21:31 -0800 Message-Id: <20211202032139.3156411-12-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211202032139.3156411-1-eric.dumazet@gmail.com> References: <20211202032139.3156411-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Note that other ip_tunnel users do not seem to hold a reference on tunnel->dev. Probably needs some investigations. Signed-off-by: Eric Dumazet --- include/net/ip_tunnels.h | 3 +++ net/ipv6/sit.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h index bc3b13ec93c9dcd3f5d4c0ad8598200912172863..0219fe907b261952ec1f140d105cd74d7eda6b40 100644 --- a/include/net/ip_tunnels.h +++ b/include/net/ip_tunnels.h @@ -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 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index 1b57ee36d6682e04085aa271c6c5c09e6e3a7b7e..057c0f83c8007fb0756ca0d3a2231fab8eebaacb 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -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; } From patchwork Thu Dec 2 03:21:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12651523 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DE61C433F5 for ; Thu, 2 Dec 2021 03:23:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355183AbhLBD0W (ORCPT ); Wed, 1 Dec 2021 22:26:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355179AbhLBD0V (ORCPT ); Wed, 1 Dec 2021 22:26:21 -0500 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5813C061748 for ; Wed, 1 Dec 2021 19:22:59 -0800 (PST) Received: by mail-pl1-x635.google.com with SMTP id y7so19273576plp.0 for ; Wed, 01 Dec 2021 19:22:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jyACcgMzCKOrJ7jkzjdrqCl+wsMAU5P9M7ysjkyA1JA=; b=ioU993W9QpuJQtJ2sIwoGsd9y0wQXEIYxN1fl71k6tAfsOOmUtCPFqNS+z/MtjEtSL +gHqvwFZmX9Y16TN1Wa/U7sKUpxSniQEgr6XNZt90Jh27RU1R3JBbukRevGgOsVD7SsJ 9IJiCXIVbdA5YaZDXJAlJ4fCQx/IMUrWqGa7CWxR7yFlOVwy0MVxdvFcNi1X+YKyc6iF BuS8oT7bdxpH3xHJVyD5FuY72+1OQw58gfI5dI9x6Pvmzi1MXuO5eSfLxVHPuEbtKixq xQbwJErVD99ZtyZwoi9vvZoZP7Pj89zqTBnS6OaqIMb5sE3vXbMHwLGwiPZzIPZ28P29 TuQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jyACcgMzCKOrJ7jkzjdrqCl+wsMAU5P9M7ysjkyA1JA=; b=mXYzVcje+TUKqaIcOK1j7pR7NEwBCBzooyhNwloQtHucfrrYDdIfWmci/2iFRtT65j YyjjUx3K+nLECs6cAtkrQR/3N0uXbojo6ld+2QeiJgOOrDxgRSpH41fPXKcRyFuDK9ZU SoUcNGlHbm60TkbdBBPLwnv/TG52rqYZKWCt5M7LKm58OX7y+avMTyN7asO5aYVsxcJC 2/IAq6x86U4waAnnsNmkcu5rB6KgmetkynjO3STIt42dYDlElB32m0sSWsv/q729WnRF smiOoZoWX0F1PXjFtFcJIFpQNTp3UbAAv1qh5KJ6NsvPx+UPS4E0+gV78PwdbHsjKNh0 cTWA== X-Gm-Message-State: AOAM531Vbz4KO3D+1TVQixavzyqlZL4QMw4cZTjswuo6dUP1NzLMdU8p J7EKkS8iG1Kr74jtMrpmBkY= X-Google-Smtp-Source: ABdhPJzzplneelQokH+YDunS5c1784HdCGngFng/BmAhDaVJ0DWer3J6ms3htFHMD1YOSyybYoJJCg== X-Received: by 2002:a17:902:7616:b0:143:a8cd:ef0 with SMTP id k22-20020a170902761600b00143a8cd0ef0mr12238125pll.48.1638415379392; Wed, 01 Dec 2021 19:22:59 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:e768:caa5:c812:6a1c]) by smtp.gmail.com with ESMTPSA id h5sm1306572pfi.46.2021.12.01.19.22.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 19:22:59 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Dmitry Vyukov , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 12/19] ipv6: add net device refcount tracker to struct ip6_tnl Date: Wed, 1 Dec 2021 19:21:32 -0800 Message-Id: <20211202032139.3156411-13-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211202032139.3156411-1-eric.dumazet@gmail.com> References: <20211202032139.3156411-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Signed-off-by: Eric Dumazet --- 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(-) diff --git a/include/net/ip6_tunnel.h b/include/net/ip6_tunnel.h index 028eaea1c854493fdab40f655216230e991e2fc5..a38c4f1e4e5c641dcede4d7fedfcdbfadbac430e 100644 --- a/include/net/ip6_tunnel.h +++ b/include/net/ip6_tunnel.h @@ -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 */ diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index d831d243969327b2cd4b539199e02a897a6c14f7..110839a88bc2ef098df38196f997335501305ad7 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -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: diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c index 484aca492cc06858319e87ba9c989de9f378e896..fe786df4f8493396b803002d25701affd59ee96c 100644 --- a/net/ipv6/ip6_tunnel.c +++ b/net/ipv6/ip6_tunnel.c @@ -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: diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c index 527e9ead7449e5229db11b73622ff723847ffc96..ed9b6d6ca65e0173c9f03e580cca2747ad023a99 100644 --- a/net/ipv6/ip6_vti.c +++ b/net/ipv6/ip6_vti.c @@ -293,7 +293,7 @@ static void vti6_dev_uninit(struct net_device *dev) RCU_INIT_POINTER(ip6n->tnls_wc[0], NULL); else vti6_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; } From patchwork Thu Dec 2 03:21:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12651525 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17FFBC433EF for ; Thu, 2 Dec 2021 03:23:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355189AbhLBD02 (ORCPT ); Wed, 1 Dec 2021 22:26:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355199AbhLBD0Y (ORCPT ); Wed, 1 Dec 2021 22:26:24 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACFE0C061574 for ; Wed, 1 Dec 2021 19:23:02 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id v23so19507890pjr.5 for ; Wed, 01 Dec 2021 19:23:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pIB1yZNjkeCvyxOHtvefP/M6d++rAd5Z49t8wZUH8rk=; b=UScCS+BLPbO986z1yEZGEDfRz31Rvf4+bCZsbV8LgmVZcaO+Vb6qaRCWcMPJTpYnmd jSh8tnjwGCwD3w7xsZO99cZp1Z5tvxUIyj+VBgKOfnkBePaXd7X73uldO7KOG7/ifHbl iFVdSFJmPExSmTRLA9K3k5QjLB5j1WvIx1a2Z/CpaM/yMBvCzH7Ji4LDUsZEvQLy7tQx zQYWnfxhEteP53C/F41nBmZXs8OLZWrKGPYSFMQj+EuM5jCid6RaIYcYAWj26ZgStySw fH2g5LYy8uILgJUzDbcy04VU5sxXindM7p3WRC07f+S6JYj7lNSjETayBe+BEkWekLcQ rA9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pIB1yZNjkeCvyxOHtvefP/M6d++rAd5Z49t8wZUH8rk=; b=PTe8fNlj68syg91QLoZ3y0+jFJzR+nYG4LBwU1Qp5n4Hu/aafy85Z6tjYsauquBEja YahKfDqbmVAnK+FbU/Zud5rZ1ccq7f5fdjGe9RLvW73Mhr5QcSuNvtITgXGu+tK4/5RL 7gkz6LCK2N9DtrAx28ZJ3QT7HawQuM9yTZd3411PbGfQvLkPMhlzSqBaZJCmK7Leut81 myMfGfKJe+N6ipvn5X00op68VU3eeTNdovNBcfzsKu0EDXa1p/8FbgOjJrwJ+eJIgHBA cVewhf1JLXJ6dVH6Ra7JFshNlGLjk0H1rPauck50kJRPOyCz00vtwZ/VYltID958l+AP CnPQ== X-Gm-Message-State: AOAM5331JP57FENqiCD1MVF6ZUPNtJzf7YaaJUwMPQ5529YvvcctASCB dNjJSCpPVy2To6NiG5wycYM= X-Google-Smtp-Source: ABdhPJxLDGeGPyoA7KFLeaxmFgkA87+h3I7/SIoNukGoNWPTy1uiCgztWMxf+8zcOOzQ+OYo4a8NUQ== X-Received: by 2002:a17:902:ea10:b0:142:112d:c0b9 with SMTP id s16-20020a170902ea1000b00142112dc0b9mr12392957plg.35.1638415382310; Wed, 01 Dec 2021 19:23:02 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:e768:caa5:c812:6a1c]) by smtp.gmail.com with ESMTPSA id h5sm1306572pfi.46.2021.12.01.19.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 19:23:01 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Dmitry Vyukov , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 13/19] net: add net device refcount tracker to struct neighbour Date: Wed, 1 Dec 2021 19:21:33 -0800 Message-Id: <20211202032139.3156411-14-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211202032139.3156411-1-eric.dumazet@gmail.com> References: <20211202032139.3156411-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Signed-off-by: Eric Dumazet --- include/net/neighbour.h | 1 + net/core/neighbour.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/net/neighbour.h b/include/net/neighbour.h index 55af812c3ed5704813bd64aa760246255aa5f93f..190b07fe089ef5c900a0d97df0bc4d667d8bdcd6 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -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; diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 72ba027c34cfea6f38a9e78927c35048ebfe7a7f..fb340347e4d88f0058383697071cfb5bfbd9f925 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -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); From patchwork Thu Dec 2 03:21:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12651527 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB96FC433F5 for ; Thu, 2 Dec 2021 03:23:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355209AbhLBD0e (ORCPT ); Wed, 1 Dec 2021 22:26:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355198AbhLBD03 (ORCPT ); Wed, 1 Dec 2021 22:26:29 -0500 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81237C061574 for ; Wed, 1 Dec 2021 19:23:07 -0800 (PST) Received: by mail-pl1-x635.google.com with SMTP id y8so19253205plg.1 for ; Wed, 01 Dec 2021 19:23:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YRhBZzAeV2LuAfYUW//Y3tEzWeNiR52G9iWZL8XYr7E=; b=XSodOiNoDSUFSzSgyoCussCKF0VsNc4ahkbOgOVLAYqiJxSUcEtgSf54Q/pJy2BeMH RN8xCOu0B5ZdPUX/bm1DCdtaEIezR4AWELoD3CV7oRp9VEIcIsnbhc6R/VkBGFvp8HQP k6yHLSvZTNmoOu2nuCyYzJQDhpsPLqFcSVMgR7zSlAhHwyUAVA2FXM8U9J2zPPvk00u9 CylZmY0nYaUbfr9GIkNYXTgWEYyGicpGMqwOgkktnPXtgvmjBHxNtSUejjHKL5O99UXs oe9R3i/zyqumMU8kpmT1o8fPecY+Flh1+sSqmIHWXcMCbxDMS7aXFch3gECRL7qwqofo DQFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YRhBZzAeV2LuAfYUW//Y3tEzWeNiR52G9iWZL8XYr7E=; b=a8QFnSx8IHtoo5Q/nF+qzRpnFF0gQrHp4F8swxhgCu8hWXUPfD+hHQLSJZS4ie1D3f gNz/Yf0HRWz42qnZz1euUE4nH9iKQscd+CRiZ8q/nbOpwMLCELaUYenahmy8HhC7parh icE+BD7uy9fucJjRa/QKS5Mg+ue8iM4N2qQDzZnPS1RXQipiY/PFM+wociEvVUqWBKBG PS9HQ8Y57ZfpZ+FFTnLWN0pB9Xvf9K5mVcIW4EiECR4ves5EBmOIvmPgKVSwL3Vw2CI+ ABwa1YFmFY1IvHO1aCIFfXj0mVqv1jJZgnpsnUpMuYp5QrsI5/4nhQaO9D0d/uaFipfS C3wA== X-Gm-Message-State: AOAM531u7pABahM+YHFESVpBSijBBBs+V1FSj35Om8dbdPJLX1K1ct5d IGZomEQyRRdnIhrLuBpoAAk= X-Google-Smtp-Source: ABdhPJx6DuI/hayy1g6DDPX/Xsclgqw7jyVXtpF4CpMGjdBkMie+1kcsJhbain3ejAFYvAIIA9Rqqw== X-Received: by 2002:a17:90a:590d:: with SMTP id k13mr2879347pji.184.1638415387110; Wed, 01 Dec 2021 19:23:07 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:e768:caa5:c812:6a1c]) by smtp.gmail.com with ESMTPSA id h5sm1306572pfi.46.2021.12.01.19.23.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 19:23:06 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Dmitry Vyukov , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 14/19] net: add net device refcount tracker to struct pneigh_entry Date: Wed, 1 Dec 2021 19:21:34 -0800 Message-Id: <20211202032139.3156411-15-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211202032139.3156411-1-eric.dumazet@gmail.com> References: <20211202032139.3156411-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Signed-off-by: Eric Dumazet --- include/net/neighbour.h | 1 + net/core/neighbour.c | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/net/neighbour.h b/include/net/neighbour.h index 190b07fe089ef5c900a0d97df0bc4d667d8bdcd6..5fffb783670a6d2432896a06d3044f6ac83feaf4 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -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[]; diff --git a/net/core/neighbour.c b/net/core/neighbour.c index fb340347e4d88f0058383697071cfb5bfbd9f925..56de74f8d2b1c896c478ded2c659b0207d7b5c75 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -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; From patchwork Thu Dec 2 03:21:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12651533 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CAE1C4332F for ; Thu, 2 Dec 2021 03:23:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355202AbhLBD0y (ORCPT ); Wed, 1 Dec 2021 22:26:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355214AbhLBD0j (ORCPT ); Wed, 1 Dec 2021 22:26:39 -0500 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95E55C061748 for ; Wed, 1 Dec 2021 19:23:16 -0800 (PST) Received: by mail-pg1-x534.google.com with SMTP id k4so15519033pgb.8 for ; Wed, 01 Dec 2021 19:23:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lPAg9CqmL/od/8VHtg2Hl2oiYPYjTcUvvNkryGEYnGg=; b=iOP9DsKwdABkQGAgY/jeGUnTLxs0yQICCNaFptPDC8xYJysB4Xj1CusN2XDg29hAqf TONF1nxXWLeQQhj31YdKHCxYLzwrBf/Ww21McdEqCfhaZ2vER1j5OO4LcA/Ghp/L0Bxx eGK/RbX+w/6JJ9uGoiNixXw8/IMCfufBvwwxsF/9EYRgNJL72Xvz5ST/8B9LSyospTfp fslIDXBAihN5yFJyFdxfCkrLPmWptVCDVoRQufwULmb9i07QXp9bfKFgu3jka4RupKRI f2/PTyejuGOisfaXVKrZvX4evLZmt5cAMZQglZppKfWPB3Y6agAi96/p6FKMNJpgcv2u xZhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lPAg9CqmL/od/8VHtg2Hl2oiYPYjTcUvvNkryGEYnGg=; b=6i9lAHV4J5f0Jf5RA5vkcVMt+omAPBIpCftQG47EQfhR6gfX/Zaqfx1xcMghyLkMHW bGfhmBJPfSgyBrXDenLuPP0WFVOvakDy4/EBEf92w9TgyJwtB0dAlTBwvCGu3fJoQzWT pau/0bLOf/yvpZYGbnw8n2dsVzBGmXyuc/mNtL781VEHk0woIWyKNQO8JlvQ46IJuCfi /Ev4HSekNv/od6roNMtmuTs2Xwfn3517zkIflwGk69o3iaaQw/P2QoEHfnFHrlrAmTV1 EXWXMrvxAgy7KjljI9SkfNdYOlhfoiGuFQCMnpkWWmyb8wzkwHv8BVdKvCe495cHAou8 z1zQ== X-Gm-Message-State: AOAM530eHZX2TR4Hl+VpmCNIVO/fQl1P/8pCLmDg7xXvqJ4lvZQiiB6S 8EXFmCDIRvQ4n4E0jEDKbtQ= X-Google-Smtp-Source: ABdhPJwxRDtwwvItXo9N4A4sBzD6A4hStIYwj9Uf8JEBYE/AGUM12kLRPifzmBDxajgJ2TgNsv27Uw== X-Received: by 2002:a63:66c7:: with SMTP id a190mr7715880pgc.463.1638415396142; Wed, 01 Dec 2021 19:23:16 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:e768:caa5:c812:6a1c]) by smtp.gmail.com with ESMTPSA id h5sm1306572pfi.46.2021.12.01.19.23.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 19:23:15 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Dmitry Vyukov , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 15/19] net: add net device refcount tracker to struct neigh_parms Date: Wed, 1 Dec 2021 19:21:35 -0800 Message-Id: <20211202032139.3156411-16-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211202032139.3156411-1-eric.dumazet@gmail.com> References: <20211202032139.3156411-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Signed-off-by: Eric Dumazet --- include/net/neighbour.h | 1 + net/core/neighbour.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/net/neighbour.h b/include/net/neighbour.h index 5fffb783670a6d2432896a06d3044f6ac83feaf4..937389e04c8e26b6f5a4c1362a90930145671889 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -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; diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 56de74f8d2b1c896c478ded2c659b0207d7b5c75..dd271ffedf11cdd3a1b6bf5fad7b0ddcc5d41e80 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -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); From patchwork Thu Dec 2 03:21:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12651529 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57369C433F5 for ; Thu, 2 Dec 2021 03:23:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355199AbhLBD0y (ORCPT ); Wed, 1 Dec 2021 22:26:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355200AbhLBD0m (ORCPT ); Wed, 1 Dec 2021 22:26:42 -0500 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75237C06174A for ; Wed, 1 Dec 2021 19:23:20 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id u17so19220337plg.9 for ; Wed, 01 Dec 2021 19:23:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/TH8J1Lr+N4KAbDXmbqKcN2jE+PzC1W24r5HvEEpBqo=; b=AmKsazsWejGUo2unyC2OMpATsNtBIRZ0lN5mNiOwOz5b54TSHhMcg53a9DceiNmTVV iyiqfKfYfKCyzKM4JYaLMOBcBOyjzw655HmozgOwd350JH1L7HCLMny4j8SpERllpvH0 EjcA8Wob5/Odjh+NSlSNbsLEUkWnoYO6BRv5M4CF6NcaLxu07BQONR0l2Z4rd1fnvE7p 6YlcVNjfzl/X54xXses/acguJvkzcTsSTGcb5TepG2udn+SPD0YDU5n1LnMCz5yjTEyx JeYQJm3AS9i0JwwoaadmQwjzGEQedELdEzG9cOqbKkkxEoeL1BkdNeOk5jy1BeK3/rUg xMkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/TH8J1Lr+N4KAbDXmbqKcN2jE+PzC1W24r5HvEEpBqo=; b=ai2vMEHq/nvt/6D139UL0hsUFMkkcg/3IDiV9xxs9/fIcDvmpz9gTRG80be2uSro9G fiCDKye5sf3U8G1BxTl1gorjrkqUTrX/dipacTCRqgT5lFG9AGlBVTbrrQXfY35wrx9F U811PIc7ncyto77j7372IDuH87oUwYCt/D6jJJlWfTjZCp+FllUO3jYSdNCwJhbvtZYF Fql2jHVe50cBf3w27rlvNifJaxgHyIVtBE/wCEfgXrzs6E4UIi3noLkTYBN6VDt/TmAg hgkrTEmvcVvkpvPSyRg7qmrYD7xQHwDsQhzQrUV0n2WSea/LCbQ6dvq9gxg1KpFxg72c I8VA== X-Gm-Message-State: AOAM531e6WfZQIedxZeU24oN4XlAL/49HWWUZ4AMKR1Fl/G5HRcs+e9q SVgJpOahMjEd7uGWvHzDiNc= X-Google-Smtp-Source: ABdhPJyfbPiJU8WkYjzUPOf6WTi2i369dzHvL5zSu5mMvPj8XxA3wce9Dwb/n3JO2TE+njwLjgH3+Q== X-Received: by 2002:a17:903:286:b0:142:4abc:88b8 with SMTP id j6-20020a170903028600b001424abc88b8mr12455719plr.25.1638415400038; Wed, 01 Dec 2021 19:23:20 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:e768:caa5:c812:6a1c]) by smtp.gmail.com with ESMTPSA id h5sm1306572pfi.46.2021.12.01.19.23.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 19:23:19 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Dmitry Vyukov , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 16/19] net: add net device refcount tracker to struct netdev_adjacent Date: Wed, 1 Dec 2021 19:21:36 -0800 Message-Id: <20211202032139.3156411-17-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211202032139.3156411-1-eric.dumazet@gmail.com> References: <20211202032139.3156411-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Signed-off-by: Eric Dumazet --- net/core/dev.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index bdfbfa4e291858f990f5e2c99c4ce0ee9ed687cd..337d927500af3c6332d7e2635449f9d4a9be007a 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6534,6 +6534,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; @@ -7298,7 +7299,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); @@ -7327,8 +7328,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; } @@ -7369,7 +7370,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); } From patchwork Thu Dec 2 03:21:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12651531 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A81BEC433EF for ; Thu, 2 Dec 2021 03:23:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355198AbhLBD0y (ORCPT ); Wed, 1 Dec 2021 22:26:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343623AbhLBD0w (ORCPT ); Wed, 1 Dec 2021 22:26:52 -0500 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57E45C061757 for ; Wed, 1 Dec 2021 19:23:29 -0800 (PST) Received: by mail-pj1-x1035.google.com with SMTP id gx15-20020a17090b124f00b001a695f3734aso3503816pjb.0 for ; Wed, 01 Dec 2021 19:23:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5toKGzfgoX9Zic6erot0JqtltzqshyxoLAvATvfXmGc=; b=WQ2hxhp4Ic+fRzsFdAw1Brw51Qa46fDfaN8DmcbVxgvjnLFVjmA8dhsvDmUjug30Q0 mOb6OAspfxeN1XI7CbCs/amlUNXvj/XNauURXuSBBJXoHvK2Hbrj5oXsjaKUvFmsnv1U YiSxde8T9CXVBQcFJWOujslG+M8OS2jMneZbrz49Uxz3iS/mKlPK1hgN/hbCI+rO6f9v PpkWGxhHPVvEw+uajwSoNB/L0DPI25LCaDvCL5hmUtzkbRRfLn1yDPiOO6uWM6cjl/ZE lyfYQ1zebjEYWLIxMjbf+xamAkItahzUUFKcvHfxOJDEcPgfipRoO0SROX8Stbs9vv42 ZzJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5toKGzfgoX9Zic6erot0JqtltzqshyxoLAvATvfXmGc=; b=Bc3SJA2fUfg48ZMt3QQ5jMb7hQ9lMGN5zHK4JDkA6767NXQyNH5Oo/m6x3kiD2Myvb XK5ZzSf3nBqow/tsj2H5SYLJt1Ce1SyDkoI7yqhxbC/5LCTsT1XGgf1DvBkKXDOtoL6Z NzEM+hqs0NSZO+38UDeoLq9lKjDwx3ngeQGcNuJ9PP3/JLpMhgI2Up27aWQ5xOM8xLUe PBhj1oLuwDO4FzCfv0d/EI7GabBXv0B2Kgoq6nedVx/3WcZpquvA6QIJ3xXZz0EgWGro s03oHVJgVwBKqbVkPDtCntfG5y/9WvbODL/oD76lwztT27bnq9/H3489gZugZMwRZSec qg0Q== X-Gm-Message-State: AOAM530D739ox2EdWaqlWm6n5aiXeB8chfid6U/bMBV8k5w3N4sR+Zli ec9cx0+vbG9g8YqLaNoBeG8= X-Google-Smtp-Source: ABdhPJzc8egj2ODlLcBjm4JjYC5SBWRa6pWwphH0f+IPMVN1Uc5ylxT04JXK/5bEL2YkydNKGyVL4g== X-Received: by 2002:a17:90b:1d07:: with SMTP id on7mr2907961pjb.45.1638415408949; Wed, 01 Dec 2021 19:23:28 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:e768:caa5:c812:6a1c]) by smtp.gmail.com with ESMTPSA id h5sm1306572pfi.46.2021.12.01.19.23.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 19:23:28 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Dmitry Vyukov , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 17/19] ipv6: add net device refcount tracker to struct inet6_dev Date: Wed, 1 Dec 2021 19:21:37 -0800 Message-Id: <20211202032139.3156411-18-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211202032139.3156411-1-eric.dumazet@gmail.com> References: <20211202032139.3156411-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Signed-off-by: Eric Dumazet --- include/net/if_inet6.h | 1 + net/ipv6/addrconf.c | 4 ++-- net/ipv6/addrconf_core.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/net/if_inet6.h b/include/net/if_inet6.h index 653e7d0f65cb7a5e7458daf860215d1873c532e7..f026cf08a8e86c54ea5d9f1abddd5f0e3caf402b 100644 --- a/include/net/if_inet6.h +++ b/include/net/if_inet6.h @@ -160,6 +160,7 @@ struct ipv6_devstat { struct inet6_dev { struct net_device *dev; + netdevice_tracker dev_tracker; struct list_head addr_list; diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 3445f8017430f145496bad78afd6378bf5cb1c02..3eee17790a82fe6c528db4e821b11444cfa26866 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -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); } diff --git a/net/ipv6/addrconf_core.c b/net/ipv6/addrconf_core.c index 1d4054bb345b72204179c17b4ebc69e11e3faf53..881d1477d24ad5af79fd744bee1e0792fcfa483d 100644 --- a/net/ipv6/addrconf_core.c +++ b/net/ipv6/addrconf_core.c @@ -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; From patchwork Thu Dec 2 03:21:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12651535 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B37FAC433F5 for ; Thu, 2 Dec 2021 03:23:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355215AbhLBD1A (ORCPT ); Wed, 1 Dec 2021 22:27:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355203AbhLBD0z (ORCPT ); Wed, 1 Dec 2021 22:26:55 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D457C061574 for ; Wed, 1 Dec 2021 19:23:33 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id o14so19253037plg.5 for ; Wed, 01 Dec 2021 19:23:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NCRWwJ15iKzDVwus3bpAunOI6VdjtwPdp927p9MxAvU=; b=QiW2SKfYGJDiDPq79Js1Kbx2IxfCyxkTc7he7AE89jZcRjL8GINVMKW9sRw4tDkp/n hFG8J74Bh2z5X6tLPc0GL5vQwJdzpbHg3Y7VSgtsi0fM7DGYyifqAr5tX5Fgwnl1MBuf //RLBosg518SLy2PLVZ7Pm4gFZfs2yOBeb4yBGFjVKku74GvwT/geTagabYONplw2Awe xZ77/wJMlbvVYPclx1P3hE7ImeaUVqSU5BN4UEc1SUjzGYDvD9VMQJGnyW/gxur+6Ilx rWrx/NF8gzSwr8cCpHLleAl23xhJYlvDSSDHaLp5Eu2sSpYSZf7UurjW4CzJi5bly3vn rFsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NCRWwJ15iKzDVwus3bpAunOI6VdjtwPdp927p9MxAvU=; b=4g2US10WM1tGoP4GSv7It104PldrIYvPJqZasYSGilTnpgCOs8qjJ2XLwowGmEaA/s PuK1FwnCBLTLxYPG0qQWd/SbRZldFMQK060V6ackbmyT+Yo/K1JKwMg0oV6zTdTAzYWm IBfCG+6QKgO5QbHa/FUR2llh9OcTb94dlM88o0YRMSFuJ0BxnKlsmFIE70nRy4zYwU6L 1CjTc6o5EjDcHoVmWRsuOZwa/z+F6c55nXgGg3xl/llMqHB4hbBZoThRdHrd8pwZky5v j9vnL7s5B+wQ5vgsMWx4aU2VKiQbhPQ/brb2Y1ODriyYeHMkr6eJnrRFppKEu/DezjXM H/qQ== X-Gm-Message-State: AOAM533E9V92VO9jRg3lKW9kJvbG2wxCHYy46uFENujeZquH5WsvqPJB kB0EpdMNZiO2H80aE+09nCk= X-Google-Smtp-Source: ABdhPJxc0EoZg3aqui+jLjNnIM49p5aPaL1p7zwhNQSe79nQd1uiawwhfrAt6azGB0jDjIysvCq05Q== X-Received: by 2002:a17:90a:98f:: with SMTP id 15mr2863249pjo.166.1638415413117; Wed, 01 Dec 2021 19:23:33 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:e768:caa5:c812:6a1c]) by smtp.gmail.com with ESMTPSA id h5sm1306572pfi.46.2021.12.01.19.23.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 19:23:32 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Dmitry Vyukov , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 18/19] ipv4: add net device refcount tracker to struct in_device Date: Wed, 1 Dec 2021 19:21:38 -0800 Message-Id: <20211202032139.3156411-19-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211202032139.3156411-1-eric.dumazet@gmail.com> References: <20211202032139.3156411-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Signed-off-by: Eric Dumazet --- include/linux/inetdevice.h | 2 ++ net/ipv4/devinet.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/linux/inetdevice.h b/include/linux/inetdevice.h index 518b484a7f07ebfa75cb8e4b41d78c15157f9aac..674aeead626089c2740ef844a7c8c8b799ee79dd 100644 --- a/include/linux/inetdevice.h +++ b/include/linux/inetdevice.h @@ -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 */ diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 323e622ff9b745350a0ce63a238774281ab326e4..fba2bffd65f7967f390dcaf5183994af1ae5493b 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -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); From patchwork Thu Dec 2 03:21:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12651537 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1DF0C433EF for ; Thu, 2 Dec 2021 03:23:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355200AbhLBD1B (ORCPT ); Wed, 1 Dec 2021 22:27:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355213AbhLBD07 (ORCPT ); Wed, 1 Dec 2021 22:26:59 -0500 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53819C061574 for ; Wed, 1 Dec 2021 19:23:37 -0800 (PST) Received: by mail-pf1-x42d.google.com with SMTP id g19so26604715pfb.8 for ; Wed, 01 Dec 2021 19:23:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TonOrxXUZEoVrlY5NkhayfSlEg7bcBHInbaBoJJpnUE=; b=j7Y0Fni0jJILUbXlFf1l1/+MjZgiWvmdYF3abTWcG1GVx0xk2PRfZRmZayIqPTVyXH aG6p072rB/YMPulRf2PHi1tVemEnfdf0n25s3JuubFvPeSFFcoy2k3zuSzYgihmHrHgd 8eZXmy+6roMQD7w+2bjFyL5CzLTjgT5lKjqcK4eLONdI6ydJj1/H2dq5Mifg13QuUC6r y15c4/9jWFWBYR6YuBOiHqDWuSf1Zm06vhOjUS8YnvPe/WmlNUBdiTL8jzrVskjKbz/z C8OaFw86K23mKrBmrgFgpcw1n//MC0HxIc0foEFOzC9j79WhcZZ4X3PtjPmLaqG5gNEe w8ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TonOrxXUZEoVrlY5NkhayfSlEg7bcBHInbaBoJJpnUE=; b=wjPjOFDtZhAz5JLsr1jQDy+/3YguJKQCmvx9xdQSE0wwOm3e4dowAqTL+Q/uQ96zB7 i5HJqpNTGK6DkAhqqBQNgiqQrEPttxer9cAuQou/TlvBkcNjw7vrhASIhVKto1ez58h+ C7kAiYUQCMViYRm5RToLjkmt1iNXuz2yjX8eLSv59LzYp4YzaK6ix7b/o3Xal/BU2C4/ jd1Et59shm9FUnIYJHyv17OKtQQrhg1MVNcggNjx2LkH63oLMP3wtpW11vWdixEvVLOC S5on1ZVV2OEYL5cN7pGfHlHJ2eyzrKf3iVyRMtZH7Rykya3SY6Je8VFMsiyq8e2Vdp0s zUow== X-Gm-Message-State: AOAM531CNtY3qLHfHYD7gkXR63geF/4gmfNN2CH0T/4f9h6bmVRQhFUk amgDJ21l9f5t6DEyea2ZRb8= X-Google-Smtp-Source: ABdhPJzUdxUaKMzEFn5TSE9+zOGD3wc3zgntVAv/0H913Y81J0J+7BfVqKOjbxsKNUs01malWJzIuA== X-Received: by 2002:a05:6a00:1396:b0:4a4:ca76:bc0f with SMTP id t22-20020a056a00139600b004a4ca76bc0fmr10282763pfg.5.1638415416925; Wed, 01 Dec 2021 19:23:36 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:e768:caa5:c812:6a1c]) by smtp.gmail.com with ESMTPSA id h5sm1306572pfi.46.2021.12.01.19.23.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 19:23:36 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Dmitry Vyukov , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 19/19] net/sched: add net device refcount tracker to struct Qdisc Date: Wed, 1 Dec 2021 19:21:39 -0800 Message-Id: <20211202032139.3156411-20-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211202032139.3156411-1-eric.dumazet@gmail.com> References: <20211202032139.3156411-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Signed-off-by: Eric Dumazet --- include/net/sch_generic.h | 2 +- net/sched/sch_generic.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h index 22179b2fda72a0a1c2fddc07eeda40716a443a46..dbf202bb1a0edad582dbaefe72aac1632e219fbd 100644 --- a/include/net/sch_generic.h +++ b/include/net/sch_generic.h @@ -125,7 +125,7 @@ struct Qdisc { spinlock_t seqlock; struct rcu_head rcu; - + netdevice_tracker dev_tracker; /* private data */ long privdata[] ____cacheline_aligned; }; diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c index d33804d41c5c5a9047c808fd37ba65ae8875fc79..8c8fbf2e385679e46a1b7af47eeac059fb8468cc 100644 --- a/net/sched/sch_generic.c +++ b/net/sched/sch_generic.c @@ -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);