From: Jani Nikula <jani.nikula@linux.intel.com>
To: Jeff Layton <jlayton@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
Rodrigo Vivi <rodrigo.vivi@intel.com>,
Tvrtko Ursulin <tursulin@ursulin.net>
Cc: Kuniyuki Iwashima <kuniyu@amazon.com>,
Qasim Ijaz <qasdev00@gmail.com>,
Nathan Chancellor <nathan@kernel.org>,
Andrew Lunn <andrew@lunn.ch>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
Jeff Layton <jlayton@kernel.org>
Subject: Re: [PATCH v6 06/10] ref_tracker: automatically register a file in debugfs for a ref_tracker_dir
Date: Mon, 05 May 2025 11:05:35 +0300 [thread overview]
Message-ID: <87frhjwkhc.fsf@intel.com> (raw)
In-Reply-To: <20250430-reftrack-dbgfs-v6-6-867c29aff03a@kernel.org>
On Wed, 30 Apr 2025, Jeff Layton <jlayton@kernel.org> wrote:
> 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.
>
> Signed-off-by: Jeff Layton <jlayton@kernel.org>
> ---
> include/linux/ref_tracker.h | 14 +++++++++
> lib/ref_tracker.c | 73 +++++++++++++++++++++++++++++++++++++++++++--
> 2 files changed, 85 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/ref_tracker.h b/include/linux/ref_tracker.h
> index 2adae128d4b5e45f156af4775a1d184bb596fa91..c6e65d7ef4d4fc74c60fcabd19166c131d4173e2 100644
> --- a/include/linux/ref_tracker.h
> +++ b/include/linux/ref_tracker.h
> @@ -5,6 +5,7 @@
> #include <linux/types.h>
> #include <linux/spinlock.h>
> #include <linux/stackdepot.h>
> +#include <linux/seq_file.h>
Nothing here requires seq_file.h as far as I can tell. Please avoid
superfluous header dependencies.
BR,
Jani.
>
> struct ref_tracker;
>
> @@ -18,12 +19,17 @@ 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
>
> +void ref_tracker_dir_debugfs(struct ref_tracker_dir *dir);
> +
> static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir,
> unsigned int quarantine_count,
> const char *class,
> @@ -37,7 +43,11 @@ static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir,
> 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();
> }
>
> @@ -66,6 +76,10 @@ static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir,
> {
> }
>
> +static inline void ref_tracker_dir_debugfs(struct ref_tracker_dir *dir)
> +{
> +}
> +
> static inline void ref_tracker_dir_exit(struct ref_tracker_dir *dir)
> {
> }
> diff --git a/lib/ref_tracker.c b/lib/ref_tracker.c
> index b69c11e83c18c19aaa2dc23f802291d4a7e82a66..3ee4fd0f33407881cfa140dcb7d8b40e3c2722de 100644
> --- a/lib/ref_tracker.c
> +++ b/lib/ref_tracker.c
> @@ -31,6 +31,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)
> {
> @@ -197,6 +205,7 @@ void ref_tracker_dir_exit(struct ref_tracker_dir *dir)
> 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);
> @@ -313,8 +322,7 @@ EXPORT_SYMBOL_GPL(ref_tracker_free);
> #ifdef CONFIG_DEBUG_FS
> #include <linux/debugfs.h>
>
> -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 = "",
> @@ -328,6 +336,67 @@ ref_tracker_dir_seq_print(struct ref_tracker_dir *dir, struct seq_file *seq)
> 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);
> + else
> + dir->dentry = ERR_PTR(-ENAMETOOLONG);
> +
> + if (IS_ERR(dir->dentry))
> + pr_warn("ref_tracker: unable to create debugfs file for %s: %pe\n",
> + name, dir->dentry);
> +}
> +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);
--
Jani Nikula, Intel
next prev parent reply other threads:[~2025-05-05 8:05 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-30 15:06 [PATCH v6 00/10] ref_tracker: add ability to register a debugfs file for a ref_tracker_dir Jeff Layton
2025-04-30 15:06 ` [PATCH v6 01/10] ref_tracker: don't use %pK in pr_ostream() output Jeff Layton
2025-04-30 15:06 ` [PATCH v6 02/10] ref_tracker: add a top level debugfs directory for ref_tracker Jeff Layton
2025-04-30 15:06 ` [PATCH v6 03/10] ref_tracker: have callers pass output function to pr_ostream() Jeff Layton
2025-04-30 15:06 ` [PATCH v6 04/10] ref_tracker: add a static classname string to each ref_tracker_dir Jeff Layton
2025-04-30 15:06 ` [PATCH v6 05/10] ref_tracker: allow pr_ostream() to print directly to a seq_file Jeff Layton
2025-04-30 15:06 ` [PATCH v6 06/10] ref_tracker: automatically register a file in debugfs for a ref_tracker_dir Jeff Layton
2025-05-05 8:05 ` Jani Nikula [this message]
2025-04-30 15:06 ` [PATCH v6 07/10] ref_tracker: add a way to create a symlink to the ref_tracker_dir debugfs file Jeff Layton
2025-05-01 10:43 ` kernel test robot
2025-04-30 15:06 ` [PATCH v6 08/10] net: add symlinks to ref_tracker_dir for netns Jeff Layton
2025-04-30 21:29 ` Kuniyuki Iwashima
2025-05-01 2:59 ` Jeff Layton
2025-05-01 3:07 ` Kuniyuki Iwashima
2025-05-01 3:42 ` Jeff Layton
2025-05-01 3:50 ` Kuniyuki Iwashima
2025-05-01 4:07 ` Jeff Layton
2025-05-01 4:26 ` Kuniyuki Iwashima
2025-04-30 15:06 ` [PATCH v6 09/10] i915: add ref_tracker_dir symlinks for each tracker Jeff Layton
2025-04-30 15:06 ` [PATCH v6 10/10] ref_tracker: eliminate the ref_tracker_dir name field Jeff Layton
2025-04-30 16:02 ` ✗ Fi.CI.CHECKPATCH: warning for ref_tracker: add ability to register a debugfs file for a ref_tracker_dir (rev2) Patchwork
2025-04-30 16:02 ` ✗ Fi.CI.SPARSE: " Patchwork
2025-04-30 16:23 ` ✗ i915.CI.BAT: failure " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87frhjwkhc.fsf@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=airlied@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=dri-devel@lists.freedesktop.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jlayton@kernel.org \
--cc=joonas.lahtinen@linux.intel.com \
--cc=kuba@kernel.org \
--cc=kuniyu@amazon.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=nathan@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=qasdev00@gmail.com \
--cc=rodrigo.vivi@intel.com \
--cc=simona@ffwll.ch \
--cc=tursulin@ursulin.net \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.