ref_tracker: automatically register a file in debugfs for a ref_tracker_dir
authorJeff Layton <jlayton@kernel.org>
Wed, 18 Jun 2025 14:24:19 +0000 (10:24 -0400)
committerJakub Kicinski <kuba@kernel.org>
Fri, 20 Jun 2025 00:02:04 +0000 (17:02 -0700)
commit65b584f5361163ba539d2c7122ca792c3cc87997
tree666af3f4518e03c0d5c0545340b90a1836632b5f
parentf6dbe294a11028db540e2dedf1929e25b1093e9b
ref_tracker: automatically register a file in debugfs for a ref_tracker_dir

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

While ref_tracker_dir_init() is generally called from a context where
sleeping is OK, ref_tracker_dir_exit() can be called from anywhere.
Thus, dentry cleanup must be handled asynchronously.

Add a new global xarray that has entries with the ref_tracker_dir
pointer as the index and the corresponding debugfs dentry pointer as the
value. Instead of removing the debugfs dentry, have
ref_tracker_dir_exit() set a mark on the xarray entry and schedule a
workqueue job. The workqueue job then walks the xarray looking for
marked entries, and removes their xarray entries and the debugfs
dentries.

Because of this, the debugfs dentry can outlive the corresponding
ref_tracker_dir. Have ref_tracker_debugfs_show() take extra care to
ensure that it's safe to dereference the dir pointer before using it.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
Link: https://patch.msgid.link/20250618-reftrack-dbgfs-v15-6-24fc37ead144@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/linux/ref_tracker.h
lib/ref_tracker.c