On Tue, 2025-05-27 at 07:33 -0400, Jeff Layton wrote:
> Now that we have dentries and the ability to create meaningful symlinks
> to them, don't keep a name string in each tracker. Switch the output
> format to print "class@address", and drop the name field.
> 
> Also, add a kerneldoc header for ref_tracker_dir_init().
> 
> Signed-off-by: Jeff Layton <jlay...@kernel.org>
> ---
>  drivers/gpu/drm/display/drm_dp_tunnel.c |  2 +-
>  drivers/gpu/drm/i915/intel_runtime_pm.c |  2 +-
>  drivers/gpu/drm/i915/intel_wakeref.c    |  2 +-
>  include/linux/ref_tracker.h             | 20 ++++++++++++++------
>  lib/ref_tracker.c                       |  6 +++---
>  lib/test_ref_tracker.c                  |  2 +-
>  net/core/dev.c                          |  2 +-
>  net/core/net_namespace.c                |  4 ++--
>  8 files changed, 24 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/gpu/drm/display/drm_dp_tunnel.c 
> b/drivers/gpu/drm/display/drm_dp_tunnel.c
> index 
> b9c12b8bf2a3e400b6d8e9d184145834c603b9e1..1205a4432eb4142344fb6eed1cb5ba5b21ec6953
>  100644
> --- a/drivers/gpu/drm/display/drm_dp_tunnel.c
> +++ b/drivers/gpu/drm/display/drm_dp_tunnel.c
> @@ -1920,7 +1920,7 @@ drm_dp_tunnel_mgr_create(struct drm_device *dev, int 
> max_group_count)
>       }
>  
>  #ifdef CONFIG_DRM_DISPLAY_DP_TUNNEL_STATE_DEBUG
> -     ref_tracker_dir_init(&mgr->ref_tracker, 16, "drm_dptun", "dptun");
> +     ref_tracker_dir_init(&mgr->ref_tracker, 16, "drm_dptun");
>  #endif
>  
>       for (i = 0; i < max_group_count; i++) {
> diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.c 
> b/drivers/gpu/drm/i915/intel_runtime_pm.c
> index 
> 3fdab3b44c08cea16ac2f73aafc2bea2ffbb19e7..c12b5d0e16fa363f3caede372e7a2031676aa7b5
>  100644
> --- a/drivers/gpu/drm/i915/intel_runtime_pm.c
> +++ b/drivers/gpu/drm/i915/intel_runtime_pm.c
> @@ -60,7 +60,7 @@ static struct drm_i915_private *rpm_to_i915(struct 
> intel_runtime_pm *rpm)
>  static void init_intel_runtime_pm_wakeref(struct intel_runtime_pm *rpm)
>  {
>       ref_tracker_dir_init(&rpm->debug, INTEL_REFTRACK_DEAD_COUNT,
> -                          "intel_runtime_pm", dev_name(rpm->kdev));
> +                          "intel_runtime_pm");
>  }
>  

I got a warning from the intel graphics CI that this was causing these
warnings:

<3> [513.235988] debugfs: File 'intel_runtime_pm@ff110001461f98a8' in directory 
'ref_tracker' already present!
<4> [513.236073] ref_tracker: ref_tracker: unable to create debugfs file for 
intel_runtime_pm@ff110001461f98a8: -EEXIST
<3> [513.242646] debugfs: File 'intel_wakeref@ff1100016ee7d790' in directory 
'ref_tracker' already present!
<4> [513.242724] ref_tracker: ref_tracker: unable to create debugfs file for 
intel_wakeref@ff1100016ee7d790: -EEXIST

I suspect these are existing bugs which are causing these ref_trackers
to be initialized more than once. If there were references taken
between these two initializations, then that could leak memory (or
worse). I think we need to ensure that these ref_trackers are only
initialized once.

I'll see if I can make a patch that does that, but if the i915 devs
want to do fix this up instead, I won't complain.


>  static intel_wakeref_t
> diff --git a/drivers/gpu/drm/i915/intel_wakeref.c 
> b/drivers/gpu/drm/i915/intel_wakeref.c
> index 
> 5269e64c58a49884f5d712557546272bfdeb8417..615fb77809291be34d94600fdd4d919461a22720
>  100644
> --- a/drivers/gpu/drm/i915/intel_wakeref.c
> +++ b/drivers/gpu/drm/i915/intel_wakeref.c
> @@ -114,7 +114,7 @@ void __intel_wakeref_init(struct intel_wakeref *wf,
>                        "wakeref.work", &key->work, 0);
>  
>  #if IS_ENABLED(CONFIG_DRM_I915_DEBUG_WAKEREF)
> -     ref_tracker_dir_init(&wf->debug, INTEL_REFTRACK_DEAD_COUNT, 
> "intel_wakeref", name);
> +     ref_tracker_dir_init(&wf->debug, INTEL_REFTRACK_DEAD_COUNT, 
> "intel_wakeref");
>  #endif
>  }
>  
> diff --git a/include/linux/ref_tracker.h b/include/linux/ref_tracker.h
> index 
> ddc5a7b2bd84692bbc1e1ae67674ec2c6857e1ec..5878e7fce712930700054033ff5f21547e75224f
>  100644
> --- a/include/linux/ref_tracker.h
> +++ b/include/linux/ref_tracker.h
> @@ -24,7 +24,6 @@ struct ref_tracker_dir {
>       struct dentry           *dentry;
>       struct dentry           *symlink;
>  #endif
> -     char                    name[32];
>  #endif
>  };
>  
> @@ -48,10 +47,21 @@ void ref_tracker_dir_symlink(struct ref_tracker_dir *dir, 
> const char *fmt, ...)
>  
>  #endif /* CONFIG_DEBUG_FS */
>  
> +/**
> + * ref_tracker_dir_init - initialize a ref_tracker dir
> + * @dir: ref_tracker_dir to be initialized
> + * @quarantine_count: max number of entries to be tracked
> + * @class: pointer to static string that describes object type
> + *
> + * Initialize a ref_tracker_dir. If debugfs is configured, then a file
> + * will also be created for it under the top-level ref_tracker debugfs
> + * directory.
> + *
> + * Note that @class must point to a static string.
> + */
>  static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir,
>                                       unsigned int quarantine_count,
> -                                     const char *class,
> -                                     const char *name)
> +                                     const char *class)
>  {
>       INIT_LIST_HEAD(&dir->list);
>       INIT_LIST_HEAD(&dir->quarantine);
> @@ -65,7 +75,6 @@ static inline void ref_tracker_dir_init(struct 
> ref_tracker_dir *dir,
>       dir->dentry = NULL;
>       dir->symlink = NULL;
>  #endif
> -     strscpy(dir->name, name, sizeof(dir->name));
>       ref_tracker_dir_debugfs(dir);
>       stack_depot_init();
>  }
> @@ -90,8 +99,7 @@ int ref_tracker_free(struct ref_tracker_dir *dir,
>  
>  static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir,
>                                       unsigned int quarantine_count,
> -                                     const char *class,
> -                                     const char *name)
> +                                     const char *class)
>  {
>  }
>  
> diff --git a/lib/ref_tracker.c b/lib/ref_tracker.c
> index 
> 5e84e5fd78e147a036d4adb511e657da07866a55..5fb384dd919e1f1ad632eaf595b954118bcfddab
>  100644
> --- a/lib/ref_tracker.c
> +++ b/lib/ref_tracker.c
> @@ -123,7 +123,7 @@ __ref_tracker_dir_pr_ostream(struct ref_tracker_dir *dir,
>       stats = ref_tracker_get_stats(dir, display_limit);
>       if (IS_ERR(stats)) {
>               pr_ostream(s, "%s%s@%p: couldn't get stats, error %pe\n",
> -                        s->prefix, dir->name, dir, stats);
> +                        s->prefix, dir->class, dir, stats);
>               return;
>       }
>  
> @@ -134,14 +134,14 @@ __ref_tracker_dir_pr_ostream(struct ref_tracker_dir 
> *dir,
>               if (sbuf && !stack_depot_snprint(stack, sbuf, STACK_BUF_SIZE, 
> 4))
>                       sbuf[0] = 0;
>               pr_ostream(s, "%s%s@%p has %d/%d users at\n%s\n", s->prefix,
> -                        dir->name, dir, stats->stacks[i].count,
> +                        dir->class, dir, stats->stacks[i].count,
>                          stats->total, sbuf);
>               skipped -= stats->stacks[i].count;
>       }
>  
>       if (skipped)
>               pr_ostream(s, "%s%s@%p skipped reports about %d/%d users.\n",
> -                        s->prefix, dir->name, dir, skipped, stats->total);
> +                        s->prefix, dir->class, dir, skipped, stats->total);
>  
>       kfree(sbuf);
>  
> diff --git a/lib/test_ref_tracker.c b/lib/test_ref_tracker.c
> index 
> d263502a4c1db248f64a66a468e96c8e4cffab25..b983ceb12afcb84ad60360a1e6fec0072e78ef79
>  100644
> --- a/lib/test_ref_tracker.c
> +++ b/lib/test_ref_tracker.c
> @@ -64,7 +64,7 @@ static int __init test_ref_tracker_init(void)
>  {
>       int i;
>  
> -     ref_tracker_dir_init(&ref_dir, 100, "selftest", "selftest");
> +     ref_tracker_dir_init(&ref_dir, 100, "selftest");
>  
>       timer_setup(&test_ref_tracker_timer, test_ref_tracker_timer_func, 0);
>       mod_timer(&test_ref_tracker_timer, jiffies + 1);
> diff --git a/net/core/dev.c b/net/core/dev.c
> index 
> bac9d29486556023cd99f5101b96b052acb9ba70..a062912525ee573504a9cc252f71aed22693d24f
>  100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -11713,7 +11713,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, 
> const char *name,
>  
>       dev->priv_len = sizeof_priv;
>  
> -     ref_tracker_dir_init(&dev->refcnt_tracker, 128, "netdev", name);
> +     ref_tracker_dir_init(&dev->refcnt_tracker, 128, "netdev");
>  #ifdef CONFIG_PCPU_DEV_REFCNT
>       dev->pcpu_refcnt = alloc_percpu(int);
>       if (!dev->pcpu_refcnt)
> diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
> index 
> 39b01af90d240df48827e5c3159c3e2253e0a44d..c03757e39c8a334d307fa1b5cc8f03ad3a8df0e0
>  100644
> --- a/net/core/net_namespace.c
> +++ b/net/core/net_namespace.c
> @@ -403,8 +403,8 @@ static __net_init void preinit_net(struct net *net, 
> struct user_namespace *user_
>  {
>       refcount_set(&net->passive, 1);
>       refcount_set(&net->ns.count, 1);
> -     ref_tracker_dir_init(&net->refcnt_tracker, 128, "net_refcnt", 
> "net_refcnt");
> -     ref_tracker_dir_init(&net->notrefcnt_tracker, 128, "net_notrefcnt", 
> "net_notrefcnt");
> +     ref_tracker_dir_init(&net->refcnt_tracker, 128, "net_refcnt");
> +     ref_tracker_dir_init(&net->notrefcnt_tracker, 128, "net_notrefcnt");
>  
>       get_random_bytes(&net->hash_mix, sizeof(u32));
>       net->dev_base_seq = 1;

-- 
Jeff Layton <jlay...@kernel.org>

Reply via email to