public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
From: Jim Cromie <jim.cromie@gmail.com>
To: Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Arnd Bergmann <arnd@arndb.de>, Jason Baron <jbaron@akamai.com>,
	Luis Chamberlain <mcgrof@kernel.org>,
	Petr Pavlu <petr.pavlu@suse.com>,
	Daniel Gomez <da.gomez@kernel.org>,
	Sami Tolvanen <samitolvanen@google.com>,
	Aaron Tomlin <atomlin@atomlin.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Shuah Khan <shuah@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>
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arch@vger.kernel.org, linux-modules@vger.kernel.org,
	linux-kselftest@vger.kernel.org, dri-devel@lists.freedesktop.org,
	Jim Cromie <jim.cromie@gmail.com>
Subject: [PATCH v3 24/24] dynamic_debug: use KBUILD_MODFILE for unique builtin module names
Date: Mon, 01 Jun 2026 12:05:10 +0000	[thread overview]
Message-ID: <20260601-dd-maint-2-v3-24-4a15b241bd3c@gmail.com> (raw)
In-Reply-To: <20260601-dd-maint-2-v3-0-4a15b241bd3c@gmail.com>

Historically dynamic-debug gets its module names from KBUILD_MODNAME.
This works well for loadable modules, as the module loader has always
required them to have unique names, but for builtins it is basically
kbasename(srcfile), which sadly gives us many modules named "main".

This makes the following ambiguous:
  bash-5.3# echo module main +m > /proc/dynamic_debug/control

since it would affect 4 independent modules named main:
  bash-5.3# ddgrep =m
  init/main.c:1265 [main]initcall_blacklist =m "blacklisting initcall %s\n"
  kernel/power/main.c:49 [main]pm_restore_gfp_mask =m "GFP mask restored\n"
  kernel/module/main.c:2862 [main]move_module =m "\t0x%lx 0x%.8lx %s\n"
  drivers/base/power/main.c:149 [main]device_pm_add =m "Adding info for %s:%s\n"

We can improve this by using KBUILD_MODFILE for dyndbg's modname in
builtins, and KBUILD_MODNAME for loadables.

The above control-file entries then become:
  init/main.c:1265 [init/main]initcall_blacklist ...
  kernel/power/main.c:49 [kernel/power/main]pm_restore_gfp_mask ...
  kernel/module/main.c:2862 [kernel/module/main]move_module ...
  drivers/base/power/main.c:149 [drivers/base/power/main]device_pm_add ...

While this is a user visible change; [params] becomes [kernel/params],
it is not a behavior change; we now match the query-module against the
subsystem/module name or its kbasename (the simple-modname), which as
before, matches all 4 modules.

This allows queries to be specific when desired: "module init/main",
while preserving the existing meaning of "module main"

The deeper reason for this change is not obvious.  If any builtin
"main" module were to add a classmap, it would attach to all "main"
modules.  If 2 "main" modules defined separate classmaps, both modules
would inadvertently share both classmaps.  Since classmaps map
classnames to 0..62, and independently defined classmaps are most
likely to start at 0 (unless author is planning to share the 0..62
range with other classmaps), we have a setup for later reserved range
conflicts.  Having unique names prevents future conflicts.

This solution isn't perfect:
1. it changes displayed [params] to [kernel/params] etc
2. its mostly redundant with "filename */main.*"
3. "module power", "module module", "module base/power" might be better
   but would break old queries.

Adapt dynamic-debug selftest:
1- Add 'test_subsystem_module_queries' to verify path-based module matching.
2- Use dynamic counting with precise regexes to determine expectations.
3- Reorder tests to run slash-query verification immediately after
   basic tests.
4- Update basic_tests and comma_terminator_tests to use 'kernel/params'
   instead of 'params' to match new path-based names for built-ins.

And adjust Documentation

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
v3: new patch in rev-3
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 Documentation/admin-guide/dynamic-debug-howto.rst  | 40 ++++++++++----------
 include/linux/dynamic_debug.h                      | 17 +++++++--
 lib/dynamic_debug.c                                |  3 +-
 .../selftests/dynamic_debug/dyndbg_selftest.sh     | 44 ++++++++++++++++++++--
 4 files changed, 77 insertions(+), 27 deletions(-)

diff --git a/Documentation/admin-guide/dynamic-debug-howto.rst b/Documentation/admin-guide/dynamic-debug-howto.rst
index 9c2f096ed1d8..8befb69575b7 100644
--- a/Documentation/admin-guide/dynamic-debug-howto.rst
+++ b/Documentation/admin-guide/dynamic-debug-howto.rst
@@ -38,12 +38,12 @@ You can view the currently configured behaviour in the *prdbg* catalog::
 
   :#> head -n7 /proc/dynamic_debug/control
   # filename:lineno [module]function flags format
-  init/main.c:1179 [main]initcall_blacklist =_ "blacklisting initcall %s\n"
-  init/main.c:1218 [main]initcall_blacklisted =_ "initcall %s blacklisted\n"
-  init/main.c:1424 [main]run_init_process =_ "  with arguments:\n"
-  init/main.c:1426 [main]run_init_process =_ "    %s\n"
-  init/main.c:1427 [main]run_init_process =_ "  with environment:\n"
-  init/main.c:1429 [main]run_init_process =_ "    %s\n"
+  init/main.c:1179 [init/main]initcall_blacklist =_ "blacklisting initcall %s\n"
+  init/main.c:1218 [init/main]initcall_blacklisted =_ "initcall %s blacklisted\n"
+  init/main.c:1424 [init/main]run_init_process =_ "  with arguments:\n"
+  init/main.c:1426 [init/main]run_init_process =_ "    %s\n"
+  init/main.c:1427 [init/main]run_init_process =_ "  with environment:\n"
+  init/main.c:1429 [init/main]run_init_process =_ "    %s\n"
 
 The 3rd space-delimited column shows the current flags, preceded by
 a ``=`` for easy use with grep/cut. ``=p`` shows enabled callsites.
@@ -59,10 +59,10 @@ query/commands to the control file.  Example::
 
   :#> ddcmd '-p; module main func run* +p'
   :#> grep =p /proc/dynamic_debug/control
-  init/main.c:1424 [main]run_init_process =p "  with arguments:\n"
-  init/main.c:1426 [main]run_init_process =p "    %s\n"
-  init/main.c:1427 [main]run_init_process =p "  with environment:\n"
-  init/main.c:1429 [main]run_init_process =p "    %s\n"
+  init/main.c:1424 [init/main]run_init_process =p "  with arguments:\n"
+  init/main.c:1426 [init/main]run_init_process =p "    %s\n"
+  init/main.c:1427 [init/main]run_init_process =p "  with environment:\n"
+  init/main.c:1429 [init/main]run_init_process =p "    %s\n"
 
 Error messages go to console/syslog::
 
@@ -161,17 +161,19 @@ file
 	file kernel/freezer.c	# ie column 1 of control file
 	file drivers/usb/*	# all callsites under it
 	file inode.c:start_*	# parse :tail as a func (above)
-	file inode.c:1-100	# parse :tail as a line-range (above)
+	file inode.c:1-100	# parse :tail as a line-range (below)
 
 module
-    The given string is compared against the module name
-    of each callsite.  The module name is the string as
-    seen in ``lsmod``, i.e. without the directory or the ``.ko``
-    suffix and with ``-`` changed to ``_``.  Examples::
-
-	module sunrpc
-	module nfsd
-	module drm*	# both drm, drm_kms_helper
+    The query string is compared against the subsystem module name of
+    each callsite, as shown in the control file.  The simple module
+    name is the string as seen in ``lsmod``, i.e. without the
+    directory or the ``.ko`` suffix and with ``-`` changed to ``_``.
+
+    Examples::
+
+	module nfsd        # simple modname (as from lsmod)
+	module init/main   # subsystem modname (as in control file)
+	module drm*	   # both drm, drm_kms_helper
 
 format
     The given string is searched for in the dynamic debug format
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 2d6983186f37..aee6f3d0916f 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -8,6 +8,17 @@
 
 #include <linux/build_bug.h>
 
+/*
+ * Pick the best name for the module:
+ * KBUILD_MODFILE includes the path (e.g., drivers/usb/core/usbcore) for built-ins.
+ * Fall back to KBUILD_MODNAME for modules (loader requires unique names).
+ */
+#ifdef KBUILD_MODFILE
+# define DDEBUG_MODNAME KBUILD_MODFILE
+#else
+# define DDEBUG_MODNAME KBUILD_MODNAME
+#endif
+
 /*
  * An instance of this structure is created in a special
  * ELF section at every dynamic debug callsite.  At runtime,
@@ -128,9 +139,9 @@ struct _ddebug_class_param {
 #define DECLARE_DYNDBG_CLASSMAP(_var, _maptype, _base, ...)		\
 	static const char *_var##_classnames[] = { __VA_ARGS__ };	\
 	static struct _ddebug_class_map __aligned(8) __used		\
-		__section("__dyndbg_class_maps") _var = {			\
+	__section("__dyndbg_class_maps") _var = {			\
 		.mod = THIS_MODULE,					\
-		.mod_name = KBUILD_MODNAME,				\
+		.mod_name = DDEBUG_MODNAME,				\
 		.base = _base,						\
 		.map_type = _maptype,					\
 		.length = ARRAY_SIZE(_var##_classnames),		\
@@ -169,7 +180,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
 #define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt)	\
 	static struct _ddebug  __aligned(8)			\
 	__section("__dyndbg_descs") name = {			\
-		.modname = KBUILD_MODNAME,			\
+		.modname = DDEBUG_MODNAME,			\
 		.function = __func__,				\
 		.filename = __FILE__,				\
 		.format = (fmt),				\
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index fdb730db385e..7f78c6b3eeaf 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -248,7 +248,8 @@ static int ddebug_change(const struct ddebug_query *query,
 
 		/* match against the module name */
 		if (query->module &&
-		    !match_wildcard(query->module, di->mod_name))
+		    !match_wildcard(query->module, di->mod_name) &&
+		    !match_wildcard(query->module, kbasename(di->mod_name)))
 			continue;
 
 		if (query->class_string) {
diff --git a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
index 8b2b7388678e..541a2ea7bcb3 100755
--- a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
+++ b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
@@ -76,9 +76,9 @@ function handle_exit_code() {
 # $1 - pattern to match, pattern in $1 is enclosed by spaces for a match ""\s$1\s"
 # $2 - number of times the pattern passed in $1 is expected to match
 # $3 - optional can be set either to "-r" or "-v"
-#       "-r" means relaxed matching in this case pattern provided in $1 is passed
-#       as is without enclosing it with spaces
-#       "-v" prints matching lines
+#       "-r" means relaxed matching in this case pattern provided in
+#       $1 is passed as is without enclosing it with spaces "-v"
+#       prints matching lines
 # $4 - optional when $3 is set to "-r" then $4 can be used to pass "-v"
 function check_match_ct {
     pattern="\s$1\s"
@@ -223,7 +223,7 @@ function basic_tests {
     check_match_ct =p 0
 
     # module params are builtin to handle boot args
-    check_match_ct '\[params\]' 4 -r
+    check_match_ct '\[kernel/params\]' 4 -r
     ddcmd module params +mpf
     check_match_ct =pmf 4
 
@@ -238,8 +238,44 @@ EOF
     ddcmd =_
 }
 
+function test_subsystem_module_queries {
+    echo -e "${GREEN}# TEST_SUBSYTEM_MODULE_QUERIES ${NC}"
+    ddcmd =_
+
+    # Find how many 'main' modules we have in total (by basename)
+    # Use a more precise regex to avoid false positives like [irqdomain]
+    local total_main=$(grep -c "\[\([^]]*/\)\?main\]" /proc/dynamic_debug/control)
+    echo "# found $total_main total 'main' modules"
+
+    if [ $total_main -eq 0 ]; then
+        echo "SKIP - no 'main' modules found to test slashes"
+        return
+    fi
+
+    echo "# testing 'module */main'"
+    ddcmd module "*/main" +p
+    # This should match modules that HAVE a slash and end in /main
+    local slash_main=$(grep -c "\[[^]]*/main\]" /proc/dynamic_debug/control)
+    check_match_ct =p $slash_main -r
+
+    echo "# testing 'module init/main' (specific path)"
+    ddcmd =_
+    ddcmd module "init/main" +p
+    local init_main=$(grep -c "\[init/main\]" /proc/dynamic_debug/control)
+    check_match_ct =p $init_main
+
+    echo "# testing 'module main' (basename match)"
+    ddcmd =_
+    ddcmd module main +p
+    # This should match ALL $total_main entries due to kbasename matching
+    check_match_ct =p $total_main
+
+    ddcmd =_
+}
+
 tests_list=(
     basic_tests
+    test_subsystem_module_queries
 )
 
 # Run tests

-- 
2.54.0


  parent reply	other threads:[~2026-06-01 12:06 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-01 12:04 [PATCH v3 00/24] dynamic-debug cleanups refactors maintenance + alignment fix Jim Cromie
2026-06-01 12:04 ` [PATCH v3 01/24] docs/dyndbg: update examples \012 to \n Jim Cromie
2026-06-04  4:06   ` Claude review: " Claude Code Review Bot
2026-06-01 12:04 ` [PATCH v3 02/24] docs/dyndbg: explain flags parse 1st Jim Cromie
2026-06-04  4:06   ` Claude review: " Claude Code Review Bot
2026-06-01 12:04 ` [PATCH v3 03/24] vmlinux.lds.h: refactor BOUNDED_SECTION_* macros into bounded_sections.lds.h Jim Cromie
2026-06-04  4:06   ` Claude review: " Claude Code Review Bot
2026-06-01 12:04 ` [PATCH v3 04/24] vmlinux.lds.h: drop unused HEADERED_SECTION* macros Jim Cromie
2026-06-04  4:06   ` Claude review: " Claude Code Review Bot
2026-06-01 12:04 ` [PATCH v3 05/24] vmlinux.lds.h: Fix ALIGN(8) omission causing NULL ptr on i386 Jim Cromie
2026-06-04  4:06   ` Claude review: " Claude Code Review Bot
2026-06-01 12:04 ` [PATCH v3 06/24] vmlinux.lds.h: remove redundant ALIGN(8) directives Jim Cromie
2026-06-04  4:06   ` Claude review: " Claude Code Review Bot
2026-06-01 12:04 ` [PATCH v3 07/24] dyndbg.lds.S: fix lost dyndbg sections in modules Jim Cromie
2026-06-04  4:06   ` Claude review: " Claude Code Review Bot
2026-06-01 12:04 ` [PATCH v3 08/24] dyndbg: factor ddebug_match_desc out from ddebug_change Jim Cromie
2026-06-04  4:06   ` Claude review: " Claude Code Review Bot
2026-06-01 12:04 ` [PATCH v3 09/24] dyndbg: add stub macro for DECLARE_DYNDBG_CLASSMAP Jim Cromie
2026-06-04  4:06   ` Claude review: " Claude Code Review Bot
2026-06-01 12:04 ` [PATCH v3 10/24] dyndbg: reword "class unknown," to "class:_UNKNOWN_" Jim Cromie
2026-06-04  4:06   ` Claude review: " Claude Code Review Bot
2026-06-01 12:04 ` [PATCH v3 11/24] dyndbg-API: remove DD_CLASS_TYPE_(DISJOINT|LEVEL)_NAMES and code Jim Cromie
2026-06-04  4:06   ` Claude review: " Claude Code Review Bot
2026-06-01 12:04 ` [PATCH v3 12/24] dyndbg: drop NUM_TYPE_ARGS Jim Cromie
2026-06-04  4:06   ` Claude review: " Claude Code Review Bot
2026-06-01 12:04 ` [PATCH v3 13/24] dyndbg: reduce verbose/debug clutter Jim Cromie
2026-06-04  4:06   ` Claude review: " Claude Code Review Bot
2026-06-01 12:05 ` [PATCH v3 14/24] dyndbg: refactor param_set_dyndbg_classes and below Jim Cromie
2026-06-04  4:06   ` Claude review: " Claude Code Review Bot
2026-06-01 12:05 ` [PATCH v3 15/24] dyndbg: tighten fn-sig of ddebug_apply_class_bitmap Jim Cromie
2026-06-04  4:06   ` Claude review: " Claude Code Review Bot
2026-06-01 12:05 ` [PATCH v3 16/24] dyndbg: replace classmap list with an array-slice Jim Cromie
2026-06-04  4:06   ` Claude review: " Claude Code Review Bot
2026-06-01 12:05 ` [PATCH v3 17/24] dyndbg: macrofy a 2-index for-loop pattern Jim Cromie
2026-06-04  4:06   ` Claude review: " Claude Code Review Bot
2026-06-01 12:05 ` [PATCH v3 18/24] dyndbg: Upgrade class param storage to u64 for 64-bit classmaps Jim Cromie
2026-06-04  4:06   ` Claude review: " Claude Code Review Bot
2026-06-01 12:05 ` [PATCH v3 19/24] dyndbg,module: make proper substructs in _ddebug_info Jim Cromie
2026-06-04  4:07   ` Claude review: " Claude Code Review Bot
2026-06-01 12:05 ` [PATCH v3 20/24] dyndbg: move mod_name down from struct ddebug_table to _ddebug_info Jim Cromie
2026-06-04  4:07   ` Claude review: " Claude Code Review Bot
2026-06-01 12:05 ` [PATCH v3 21/24] dyndbg: hoist classmap-filter-by-modname up to ddebug_add_module Jim Cromie
2026-06-04  4:07   ` Claude review: " Claude Code Review Bot
2026-06-01 12:05 ` [PATCH v3 22/24] selftests-dyndbg: add a dynamic_debug run_tests target Jim Cromie
2026-06-04  4:07   ` Claude review: " Claude Code Review Bot
2026-06-01 12:05 ` [PATCH v3 23/24] dyndbg: change __dynamic_func_call_cls* macros into expressions Jim Cromie
2026-06-04  4:07   ` Claude review: " Claude Code Review Bot
2026-06-01 12:05 ` Jim Cromie [this message]
2026-06-04  4:07   ` Claude review: dynamic_debug: use KBUILD_MODFILE for unique builtin module names Claude Code Review Bot
2026-06-04  4:06 ` Claude review: dynamic-debug cleanups refactors maintenance + alignment fix Claude Code Review Bot

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=20260601-dd-maint-2-v3-24-4a15b241bd3c@gmail.com \
    --to=jim.cromie@gmail.com \
    --cc=airlied@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=atomlin@atomlin.com \
    --cc=corbet@lwn.net \
    --cc=da.gomez@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jbaron@akamai.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mcgrof@kernel.org \
    --cc=mripard@kernel.org \
    --cc=petr.pavlu@suse.com \
    --cc=samitolvanen@google.com \
    --cc=shuah@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=skhan@linuxfoundation.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox