From: Jim Cromie <jim.cromie@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Jason Baron <jbaron@akamai.com>,
Jim Cromie <jim.cromie@gmail.com>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.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>, Arnd Bergmann <arnd@arndb.de>,
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>
Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
dri-devel@lists.freedesktop.org, linux-arch@vger.kernel.org,
linux-modules@vger.kernel.org
Subject: [PATCH v5 09/18] dyndbg: use KBUILD_MODFILE for unique builtin module names
Date: Thu, 02 Jul 2026 10:41:01 -0600 [thread overview]
Message-ID: <20260702-dd-maint-2-v5-9-24f22b052bf2@gmail.com> (raw)
In-Reply-To: <20260702-dd-maint-2-v5-0-24f22b052bf2@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".
IOW, it makes this ambiguous:
bash-5.3# echo module main +m > /proc/dynamic_debug/control
since it would affect all 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 (which is unique), and KBUILD_MODNAME for loadables (which is
already required/guaranteed to be unique by module-loader):
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]
etc, 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. Ideally, queries like "module power", "module module", "module
base/power" might be better but would break old queries.
Adjust Documentation with "simple modname" and "subsystem modname".
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
v5: move ahead of array-slice patch to silence sashiko complaint about it
v4: call match_wildcard_hyphen() to allow dash vs underscore modname equivalence
v3: use KBUILD_MODFILE to give unique modnames for builtins
---
Documentation/admin-guide/dynamic-debug-howto.rst | 42 +++++++++++++----------
include/linux/dynamic_debug.h | 15 ++++++--
lib/dynamic_debug.c | 3 +-
3 files changed, 38 insertions(+), 22 deletions(-)
diff --git a/Documentation/admin-guide/dynamic-debug-howto.rst b/Documentation/admin-guide/dynamic-debug-howto.rst
index 9c2f096ed1d8..99bbae37d34e 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,21 @@ 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, or its simple name.
+ 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 */main # any subsystem ending in main
+ module main # simple modname, selects same as above
+ 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 9ae1accb9bf6..da9e5c35bc43 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -10,6 +10,17 @@
#define __DDEBUG_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+/*
+ * 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,
@@ -121,7 +132,7 @@ struct ddebug_class_param {
static struct ddebug_class_map __aligned(8) __used \
__section("__dyndbg_classes") _var = { \
.mod = THIS_MODULE, \
- .mod_name = KBUILD_MODNAME, \
+ .mod_name = DDEBUG_MODNAME, \
.base = _base, \
.map_type = _maptype, \
.length = (sizeof(_var##_classnames) / sizeof(_var##_classnames[0])), \
@@ -160,7 +171,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
#define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt) \
static struct _ddebug __aligned(8) \
__section("__dyndbg") 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 2e321b7eb957..ce42e03f1600 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -239,7 +239,8 @@ static int ddebug_change(const struct ddebug_query *query,
/* match against the module name */
if (query->module &&
- !match_wildcard(query->module, dt->mod_name))
+ !match_wildcard_hyphen(query->module, dt->mod_name) &&
+ !match_wildcard_hyphen(query->module, kbasename(dt->mod_name)))
continue;
if (query->class_string) {
--
2.54.0
next prev parent reply other threads:[~2026-07-02 16:41 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-02 16:40 [PATCH v5 00/18] dyndbg: cleanups, refactors in prep for API fix Jim Cromie
2026-07-02 16:40 ` [PATCH v5 01/18] dyndbg: factor ddebug_match_desc out from ddebug_change Jim Cromie
2026-07-02 16:40 ` [PATCH v5 02/18] dyndbg: add stub macro for DECLARE_DYNDBG_CLASSMAP Jim Cromie
2026-07-02 16:40 ` [PATCH v5 03/18] dyndbg: reword "class unknown," to "class:_UNKNOWN_" Jim Cromie
2026-07-02 16:40 ` [PATCH v5 04/18] dyndbg-API: remove DD_CLASS_TYPE_(DISJOINT|LEVEL)_NAMES and code Jim Cromie
2026-07-02 16:40 ` [PATCH v5 05/18] dyndbg: drop NUM_TYPE_ARGS Jim Cromie
2026-07-02 16:40 ` [PATCH v5 06/18] dyndbg: bump num-tokens in a query-cmd from 9 to 15 Jim Cromie
2026-07-02 16:40 ` [PATCH v5 07/18] dyndbg: reduce verbose/debug clutter Jim Cromie
2026-07-02 16:41 ` [PATCH v5 08/18] lib/parser: add match_wildcard_hyphen() for agnostic matching Jim Cromie
2026-07-02 16:41 ` Jim Cromie [this message]
2026-07-02 16:41 ` [PATCH v5 10/18] dyndbg: refactor param_set_dyndbg_classes and below Jim Cromie
2026-07-02 16:41 ` [PATCH v5 11/18] dyndbg: tighten fn-sig of ddebug_apply_class_bitmap Jim Cromie
2026-07-02 16:41 ` [PATCH v5 12/18] dyndbg: replace classmap list with an array-slice Jim Cromie
2026-07-02 16:41 ` [PATCH v5 13/18] dyndbg: macrofy a 2-index for-loop pattern Jim Cromie
2026-07-02 16:41 ` [PATCH v5 14/18] dyndbg: pin class param storage to u32 Jim Cromie
2026-07-02 16:41 ` [PATCH v5 15/18] dyndbg,module: make proper substructs in _ddebug_info Jim Cromie
2026-07-02 16:41 ` [PATCH v5 16/18] dyndbg: move mod_name down from struct ddebug_table to _ddebug_info Jim Cromie
2026-07-02 16:41 ` [PATCH v5 17/18] dyndbg: hoist classmap-filter-by-modname up to ddebug_add_module Jim Cromie
2026-07-02 16:41 ` [PATCH v5 18/18] dyndbg: change __dynamic_func_call_cls* macros into expressions Jim Cromie
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=20260702-dd-maint-2-v5-9-24f22b052bf2@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-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=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