From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 079EB86349 for ; Wed, 4 Jun 2025 02:09:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749002962; cv=none; b=rORnMvrKvTEJYW+GAsDtfq6hqZi/yikMHNHaXmUeLWWKLGt9L9EBeQ9gQZdiYeQAqk6KYl5MNz6Ff2VkuHMTtP5tVYxSJwrQNbppH+kiScmALJYyT38JHNYZ/WH0h8XEYWD1OJPVaimSHMgoZDz2wBCIrihtD1wWF6dLiPjSTQA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749002962; c=relaxed/simple; bh=Efk+BVIfh3XEve93d7ZquU9jWT6Kg6fl6L82+c/15o8=; h=Date:To:From:Subject:Message-Id; b=r4+2P8Z1Pr51BT+MYBY1NzHU7OXhUyv85ORnbllXjPSLCRaAe1+iPJAAm3ey/yB/1tAprbVxZqRyEjSj5dSPuA7eW9J5ipp1LAMnAKKDVo3WEqP+uPbvC8i22ojrgK/tXJqfWyUYZoFV/TFfX9tckQXK5LPNz1GBn55ZFZxcVrE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=EJPUycqM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="EJPUycqM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FEA2C4CEED; Wed, 4 Jun 2025 02:09:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1749002961; bh=Efk+BVIfh3XEve93d7ZquU9jWT6Kg6fl6L82+c/15o8=; h=Date:To:From:Subject:From; b=EJPUycqMfI/lUtE2P7zf1XIMm+XMZLyu8owzXEtkCXfYIHJRAt5cxv+fxj0Kza2O5 qznOD9Ps8OV3ysDBhoz53Jsj26oN5U5aWPnxZIWv5/3X76pFCZV4WLnFyyoGLfyzb8 iiK50sSEL2ZCGC8TKyj6bAcXG5qtRnd1XxSq7i8A= Date: Tue, 03 Jun 2025 19:09:20 -0700 To: mm-commits@vger.kernel.org,tzimmermann@suse.de,tursulin@ursulin.net,thomas.weissschuh@linutronix.de,rodrigo.vivi@intel.com,qasdev00@gmail.com,pabeni@redhat.com,nathan@kernel.org,mripard@kernel.org,maarten.lankhorst@linux.intel.com,kuniyu@amazon.com,kuba@kernel.org,krzysztof.karas@intel.com,joonas.lahtinen@linux.intel.com,jani.nikula@linux.intel.com,horms@kernel.org,edumazet@google.com,davem@davemloft.net,andrew@lunn.ch,airlied@gmail.com,jlayton@kernel.org,akpm@linux-foundation.org From: Andrew Morton Subject: + ref_tracker-automatically-register-a-file-in-debugfs-for-a-ref_tracker_dir.patch added to mm-nonmm-unstable branch Message-Id: <20250604020921.5FEA2C4CEED@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The patch titled Subject: ref_tracker: automatically register a file in debugfs for a ref_tracker_dir has been added to the -mm mm-nonmm-unstable branch. Its filename is ref_tracker-automatically-register-a-file-in-debugfs-for-a-ref_tracker_dir.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/ref_tracker-automatically-register-a-file-in-debugfs-for-a-ref_tracker_dir.patch This patch will later appear in the mm-nonmm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Jeff Layton Subject: ref_tracker: automatically register a file in debugfs for a ref_tracker_dir Date: Tue, 03 Jun 2025 07:27:17 -0400 Currently, there is no convenient way to see the info that the ref_tracking infrastructure collects. Attempt to create a file in debugfs when called from ref_tracker_dir_init(). The file is given the name "class@%px", as having the unmodified address is helpful for debugging. This should be safe since this directory is only accessible by root If debugfs file creation fails, a pr_warn will be isssued. Link: https://lkml.kernel.org/r/20250603-reftrack-dbgfs-v13-6-7b2a425019d8@kernel.org Signed-off-by: Jeff Layton Cc: Andrew Lunn Cc: Dave Airlie Cc: David S. Miller Cc: Eric Dumaze Cc: Jakub Kacinski Cc: Jani Nikula Cc: Jonas Lahtinen Cc: Krzysztof Karas Cc: Kuniyuki Iwashima Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Nathan Chancellor Cc: Paolo Abeni Cc: Qasim Ijaz Cc: Rodrigo Vivi Cc: Simon Horman Cc: Thomas Weißschuh Cc: Thomas Zimemrmann Cc: Tvrtko Ursulin Signed-off-by: Andrew Morton --- include/linux/ref_tracker.h | 23 +++++++++++ lib/ref_tracker.c | 67 ++++++++++++++++++++++++++++++++-- 2 files changed, 88 insertions(+), 2 deletions(-) --- a/include/linux/ref_tracker.h~ref_tracker-automatically-register-a-file-in-debugfs-for-a-ref_tracker_dir +++ a/include/linux/ref_tracker.h @@ -20,12 +20,27 @@ struct ref_tracker_dir { struct list_head list; /* List of active trackers */ struct list_head quarantine; /* List of dead trackers */ const char *class; /* object classname */ +#ifdef CONFIG_DEBUG_FS + struct dentry *dentry; +#endif char name[32]; #endif }; #ifdef CONFIG_REF_TRACKER +#ifdef CONFIG_DEBUG_FS + +void ref_tracker_dir_debugfs(struct ref_tracker_dir *dir); + +#else /* CONFIG_DEBUG_FS */ + +static inline void ref_tracker_dir_debugfs(struct ref_tracker_dir *dir) +{ +} + +#endif /* CONFIG_DEBUG_FS */ + static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir, unsigned int quarantine_count, const char *class, @@ -39,7 +54,11 @@ static inline void ref_tracker_dir_init( refcount_set(&dir->untracked, 1); refcount_set(&dir->no_tracker, 1); dir->class = class; +#ifdef CONFIG_DEBUG_FS + dir->dentry = NULL; +#endif strscpy(dir->name, name, sizeof(dir->name)); + ref_tracker_dir_debugfs(dir); stack_depot_init(); } @@ -68,6 +87,10 @@ static inline void ref_tracker_dir_init( { } +static inline void ref_tracker_dir_debugfs(struct ref_tracker_dir *dir) +{ +} + static inline void ref_tracker_dir_exit(struct ref_tracker_dir *dir) { } --- a/lib/ref_tracker.c~ref_tracker-automatically-register-a-file-in-debugfs-for-a-ref_tracker_dir +++ a/lib/ref_tracker.c @@ -29,6 +29,14 @@ struct ref_tracker_dir_stats { } stacks[]; }; +#ifdef CONFIG_DEBUG_FS +static void ref_tracker_debugfs_remove(struct ref_tracker_dir *dir); +#else +static inline void ref_tracker_debugfs_remove(struct ref_tracker_dir *dir) +{ +} +#endif + static struct ref_tracker_dir_stats * ref_tracker_get_stats(struct ref_tracker_dir *dir, unsigned int limit) { @@ -185,6 +193,7 @@ void ref_tracker_dir_exit(struct ref_tra bool leak = false; dir->dead = true; + ref_tracker_debugfs_remove(dir); spin_lock_irqsave(&dir->lock, flags); list_for_each_entry_safe(tracker, n, &dir->quarantine, head) { list_del(&tracker->head); @@ -312,8 +321,7 @@ static void __ostream_printf pr_ostream_ va_end(args); } -static __maybe_unused int -ref_tracker_dir_seq_print(struct ref_tracker_dir *dir, struct seq_file *seq) +static int ref_tracker_dir_seq_print(struct ref_tracker_dir *dir, struct seq_file *seq) { struct ostream os = { .func = pr_ostream_seq, .prefix = "", @@ -327,6 +335,61 @@ ref_tracker_dir_seq_print(struct ref_tra return os.used; } +static int ref_tracker_debugfs_show(struct seq_file *f, void *v) +{ + struct ref_tracker_dir *dir = f->private; + + return ref_tracker_dir_seq_print(dir, f); +} + +static int ref_tracker_debugfs_open(struct inode *inode, struct file *filp) +{ + struct ref_tracker_dir *dir = inode->i_private; + + return single_open(filp, ref_tracker_debugfs_show, dir); +} + +static const struct file_operations ref_tracker_debugfs_fops = { + .owner = THIS_MODULE, + .open = ref_tracker_debugfs_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +/** + * ref_tracker_dir_debugfs - create debugfs file for ref_tracker_dir + * @dir: ref_tracker_dir to be associated with debugfs file + * + * In most cases, a debugfs file will be created automatically for every + * ref_tracker_dir. If the object was created before debugfs is brought up + * then that may fail. In those cases, it is safe to call this at a later + * time to create the file. + */ +void ref_tracker_dir_debugfs(struct ref_tracker_dir *dir) +{ + char name[NAME_MAX + 1]; + int ret; + + /* No-op if already created */ + if (!IS_ERR_OR_NULL(dir->dentry)) + return; + + ret = snprintf(name, sizeof(name), "%s@%px", dir->class, dir); + name[sizeof(name) - 1] = '\0'; + + if (ret < sizeof(name)) + dir->dentry = debugfs_create_file(name, S_IFREG | 0400, + ref_tracker_debug_dir, dir, + &ref_tracker_debugfs_fops); +} +EXPORT_SYMBOL(ref_tracker_dir_debugfs); + +static void ref_tracker_debugfs_remove(struct ref_tracker_dir *dir) +{ + debugfs_remove(dir->dentry); +} + static int __init ref_tracker_debugfs_init(void) { ref_tracker_debug_dir = debugfs_create_dir("ref_tracker", NULL); _ Patches currently in -mm which might be from jlayton@kernel.org are ref_tracker-dont-use-%pk-in-pr_ostream-output.patch ref_tracker-add-a-top-level-debugfs-directory-for-ref_tracker.patch ref_tracker-have-callers-pass-output-function-to-pr_ostream.patch ref_tracker-add-a-static-classname-string-to-each-ref_tracker_dir.patch ref_tracker-allow-pr_ostream-to-print-directly-to-a-seq_file.patch ref_tracker-automatically-register-a-file-in-debugfs-for-a-ref_tracker_dir.patch ref_tracker-add-a-way-to-create-a-symlink-to-the-ref_tracker_dir-debugfs-file.patch net-add-symlinks-to-ref_tracker_dir-for-netns.patch ref_tracker-eliminate-the-ref_tracker_dir-name-field.patch