From patchwork Fri Dec 3 02:46:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12654119 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 D521BC433F5 for ; Fri, 3 Dec 2021 02:47:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350856AbhLCCuh (ORCPT ); Thu, 2 Dec 2021 21:50:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350481AbhLCCug (ORCPT ); Thu, 2 Dec 2021 21:50:36 -0500 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D38CC06174A for ; Thu, 2 Dec 2021 18:47:13 -0800 (PST) Received: by mail-pg1-x52f.google.com with SMTP id r138so1600747pgr.13 for ; Thu, 02 Dec 2021 18:47: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=JFPeeIF9LdcBAftFvXJ114QsIch1nlGj9KpbveqAer4=; b=MiltKiyaeGmcgFdr+xyloPvGY7ryE7g77X07os83DSf+2i0VEboyGNZTwIXPWhFDzR o1LLatBxBLtDp5AshvP3GKwBF/psMfKmYOjf8+46eVDv0bvSUqLyVFFdEeK/lpepeqXk rXj7dUBl5ljhsF+kglxC/uvHf8qxWIMaisZGO/3HZSn/cgofw2NnHykxDgv3Q1zQbGOt uLS9GYKMehqdjolMEyodIiLHxoaCTzD0TCBHuapCMw6+L4H+6IbJLkydUO3HPsMTtmHr EnRTXEtdkhkMInVz+5bYM/vyjIg2SQX3ZAZG39TBrLAs+NecUtZKAI7/qBglxBQ/o4w9 34HQ== 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=JFPeeIF9LdcBAftFvXJ114QsIch1nlGj9KpbveqAer4=; b=pMSHvaQ1mKIQVzjYEbXwEjmmFCGW6xJJ+pD+F8tDJqzDtOdBsZmkcbwWvDMg0iiPht 7hchPwrEvnpEWoxBRIG6/t6OdAfi/jSF/+Ktplc7BQIi3sSYx8PsO9P/sURBT6l1uWnk fIF1Lkum8ChEw71NxcCpJLh4fbwO/AfaOLj8gGUL3uPjBY4SI/RZTUkwniRCR8znW2Js QH5aBn9m/wdXYnSZSvmoMauaN25zYIxUMsfnLmeyXrpGSWtgLDjXMxxZacoVd7jaMtYV BmFa9a8bbrUqZuDnrDgTJUcSlhTtwVSvsF8KvpdE/AzTt7D0/yVEhca0ZZwSFv6Ysp8J ISkg== X-Gm-Message-State: AOAM530/K3tbkF1nM1W0wB3k2WPbxM06JBSqrcpXycbDnhy4EKVscxNf /jRSvngcrX0iNgybpgyeFsI= X-Google-Smtp-Source: ABdhPJw2XGBnxreBAvycIW7dIf2ulJDDoVc4Ami9a3X/9uQB2aKJtlX9H5iEXlrCaw8iEh7vbFoAhA== X-Received: by 2002:a63:d257:: with SMTP id t23mr2381087pgi.533.1638499632906; Thu, 02 Dec 2021 18:47:12 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.47.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:47:12 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 01/23] lib: add reference counting tracking infrastructure Date: Thu, 2 Dec 2021 18:46:18 -0800 Message-Id: <20211203024640.1180745-2-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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 | 5 ++ lib/Makefile | 2 + lib/ref_tracker.c | 140 ++++++++++++++++++++++++++++++++++++ 4 files changed, 220 insertions(+) create mode 100644 include/linux/ref_tracker.h create mode 100644 lib/ref_tracker.c 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..655b0e43f260bfca63240794191e3f1890b2e801 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -680,6 +680,11 @@ config STACK_HASH_ORDER Select the hash size as a power of 2 for the stackdepot hash table. Choose a lower value to reduce the memory impact. +config REF_TRACKER + bool + depends on STACKTRACE_SUPPORT + select STACKDEPOT + config SBITMAP bool 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 Fri Dec 3 02:46:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12654121 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 86328C433F5 for ; Fri, 3 Dec 2021 02:47:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378239AbhLCCum (ORCPT ); Thu, 2 Dec 2021 21:50:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378229AbhLCCul (ORCPT ); Thu, 2 Dec 2021 21:50:41 -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 4EB73C06174A for ; Thu, 2 Dec 2021 18:47:18 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id v19so1102547plo.7 for ; Thu, 02 Dec 2021 18:47:18 -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=aGbL3Gnq4e/kpPuB+kdBYIQcENIxUxFUX/W3zTVIrn4=; b=TDCoBXtbpNU+umBIGT7jXoQdZHpvwFucpRodk0bKVAB2t2qYn1yvdCTTEy7o9Ia5v/ ngD3Lb92iI6FNTMKeElPY0fLk4RW/0vTiSLQ98aAmFoaXWz/Qq7hPuBI96flpgcqa07h EbBa0gmJWFwgUttAadC6sYyuWf0/GUxQFMzJ6xUn6Lj2wzw3uTtW0csLrHWU5W7TdOrq YRvA+ZUR8Mt3ytPaheNHXWULMQcuWETcnaranRrVi+nY6jbz7dylth6aUSPqImGEEqUc VEliOkS8IQPSCzfZ59iZvm+20BvsaHvn8J0290qmA3mciFOwFJMuAjz5AKTuziLYYryn 7Fgw== 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=aGbL3Gnq4e/kpPuB+kdBYIQcENIxUxFUX/W3zTVIrn4=; b=I242eezwGVI8MfB7NagGgu3g+Qu+U9PpPMDKB0TpRvee+nW6X2gtIemishcvkPCvj5 Aw4uLUmweJ+8XYUYQGPos0V7l8k3Y6CMS/zhTxKZOJz4eJlxL3p9owes3x6TFdpFEZ90 YjUohZE+B/5VyVhXcABME//BZ1FFlgsBTgv4gpgDQoEiHTTgv+PQKecXo/juBCzzVIRC SR6W7w4NWML4HddANy7HVxqk/MTLojSSz0Cx6EqHjI5r6pv2Ly6vr26iELYaYP+P7whZ 2t6tnEELCkxUN1AvolmXuXBHceoPnummxgLEubt6Ug6o9VtRp4D66rSxNByNROh3YnkM bWfg== X-Gm-Message-State: AOAM532bi5mz/a7+PJrOui32hI0l3oT1qHcdGdUXYDo3cydgBbNDckmh bqA/I0iP5eMECqVXOd4YnPYpNfmyAFQ= X-Google-Smtp-Source: ABdhPJzUbvRGH0by9dVy2/6Hr6ntAdJY+3xMWPwx82L3sWjhsK0y05FpNGbH2+eIL170TSTLgW2v3g== X-Received: by 2002:a17:90b:38c7:: with SMTP id nn7mr10655323pjb.105.1638499637807; Thu, 02 Dec 2021 18:47:17 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.47.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:47:17 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 02/23] lib: add tests for reference tracker Date: Thu, 2 Dec 2021 18:46:19 -0800 Message-Id: <20211203024640.1180745-3-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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 --- lib/Kconfig.debug | 10 ++++ lib/Makefile | 2 +- lib/test_ref_tracker.c | 115 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 lib/test_ref_tracker.c 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..19d7dec70cc62f0a7b274cd5ec8bf8cec62b0af3 --- /dev/null +++ b/lib/test_ref_tracker.c @@ -0,0 +1,115 @@ +// 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(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) +{ + ref_tracker_alloc(&ref_dir, &tracker[0], GFP_ATOMIC); + 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 Fri Dec 3 02:46:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12654123 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 E7334C433EF for ; Fri, 3 Dec 2021 02:47:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378267AbhLCCur (ORCPT ); Thu, 2 Dec 2021 21:50:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378255AbhLCCup (ORCPT ); Thu, 2 Dec 2021 21:50:45 -0500 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7283EC061758 for ; Thu, 2 Dec 2021 18:47:22 -0800 (PST) Received: by mail-pl1-x632.google.com with SMTP id q17so1088132plr.11 for ; Thu, 02 Dec 2021 18:47:22 -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=iYXgR/ok4gbZqsXu7m8s8c7A+21ufwrO9AwNNSuqCvs=; b=YRZzqdAQ/8AgYjRTg2tOO3c+4UFc3Xx9AWHxOIzxd8DwiH90vWz6yo2LtJl4DEbMIi ovZSER8lyV0Ie0QkBCXOcRT9lh4ye0yNX8Kr5TNNyZuP4qDP86OOQVv+So+rkhEd1zBz d7piyDM1GiqbnXnX6x7MkW6vQ9Nah6RjlfGeSlPEl03iA1jrNdkI5aebemvu9lg9KvFb 9+c4BY0mqkdnT72Y9VrtTFbFWaDCWW6+PCEIueV5UUj+ZYAC+XgrKQex5CKYiwPa+zqJ e6w3rUtGVsOnDRcv21JSzbeXwUC/SXYOxwPm/5CZrWQsyYOpAUJuUnsVWUf1g02JzEmK ne7Q== 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=iYXgR/ok4gbZqsXu7m8s8c7A+21ufwrO9AwNNSuqCvs=; b=7DJ2ybUvx2F3ODonoDsTqzQwUkLuCQUexUVYWuj3e8PUGJV1AsiDiwf55kQl1DIUae qbVMvwIgHW49lkuu9h6fcpdZ+2MkFlz4lBQ58H8pqBiWG4MNEe2L/LTa0NBBqdiGP44Q w+LNRs9zGZJvMJLwAbs7hvUwwDTswyMjJA2MpAkLftuQNkjSAWwHS+nBLirPfngOitFb dIW8voLQwwQ0HKA3Pv4l9tjl31yMDHjKbrJzukyxmDvCyKOLPIvvQI0tQEIp6w0pOJ9Z aVxVDas4M1d0XdsDnf55AjTdtCvoqzamLWl4MRw6c0HaF6Ed6G5SE8shJPkRJqh2Nvia 5S5g== X-Gm-Message-State: AOAM531vWIclFltKM2wGmqSzT7INiRB4/fRxvUAXX0c5eTuYCguUnydV mRNn6M3rfA/qsUxWpffxDao= X-Google-Smtp-Source: ABdhPJw3KzhaPXDHN5WTk04IP+RqLLZNm5Im18Cs2HAvowZ5CIHOAqag3WEFGzDKGhX4xrSH8eCvdA== X-Received: by 2002:a17:90a:d684:: with SMTP id x4mr10682975pju.244.1638499641926; Thu, 02 Dec 2021 18:47:21 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.47.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:47:21 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 03/23] net: add dev_hold_track() and dev_put_track() helpers Date: Thu, 2 Dec 2021 18:46:20 -0800 Message-Id: <20211203024640.1180745-4-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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 | 44 +++++++++++++++++++++++++++++++++++++++ net/Kconfig | 8 +++++++ net/core/dev.c | 3 +++ 3 files changed, 55 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 65117f01d5f2a9c9e815b6c967d5e9e4c94af0ae..daeda6ae8d6520c38ff0ce18bac2dc957940de5d 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,40 @@ static inline void dev_hold(struct net_device *dev) } } +static inline void netdev_tracker_alloc(struct net_device *dev, + netdevice_tracker *tracker, gfp_t gfp) +{ +#ifdef CONFIG_NET_DEV_REFCNT_TRACKER + ref_tracker_alloc(&dev->refcnt_tracker, tracker, gfp); +#endif +} + +static inline void netdev_tracker_free(struct net_device *dev, + netdevice_tracker *tracker) +{ +#ifdef CONFIG_NET_DEV_REFCNT_TRACKER + ref_tracker_free(&dev->refcnt_tracker, tracker); +#endif +} + +static inline void dev_hold_track(struct net_device *dev, + netdevice_tracker *tracker, gfp_t gfp) +{ + if (dev) { + dev_hold(dev); + netdev_tracker_alloc(dev, tracker, gfp); + } +} + +static inline void dev_put_track(struct net_device *dev, + netdevice_tracker *tracker) +{ + if (dev) { + netdev_tracker_free(dev, tracker); + dev_put(dev); + } +} + /* Carrier loss detection, dial on demand. The functions netif_carrier_on * and _off may be called from IRQ context, but it is caller * who is responsible for serialization of these calls. 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 aba8acc1238c2213b9fc0c47c93568f731f375e5..1740d6cfe86b58359cceaec7ee9cc015a3843723 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -9864,6 +9864,7 @@ static void netdev_wait_allrefs(struct net_device *dev) netdev_unregister_timeout_secs * HZ)) { pr_emerg("unregister_netdevice: waiting for %s to become free. Usage count = %d\n", dev->name, refcnt); + ref_tracker_dir_print(&dev->refcnt_tracker, 10); warning_time = jiffies; } } @@ -10154,6 +10155,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, dev = PTR_ALIGN(p, NETDEV_ALIGN); dev->padded = (char *)dev - (char *)p; + ref_tracker_dir_init(&dev->refcnt_tracker, 128); #ifdef CONFIG_PCPU_DEV_REFCNT dev->pcpu_refcnt = alloc_percpu(int); if (!dev->pcpu_refcnt) @@ -10270,6 +10272,7 @@ void free_netdev(struct net_device *dev) list_for_each_entry_safe(p, n, &dev->napi_list, dev_list) netif_napi_del(p); + ref_tracker_dir_exit(&dev->refcnt_tracker); #ifdef CONFIG_PCPU_DEV_REFCNT free_percpu(dev->pcpu_refcnt); dev->pcpu_refcnt = NULL; From patchwork Fri Dec 3 02:46: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: 12654125 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 EA1C4C433FE for ; Fri, 3 Dec 2021 02:47:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378218AbhLCCut (ORCPT ); Thu, 2 Dec 2021 21:50:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378237AbhLCCus (ORCPT ); Thu, 2 Dec 2021 21:50:48 -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 B97BFC06174A for ; Thu, 2 Dec 2021 18:47:25 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id nn15-20020a17090b38cf00b001ac7dd5d40cso1292569pjb.3 for ; Thu, 02 Dec 2021 18:47:25 -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=TRGi1Y/v8gSjSr7WA85PbfYUHy9YzOpPnxw4XG0Peio=; b=Ok2yZDfF+zoIY5VsR7ayreU4Hq8iZad7esL4l7fF0XuoPBy7sg3HXUlxaDac5f1l1R zmjtF5X8TMS4gDwhd4WtoOqLgZJmM2BW51kZhSr4YxfmD9f6mi+7h/ZRAmtgZxxJNruq tcddc6AEOMsETdhoqxpue9aQFBQOBP8nlwNg6+jpALSAdvLhDFjsYIblxDyz2l1NVTgD jSWyMyntBkc6tgD0MPC4tKfMy8Mx348wsFe04nel5ES0BdDavwZ48vi+E3VTy2IPueN7 cBKmno9dwEKzJt5vcOAVzzfmluRYd9NDJZcNI9WubZx0TQOrFeioHcpPqHGwZSK/rwg7 gakw== 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=TRGi1Y/v8gSjSr7WA85PbfYUHy9YzOpPnxw4XG0Peio=; b=vNG9RjfPllx/bGNBsqCOA0tmJ6kkBTOIkRQZMAxzvJxbpWaXQo91Z1yW8WEmL6dJVa 1gLPGueN1d7kSXQjOKB1rHoWz8CqX/fnn2BtxCXSHHnrUnEczgCFg3VbYGIK6M6QS1JG /7krlY1iREkXK7IQgnFfxK+8zl8Zd8xgkQ/O+ORvtjvGswP/MFj3dmsJTpNmdaeunT7e vV69TRxWJvqas6gXDX8/PqC1sF2G/QmDQ6BzP1VmIoUAiQrqzs3lIEJq2bClaUTOmqoN ZI9ER8O3M4C7OCR6Ggw1T2qsB3DTEgqllO80JAfoucBCkg5+onMzHl1qVw7pL5Os0Yw7 +Leg== X-Gm-Message-State: AOAM530tzmJeHcAIcYTJyka85M5F5ZmM18T2XSMCmuentRErYuBt0sF+ mwwTDeGryK0uqId/hjLKEN2LaKWWYjg= X-Google-Smtp-Source: ABdhPJyZzxXzxNoAvRNXld32U0acdoiPhSF7TmYeMdnDi17p+J0AE9VE9P8V8A21WABN6JtPO2wrsA== X-Received: by 2002:a17:902:a717:b0:142:76bc:da69 with SMTP id w23-20020a170902a71700b0014276bcda69mr19739560plq.12.1638499645356; Thu, 02 Dec 2021 18:47:25 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.47.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:47:25 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 04/23] net: add net device refcount tracker to struct netdev_rx_queue Date: Thu, 2 Dec 2021 18:46:21 -0800 Message-Id: <20211203024640.1180745-5-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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 daeda6ae8d6520c38ff0ce18bac2dc957940de5d..5bda48d81240e010bffb1cfa96e7a84c733a919a 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 Fri Dec 3 02:46: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: 12654127 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 273B3C433F5 for ; Fri, 3 Dec 2021 02:47:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378229AbhLCCux (ORCPT ); Thu, 2 Dec 2021 21:50:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378242AbhLCCux (ORCPT ); Thu, 2 Dec 2021 21:50:53 -0500 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF42AC06174A for ; Thu, 2 Dec 2021 18:47:29 -0800 (PST) Received: by mail-pl1-x62f.google.com with SMTP id y7so1150420plp.0 for ; Thu, 02 Dec 2021 18:47: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=48N6fDcox0daRV3v03PbzXuddU0gNFZuG8z1YrrJ8J0=; b=FAy+I+H4vcT+hO9U6Jtw5wZNpmQrpFAzIImDdyH3u4ApRFWRTdIGRFeZDgiieiLq+A wenzMCwgaWtgbnHBHjLvUVO6kRlTWtvOn5/eB1Co+RVRgTml45mAs67nJYuj1Cf6oNbm WR0CJ1YG9Cjkx7lgp7oY0oVBWadwlAOWfEakeLGtzrZfZkllWIcoE4ZlLITJCX5aA6Hm dd88M8I0pa3G4JQiNkutq3iXjVKrkKNS4muVjW1drnfQlDODjw6OqnAU4axXDp2SI6gu z1aVCs/D2C5hUhywM6uSKc3AtR06YmGVTF4lSc2PmhFu+sXixZT5od1dDBPqNTklBxix cW+Q== 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=48N6fDcox0daRV3v03PbzXuddU0gNFZuG8z1YrrJ8J0=; b=Vsu4zubyuiAVi9F5cfiMk5tDAQrhVva+e8y/2NoCgHjK81sJ9AS8PKiv3htZYJmFCZ 2MBxNe9dds8L5IA/ID/2THq+BlBwKw3NnC2BTl4uJDolE9n+tMcCbA887lk42gF7+aFc 9WgBipNHTrnYp8RXKaV9qVORuqRlGg4C0oQE8Wo6x8gZAgd+pvi6ScJjEah63J+ZL17j 9Bsbplha4spMkoWGk7Pne93Tm2xYvFhVM1fdTyWGtefUD+x0OmTsAJfKfLhES3eD/4i0 h8JhYi4x0Nd9gDjovQoR238C3fpskMVZu1gNECxO+PfX5WY4AlrSmNFq2w+z9tcdozgL JTuQ== X-Gm-Message-State: AOAM530DF7rEIMiAB6WKv8hCscI1++F8H/JydC18f2tnldbnXKRV8K8a icxZGSXPOXfdeeIjxGe4kME= X-Google-Smtp-Source: ABdhPJyDoomTDBaRekCSUiyQn3e5/6XjynblHDsQKQyKq2aBr4HORJBIPlyhhqLAu3dHP8ePt+4jUQ== X-Received: by 2002:a17:902:cecf:b0:141:e15d:4a2a with SMTP id d15-20020a170902cecf00b00141e15d4a2amr19692915plg.66.1638499649570; Thu, 02 Dec 2021 18:47:29 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.47.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:47:28 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 05/23] net: add net device refcount tracker to struct netdev_queue Date: Thu, 2 Dec 2021 18:46:22 -0800 Message-Id: <20211203024640.1180745-6-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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 5bda48d81240e010bffb1cfa96e7a84c733a919a..3223f7db128de3a7353e6d50255c01ccf6c90ba7 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 Fri Dec 3 02:46: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: 12654129 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 9FA23C433F5 for ; Fri, 3 Dec 2021 02:47:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378252AbhLCCu6 (ORCPT ); Thu, 2 Dec 2021 21:50:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378242AbhLCCu5 (ORCPT ); Thu, 2 Dec 2021 21:50:57 -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 29CBEC06174A for ; Thu, 2 Dec 2021 18:47:34 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id r138so1601316pgr.13 for ; Thu, 02 Dec 2021 18:47: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=eOkbTqC70cMxk+SiiC//4vDcMoRtO5s+8GF7iQiCxQY=; b=ht5nFeUHuKWMoCQigdCou7MA5/wRZtVPypuPAMfCuWHZVTI0zjJSWUBDKV1Uub7yHI do3MYwTUyKntCx7xGERunn8jXBUG0zgQGSuDoIYVXP5Ia8IOKDbqpPWchejU22gzcFEq 2rNZ9Ue7qkTa2cV59021RK1ZwsAgQJ5iv7pYiClwGUbVZXvweiYcQkgMrARitvrriw1A THqA7Tto5IzWSJJv//lL3X3dnkHQHrejwD9ZqZyt2nbPVP15Ay2PTsUPylX44rS35tWS oRsuR6DuUGtkX4DVdQTtHl6retvxBSofCLvlfnjKyUi0/b5hZgD0oKve1QswYuwWYn1F eQVA== 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=eOkbTqC70cMxk+SiiC//4vDcMoRtO5s+8GF7iQiCxQY=; b=8KibDtvfuwO+mnSbTchvLuF6mHc68AbMmUtwHwj755pUG1LMlBPL+/AxePInEyi8bB Ym6eCAcbMFi1fEFcpYDudLop8pJpQptg4Rv2fbAl6M9VbcX4fLyq9PYMspIANnDT4gdO OWnMeSY/tsDpPta4A1d0Go0gYgpnyDhmz3SsuVUZS8QNy+DtEfykqahnXZFR39tI9Ltf g7NgzbFOxneSBroTgOHQk9VncNHMyA6f3/7wuPF5Rrfm/Y/arHT5pdb6I2yJqdi5Gy5k yLrbdiiqmNOLJZeyXGyfF0+cVHll7RRO223ci2p/tA2XJe5nGtKUkGfXV3wwBRnMhjL1 OxEw== X-Gm-Message-State: AOAM531q8qhCvBSN0klQmN5mZsIhvpmCyY+l7HPm2HBD5L8U1iREoJBX mNtYlAeITCnPJjda2O0gPXU= X-Google-Smtp-Source: ABdhPJw3LyI4feNacea/UoPLLweXpLKTh4n8vxg1WNPkBP/HmoYZEscX4nDq9cY+PQE8C3B9vIuICA== X-Received: by 2002:a05:6a00:1350:b0:49f:e389:8839 with SMTP id k16-20020a056a00135000b0049fe3898839mr16466263pfu.51.1638499653711; Thu, 02 Dec 2021 18:47:33 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.47.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:47:33 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 06/23] net: add net device refcount tracker to ethtool_phys_id() Date: Thu, 2 Dec 2021 18:46:23 -0800 Message-Id: <20211203024640.1180745-7-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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 Fri Dec 3 02:46: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: 12654131 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 D54F5C433EF for ; Fri, 3 Dec 2021 02:47:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378224AbhLCCvB (ORCPT ); Thu, 2 Dec 2021 21:51:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350096AbhLCCvA (ORCPT ); Thu, 2 Dec 2021 21:51:00 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AD5DC061757 for ; Thu, 2 Dec 2021 18:47:37 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id p18so1080182plf.13 for ; Thu, 02 Dec 2021 18:47: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=iCVrtbrupO2p3CSbIlgpBTs9TIXh0ks/7pAWJkZoW3E=; b=gttNy+sOkoCfam70kewyLMG9bedu4+vLNpYuyoWzwCc+MQc3nrzT6khC6wjrZ7ZHDW bIOAKIXBDDzHn38F6JQ5mXaig+PJMyuKbzc2m/jMd0keO5v1IWg+12YGqGhtmld0amxU EwFrUtqe0vXK3JJ+F1xVRcEMr/GnUNFePiUtFOXJWWAPQhF9IjK497TdcMDJSKzNeE+o XKq2+nbKYT2Y+NuXrdVUxM0wtIWRfFj3QVE8ShCD9EJE26HakzLZxYZ5/Z7wS1FKPS7Y eT1uqsv+cxJcKlXpTYkLrwfQSv5rzW9ghKHX/s7ASYdVglcuVd45YIxJdDk2rSkmCZBr IeCA== 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=iCVrtbrupO2p3CSbIlgpBTs9TIXh0ks/7pAWJkZoW3E=; b=4WX8XBrlwBRuRE6G6o17fJIaP5IYSmLvkyt9vYjzLYEPBABp8zTZJJzyuXwHkZjq/K t49uqaDphKYk18cNSIDpxbGM6rnNukPgHk1T4a6/V3cew3dTg87xCQmwBumaSWg38lY1 8vb2JbOCFiX8EOTdaBMLaIkVwSKP2A8ymCncwfYUhmu60HIaEClT3SiDqYydYjdEY8G7 hcZgHqE9p6VGXdwPAZObsXCbFDOXSzuqkP0oz6U1LYATMLpHIGd49veCUfUvX0pPoBzv FO2VqTbWNrlFVS2digDA0VAVCIkCYe3Uz5fKhHqO5KB4RO0yxfuDNwCeZVj7ln1YxOIM 6L6Q== X-Gm-Message-State: AOAM533BzDSdAruZEyubMWCK4bSga4No7L1H4r/GjUjRMpVRewzvgnQl HNdlwSVxjLuWT/4CNeOfUt0= X-Google-Smtp-Source: ABdhPJxzcuVhd69wEtGUrva/6izm+zhnMvTDbANPO51WhroYcNNlqv2SEqUKFOGSO18ZXQk7z3dSgQ== X-Received: by 2002:a17:903:2093:b0:142:7dff:f7de with SMTP id d19-20020a170903209300b001427dfff7demr19963093plc.75.1638499657195; Thu, 02 Dec 2021 18:47:37 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:47:36 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 07/23] net: add net device refcount tracker to dev_ifsioc() Date: Thu, 2 Dec 2021 18:46:24 -0800 Message-Id: <20211203024640.1180745-8-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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 Fri Dec 3 02:46: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: 12654133 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 68A75C433EF for ; Fri, 3 Dec 2021 02:47:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378255AbhLCCvE (ORCPT ); Thu, 2 Dec 2021 21:51:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350096AbhLCCvE (ORCPT ); Thu, 2 Dec 2021 21:51:04 -0500 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EC60C061757 for ; Thu, 2 Dec 2021 18:47:41 -0800 (PST) Received: by mail-pl1-x634.google.com with SMTP id p18so1080249plf.13 for ; Thu, 02 Dec 2021 18:47:41 -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=+2LwuTZxf6hfMURpQK8QlcUjSRki4HDA2qnkJ82nk9A=; b=CQrCdJ+l/g87es3R5DZ/BmNKJJLpl+Luy44nAfpqtReJ3o1YIsg9m2Qym8t7tZ5Z9K juIU4yo40dskiBRBxSHXUlLF0z9WoFaxy14NnqqcTgIDxlmbqIpAdnTxaVNIr9A+yexz 0YY9W+7OEpnrEIu8bKf012K5PCOZ8zMMZR1VwsI83RWgvhiBG78KrIxuoIgixZeQ1RRu Uc6wMHGk0G0x7aLVmV+A8CcKBmN1wm0rKNhbSsLpF6HQOnvcJEotzeubuL9Tqm8dnQt6 T6BgYSsAKUHd74MsWDzbI5LenX99EMvbo9DM1P4G4kxKwr/Ry1G9LcQ39moLUnVFT2V/ y2fw== 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=+2LwuTZxf6hfMURpQK8QlcUjSRki4HDA2qnkJ82nk9A=; b=p4GqFonehAkfFjFSyAcveJ6y5fqplTzpYqhpLezSE/hafBQiR8mPtA41Qh5koKkBe2 y6NTs+5MN7eaq4qlUs1jiu6rRdp6Qc6kSA+p4P1+4xaRFDIYREAOSkSYoXJab7lr9DhS n5QXPR06ttzLVrLCBP6upfh7sCtj4/TFRFuFiqlwFRAFeKblJ3LSX+dqp1xZuduwfZ8K seh47b7ZayDeBOCbDASnwEdaeiimCyI5tR699DeiIfh3j7ENSIZhFTTu11fFZXDLlPBt Q6CYRX+5VsQdEZJazvBu53mR8JmgIqAisWFTV2/LYjKIr48Km2epPIsLIawZgll47eW9 BvfA== X-Gm-Message-State: AOAM5338g/M4l+5LbTmVuAyN7BmbCxrjAtbdfewqasmgOljHvvJecd6w +pARLb0f1MPWFkCDwtWAbdY= X-Google-Smtp-Source: ABdhPJybjWGULJU6D+OOvrl9WC1u2PKujZVWc2Xfyrnllr2X65FT+hrCCKKS+IixwtZtwpYFG+cleA== X-Received: by 2002:a17:90b:1e51:: with SMTP id pi17mr10699625pjb.245.1638499660847; Thu, 02 Dec 2021 18:47:40 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.47.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:47:40 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 08/23] drop_monitor: add net device refcount tracker Date: Thu, 2 Dec 2021 18:46:25 -0800 Message-Id: <20211203024640.1180745-9-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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/net/devlink.h | 3 +++ net/core/drop_monitor.c | 6 +++--- 2 files changed, 6 insertions(+), 3 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..3d0ab2eec91667bdfac93878a046fc727fc22b99 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; @@ -864,9 +864,9 @@ net_dm_hw_metadata_copy(const struct devlink_trap_metadata *metadata) } static void -net_dm_hw_metadata_free(const struct devlink_trap_metadata *hw_metadata) +net_dm_hw_metadata_free(struct devlink_trap_metadata *hw_metadata) { - dev_put(hw_metadata->input_dev); + dev_put_track(hw_metadata->input_dev, &hw_metadata->dev_tracker); kfree(hw_metadata->fa_cookie); kfree(hw_metadata->trap_name); kfree(hw_metadata->trap_group_name); From patchwork Fri Dec 3 02:46: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: 12654135 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 26E9AC433EF for ; Fri, 3 Dec 2021 02:47:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378258AbhLCCvI (ORCPT ); Thu, 2 Dec 2021 21:51:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378242AbhLCCvI (ORCPT ); Thu, 2 Dec 2021 21:51:08 -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 17AFEC06174A for ; Thu, 2 Dec 2021 18:47:45 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id m15so1610189pgu.11 for ; Thu, 02 Dec 2021 18:47: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=xW5ouGZq4ABNETkcCBjnJear5A4Z2uZYh2WCONXgZTQ=; b=d+B0yu8GGdFUPmr9J3tI2/HBr1SqlyEmKgsFJHLqBPdOFbg5kKfQRLi4latAj7darW n9kh4YEO7c5W+qbkeD+ZB66EQ7CFl2zeIB8GVKd9pamfbAXOqbKSgTK/4EnBtIcyIzPs /j4dyD9m4+qG/OuSuT5easYiYDUWEX2yrFfLCiKBYUgoPS9HOYyxXyunMJolt/onWcpr I+k0XtTwgD9B+10RGf5rTGh4zzRA+YSpp5Rz1VxPdhDBpfjaOll537fbxQ7ENQvJ9026 RY/AblQFjUYYYFbv40hGkimkq6KvNe/DacgKG03KVyHMnl79IaPjsvwLwHHTmdYRZ9ca L3sg== 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=xW5ouGZq4ABNETkcCBjnJear5A4Z2uZYh2WCONXgZTQ=; b=cq+BWz3f6Fg9L32q+1CGH4Pl5O5Z94j+jkGs+la9HSrA1Lb9/x0/TpKl46zaY/3p5o 8/XcstOJEe12xiJnKrhwCnnBd4JEgrbvC4OgiCz+ba+7umnaHXAT+GJF/RzJWaa5ENya kLULtmH//Q7UFn+l1prbuApyOfqYkoTwAVrjdMBT6+I+EQErBZc5DhlAlE4ZgUqqQ2yE bLQHe6KjeO9jsy7M0ifBYkRLlUY34JRtTxOdcPt5wgB9A6q5OjJOqCy9oyQL5boTkDDD k4MBG7NF/Ol70vsdVXX68qQLpiaK2cHDPIy5j2zASxtLBmeduhAZ+q97/4dTNRbs1VaT rCtA== X-Gm-Message-State: AOAM533hW5agQ4DQEk4xZVWyy+YujWy2rlqrhbiATTSBHpxgOCZm5Bhc FK7TbOT5MRPqMw/RsES976w1CQ05DMc= X-Google-Smtp-Source: ABdhPJzxwKaLymNljWrUT0LU1s2BHEvqYpLlPzMay80ygNtxcrqJgwnBXIQ6Vo4cUkJN82276RlwgQ== X-Received: by 2002:a05:6a00:21c3:b0:4a7:ffeb:ec1f with SMTP id t3-20020a056a0021c300b004a7ffebec1fmr16661419pfj.60.1638499664672; Thu, 02 Dec 2021 18:47:44 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.47.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:47:44 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 09/23] net: dst: add net device refcount tracking to dst_entry Date: Thu, 2 Dec 2021 18:46:26 -0800 Message-Id: <20211203024640.1180745-10-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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 3223f7db128de3a7353e6d50255c01ccf6c90ba7..d2bbae8464fc9a2367ee063bdbcba4caa994fa5c 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -3882,6 +3882,23 @@ static inline void dev_put_track(struct net_device *dev, } } +static inline void dev_replace_track(struct net_device *odev, + struct net_device *ndev, + netdevice_tracker *tracker, + gfp_t gfp) +{ +#ifdef CONFIG_NET_DEV_REFCNT_TRACKER + if (odev) + ref_tracker_free(&odev->refcnt_tracker, tracker); +#endif + dev_hold(ndev); + dev_put(odev); +#ifdef CONFIG_NET_DEV_REFCNT_TRACKER + if (ndev) + ref_tracker_alloc(&ndev->refcnt_tracker, tracker, gfp); +#endif +} + /* Carrier loss detection, dial on demand. The functions netif_carrier_on * and _off may be called from IRQ context, but it is caller * who is responsible for serialization of these calls. 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 Fri Dec 3 02:46: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: 12654137 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 49C78C433EF for ; Fri, 3 Dec 2021 02:47:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350572AbhLCCvM (ORCPT ); Thu, 2 Dec 2021 21:51:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378260AbhLCCvL (ORCPT ); Thu, 2 Dec 2021 21:51:11 -0500 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B845C06174A for ; Thu, 2 Dec 2021 18:47:48 -0800 (PST) Received: by mail-pg1-x529.google.com with SMTP id 133so1603651pgc.12 for ; Thu, 02 Dec 2021 18:47:48 -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=SqS8l1rp8xDuoheLvvuPOhg+iERtHrbdIDpDHRwHj/U=; b=MLyQfQC2zvqH+yfZalUdKyMmR8LnP1rs7rYn4ffvFljXamsINOmgFpd67bjYSN2Io0 yl7xkHH3p6zazd4uA9d44UrDFyPwOb+LoAfXJ9ehk91x0tuIzbQY2iqDqKPL5JVeTsQF kQsLpolb1AVAA7mu5MGfrME7Kl05hW1rbHKAnqfatuDd2IbXmebnWRp+7A9IbTCyxWRq O8KXVL6FaIQYlLY0ZaHTZxrSHLMMeUg6R8ijknlRz6rwolnALq8+UBqSh2VdtYmWAJDO 4eXmgM2NpEmHvLDX9FdaPGrMYFSQ74D+48FeUpJ7zVVm8jQ5jR6VvBgx0WSNzbFReSFm gbLQ== 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=SqS8l1rp8xDuoheLvvuPOhg+iERtHrbdIDpDHRwHj/U=; b=2RVJCdGjEcsEZHITJtZoAxzgGV5ezce4e2Ag9NXQr4JwkAFszBBykv/F59Kdtl/uyZ vP9qn1t/EQraq9o8D2Vag4jz7pgkjCque5iQy/WtQfOXIBm+MhFTsj2HhI41LgezsSwx mDqYksW3Zfu78PZ8pzFBfXtCLkGghycoOfWyU0L625FsnNZ/iZz9VcrTlrFgdWRgPhjZ JuFmRx2KI4PCjfQ16cEOokJzf0aSAFoy208TS/8PIxsTpkosBE3GyaXQ9YQCNHU8E4ts FuS8BcexecMIgGl4gHKrYcPP6jCmId/qQ3SG1WTVwAjuneGzWmWGyEV4jGc6AqdFeQGf ENBw== X-Gm-Message-State: AOAM5322BHHqXpzJkH1tfOEUPH/zZCB7Lj5ElLNlPXywHmW8hr6wh087 1yUKNO0YwsqEV9gshcGW6Zg= X-Google-Smtp-Source: ABdhPJxXfcFLG69xpkEwlE4Dssyqw7E5wtSCIFfrqk3hr6iiYISw3uZ65TKAs+YYmbM3NleRHdzfNA== X-Received: by 2002:a65:6902:: with SMTP id s2mr2427887pgq.457.1638499668091; Thu, 02 Dec 2021 18:47:48 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.47.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:47:47 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 10/23] ipv6: add net device refcount tracker to rt6_probe_deferred() Date: Thu, 2 Dec 2021 18:46:27 -0800 Message-Id: <20211203024640.1180745-11-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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 Fri Dec 3 02:46: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: 12654139 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 35AB5C433F5 for ; Fri, 3 Dec 2021 02:47:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378247AbhLCCvP (ORCPT ); Thu, 2 Dec 2021 21:51:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378260AbhLCCvP (ORCPT ); Thu, 2 Dec 2021 21:51:15 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04638C06174A for ; Thu, 2 Dec 2021 18:47:52 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id n15-20020a17090a160f00b001a75089daa3so4054306pja.1 for ; Thu, 02 Dec 2021 18:47:52 -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=CC+G1w21LFBn90K6gAip7Dqueu3xcesCxWFiIThECwY=; b=cNVlcEeMXxr5RkobVV1WOG9OjYCibCJTV6qFHkgGWgIZb1OJdCQ9FuB3T0PJZ6gH8S y3NN9SPydt+vDbuVhYw7tJKVvlS6WGDVYGcLGR5yL1d/U9XMcv9NfuN2xKehd8Ll1z6D UdC2twyU1qqQ+/0Vv6L8mjufFjvoOspYSDtumKoW8zD1YnmsGXhR8+INPYteWOFQJlQ3 O9QzkFuOHErWgNAcbhmIBZ5b5hqN52SUZNpp7XzLZs1GG55SwxQWSvaTDXpauI7y+7Fd EiqE9HHhQ57wRZYC9FIDnTfc8oiJoDjqCe1a+GWCg8BU5fPiEZtYadCqe1DBCHbW4OYF dW1A== 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=CC+G1w21LFBn90K6gAip7Dqueu3xcesCxWFiIThECwY=; b=XWJQmtWcYsKahQbBIkiTIzH4vDtYbiWZ1kzWAbn67sSYEJz6aslPFvjtZpmkVF4TAU NY0daSzdZ0DWgygc1dEZq6KZF7Ljkk145z+HIlQJDIZHI2CVYhIEXeIhP2B45UBA/O/M V3jm/FcWys0WQYB3puub6PMO1E38dyjl64AgbjLr7uJ6PfjscsvgJAq69n7eC/5l04sI 8eCPWJZpDhbiwXW2oW11jn8qmLxHlA3H6GOOTWaY+L1jHc7szRqPrm5AkEKKLzyCZIYk YNSm9u3qTFitk7p8s6IldP1ClBlPCDrRU8B2YJ+4VF0sYUtgCyIYX392pGd+Jhi31AgI x0Lw== X-Gm-Message-State: AOAM531TIM8tt4s0Giwhzy87/37yUh/pBe2PRbK41yqBg0WsRka0KIeZ mI/k/8wOeG23CMkP8wF9PAQ= X-Google-Smtp-Source: ABdhPJwYr4W7qlCi4LSzsNahrbfYBBto/uotImbAdEIexSW1CcpF/56BN0Oi1RUiNH3MeoRTMDcKvw== X-Received: by 2002:a17:902:c404:b0:142:28c5:5416 with SMTP id k4-20020a170902c40400b0014228c55416mr19901148plk.62.1638499671554; Thu, 02 Dec 2021 18:47:51 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.47.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:47:51 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 11/23] sit: add net device refcount tracking to ip_tunnel Date: Thu, 2 Dec 2021 18:46:28 -0800 Message-Id: <20211203024640.1180745-12-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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 Fri Dec 3 02:46: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: 12654141 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 6115FC433EF for ; Fri, 3 Dec 2021 02:47:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378260AbhLCCvS (ORCPT ); Thu, 2 Dec 2021 21:51:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350593AbhLCCvS (ORCPT ); Thu, 2 Dec 2021 21:51:18 -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 4C55AC06174A for ; Thu, 2 Dec 2021 18:47:55 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id u17so1099703plg.9 for ; Thu, 02 Dec 2021 18:47:55 -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=TvekCyDlnpJy8Yfx/5JgJmFSWSd+IHup3z0pyOKys8k=; b=I6iTB6IMultl4X9ze4OnqJleR7TXwGY1ffxWkiGgryT4cSvV36j5MMYqg5gRAGqA1U cUeHLOnybnqcgzB8IgDd8QQB5fftKxbwK3traQh6+JoC0/CWCg9Flr9WeqniyhUbfCSg XAaztQgB/du3MJy9O/G1Kd5BjuzWloWNNnaM34re4FurK58S6vGuXY7kbduefbmfwJyg oi+XPfaiBA9rDmL+bVtE0+fPXAT38POB69SKad5lgq6NSxA3UAkO3Bxvb+afSILesYAG HGqzr67SN/NSS6gvhZessnK5o29AtTf4BMou0+jzqleARj3djFGx2s39T/4Fm1dLYEgV gZqg== 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=TvekCyDlnpJy8Yfx/5JgJmFSWSd+IHup3z0pyOKys8k=; b=wVSC/mdNwkpZ85IuRbp13lZUWQc2FDZDjrZc4HYAhUZu6VCNldKeaSlXVS8OQnpl8P 0cGRVZZUQp/o3LP7cyoUbMOUFnP2SFhySqT+ugixUAjqU5/+lWQQpT30Qm2525u2m5ox w551SedJMWTvik2GBly4Cnw++vsWCCh+s08b6jhMWdzqX6fSGzsJlc8QYrgOs+n1GOhl 9wdzPZFhzMOuB7ZZrsfuUAveLwPQpY/e0iCKMZFj57jX6WgX0og+24sMWg0Fr6DzoU9U UEtk/UEol1sZOceJ73PbVCQQJ6akMtis3ieAJfocZneNSbgnxqgzsGFf0bUIfjz0DigQ HBjA== X-Gm-Message-State: AOAM533R522icjG2TTJEDMdr4aseo/IZ369yYJU+rhsU8gzSR6LLWQS0 tRLCzysL3C8iJZN7wIK7gaw= X-Google-Smtp-Source: ABdhPJzMC2TODWL84+Y9GGBVdvUY/3VcST3XbntE6rh/IaGoYTqtfbvZ4GEuEXJR+lUdgKwzkzKOyg== X-Received: by 2002:a17:90b:1a87:: with SMTP id ng7mr10677856pjb.86.1638499674884; Thu, 02 Dec 2021 18:47:54 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.47.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:47:54 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 12/23] ipv6: add net device refcount tracker to struct ip6_tnl Date: Thu, 2 Dec 2021 18:46:29 -0800 Message-Id: <20211203024640.1180745-13-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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 Fri Dec 3 02:46: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: 12654143 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 77C88C433F5 for ; Fri, 3 Dec 2021 02:48:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378262AbhLCCvW (ORCPT ); Thu, 2 Dec 2021 21:51:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350635AbhLCCvW (ORCPT ); Thu, 2 Dec 2021 21:51:22 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52476C06174A for ; Thu, 2 Dec 2021 18:47:59 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id i12so1494630pfd.6 for ; Thu, 02 Dec 2021 18:47: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=7qwiO23AB0bDvllXH4j2dl319YdLwYZlD78jd251Gbg=; b=CbJiqzNEUc6seRSRhV9xRgGFCOoHbC7s5cxnG2HYxaaA5w3y3kSVMDWZ/6A0FkAZzg uCqlbJae867GUDIIAOUFG3DfPi5OEEnySYA9sX8O+VNTvYLJBxo+7B40OIykMdKmKoCu CX3i9sEem7Oxb4cO0m60MC27aCBCET5jpAxlyKHVXpQbc/qeMm/2lHK7KPgLnsjb31P5 zI6vMCaYJE3/uFLxipYFZh0nY7WT2p7H1xa3oM5z+PvFj8HULwtZim3erHfo5RzSd1Ow ac0m+TJ+GEJf2/Kg9kJ6j70/w7fxlJAQHIL7ZLAuMYO3RnTGDRG3ql5GNURNR4zIjEp4 jTzw== 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=7qwiO23AB0bDvllXH4j2dl319YdLwYZlD78jd251Gbg=; b=7lZRZKTvOCM+Y6yCJGAjo7pumCznvMNsTqvWdkESiXDF12ynWcv2MoqJaABkLmRN+b dSaAQ0yWODT3kcLb5WkPcaWMo/bfdB/mtN2YBxLT1vhlf+6ChwvR8X+mgvGsrNB+Bf+Y zfkwxfkVMKRddB3oWXN2TqFuWy6WJmr+2S03dSkpDK5fbh44uTYvSO5Aqf6GihgmrGpp xatGfuozVEe0SSBn8fvzsAVS05PopypVyngM4FofoptKC21Ta1VoKljeD+obEcqOG6WN IoVK230oRhaLF71mXrgzHppAp8Itpyi7uyc5HvOOr23r6LZhLgIQBEvek2WIahk4NUYA ISAg== X-Gm-Message-State: AOAM5303go0r2nkN/RWvryVv7gaC7RFE362NBxV4B1khdsm+TTCquBsF ECOHl9LHK5A4w0m3Bvlgx/o= X-Google-Smtp-Source: ABdhPJx7nmMPmk+IcGZeBph86A7BBv7CRTR/OpNy5BUknqL4ZYj2p1799YmUFjuymUxtkK+znvtE3A== X-Received: by 2002:a05:6a00:24cd:b0:49f:a4d8:3d43 with SMTP id d13-20020a056a0024cd00b0049fa4d83d43mr16542981pfv.49.1638499678871; Thu, 02 Dec 2021 18:47:58 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.47.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:47:58 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 13/23] net: add net device refcount tracker to struct neighbour Date: Thu, 2 Dec 2021 18:46:30 -0800 Message-Id: <20211203024640.1180745-14-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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 Fri Dec 3 02:46: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: 12654145 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 5E2E7C433EF for ; Fri, 3 Dec 2021 02:48:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378266AbhLCCvZ (ORCPT ); Thu, 2 Dec 2021 21:51:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350593AbhLCCvZ (ORCPT ); Thu, 2 Dec 2021 21:51:25 -0500 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A697C061757 for ; Thu, 2 Dec 2021 18:48:02 -0800 (PST) Received: by mail-pg1-x531.google.com with SMTP id f125so1701831pgc.0 for ; Thu, 02 Dec 2021 18:48: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=GDtiZ9MlMKx0wR1tSzrOI9t3DpPfRAAmdOIzJGgoHJE=; b=Xpm4yZ+s5QnzE+gBYAUjlFILY1K1sF9RuBhlAlNxCOvCcDH21y0WJanM5jy7eLhkt6 659bcKcMF7SArxEY/jHdnmrdRusRIQFZXzBsSy5DCSGadGbCgYuYLRy/AT1sM+cwn9gu hAUy1nYl5uZbyap3k2+76js+b0Q/bmr6Yz668ZrMRwXXP8R8Zn2q8ejWGs7etaGGhGKw gz0eVBubpaecUzkrrD1C8dVbi9PCRtqk7g3GW0lLwtD/x6lsbtHYfKkKfHdgQl9sNc+b NsU2RjrL2qrdSRRpM6gBwvpuxbXiF08TU3DK08Dm29We/XCAuh+Sv18C/k00TrmlTb7s jWWw== 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=GDtiZ9MlMKx0wR1tSzrOI9t3DpPfRAAmdOIzJGgoHJE=; b=eoYf2hLwWAL3Ckdirbcp4Jaboh7B/QLuiTFoEULdC3rCPZv+w4E3q5wp86fE+0VP3+ HSp0151RtyaxAqPUd4a067ALLwcjwkEonp7WxcaORhXrmmty9477Y7Q2aHsmWmZgMnKZ YFk/KggiDpCB9R6Fj5XduBRnYvkHJXGWpXOL7tSnb9NfWil6vQbwu8FLpE3gOm6+nuV5 rLsawfAfv/kJEQ4B4n1Z1VcQcT22wJKG872TpDCY5ViCjKDEQFR0l6mIn4V0HhnYCUkH ZkmxTFZ5ZvACgMPf/3RChqZ/8l0JK85NSNY0Ox9j87l4kLBL06cv/6fwzqztSb0KYwb7 JFhA== X-Gm-Message-State: AOAM5324aAdiz15ET9ump/8hDl/j4bVc5n/7AnZlk0P0aLtwCmAA7eBz xAX2hrqzQoEGLn80RgEWCZc= X-Google-Smtp-Source: ABdhPJwCv3o1R9x4ohZcdhgXhnDJjLexWrEz/i8pe55OD9K/DO1MqVnkoN/TZbLLocSsUCgQwCCpDw== X-Received: by 2002:a62:7c8b:0:b0:49f:a8ae:de33 with SMTP id x133-20020a627c8b000000b0049fa8aede33mr16356740pfc.29.1638499681997; Thu, 02 Dec 2021 18:48:01 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.48.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:48:01 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 14/23] net: add net device refcount tracker to struct pneigh_entry Date: Thu, 2 Dec 2021 18:46:31 -0800 Message-Id: <20211203024640.1180745-15-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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 Fri Dec 3 02:46: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: 12654147 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 C7039C433EF for ; Fri, 3 Dec 2021 02:48:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378268AbhLCCv3 (ORCPT ); Thu, 2 Dec 2021 21:51:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350635AbhLCCv2 (ORCPT ); Thu, 2 Dec 2021 21:51:28 -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 CEF69C061757 for ; Thu, 2 Dec 2021 18:48:05 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id x7so1277596pjn.0 for ; Thu, 02 Dec 2021 18:48:05 -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=qDwXdMqlBKlcabo1l62Px149VuPWYKtTf0Af1AK9Ihw=; b=fC3aHnhDfoJcvt6dII6L3QZKE5iQbTT+0XqidI7SJdA03Dp//FCFp2bQKbVjGFVfs7 sMJ29A5cdOeH1VHxCFzzZ0WPqRZuB/ZzY2gpHLn8tvTKjvYemrxSVVzp9kTJ3axJ695k DPoKrlamBBbsidPSmSPSlukQPaE8X0oaQZiuSvrOGe/07uP0eDfSn9wqeBc+2pemmi/7 Gv8nLK3onTkCYaVVnI28n/VcpdHLk8AH5sf4NO4LWo0jG/zjXyey49uvI6j8sUI0YWSE uxqF+jzNUxIf53q1wWVklJRlAUoFyRmKTKp+OSTNGw98yXPf43t38GlztccbdcMSLLcu o+WA== 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=qDwXdMqlBKlcabo1l62Px149VuPWYKtTf0Af1AK9Ihw=; b=yd496Ruvxv6OB/mNPYxJsblhMT/Uqqo2IfHYh97lF4WLlxY9htGc/rU7uGrjGsGA0M 4A3NhyLEwyJdDBfHaN1EyVTciYk2yyF0Owvajdb4Rsxx+oWT+zqe+e6a7tG7G2SCz90G DhSKFS0EbjJLnSzHj+KPbEoKrrhAnVJ4xzizK21Ozmz5xhHvok3xmnNuo7ev75RpF381 cuAoLXFLr4XxYy26v6fS6OKiPy/mFH16V2frgNV922cD7bcU2chpDs0phEHLQuWm2YZs votRvwUqq78fnM8POSLMijw+JqCqPIBA5y3beHqdw20fY26qP+6p1xgkn0cuPFg02wzl YpVg== X-Gm-Message-State: AOAM531UcroNeNZ9uwl+g9uwOb1MLlBFLCz2R4m0PBHDkeFSiUOImuiB GrnhO/f7wMyBy+D+yA6mpHM= X-Google-Smtp-Source: ABdhPJwKwmJiFKhX5HFwT5SAbCS4sMDB/LCJPhLBqtd6w+I8E89rvU0cHLY/g0nmX/g1fWkZy6Y6mQ== X-Received: by 2002:a17:902:8d8a:b0:143:bb4a:d1a with SMTP id v10-20020a1709028d8a00b00143bb4a0d1amr19599467plo.1.1638499685464; Thu, 02 Dec 2021 18:48:05 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.48.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:48:05 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 15/23] net: add net device refcount tracker to struct neigh_parms Date: Thu, 2 Dec 2021 18:46:32 -0800 Message-Id: <20211203024640.1180745-16-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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 Fri Dec 3 02:46: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: 12654149 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 BFA4AC433EF for ; Fri, 3 Dec 2021 02:48:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378270AbhLCCvc (ORCPT ); Thu, 2 Dec 2021 21:51:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378269AbhLCCvb (ORCPT ); Thu, 2 Dec 2021 21:51:31 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3E4EC061757 for ; Thu, 2 Dec 2021 18:48:08 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id x5so1546060pfr.0 for ; Thu, 02 Dec 2021 18:48:08 -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=20Cb5L4Nfh6M+TGH/ohYepS0hgWA3PLHDkuxzPE2zO0=; b=b1y0hvvODp4aUqy4VRJeN4mnsi80HDuqUbHPIpjAiccEEV6CFJh+CISv2XkWczU2Uc vkITUNVbOtn+cesV5N6Na7CbKUFL2VHFQ/TwgFJw+l2tmFmrH2uOyRH61fSzPg8ZCkGS YWRhwHQyL6RVUKYS7C4fmWqeQN2oRr6wcxvqIOf3XRWlEK7O/dlJyoLzyW1cM1UJN8AE IKDGn6v1iysiJwNTW/RXQHXHPZIov3Ew71O2R8id9oDOlM4NK0BYxP087jiriGyGruy9 aMmWbqltx8wMPzJOwu0+XVVMgZdURPzrrDrF2S/1ionmU5EJymRbnj4Hw4CtSj6hKggV ah5A== 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=20Cb5L4Nfh6M+TGH/ohYepS0hgWA3PLHDkuxzPE2zO0=; b=SZpIMcHjRE0bKdqpTjskEBaljCJdm86wRL41cx8n0VjOp5L5NkqxLw0pPRheLb97yC vqn2PzgCgbPcqDYd3s+q6UBP06tLilnxwMyZYn+HItI+l3dSxnwXKuSAFYFY97fnWP1Q eeV1XOezN49AzxAHTf0W+35MQwFf0VlAl6rNpOy+z7vrRchMYiaUfu59JV1mtNZ/4uSF 2PJLTC/m9FXA8tr2BQZi3L7OPxAttxBSY8VUbU/O/KppNERr2fWVhEIfaqQxGEfII445 qafOBeUz+ki9Bel0vxDyNVVPZRlQo7eJHcXOScbtPBSvndTpMLmW480sxjvY+zVmvZXV f12w== X-Gm-Message-State: AOAM5307pyLCE0Y+6W9G9HRzgd9Foh2+/qPpjMsvFqo/Lb+E3vBdNRVX 39PghIh2Z7QVO86vHSdgJMc= X-Google-Smtp-Source: ABdhPJwCymo+fxCDMIaxF2rsqHnd5NzqmOjOZF9fEbIwx/m51uH8L7gq+WmvAZPRBmc/+dHQF4K1QQ== X-Received: by 2002:a63:2cd1:: with SMTP id s200mr2423573pgs.489.1638499688351; Thu, 02 Dec 2021 18:48:08 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.48.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:48:08 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 16/23] net: add net device refcount tracker to struct netdev_adjacent Date: Thu, 2 Dec 2021 18:46:33 -0800 Message-Id: <20211203024640.1180745-17-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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 1740d6cfe86b58359cceaec7ee9cc015a3843723..4420086f3aeb34614fc8222206dff2b2caa31d02 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6537,6 +6537,7 @@ static __latent_entropy void net_rx_action(struct softirq_action *h) struct netdev_adjacent { struct net_device *dev; + netdevice_tracker dev_tracker; /* upper master flag, there can only be one master device per list */ bool master; @@ -7301,7 +7302,7 @@ static int __netdev_adjacent_dev_insert(struct net_device *dev, adj->ref_nr = 1; adj->private = private; adj->ignore = false; - dev_hold(adj_dev); + dev_hold_track(adj_dev, &adj->dev_tracker, GFP_KERNEL); pr_debug("Insert adjacency: dev %s adj_dev %s adj->ref_nr %d; dev_hold on %s\n", dev->name, adj_dev->name, adj->ref_nr, adj_dev->name); @@ -7330,8 +7331,8 @@ static int __netdev_adjacent_dev_insert(struct net_device *dev, if (netdev_adjacent_is_neigh_list(dev, adj_dev, dev_list)) netdev_adjacent_sysfs_del(dev, adj_dev->name, dev_list); free_adj: + dev_put_track(adj_dev, &adj->dev_tracker); kfree(adj); - dev_put(adj_dev); return ret; } @@ -7372,7 +7373,7 @@ static void __netdev_adjacent_dev_remove(struct net_device *dev, list_del_rcu(&adj->list); pr_debug("adjacency: dev_put for %s, because link removed from %s to %s\n", adj_dev->name, dev->name, adj_dev->name); - dev_put(adj_dev); + dev_put_track(adj_dev, &adj->dev_tracker); kfree_rcu(adj, rcu); } From patchwork Fri Dec 3 02:46: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: 12654151 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 CC0DBC433EF for ; Fri, 3 Dec 2021 02:48:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378272AbhLCCvf (ORCPT ); Thu, 2 Dec 2021 21:51:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378269AbhLCCve (ORCPT ); Thu, 2 Dec 2021 21:51:34 -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 B0A54C06174A for ; Thu, 2 Dec 2021 18:48:11 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id 137so1655012pgg.3 for ; Thu, 02 Dec 2021 18:48:11 -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=K+AadUv33QFmjFDOBOvnFpBm7Lw7zZYJtLUilhe63TU=; b=ZJ4PlXxjX2lftb8BX5v0JSYBVXhN/flxonV6GkHwzVI0o0qOKeUZoNCfjR9nJTmVF5 cPFWpAJdRk53+t+meXand+XoH3Qbp6S/OM4/Srcisg1oBlKHCuXAGRUxQqwTNWpqVx68 a2VVEi4KJqPaUf1ujJ6zgA8oi9h20lxmCgKRIfdgeZn1YcItZmCOcYDqGa/jPklVGbGp YQDZo6RPIi6cK0mI5sEevS2nqkVr81jsTaQXFYOupMs0w3OGkovFb3lGFZDgSBdgO3gi PrIXKmh+9P3VWR9Qmfwu/FfufT6Uvx9pPSnijekzbceKZWURxEULnjZlTGNyuGTP9mxB N+Aw== 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=K+AadUv33QFmjFDOBOvnFpBm7Lw7zZYJtLUilhe63TU=; b=VsWVEzFLWzlXhojXXfZ5PxC0P7sg7YtT+n7zBRAwsM4UXOTg6QnguR0DxA8A6Pym5f +RPYc0U8gdXHImYZ+DDl1tQKG8zF5aqBGgzxzlkbw3gIkyOjTH5cuUI4HSenUt3MSPl7 VhHcCzPWmxKFBYjdsbo8nxtG/CLZ6JhGTujehUTMhIe72cqV930XeM2tIS+/WjMa23Mz AYWwSjfHvZxcNawc9ZC09NTR7IulCOgUgINPBosDnJmLMtfCWO83jPyB0kzO9PmjYI0b BtHM7Qk2iVtIAEvVQD1atk3wP+pyJ7aWpgs8ATxPhjipf4yPK1HfxyDPULzsKN/qHnpK h6lA== X-Gm-Message-State: AOAM533RyQIq8FiAHNYMO1Y/Q9ZOcKdJjw4VBa2uECzkdmJuKJCz+3va BgegghVGeI0TEB0x6cgXDgg= X-Google-Smtp-Source: ABdhPJwQWmUo3EeJjEmhqdCdAErHrw4N1NCmN1Smpz9OC+/QpFBAtjb1RCm7Ah3jeRt50qwPScGJhQ== X-Received: by 2002:a63:6a82:: with SMTP id f124mr2529692pgc.154.1638499691248; Thu, 02 Dec 2021 18:48:11 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.48.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:48:10 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 17/23] ipv6: add net device refcount tracker to struct inet6_dev Date: Thu, 2 Dec 2021 18:46:34 -0800 Message-Id: <20211203024640.1180745-18-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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 Fri Dec 3 02:46: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: 12654153 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 BC739C433EF for ; Fri, 3 Dec 2021 02:48:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378276AbhLCCvj (ORCPT ); Thu, 2 Dec 2021 21:51:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378269AbhLCCvh (ORCPT ); Thu, 2 Dec 2021 21:51:37 -0500 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55EB9C06174A for ; Thu, 2 Dec 2021 18:48:14 -0800 (PST) Received: by mail-pg1-x532.google.com with SMTP id k4so1624795pgb.8 for ; Thu, 02 Dec 2021 18:48:14 -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=n5f/tXjsxBdlKXOqSXxOpThsLdatHM6TCJlr2uwfB3o=; b=BowOCAx1vsK65TIeE0YAcV2kru1Ug94aaFwFVnYVvrkTtL4Xju9S+xfRwANRuIFL84 ozK9frXUQCfG6jtc18CMyEBG1z6w9tr7ZyrOkS/v8byQLIt7XNYiMWTVdgsMLufrz4LL OuxddJ/2joCNpv7qyG40d8K84Hng/i0kYDGotHOgZFX+uJMubEkCRddlcUzihYO45ERb yMxMLUA8vHWOhjccnmT91+K/WjJUQMAJteHOSeW0aZF9xZ+15/PWnCtIeFyELOsPHgmT hl9gZQ7aWK1k/UYr0JnNgGbckdbtcDizMTpbPtHyutBPuha2iqp1FEzedNQE6KYVA97p 6hdA== 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=n5f/tXjsxBdlKXOqSXxOpThsLdatHM6TCJlr2uwfB3o=; b=oQc6J6yzqqn07HNEQbwknSDDG2zEqIId2Ieaxnm9v6k5KXxlCS7GF7Q6GhaWAmJAim ya4bMOYN1pGN5/+ZmGmbNbjpc0sa7uKXsT1vH6sV56+m59MmiqEKJtYC7gZztAGq0c9I cleZJd3ZD+XrjQNlUj9hYzR/9ziKMGzSDLX+AOq7RNPgE7cE0ZCJVwSmwQFowBZZzvty 88F0oq+/wS4+zPzIgiUHpuMwmI6f9KOXEt1Jek6qHhxnsNqdVt9Cv5gITvl9hmd6nP5E xbogiUbzKsvbE9IUbsYDwkvzIwFw1CM8/2HiLw9I+eSrUcH7JslOClj1oYx92g0rCeVx nPsQ== X-Gm-Message-State: AOAM533JPhb5LDI8H5xFxte0ZfeVn0YfdHcCwq2BruwgWJBq0i1LeFu0 UKC2mA1HLBCkYlEHjPBy98c= X-Google-Smtp-Source: ABdhPJwp+zIIQsr1P/+EldniOkPAImCNFN4VT52G/EHmAm+nGcLJyHpn+Gva0PvXPscYNvr2KnS8nw== X-Received: by 2002:a05:6a00:2387:b0:49f:af00:d5d0 with SMTP id f7-20020a056a00238700b0049faf00d5d0mr16716516pfc.1.1638499693908; Thu, 02 Dec 2021 18:48:13 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.48.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:48:13 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 18/23] ipv4: add net device refcount tracker to struct in_device Date: Thu, 2 Dec 2021 18:46:35 -0800 Message-Id: <20211203024640.1180745-19-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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 Fri Dec 3 02:46: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: 12654155 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 48B89C433EF for ; Fri, 3 Dec 2021 02:48:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378279AbhLCCvl (ORCPT ); Thu, 2 Dec 2021 21:51:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243291AbhLCCvk (ORCPT ); Thu, 2 Dec 2021 21:51:40 -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 41FBAC06174A for ; Thu, 2 Dec 2021 18:48:17 -0800 (PST) Received: by mail-pg1-x536.google.com with SMTP id f125so1702182pgc.0 for ; Thu, 02 Dec 2021 18:48: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=fT2Qu6/ffgiG1NGeWHN8tdR6mwWo+LW/WTBHIOFKRSI=; b=izrdx+V/2GAhKrR6rFhXOrKem/B20UMkMEZiBfTN7d+PiGIzV2/EXIQ/5PnoR1aXMb wCNxLCCEhAsBOZSc6i8pUTfZ72ZnNQVJaghBi/W5F8+yaD9XXMnXhm7JINl9Gz0q/J3R pcOSs9xQsZG52Em8kfqE7+vl73wsvAC2oTEApYUSrSYI1kUZVAd9SRQntBrQsaCQLruW BY8k4mJjnVNxIXQJTS9xPeL5EiqK6F/23AnZLznwTZt22Bt+SJv89R+SpVdlQ5DdFfY4 fE5L3kpVPFbNiaKlt2Aucri7+d6I1zer6iXZVXML6oBuXNUO/w7uyy3/bSLY3hvxKSDL yoxQ== 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=fT2Qu6/ffgiG1NGeWHN8tdR6mwWo+LW/WTBHIOFKRSI=; b=GafX7wn5zH5Pi5+ejRnOm8XTRUBvhId9Yz+wBbgG7fNpnEFivSX0tnU/1AioTA9lMl vTS7groc0VTQg3oL6uuGN67/Wv8WXS92u5NWxhossr/SAdoF0Pb9cY4ofEyp6ab4RhBH Q14OtpuaWzfzEkTgOyw1cywio4WWaSfwvVWaXKEC8eVDIzqC330tDRSacLM90E0hFkP3 r2a2PacZBm3HPS9uht8qsZez7XIDZt0lOio9Xaidv8nHLLmU1ZAin3LlmfuQrKEonnN2 x7xXUcX1tQkyavD0j4bqJ7giYJPlv+gTYdcyy8QYLXX7kZAuo6iLDORdIIcxUHJkYX1k Y95w== X-Gm-Message-State: AOAM531GhiE8WboYbwcK93zJoQHVNTIEXPZPGHI02RF3HrtkH/OuxgpQ pXoGwvWsEAAi1p7l6jJ/jrE= X-Google-Smtp-Source: ABdhPJxSUGTf+5a0kJR6ZtVMZXC8iYzn2sMSosnaP6wGwV7/RMCIIz+7JP9C2Bl8xRAJY4FKUn+yUA== X-Received: by 2002:aa7:8886:0:b0:49f:fae6:c5f5 with SMTP id z6-20020aa78886000000b0049ffae6c5f5mr16473805pfe.8.1638499696843; Thu, 02 Dec 2021 18:48:16 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.48.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:48:16 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 19/23] net/sched: add net device refcount tracker to struct Qdisc Date: Thu, 2 Dec 2021 18:46:36 -0800 Message-Id: <20211203024640.1180745-20-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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); From patchwork Fri Dec 3 02:46: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: 12654157 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 E0B2EC433F5 for ; Fri, 3 Dec 2021 02:48:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378277AbhLCCvp (ORCPT ); Thu, 2 Dec 2021 21:51:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243291AbhLCCvn (ORCPT ); Thu, 2 Dec 2021 21:51:43 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 907AFC06174A for ; Thu, 2 Dec 2021 18:48:20 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id j6-20020a17090a588600b001a78a5ce46aso4079151pji.0 for ; Thu, 02 Dec 2021 18:48: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=ZJIQeK0EgG/UV5Pt+YkA9U7JwgoNnEnSIPXGj3Jg9Fg=; b=L1uMVXmb4X2+FpKOA9muyrb3cnE3qVmxMS6oBUluU2d15OkQBuWAE6iOvR0ABP1uFW EoUqoUy4KnyxEHJarGxqfA4juDQ0wTGgGqFBJIZfGBdc3Jk5Tih+ptmaCXABlHM8mcF3 ibQ9qvB25oKtWQCI/L1TzyfnmUdsMR+Rj1YbmQ4s1nkYaUYgCpwNgx6J3xe2Xli32Ma3 eavSKjmu9FyY/SIZ8d5QFWaYYpzMDxZNxJwlUJcYsoYtEeajy5JfceS/3/3SOm5J1X4y q9M7oL5dzk1M8YiIYM/K9xNb8CBOofSX4xQEc0kWX7JdFeoZChfM//NxxCb07VGaf2TI T7Hg== 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=ZJIQeK0EgG/UV5Pt+YkA9U7JwgoNnEnSIPXGj3Jg9Fg=; b=5r/XoH9LU2LZzI/ozhqLiwXWQkpY/xZjcCtFIrc2KlAZmLkIwel481O/HTEzh++9s8 xHhqI6ngxBmhDenVNpd8PQX+Pa8lPsawQMQD9pBeR5I9Nj1//6238odQUQz3uOjyoKGB 1cDSJ8/urdrVE+LxcpIBN+iuKbgdgEZTN81IZe6pUb7IdM3jpn74cof0wk2cUTeizPxO Z5XA6UnkoZvp0tuPX8kb4qMv8Ugci/OIzZSrLkY2LWu7JfGuQUvnfsgWowgO7uJ+b+2T 8BLqUVuM+HQWEvbLGtU4mHQq67qhpq6wDAPTvWS1MKSS3WMxup3DQqMYFv7pAotFgqXq NqYw== X-Gm-Message-State: AOAM5321q4wxyPkJXCxRXGXpUf8jGsvyU2lDawLbC8ak/ogUJt7bpCWN v8YQrm9ZpcUg3qv/GMKsAUbpj+FMEJg= X-Google-Smtp-Source: ABdhPJwgJqmIJbTu1O8PpxXhTwO5zB+0SgBPBJrwVAPmb2fNEf5BLZQKXSQCJ8jJvl2kBMdtUIBCFQ== X-Received: by 2002:a17:90b:4a0f:: with SMTP id kk15mr10444126pjb.223.1638499700126; Thu, 02 Dec 2021 18:48:20 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.48.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:48:19 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 20/23] net: linkwatch: add net device refcount tracker Date: Thu, 2 Dec 2021 18:46:37 -0800 Message-Id: <20211203024640.1180745-21-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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 Add a netdevice_tracker inside struct net_device, to track the self reference when a device is in lweventlist. Signed-off-by: Eric Dumazet --- include/linux/netdevice.h | 1 + net/core/link_watch.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index d2bbae8464fc9a2367ee063bdbcba4caa994fa5c..990fb906b524860451b32df6b4bf625780b6d9d7 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2279,6 +2279,7 @@ struct net_device { struct bpf_xdp_entity xdp_state[__MAX_XDP_MODE]; u8 dev_addr_shadow[MAX_ADDR_LEN]; + netdevice_tracker linkwatch_dev_tracker; }; #define to_net_dev(d) container_of(d, struct net_device, dev) diff --git a/net/core/link_watch.c b/net/core/link_watch.c index 9599afd0862dabfca4560de6ec36606bf3742fd6..d7d089963b1da4142a0863715382aa81241625eb 100644 --- a/net/core/link_watch.c +++ b/net/core/link_watch.c @@ -109,7 +109,7 @@ static void linkwatch_add_event(struct net_device *dev) spin_lock_irqsave(&lweventlist_lock, flags); if (list_empty(&dev->link_watch_list)) { list_add_tail(&dev->link_watch_list, &lweventlist); - dev_hold(dev); + dev_hold_track(dev, &dev->linkwatch_dev_tracker, GFP_ATOMIC); } spin_unlock_irqrestore(&lweventlist_lock, flags); } @@ -166,7 +166,7 @@ static void linkwatch_do_dev(struct net_device *dev) netdev_state_change(dev); } - dev_put(dev); + dev_put_track(dev, &dev->linkwatch_dev_tracker); } static void __linkwatch_run_queue(int urgent_only) From patchwork Fri Dec 3 02:46: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: 12654159 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 46023C433EF for ; Fri, 3 Dec 2021 02:48:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378282AbhLCCvr (ORCPT ); Thu, 2 Dec 2021 21:51:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243291AbhLCCvr (ORCPT ); Thu, 2 Dec 2021 21:51:47 -0500 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB50EC06174A for ; Thu, 2 Dec 2021 18:48:23 -0800 (PST) Received: by mail-pf1-x436.google.com with SMTP id 8so1505466pfo.4 for ; Thu, 02 Dec 2021 18:48:23 -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=uOGDxUJKSk/sPCLCmeDkNNHP+gUxPNLx3WgXYaYfGGQ=; b=WIrmF0QqnBl45nCot1nWCrdBpNHZNq/MXn+JkP7rRjemAwHK8fq3HLfTtqlFCzYcJm NMfsm+een5yWBRiU5CmOO8YsMCEiTNbDBYTOMrbC89u7FQd4BzIGXweD7b1DdB+2vmYP RT9Tua9upgSGtYWTZc9vUf+fnmvZijCvWlB4OUngy7dj/7NU0GTzxwKBmkdoOGAlcQtD pb4YFHrU9z/SJb/E1trLjTHcNCHIgu9YvzCrVS+xxgWeXpysBf/kbG0Umhak5/RFvfOC wS7mnBjq8o+WSoA89srzfc5S7o/eZ1eke68RQA7Bg7G9qGPoWv6MVtkaMZiFklkZ4FNn bC2A== 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=uOGDxUJKSk/sPCLCmeDkNNHP+gUxPNLx3WgXYaYfGGQ=; b=1/7PDufDvXQaIttESkkLZCc2m6ATEDRaKZdp0vb/nWlT6Qbfl9NEJ3hldv5xwXx/2R tx3nMrWJ5SNFQ7GEcR6smUS6zlLJZCl/jPBw22tSBeHZJib/aP1p4wAdqu8cqr6/PDF/ a7pgcJ3KLhIN0bdZFEBCfEDj3tKtjdNFZoyzym2asJ+gyyZL/fOnBEA7DlRFwDywclul K+BVFLkdQU5m6fB7xTI+IrDW7mosaKXKLhGGrKCv2jf+COKU3UeXI5pOz2xseLEzo1WG xe3GMn5CAhw3jkuCQrR1xPEjDXMHSTH2Uu1gOPS0EdF2mcxDMzfdSvohgvNLoqS+YSxY u2iA== X-Gm-Message-State: AOAM533B2HaWia7yn6ThM9VaXn/Ks2bXcmDyxJ7cvnIjqdOYXdw4Jmow s+sFO7VXNXDOiOweSaNmgfY= X-Google-Smtp-Source: ABdhPJzZO5a7aBvu42U14Xoq61pyDVk94I+LPLPzI5cd107E3DrvjAj0YKpfMjZtnPR8jF0Dy9aiWg== X-Received: by 2002:a65:4cc7:: with SMTP id n7mr2452528pgt.179.1638499703554; Thu, 02 Dec 2021 18:48:23 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.48.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:48:23 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 21/23] net: failover: add net device refcount tracker Date: Thu, 2 Dec 2021 18:46:38 -0800 Message-Id: <20211203024640.1180745-22-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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/failover.h | 1 + net/core/failover.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/net/failover.h b/include/net/failover.h index bb15438f39c7d98fe7c5637f08c3cfb23e7e79d2..f2b42b4b9cd6c1fb6561e7deca3c549dcf04f20f 100644 --- a/include/net/failover.h +++ b/include/net/failover.h @@ -25,6 +25,7 @@ struct failover_ops { struct failover { struct list_head list; struct net_device __rcu *failover_dev; + netdevice_tracker dev_tracker; struct failover_ops __rcu *ops; }; diff --git a/net/core/failover.c b/net/core/failover.c index b5cd3c727285d7a1738118c246abce8d31dac08f..dcaa92a85ea23c54bc5ea68eb8a0f38fb31ff436 100644 --- a/net/core/failover.c +++ b/net/core/failover.c @@ -252,7 +252,7 @@ struct failover *failover_register(struct net_device *dev, return ERR_PTR(-ENOMEM); rcu_assign_pointer(failover->ops, ops); - dev_hold(dev); + dev_hold_track(dev, &failover->dev_tracker, GFP_KERNEL); dev->priv_flags |= IFF_FAILOVER; rcu_assign_pointer(failover->failover_dev, dev); @@ -285,7 +285,7 @@ void failover_unregister(struct failover *failover) failover_dev->name); failover_dev->priv_flags &= ~IFF_FAILOVER; - dev_put(failover_dev); + dev_put_track(failover_dev, &failover->dev_tracker); spin_lock(&failover_lock); list_del(&failover->list); From patchwork Fri Dec 3 02:46: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: 12654161 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 CD6B5C433F5 for ; Fri, 3 Dec 2021 02:48:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378287AbhLCCvv (ORCPT ); Thu, 2 Dec 2021 21:51:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378281AbhLCCvu (ORCPT ); Thu, 2 Dec 2021 21:51:50 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63631C061757 for ; Thu, 2 Dec 2021 18:48:27 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id x7so1278157pjn.0 for ; Thu, 02 Dec 2021 18:48:27 -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=B7Re4yLZ+fuYk4ANOX5YYpTdXnzZcADisbjZ5HdspLY=; b=gC/oHPrEFOVhy88cOw2COweOFlE5lWIUB3rRXGr6h/tJNCQ6BrklX5yAPie4n1Tc4F NwOlUse9p1NJKnEW1hO7JYczRuOIG6aQh4gzY+K6RDZthFQ0+l4EnFnVRFdHvFXVngcp MU8vH8IxM+X4GZ2vT+Mvd0IwPnBeBWZqJc+prBpIz6PBasTvDGGfqHIsDBOlgmErHnIM GcgcckLdGin5nWkGaHJTLM+2HHRtRfa3J9WkPLaxaLhZYb4tiXl/1Vbt2GgSjQG4fqpN OOvY0u5GRfw95HkfpGEBh90m/livBwMN0X1NewVUsIqbFLXAHYcVnJFXkN2zfEWqJE2C MwBQ== 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=B7Re4yLZ+fuYk4ANOX5YYpTdXnzZcADisbjZ5HdspLY=; b=A4aeHsBLaNA+tSeBmaNwzJy21RMePGppV9AbpWvd2VhluTV+P0bmiuedV2kihCAYiB 9eASZuxrObuVVmUKHfYrEAygd1OSp9qPmvVHlzcFAlYX6EG5Ra7HjOkXBw4lnJz8jo3S pJ2KiZAUkr9fs1iJgfFPtnKXaYU4OqgTUoNsN4uZppLmmeJrWqK6rjDwZHCY09MuDzdx itTItfi8rYeCw3GBG81lruPpXoQqSMkXF+Emy+PWohDBAG2qqB8jdstFk2l04cRFfFar GLrsvBCChVgMjSSbJD1b04ldx+9RIXQxY/zl94ctNUDGhFadO9wJw4HvriX1sEGywEKQ ResQ== X-Gm-Message-State: AOAM531dg0XHePWLBNVt/WnQabwcuTR3SaOvYYjZw21rPba/m5v/8Qo+ rXtSQVZWWHo3yDsPll87DaY= X-Google-Smtp-Source: ABdhPJwZJmGphbWw6Pfuk2oiQ9ivB8YgTF/IVdUJ5LzdEpc2gtA9On/GH9BfqsjqDIrB5heu2Gf2kQ== X-Received: by 2002:a17:90a:590d:: with SMTP id k13mr10486668pji.184.1638499706988; Thu, 02 Dec 2021 18:48:26 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.48.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:48:26 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 22/23] ipmr, ip6mr: add net device refcount tracker to struct vif_device Date: Thu, 2 Dec 2021 18:46:39 -0800 Message-Id: <20211203024640.1180745-23-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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/mroute_base.h | 1 + net/ipv4/ipmr.c | 3 ++- net/ipv6/ip6mr.c | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/linux/mroute_base.h b/include/linux/mroute_base.h index 8071148f29a6ec6a95df7e74bbfdeab5b5f6a644..91ab497bd3e579b9d78f423d8c28310cf6b07f58 100644 --- a/include/linux/mroute_base.h +++ b/include/linux/mroute_base.h @@ -26,6 +26,7 @@ */ struct vif_device { struct net_device *dev; + netdevice_tracker dev_tracker; unsigned long bytes_in, bytes_out; unsigned long pkt_in, pkt_out; unsigned long rate_limit; diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 2dda856ca260259e5626577e2b2993a6d9967aa6..4c7aca884fa9a35816008a5f3a1a58dd1baf6c06 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -696,7 +696,7 @@ static int vif_delete(struct mr_table *mrt, int vifi, int notify, if (v->flags & (VIFF_TUNNEL | VIFF_REGISTER) && !notify) unregister_netdevice_queue(dev, head); - dev_put(dev); + dev_put_track(dev, &v->dev_tracker); return 0; } @@ -896,6 +896,7 @@ static int vif_add(struct net *net, struct mr_table *mrt, /* And finish update writing critical data */ write_lock_bh(&mrt_lock); v->dev = dev; + netdev_tracker_alloc(dev, &v->dev_tracker, GFP_ATOMIC); if (v->flags & VIFF_REGISTER) mrt->mroute_reg_vif_num = vifi; if (vifi+1 > mrt->maxvif) diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index 36ed9efb88254003720549da52f39b11e9bf911f..a77a15a7f3dcb61c53a86e055b8a1507d9d591f8 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -746,7 +746,7 @@ static int mif6_delete(struct mr_table *mrt, int vifi, int notify, if ((v->flags & MIFF_REGISTER) && !notify) unregister_netdevice_queue(dev, head); - dev_put(dev); + dev_put_track(dev, &v->dev_tracker); return 0; } @@ -919,6 +919,7 @@ static int mif6_add(struct net *net, struct mr_table *mrt, /* And finish update writing critical data */ write_lock_bh(&mrt_lock); v->dev = dev; + netdev_tracker_alloc(dev, &v->dev_tracker, GFP_ATOMIC); #ifdef CONFIG_IPV6_PIMSM_V2 if (v->flags & MIFF_REGISTER) mrt->mroute_reg_vif_num = vifi; From patchwork Fri Dec 3 02:46:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12654163 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 6E8CDC433EF for ; Fri, 3 Dec 2021 02:48:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378281AbhLCCvy (ORCPT ); Thu, 2 Dec 2021 21:51:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243536AbhLCCvy (ORCPT ); Thu, 2 Dec 2021 21:51:54 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5859EC061757 for ; Thu, 2 Dec 2021 18:48:31 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id fv9-20020a17090b0e8900b001a6a5ab1392so1317630pjb.1 for ; Thu, 02 Dec 2021 18:48: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=0ueK711Sqj023gTBd/tQUmqv75JSIuZMHZ4ezZabzok=; b=KlUDesw8YSizLlQhEfHdLI9QCaWH2ugPczTJSmFz4qf49JfvNhVu2ck9fJqgROWX7L x2sIOSnVQ2PBv1vi0buoXBG0b4cmC+ocjLhnLSrP2ZdOXNSQ6zt1XbWrVNdrcUpmrRF7 kwaATo/2Ijxq1KkgFktTsZGZqiruqN41aprvwqaV9Gd6Z8/6RqkSfYd4s+f/KW/RwK5Z ERo0EiyrTVCEjOF3audO+9alxYlZ48N7NXzfq2HWyu2XHGbt13bSlT6ZgDsO3iXzgNOa BxTgPjxcN25Ym/J4buszCzizMtulgOcllayQ7p9BJJ+heU610lBoBcgyTO/PUnWikfDh bosw== 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=0ueK711Sqj023gTBd/tQUmqv75JSIuZMHZ4ezZabzok=; b=K65hXerG/9Sd+C9o+j6s6K33K6zBRJ5Lf613sEexaWArze6ckLbpmiAmsJWJjyPh4A 89A9fEI4TTptXhF6lpfobkfFm3rRBIqS9lkkDTZC/ts/5d/n6T2Mza1mmL1wPfjLBlJA BZg3Qe7Iog9QHOAUnvZAdEHAE0kVA1EZSfCSlXxxKI5wECOx3paEIkAKLH2CVz3UgOEV Ql26LE0b2qxU+JZ9dVAOq98MVrpvkdhhA3RvyzTQUOXljHFH/QoeFHw7n22xz8aBWJK8 RjhP9Qh922g6iKlDOjAUwnysW8IfYfWM/QpETLuBRRESL+mt6tXqq2uQuovDopI8Hswh qbkA== X-Gm-Message-State: AOAM530g1ZFP9ZIfqPjMgNcj2WalySA27uk2KNx5VnrvqFFyWGl+BzYE 9srKkouWaVJPS4yR250eWsQ= X-Google-Smtp-Source: ABdhPJw7kHjDgxV4vbW8Mt6LiAxPh1MEjLdqnzCfNIj7jeLeJaXv5MPYRi6cMMc9R7fxXsEj0hdhCQ== X-Received: by 2002:a17:90b:3b8e:: with SMTP id pc14mr10367006pjb.129.1638499710942; Thu, 02 Dec 2021 18:48:30 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6c4b:c5cb:ac63:1ebf]) by smtp.gmail.com with ESMTPSA id k2sm1230260pfc.53.2021.12.02.18.48.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 18:48:30 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Dmitry Vyukov , Eric Dumazet Subject: [PATCH v2 net-next 23/23] netpoll: add net device refcount tracker to struct netpoll Date: Thu, 2 Dec 2021 18:46:40 -0800 Message-Id: <20211203024640.1180745-24-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203024640.1180745-1-eric.dumazet@gmail.com> References: <20211203024640.1180745-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 --- drivers/net/netconsole.c | 2 +- include/linux/netpoll.h | 1 + net/core/netpoll.c | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index ccecba908ded61370f8fc408ea53aa1ff305aca3..ab8cd555102083c2f0179898681489b987afe5b0 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -721,7 +721,7 @@ static int netconsole_netdev_event(struct notifier_block *this, __netpoll_cleanup(&nt->np); spin_lock_irqsave(&target_list_lock, flags); - dev_put(nt->np.dev); + dev_put_track(nt->np.dev, &nt->np.dev_tracker); nt->np.dev = NULL; nt->enabled = false; stopped = true; diff --git a/include/linux/netpoll.h b/include/linux/netpoll.h index e6a2d72e0dc7a6929d32a2e994f24719e073121e..bd19c4b91e31204e85d30884720b761116d5c036 100644 --- a/include/linux/netpoll.h +++ b/include/linux/netpoll.h @@ -24,6 +24,7 @@ union inet_addr { struct netpoll { struct net_device *dev; + netdevice_tracker dev_tracker; char dev_name[IFNAMSIZ]; const char *name; diff --git a/net/core/netpoll.c b/net/core/netpoll.c index edfc0f8011f88a7d46d69e94c6343489369fa78c..db724463e7cd5089d85d8f75a77ad83bbece82dc 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -776,7 +776,7 @@ int netpoll_setup(struct netpoll *np) err = __netpoll_setup(np, ndev); if (err) goto put; - + netdev_tracker_alloc(ndev, &np->dev_tracker, GFP_KERNEL); rtnl_unlock(); return 0; @@ -853,7 +853,7 @@ void netpoll_cleanup(struct netpoll *np) if (!np->dev) goto out; __netpoll_cleanup(np); - dev_put(np->dev); + dev_put_track(np->dev, &np->dev_tracker); np->dev = NULL; out: rtnl_unlock();