[PATCH v10 14/38] dyndbg: Bind callsites and classmaps to DDEBUG_MODNAME
From: Jim Cromie via B4 Relay <devnull+jim.cromie.gmail.com@kernel.org>
Date: 2026-09-16 15:33:00
Also in:
b4-sent, dri-devel, linux-arch, linux-doc, linux-kbuild, linux-kselftest, linux-pm, lkml
Subsystem:
dynamic debug, kernel selftest framework, the rest · Maintainers:
Jason Baron, Jim Cromie, Shuah Khan, Shuah Khan, Linus Torvalds
From: Jim Cromie <jim.cromie@gmail.com> Currently, dyndbg binds KBUILD_MODNAME directly into callsite and classmap declarator macros. For built-ins, KBUILD_MODNAME defaults to the basename of the source file. For many subsystems, this fragments what should be a single module into separate file basenames: kernel/power/ produces "main", "suspend", "hibernate", "snapshot", and "swap" when all should be "power". Conversely, multiple unrelated built-in files across the tree (init/main.c, kernel/power/main.c) all collide under "main". While consolidating these fragments into unified subsystem names is desirable for query targeting and classmaps, attempting a bulk heuristic renaming across Kbuild introduces broad churn and disrupts control file output across the kernel. Module naming should remain under explicit maintainer control instead. Define DDEBUG_MODNAME in include/linux/dynamic_debug.h guarded with #ifndef, defaulting cleanly to KBUILD_MODNAME. Bind DDEBUG_MODNAME into callsite and classmap declarator macros instead of hardcoding KBUILD_MODNAME. This establishes an opt-in hook allowing subsystem maintainers to consolidate their module fragments if desired (e.g. via ccflags-y += -DDDEBUG_MODNAME='"power"' in a subsystem Makefile) while preserving existing module-name invariants by default. What's Unchanged: - Default module names remain strictly identical to KBUILD_MODNAME. - Zero callsite memory overhead or layout changes in struct _ddebug. - dynamic_debug/control output remains unchanged across the tree. Signed-off-by: Jim Cromie <jim.cromie@gmail.com> --- include/linux/dynamic_debug.h | 12 +++++++-- .../selftests/dynamic_debug/dyndbg_selftest.sh | 29 +++++++++++----------- 2 files changed, 25 insertions(+), 16 deletions(-)
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index baf5c0853f45..85863e24ad13 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h@@ -10,6 +10,14 @@ #define __DDEBUG_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) +/* + * DDEBUG_MODNAME: Subsystem/module name hook for callsites and classmaps. + * Defaults to KBUILD_MODNAME. + */ +#ifndef DDEBUG_MODNAME +#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 +129,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, \ .class_names = _var##_classnames, \
@@ -160,7 +168,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/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
index 972f12c70a8e..09a8dbf239dc 100755
--- a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
+++ b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh@@ -267,34 +267,35 @@ function FT_grammar_errs { ddcmd =_ } -# these queries run against the builtin module: params, and change -# flags. The control file state-of-interest is found by path, -# kernel/params.c, to avoid module keyword entirely +# these queries run against the builtin file: kernel/params.c, and change +# flags. The control file state-of-interest is found by path $f, +# perfectly binding the stimulus scope to the observation slice. function FT_basic_queries { v_echo "${GREEN}# BASIC_TESTS ${NC}" if [ $LACK_DD_BUILTIN -eq 1 ]; then - echo "SKIP - test requires params, which is a builtin module" + echo "SKIP - test requires dynamic_debug built into kernel" return fi + local f='kernel/params.c' ddcmd =_ # zero everything - ddcmd "module params +mf" 'kernel/params.c' - ddcmd "module params +l" 'kernel/params.c' - ddcmd "module params -m" 'kernel/params.c' - ddcmd "module params =_" 'kernel/params.c' + ddcmd "file $f +mf" "$f" + ddcmd "file $f +l" "$f" + ddcmd "file $f -m" "$f" + ddcmd "file $f =_" "$f" # multi-query commands split on ; on a single line - ddcmd "module params +mf ; module params func parse_args +sl" 'kernel/params.c' + ddcmd "file $f +mf ; file $f func parse_args +sl" "$f" # verify multi-cmd input, newline separated, with embedded comments ddcmd =_ # reset before multiline query to capture full transition - ddcmd "module params =_ # clear params - module params +ml # set flags - module params func parse_args +fs # set other flags" \ - 'kernel/params.c' + ddcmd "file $f =_ # clear params + file $f +ml # set flags + file $f func parse_args +fs # set other flags" \ + "$f" # clear flags and verify - ddcmd "module params =_" 'kernel/params.c' + ddcmd "file $f =_" "$f" } # Built-in Feature Tests (Can run on any CONFIG_DYNAMIC_DEBUG kernel, modular or monolithic)
--
2.55.0