* [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y
@ 2025-04-02 17:41 Jim Cromie
2025-04-02 17:41 ` [PATCH v3 01/54] vmlinux.lds.h: fixup HEADERED_SECTION{,_BY} macros Jim Cromie
` (53 more replies)
0 siblings, 54 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
This series fixes dynamic-debug's support for DRM debug-categories.
Classmaps-v1 evaded full review, and got committed in 2 chunks:
b7b4eebdba7b..6ea3bf466ac6 # core dyndbg changes
0406faf25fb1..ee7d633f2dfb # drm adoption
Then DRM-CI found a regression when booting with drm.debug=<initval>;
the pr_debug callsites' static-keys under the drm-dbgs in drm.ko got
enabled, but those in drivers & helpers did not, since they weren't
yet modprobed, and didn't yet exist.
new in v3:
I've flip-flopped again (evolved) on class "protection"
Simply put, /sys/module/drm/parameters/debug is ABI.
If that is true, its an inviolate user expectation that their settings
are authoritative, and we cannot slide dynamic-debug in underneath
without accepting that constraint, special-cases and interface
annoyances not withstanding.
That said, w/o a PARAM, there is no ABI, so classmap use-cases without
one are left unprotected, so that they can be adjusted without
explicit "class FOO" queries. This should satisfy the
keep-both-pieces crowd.
Note also: theres only 1 reason to want to get under the ABI: you want
to turn off some of a class's debugs, because they enlarge and clutter
the logs you must review.
# iirc, these are high volume
:#> echo module driverX class DRM_UT_VBL -p > control
But this isnt actually needed in this case; DRM_UT_VBL is already
pretty specific, and controllable directly from drm.debug.
Someday "mfsl" flags might apply to drm-dbg, but all drm's logging
prefixes are currently hardcoded, and may be semi-ABI, since
log-watchers might key on particular formats (however suboptimal that
might be).
This change is expressed separately, in a new patch:
0028-dyndbg-restore-classmap-protection-when-theres-a-.patch
Minor changes:
. more late cleanup patches pulled forward in parts
. split doc of 2 parsing features
. merge parsing features, tests, docs
. added v2 reviewed-by tags.
. dropped extraneous patches
For your testing convenience, its here:
https://github.com/jimc/linux.git
commit 5cbe833ce591cdb076310b7dcf479fd566f10a22 (HEAD -> dd-fix-614, ghlinux/dd-fix-614)
-v2 is here:
https://lore.kernel.org/lkml/20250320185238.447458-1-jim.cromie@gmail.com/
Design Review / Restatemment:
My primary design goal for dyndbg-classmaps was DIRECT support of DRM,
with NO api changes, starting with the enum drm_debug_category typing,
and keeping as much of the existing macro stack as unaltered as possible.
Some UUID-ish thing was OO-scope; pessimizing unseen optimizations on
compile-time constant ints (that could fit in a byte), across DRM's
macro stack, with ~5k expansions, would be ungood.
Immediate consequences:
= unique integers are *hard* to coordinate across the whole kernel.
= 0 is not special - DRM_UT_CORE is already used.
other users probably want it too
= 0..N are special - in several ways:
1. DRM_UT_<*> is 0..10
its the natural range, everybody wants it.
2. they're exposed in sysfs knobs.
ie: echo 0x1ff > /sys/module/drm/parameters/debug
all classmap-param users get 0..N on their knob.
= DRM_UT_<*> has only 10 categories/classes
small enough for DIRECT storage inside the _ddebug descriptor
= DRM's enum gives us both class-names and class/category values.
classnames === stringified DRM_UT_<*>
class_ids === bare DRM_UT_<*>
all future classmap users are expected to follow this model.
To accommodate the "special" contraints, we need to "privatize" the
class_id's, per module/group. We can do this in a few steps:
= modules declare their map: classnames => Ids.
author defined, user oriented
classnames/strings is wide, expressive, *flat* interface
2-levels used: DRM_UT_*, no 3-levels yet;
_UT could vary, but has no meaning now.
We can use the known (and desired) ordering/contiguity of the 0..Ns
here, and of the array of classnames, to simplify the specification of
the map:
_CLASSMAP_DEFINE (_base-ID/start-of-range, list-of-classnames)
no sparse maps, no reorder-maps, nothing extra to think about. Just
consecutive classnames mapped to consecutive class_ids / categories.
= dyndbg refuses direct selection by class_ids.
this privatizes the numbers
"speak my class-name if you expect a response".
= dyndbg requires "grammar access only"
no other control exists, not contemplated.
ie: "class DRM_UT_CORE +p" >control
ie: "name the class to change it"
class-param handler writes cmd-strings per changed class bit.
= classname --> class_id lookup "validates" the user.
unknown classnames can be discarded, per module.
other modules get the same,
no other class-user would accidentally know "DRM_UT_CORE"
= with private class_ids per module.
a small 0..N range is enough.
32 is a practical limit for a single classmap,
if you think "echo 0x12345678 > $sysknob" is practical.
16 is more practical, DRM has 10.
we have 63.
This allows ...
= multiple classmaps are supported
as long as the mapped class_ids dont conflict.
a fair requirement for a narrow, future use-case.
this is now verified in this patchset.
7x 8-bit classes is workable (if you'd like)
= "legacy" class.
all existing (un-class'd) pr_debugs.
class_id is a 6-bit integer,
so all existing pr_debugs need a default.
63 = 2^6-1 is our _DFLT
0..62 is then available for named classes. (0 is not special)
63 is "legacy".
Jim Cromie (54):
vmlinux.lds.h: fixup HEADERED_SECTION{,_BY} macros
docs/dyndbg: update examples \012 to \n
docs/dyndbg: explain flags parse 1st
test-dyndbg: fixup CLASSMAP usage error
dyndbg: reword "class unknown," to "class:_UNKNOWN_"
dyndbg: make ddebug_class_param union members same size
dyndbg: drop NUM_TYPE_ARRAY
dyndbg: reduce verbose/debug clutter
dyndbg: refactor param_set_dyndbg_classes and below
dyndbg: tighten fn-sig of ddebug_apply_class_bitmap
dyndbg: replace classmap list with a vector
dyndbg: macrofy a 2-index for-loop pattern
dyndbg,module: make proper substructs in _ddebug_info
dyndbg: hoist classmap-filter-by-modname up to ddebug_add_module
dyndbg: ddebug_table.mod_name down to _ddebug_info
dyndbg-API: remove DD_CLASS_TYPE_(DISJOINT|LEVEL)_NAMES and code
dyndbg-API: replace DECLARE_DYNDBG_CLASSMAP
selftests-dyndbg: add tools/testing/selftests/dynamic_debug/*
dyndbg: detect class_id reservation conflicts
dyndbg: check DYNAMIC_DEBUG_CLASSMAP_DEFINE args at compile-time
dyndbg-test: change do_prints testpoint to accept a loopct
dyndbg-API: promote DYNAMIC_DEBUG_CLASSMAP_PARAM to API
dyndbg: treat comma as a token separator
dyndbg: split multi-query strings with %
selftests-dyndbg: add test_mod_submod
dyndbg: change __dynamic_func_call_cls* macros into expressions
dyndbg: drop "protection" of class'd pr_debugs from legacy queries
dyndbg: restore classmap protection when theres a controlling_param
docs/dyndbg: add classmap info to howto
drm: use correct ccflags-y spelling
drm-dyndbg: adapt drm core to use dyndbg classmaps-v2
drm-dyndbg: adapt DRM to invoke DYNAMIC_DEBUG_CLASSMAP_PARAM
drm-print: fix config-dependent unused variable
drm-dyndbg: DRM_CLASSMAP_USE in amdgpu driver
drm-dyndbg: DRM_CLASSMAP_USE in i915 driver
drm-dyndbg: DRM_CLASSMAP_USE in drm_crtc_helper
drm-dyndbg: DRM_CLASSMAP_USE in drm_dp_helper
drm-dyndbg: DRM_CLASSMAP_USE in nouveau
drm-dyndbg: add DRM_CLASSMAP_USE to Xe driver
drm-dyndbg: add DRM_CLASSMAP_USE to virtio_gpu
drm-dyndbg: add DRM_CLASSMAP_USE to simpledrm
drm-dyndbg: add DRM_CLASSMAP_USE to bochs
drm-dyndbg: add DRM_CLASSMAP_USE to etnaviv
drm-dyndbg: add DRM_CLASSMAP_USE to gma500 driver
drm-dyndbg: add DRM_CLASSMAP_USE to radeon
drm-dyndbg: add DRM_CLASSMAP_USE to vmwgfx driver
drm-dyndbg: add DRM_CLASSMAP_USE to vkms driver
drm-dyndbg: add DRM_CLASSMAP_USE to udl driver
drm-dyndbg: add DRM_CLASSMAP_USE to mgag200 driver
drm-dyndbg: add DRM_CLASSMAP_USE to the gud driver
drm-dyndbg: add DRM_CLASSMAP_USE to the qxl driver
drm-dyndbg: add DRM_CLASSMAP_USE to the drm_gem_shmem_helper driver
drm: restore CONFIG_DRM_USE_DYNAMIC_DEBUG un-BROKEN
drm: RFC - make drm_dyndbg_user.o for drm-*_helpers, drivers
.../admin-guide/dynamic-debug-howto.rst | 143 +++-
MAINTAINERS | 3 +-
drivers/gpu/drm/Kconfig | 3 +-
drivers/gpu/drm/Makefile | 12 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 12 +-
drivers/gpu/drm/display/drm_dp_helper.c | 12 +-
drivers/gpu/drm/drm_crtc_helper.c | 12 +-
drivers/gpu/drm/drm_dyndbg_user.c | 11 +
drivers/gpu/drm/drm_gem_shmem_helper.c | 1 +
drivers/gpu/drm/drm_print.c | 38 +-
drivers/gpu/drm/etnaviv/etnaviv_drv.c | 2 +
drivers/gpu/drm/gma500/psb_drv.c | 2 +
drivers/gpu/drm/gud/gud_drv.c | 2 +
drivers/gpu/drm/i915/i915_params.c | 12 +-
drivers/gpu/drm/mgag200/mgag200_drv.c | 2 +
drivers/gpu/drm/nouveau/nouveau_drm.c | 12 +-
drivers/gpu/drm/qxl/qxl_drv.c | 2 +
drivers/gpu/drm/radeon/radeon_drv.c | 2 +
drivers/gpu/drm/tiny/bochs.c | 2 +
drivers/gpu/drm/tiny/simpledrm.c | 2 +
drivers/gpu/drm/udl/udl_main.c | 2 +
drivers/gpu/drm/virtio/virtgpu_drv.c | 2 +
drivers/gpu/drm/vkms/vkms_drv.c | 2 +
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 2 +
drivers/gpu/drm/xe/xe_drm_client.c | 2 +
include/asm-generic/vmlinux.lds.h | 12 +-
include/drm/drm_print.h | 12 +
include/linux/dynamic_debug.h | 216 ++++--
kernel/module/main.c | 15 +-
lib/Kconfig.debug | 24 +-
lib/Makefile | 3 +
lib/dynamic_debug.c | 637 +++++++++++-------
lib/test_dynamic_debug.c | 203 ++++--
lib/test_dynamic_debug_submod.c | 21 +
tools/testing/selftests/Makefile | 1 +
.../testing/selftests/dynamic_debug/Makefile | 9 +
tools/testing/selftests/dynamic_debug/config | 7 +
.../dynamic_debug/dyndbg_selftest.sh | 373 ++++++++++
38 files changed, 1353 insertions(+), 477 deletions(-)
create mode 100644 drivers/gpu/drm/drm_dyndbg_user.c
create mode 100644 lib/test_dynamic_debug_submod.c
create mode 100644 tools/testing/selftests/dynamic_debug/Makefile
create mode 100644 tools/testing/selftests/dynamic_debug/config
create mode 100755 tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
--
2.49.0
^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v3 01/54] vmlinux.lds.h: fixup HEADERED_SECTION{,_BY} macros
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-15 9:59 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 02/54] docs/dyndbg: update examples \012 to \n Jim Cromie
` (52 subsequent siblings)
53 siblings, 1 reply; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
commit 1d926e259d8f ("vmlinux.lds.h: add HEADERED_SECTION_* macros")
I flubbed the defn of the outer 2 macros; they missed the extra arg
needed: _front/_hdr. Fix it now, before anyone notices.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
include/asm-generic/vmlinux.lds.h | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 0d5b186abee8..c9c66089ea2f 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -219,10 +219,11 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
KEEP(*(.gnu.linkonce.##_sec_)) \
BOUNDED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_)
-#define HEADERED_SECTION_BY(_sec_, _label_) \
- HEADERED_SECTION_PRE_LABEL(_sec_, _label_, __start, __stop)
+#define HEADERED_SECTION_BY(_sec_, _label_, _front) \
+ HEADERED_SECTION_PRE_LABEL(_sec_, _label_, __start, __stop, _front)
-#define HEADERED_SECTION(_sec) HEADERED_SECTION_BY(_sec, _sec)
+#define HEADERED_SECTION(_sec, _front) \
+ HEADERED_SECTION_BY(_sec, _sec, _front)
#ifdef CONFIG_TRACE_BRANCH_PROFILING
#define LIKELY_PROFILE() \
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 02/54] docs/dyndbg: update examples \012 to \n
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
2025-04-02 17:41 ` [PATCH v3 01/54] vmlinux.lds.h: fixup HEADERED_SECTION{,_BY} macros Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-15 9:59 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 03/54] docs/dyndbg: explain flags parse 1st Jim Cromie
` (51 subsequent siblings)
53 siblings, 1 reply; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
commit 47ea6f99d06e ("dyndbg: use ESCAPE_SPACE for cat control")
changed the control-file to display format strings with "\n" rather
than "\012". Update the docs to match the new reality.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
Tested-by: Louis Chauvet<louis.chauvet@bootlin.com>
---
-v2 fix missed \012's
---
.../admin-guide/dynamic-debug-howto.rst | 20 +++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/Documentation/admin-guide/dynamic-debug-howto.rst b/Documentation/admin-guide/dynamic-debug-howto.rst
index 7c036590cd07..4ac18c0a1d95 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\012
- init/main.c:1218 [main]initcall_blacklisted =_ "initcall %s blacklisted\012"
- init/main.c:1424 [main]run_init_process =_ " with arguments:\012"
- init/main.c:1426 [main]run_init_process =_ " %s\012"
- init/main.c:1427 [main]run_init_process =_ " with environment:\012"
- init/main.c:1429 [main]run_init_process =_ " %s\012"
+ 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"
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:\012"
- init/main.c:1426 [main]run_init_process =p " %s\012"
- init/main.c:1427 [main]run_init_process =p " with environment:\012"
- init/main.c:1429 [main]run_init_process =p " %s\012"
+ 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"
Error messages go to console/syslog::
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 03/54] docs/dyndbg: explain flags parse 1st
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
2025-04-02 17:41 ` [PATCH v3 01/54] vmlinux.lds.h: fixup HEADERED_SECTION{,_BY} macros Jim Cromie
2025-04-02 17:41 ` [PATCH v3 02/54] docs/dyndbg: update examples \012 to \n Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 04/54] test-dyndbg: fixup CLASSMAP usage error Jim Cromie
` (50 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie, linux-doc
When writing queries to >control, flags are parsed 1st, since they are
the only required field, and they require specific compositions. So
if the flags draw an error (on those specifics), then keyword errors
aren't reported. This can be mildly confusing/annoying, so explain it
instead.
cc: linux-doc@vger.kernel.org
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
Documentation/admin-guide/dynamic-debug-howto.rst | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/Documentation/admin-guide/dynamic-debug-howto.rst b/Documentation/admin-guide/dynamic-debug-howto.rst
index 4ac18c0a1d95..63a511f2337b 100644
--- a/Documentation/admin-guide/dynamic-debug-howto.rst
+++ b/Documentation/admin-guide/dynamic-debug-howto.rst
@@ -109,9 +109,18 @@ The match-spec's select *prdbgs* from the catalog, upon which to apply
the flags-spec, all constraints are ANDed together. An absent keyword
is the same as keyword "*".
-
-A match specification is a keyword, which selects the attribute of
-the callsite to be compared, and a value to compare against. Possible
+Note: because the match-spec can be empty, the flags are checked 1st,
+then the pairs of keyword values. Flag errs will hide keyword errs:
+
+ bash-5.2# ddcmd mod bar +foo
+ dyndbg: read 13 bytes from userspace
+ dyndbg: query 0: "mod bar +foo" mod:*
+ dyndbg: unknown flag 'o'
+ dyndbg: flags parse failed
+ dyndbg: processed 1 queries, with 0 matches, 1 errs
+
+So a match-spec is a keyword, which selects the attribute of the
+callsite to be compared, and a value to compare against. Possible
keywords are:::
match-spec ::= 'func' string |
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 04/54] test-dyndbg: fixup CLASSMAP usage error
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (2 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 03/54] docs/dyndbg: explain flags parse 1st Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 05/54] dyndbg: reword "class unknown, " to "class:_UNKNOWN_" Jim Cromie
` (49 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
commit 6ea3bf466ac6 ("dyndbg: test DECLARE_DYNDBG_CLASSMAP, sysfs nodes")
A closer look at test_dynamic_debug.ko logging output reveals a macro
usage error:
lib/test_dynamic_debug.c:105 [test_dynamic_debug]do_cats =p "LOW msg\n" class:MID
lib/test_dynamic_debug.c:106 [test_dynamic_debug]do_cats =p "MID msg\n" class:HI
lib/test_dynamic_debug.c:107 [test_dynamic_debug]do_cats =_ "HI msg\n" class unknown, _id:13
107 says: HI is unknown, and 105,106 have a LOW/MID and MID/HI skew.
DECLARE_DYNDBG_CLASSMAP() _base arg must equal the enum's 1st value,
in this case it was _base + 1. This leaves HI class un-selectable.
NB: the macro could better validate its arguments.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
Tested-by: Louis Chauvet<louis.chauvet@bootlin.com>
---
lib/test_dynamic_debug.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
index 77c2a669b6af..396144cf351b 100644
--- a/lib/test_dynamic_debug.c
+++ b/lib/test_dynamic_debug.c
@@ -75,7 +75,7 @@ DD_SYS_WRAP(disjoint_bits, p);
DD_SYS_WRAP(disjoint_bits, T);
/* symbolic input, independent bits */
-enum cat_disjoint_names { LOW = 11, MID, HI };
+enum cat_disjoint_names { LOW = 10, MID, HI };
DECLARE_DYNDBG_CLASSMAP(map_disjoint_names, DD_CLASS_TYPE_DISJOINT_NAMES, 10,
"LOW", "MID", "HI");
DD_SYS_WRAP(disjoint_names, p);
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 05/54] dyndbg: reword "class unknown, " to "class:_UNKNOWN_"
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (3 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 04/54] test-dyndbg: fixup CLASSMAP usage error Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 06/54] dyndbg: make ddebug_class_param union members same size Jim Cromie
` (48 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
When a dyndbg classname is unknown to a kernel module (as before
previous patch), the callsite is un-addressable via >control queries.
The control-file displays this condition as "class unknown,"
currently. That spelling is sub-optimal/too-generic, so change it to
"class:_UNKNOWN_" to loudly announce the erroneous situation, and to
make it uniquely greppable.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
lib/dynamic_debug.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 5a007952f7f2..147540c57154 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -1154,7 +1154,7 @@ static int ddebug_proc_show(struct seq_file *m, void *p)
if (class)
seq_printf(m, " class:%s", class);
else
- seq_printf(m, " class unknown, _id:%d", dp->class_id);
+ seq_printf(m, " class:_UNKNOWN_ _id:%d", dp->class_id);
}
seq_putc(m, '\n');
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 06/54] dyndbg: make ddebug_class_param union members same size
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (4 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 05/54] dyndbg: reword "class unknown, " to "class:_UNKNOWN_" Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 07/54] dyndbg: drop NUM_TYPE_ARRAY Jim Cromie
` (47 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
struct ddebug_class_param keeps a ref to the state-storage of the
param; make both class-types use the same unsigned long storage type.
ISTM this is simpler and safer; it avoids an irrelevant difference,
and if 2 users somehow get class-type mixed up (or refer to the wrong
union member), at least they will both see the same value.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
include/linux/dynamic_debug.h | 2 +-
lib/dynamic_debug.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index ff44ec346162..b9afc7731b7c 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -124,7 +124,7 @@ struct _ddebug_info {
struct ddebug_class_param {
union {
unsigned long *bits;
- unsigned int *lvl;
+ unsigned long *lvl;
};
char flags[8];
const struct ddebug_class_map *map;
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 147540c57154..55df35df093b 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -799,7 +799,7 @@ int param_get_dyndbg_classes(char *buffer, const struct kernel_param *kp)
case DD_CLASS_TYPE_LEVEL_NAMES:
case DD_CLASS_TYPE_LEVEL_NUM:
- return scnprintf(buffer, PAGE_SIZE, "%d\n", *dcp->lvl);
+ return scnprintf(buffer, PAGE_SIZE, "%ld\n", *dcp->lvl);
default:
return -1;
}
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 07/54] dyndbg: drop NUM_TYPE_ARRAY
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (5 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 06/54] dyndbg: make ddebug_class_param union members same size Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 08/54] dyndbg: reduce verbose/debug clutter Jim Cromie
` (46 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
ARRAY_SIZE works here, since array decl is complete.
no functional change
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
include/linux/dynamic_debug.h | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index b9afc7731b7c..ac199293d203 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -107,11 +107,9 @@ struct ddebug_class_map {
.mod_name = KBUILD_MODNAME, \
.base = _base, \
.map_type = _maptype, \
- .length = NUM_TYPE_ARGS(char*, __VA_ARGS__), \
+ .length = ARRAY_SIZE(_var##_classnames), \
.class_names = _var##_classnames, \
}
-#define NUM_TYPE_ARGS(eltype, ...) \
- (sizeof((eltype[]){__VA_ARGS__}) / sizeof(eltype))
/* encapsulate linker provided built-in (or module) dyndbg data */
struct _ddebug_info {
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 08/54] dyndbg: reduce verbose/debug clutter
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (6 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 07/54] dyndbg: drop NUM_TYPE_ARRAY Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 09/54] dyndbg: refactor param_set_dyndbg_classes and below Jim Cromie
` (45 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
currently, for verbose=3, these are logged (blank lines for clarity):
dyndbg: query 0: "class DRM_UT_CORE +p" mod:*
dyndbg: split into words: "class" "DRM_UT_CORE" "+p"
dyndbg: op='+'
dyndbg: flags=0x1
dyndbg: *flagsp=0x1 *maskp=0xffffffff
dyndbg: parsed: func="" file="" module="" format="" lineno=0-0 class=...
dyndbg: no matches for query
dyndbg: no-match: func="" file="" module="" format="" lineno=0-0 class=...
dyndbg: processed 1 queries, with 0 matches, 0 errs
That is excessive, so this patch:
- shrinks 3 lines of 2nd stanza to single line
- drops 1st 2 lines of 3rd stanza
3rd line is like 1st, with result, not procedure.
2nd line is just status, retold in 4th, with more info.
New output:
dyndbg: query 0: "class DRM_UT_CORE +p" mod:*
dyndbg: split into words: "class" "DRM_UT_CORE" "+p"
dyndbg: op='+' flags=0x1 *flagsp=0x1 *maskp=0xffffffff
dyndbg: no-match: func="" file="" module="" format="" lineno=0-0 class=...
dyndbg: processed 1 queries, with 0 matches, 0 errs
Also reduce verbose=3 messages in ddebug_add_module
When modprobing a module, dyndbg currently logs/says "add-module", and
then "skipping" if the module has no prdbgs. Instead just check 1st
and return quietly.
no functional change
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
-v2 squash several verbose cleanups together
---
lib/dynamic_debug.c | 21 ++++++---------------
1 file changed, 6 insertions(+), 15 deletions(-)
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 55df35df093b..c609ff873224 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -264,9 +264,6 @@ static int ddebug_change(const struct ddebug_query *query,
}
mutex_unlock(&ddebug_lock);
- if (!nfound && verbose)
- pr_info("no matches for query\n");
-
return nfound;
}
@@ -499,7 +496,6 @@ static int ddebug_parse_flags(const char *str, struct flag_settings *modifiers)
pr_err("bad flag-op %c, at start of %s\n", *str, str);
return -EINVAL;
}
- v3pr_info("op='%c'\n", op);
for (; *str ; ++str) {
for (i = ARRAY_SIZE(opt_array) - 1; i >= 0; i--) {
@@ -513,7 +509,6 @@ static int ddebug_parse_flags(const char *str, struct flag_settings *modifiers)
return -EINVAL;
}
}
- v3pr_info("flags=0x%x\n", modifiers->flags);
/* calculate final flags, mask based upon op */
switch (op) {
@@ -529,7 +524,7 @@ static int ddebug_parse_flags(const char *str, struct flag_settings *modifiers)
modifiers->flags = 0;
break;
}
- v3pr_info("*flagsp=0x%x *maskp=0x%x\n", modifiers->flags, modifiers->mask);
+ v3pr_info("op='%c' flags=0x%x maskp=0x%x\n", op, modifiers->flags, modifiers->mask);
return 0;
}
@@ -539,7 +534,7 @@ static int ddebug_exec_query(char *query_string, const char *modname)
struct flag_settings modifiers = {};
struct ddebug_query query = {};
#define MAXWORDS 9
- int nwords, nfound;
+ int nwords;
char *words[MAXWORDS];
nwords = ddebug_tokenize(query_string, words, MAXWORDS);
@@ -557,10 +552,7 @@ static int ddebug_exec_query(char *query_string, const char *modname)
return -EINVAL;
}
/* actually go and implement the change */
- nfound = ddebug_change(&query, &modifiers);
- vpr_info_dq(&query, nfound ? "applied" : "no-match");
-
- return nfound;
+ return ddebug_change(&query, &modifiers);
}
/* handle multiple queries in query string, continue on error, return
@@ -1234,11 +1226,10 @@ static int ddebug_add_module(struct _ddebug_info *di, const char *modname)
{
struct ddebug_table *dt;
- v3pr_info("add-module: %s.%d sites\n", modname, di->num_descs);
- if (!di->num_descs) {
- v3pr_info(" skip %s\n", modname);
+ if (!di->num_descs)
return 0;
- }
+
+ v3pr_info("add-module: %s %d sites\n", modname, di->num_descs);
dt = kzalloc(sizeof(*dt), GFP_KERNEL);
if (dt == NULL) {
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 09/54] dyndbg: refactor param_set_dyndbg_classes and below
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (7 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 08/54] dyndbg: reduce verbose/debug clutter Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 10/54] dyndbg: tighten fn-sig of ddebug_apply_class_bitmap Jim Cromie
` (44 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
Refactor callchain below param_set_dyndbg_classes(1) to allow mod-name
specific settings. Split (1) into upper/lower fns, adding modname
param to lower, and passing NULL in from upper. Below that, add the
same param to ddebug_apply_class_bitmap(), and pass it thru to
_ddebug_queries(), replacing NULL with the param.
This allows the callchain to update the classmap in just one module,
vs just all as currently done. While the sysfs param is unlikely to
ever update just one module, the callchain will be used for modprobe
handling, which should update only that just-probed module.
In ddebug_apply_class_bitmap(), also check for actual changes to the
bits before announcing them, to declutter logs.
No functional change.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
v3 s/modnm/mod_name/g
---
lib/dynamic_debug.c | 65 ++++++++++++++++++++++++++++-----------------
1 file changed, 40 insertions(+), 25 deletions(-)
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index c609ff873224..3ad2e38c9ae2 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -593,9 +593,10 @@ static int ddebug_exec_queries(char *query, const char *modname)
return nfound;
}
-/* apply a new bitmap to the sys-knob's current bit-state */
+/* apply a new class-param setting */
static int ddebug_apply_class_bitmap(const struct ddebug_class_param *dcp,
- unsigned long *new_bits, unsigned long *old_bits)
+ unsigned long *new_bits, unsigned long *old_bits,
+ const char *query_modname)
{
#define QUERY_SIZE 128
char query[QUERY_SIZE];
@@ -603,7 +604,9 @@ static int ddebug_apply_class_bitmap(const struct ddebug_class_param *dcp,
int matches = 0;
int bi, ct;
- v2pr_info("apply: 0x%lx to: 0x%lx\n", *new_bits, *old_bits);
+ if (*new_bits != *old_bits)
+ v2pr_info("apply bitmap: 0x%lx to: 0x%lx for %s\n", *new_bits,
+ *old_bits, query_modname ?: "'*'");
for (bi = 0; bi < map->length; bi++) {
if (test_bit(bi, new_bits) == test_bit(bi, old_bits))
@@ -612,12 +615,16 @@ static int ddebug_apply_class_bitmap(const struct ddebug_class_param *dcp,
snprintf(query, QUERY_SIZE, "class %s %c%s", map->class_names[bi],
test_bit(bi, new_bits) ? '+' : '-', dcp->flags);
- ct = ddebug_exec_queries(query, NULL);
+ ct = ddebug_exec_queries(query, query_modname);
matches += ct;
v2pr_info("bit_%d: %d matches on class: %s -> 0x%lx\n", bi,
ct, map->class_names[bi], *new_bits);
}
+ if (*new_bits != *old_bits)
+ v2pr_info("applied bitmap: 0x%lx to: 0x%lx for %s\n", *new_bits,
+ *old_bits, query_modname ?: "'*'");
+
return matches;
}
@@ -672,7 +679,7 @@ static int param_set_dyndbg_classnames(const char *instr, const struct kernel_pa
continue;
}
curr_bits ^= BIT(cls_id);
- totct += ddebug_apply_class_bitmap(dcp, &curr_bits, dcp->bits);
+ totct += ddebug_apply_class_bitmap(dcp, &curr_bits, dcp->bits, NULL);
*dcp->bits = curr_bits;
v2pr_info("%s: changed bit %d:%s\n", KP_NAME(kp), cls_id,
map->class_names[cls_id]);
@@ -682,7 +689,7 @@ static int param_set_dyndbg_classnames(const char *instr, const struct kernel_pa
old_bits = CLASSMAP_BITMASK(*dcp->lvl);
curr_bits = CLASSMAP_BITMASK(cls_id + (wanted ? 1 : 0 ));
- totct += ddebug_apply_class_bitmap(dcp, &curr_bits, &old_bits);
+ totct += ddebug_apply_class_bitmap(dcp, &curr_bits, &old_bits, NULL);
*dcp->lvl = (cls_id + (wanted ? 1 : 0));
v2pr_info("%s: changed bit-%d: \"%s\" %lx->%lx\n", KP_NAME(kp), cls_id,
map->class_names[cls_id], old_bits, curr_bits);
@@ -696,18 +703,9 @@ static int param_set_dyndbg_classnames(const char *instr, const struct kernel_pa
return 0;
}
-/**
- * param_set_dyndbg_classes - class FOO >control
- * @instr: string echo>d to sysfs, input depends on map_type
- * @kp: kp->arg has state: bits/lvl, map, map_type
- *
- * Enable/disable prdbgs by their class, as given in the arguments to
- * DECLARE_DYNDBG_CLASSMAP. For LEVEL map-types, enforce relative
- * levels by bitpos.
- *
- * Returns: 0 or <0 if error.
- */
-int param_set_dyndbg_classes(const char *instr, const struct kernel_param *kp)
+static int param_set_dyndbg_module_classes(const char *instr,
+ const struct kernel_param *kp,
+ const char *mod_name)
{
const struct ddebug_class_param *dcp = kp->arg;
const struct ddebug_class_map *map = dcp->map;
@@ -744,8 +742,8 @@ int param_set_dyndbg_classes(const char *instr, const struct kernel_param *kp)
KP_NAME(kp), inrep, CLASSMAP_BITMASK(map->length));
inrep &= CLASSMAP_BITMASK(map->length);
}
- v2pr_info("bits:%lx > %s\n", inrep, KP_NAME(kp));
- totct += ddebug_apply_class_bitmap(dcp, &inrep, dcp->bits);
+ v2pr_info("bits:0x%lx > %s.%s\n", inrep, mod_name ?: "*", KP_NAME(kp));
+ totct += ddebug_apply_class_bitmap(dcp, &inrep, dcp->bits, mod_name);
*dcp->bits = inrep;
break;
case DD_CLASS_TYPE_LEVEL_NUM:
@@ -758,7 +756,7 @@ int param_set_dyndbg_classes(const char *instr, const struct kernel_param *kp)
old_bits = CLASSMAP_BITMASK(*dcp->lvl);
new_bits = CLASSMAP_BITMASK(inrep);
v2pr_info("lvl:%ld bits:0x%lx > %s\n", inrep, new_bits, KP_NAME(kp));
- totct += ddebug_apply_class_bitmap(dcp, &new_bits, &old_bits);
+ totct += ddebug_apply_class_bitmap(dcp, &new_bits, &old_bits, mod_name);
*dcp->lvl = inrep;
break;
default:
@@ -767,16 +765,33 @@ int param_set_dyndbg_classes(const char *instr, const struct kernel_param *kp)
vpr_info("%s: total matches: %d\n", KP_NAME(kp), totct);
return 0;
}
+
+/**
+ * param_set_dyndbg_classes - classmap kparam setter
+ * @instr: string echo>d to sysfs, input depends on map_type
+ * @kp: kp->arg has state: bits/lvl, map, map_type
+ *
+ * enable/disable all class'd pr_debugs in the classmap. For LEVEL
+ * map-types, enforce * relative levels by bitpos.
+ *
+ * Returns: 0 or <0 if error.
+ */
+int param_set_dyndbg_classes(const char *instr, const struct kernel_param *kp)
+{
+ return param_set_dyndbg_module_classes(instr, kp, NULL);
+}
EXPORT_SYMBOL(param_set_dyndbg_classes);
/**
- * param_get_dyndbg_classes - classes reader
+ * param_get_dyndbg_classes - classmap kparam getter
* @buffer: string description of controlled bits -> classes
* @kp: kp->arg has state: bits, map
*
- * Reads last written state, underlying prdbg state may have been
- * altered by direct >control. Displays 0x for DISJOINT, 0-N for
- * LEVEL Returns: #chars written or <0 on error
+ * Reads last written state, underlying pr_debug states may have been
+ * altered by direct >control. Displays 0x for DISJOINT classmap
+ * types, 0-N for LEVEL types.
+ *
+ * Returns: ct of chars written or <0 on error
*/
int param_get_dyndbg_classes(char *buffer, const struct kernel_param *kp)
{
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 10/54] dyndbg: tighten fn-sig of ddebug_apply_class_bitmap
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (8 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 09/54] dyndbg: refactor param_set_dyndbg_classes and below Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 11/54] dyndbg: replace classmap list with a vector Jim Cromie
` (43 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
old_bits arg is currently a pointer to the input bits, but this could
allow inadvertent changes to the input by the fn. Disallow this.
And constify new_bits while here.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
lib/dynamic_debug.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 3ad2e38c9ae2..621e04b1f28c 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -595,7 +595,8 @@ static int ddebug_exec_queries(char *query, const char *modname)
/* apply a new class-param setting */
static int ddebug_apply_class_bitmap(const struct ddebug_class_param *dcp,
- unsigned long *new_bits, unsigned long *old_bits,
+ const unsigned long *new_bits,
+ const unsigned long old_bits,
const char *query_modname)
{
#define QUERY_SIZE 128
@@ -604,12 +605,12 @@ static int ddebug_apply_class_bitmap(const struct ddebug_class_param *dcp,
int matches = 0;
int bi, ct;
- if (*new_bits != *old_bits)
+ if (*new_bits != old_bits)
v2pr_info("apply bitmap: 0x%lx to: 0x%lx for %s\n", *new_bits,
- *old_bits, query_modname ?: "'*'");
+ old_bits, query_modname ?: "'*'");
for (bi = 0; bi < map->length; bi++) {
- if (test_bit(bi, new_bits) == test_bit(bi, old_bits))
+ if (test_bit(bi, new_bits) == test_bit(bi, &old_bits))
continue;
snprintf(query, QUERY_SIZE, "class %s %c%s", map->class_names[bi],
@@ -621,9 +622,9 @@ static int ddebug_apply_class_bitmap(const struct ddebug_class_param *dcp,
v2pr_info("bit_%d: %d matches on class: %s -> 0x%lx\n", bi,
ct, map->class_names[bi], *new_bits);
}
- if (*new_bits != *old_bits)
+ if (*new_bits != old_bits)
v2pr_info("applied bitmap: 0x%lx to: 0x%lx for %s\n", *new_bits,
- *old_bits, query_modname ?: "'*'");
+ old_bits, query_modname ?: "'*'");
return matches;
}
@@ -679,7 +680,7 @@ static int param_set_dyndbg_classnames(const char *instr, const struct kernel_pa
continue;
}
curr_bits ^= BIT(cls_id);
- totct += ddebug_apply_class_bitmap(dcp, &curr_bits, dcp->bits, NULL);
+ totct += ddebug_apply_class_bitmap(dcp, &curr_bits, *dcp->bits, NULL);
*dcp->bits = curr_bits;
v2pr_info("%s: changed bit %d:%s\n", KP_NAME(kp), cls_id,
map->class_names[cls_id]);
@@ -689,7 +690,7 @@ static int param_set_dyndbg_classnames(const char *instr, const struct kernel_pa
old_bits = CLASSMAP_BITMASK(*dcp->lvl);
curr_bits = CLASSMAP_BITMASK(cls_id + (wanted ? 1 : 0 ));
- totct += ddebug_apply_class_bitmap(dcp, &curr_bits, &old_bits, NULL);
+ totct += ddebug_apply_class_bitmap(dcp, &curr_bits, old_bits, NULL);
*dcp->lvl = (cls_id + (wanted ? 1 : 0));
v2pr_info("%s: changed bit-%d: \"%s\" %lx->%lx\n", KP_NAME(kp), cls_id,
map->class_names[cls_id], old_bits, curr_bits);
@@ -743,7 +744,7 @@ static int param_set_dyndbg_module_classes(const char *instr,
inrep &= CLASSMAP_BITMASK(map->length);
}
v2pr_info("bits:0x%lx > %s.%s\n", inrep, mod_name ?: "*", KP_NAME(kp));
- totct += ddebug_apply_class_bitmap(dcp, &inrep, dcp->bits, mod_name);
+ totct += ddebug_apply_class_bitmap(dcp, &inrep, *dcp->bits, mod_name);
*dcp->bits = inrep;
break;
case DD_CLASS_TYPE_LEVEL_NUM:
@@ -756,7 +757,7 @@ static int param_set_dyndbg_module_classes(const char *instr,
old_bits = CLASSMAP_BITMASK(*dcp->lvl);
new_bits = CLASSMAP_BITMASK(inrep);
v2pr_info("lvl:%ld bits:0x%lx > %s\n", inrep, new_bits, KP_NAME(kp));
- totct += ddebug_apply_class_bitmap(dcp, &new_bits, &old_bits, mod_name);
+ totct += ddebug_apply_class_bitmap(dcp, &new_bits, old_bits, mod_name);
*dcp->lvl = inrep;
break;
default:
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 11/54] dyndbg: replace classmap list with a vector
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (9 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 10/54] dyndbg: tighten fn-sig of ddebug_apply_class_bitmap Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-15 9:59 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 12/54] dyndbg: macrofy a 2-index for-loop pattern Jim Cromie
` (42 subsequent siblings)
53 siblings, 1 reply; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
Classmaps are stored in an elf section/array, but currently are
individually list-linked onto dyndbg's per-module ddebug_table for
operation. This is unnecessary.
Just like dyndbg's descriptors, classes are packed in compile order;
so even with many builtin modules employing multiple classmaps, each
modules' maps are packed contiguously, and can be treated as a
array-start-address & array-length.
So this drops the whole list building operation done in
ddebug_attach_module_classes(), and removes the list-head members.
The "select-by-modname" condition is reused to find the start,end of
the subrange.
NOTE: This "filter-by-modname" on classmaps should really be done in
ddebug_add_module(1); ie at least one step closer to ddebug_init(2),
which already splits up pr-debug descriptors into subranges by
modname, then calls (1) on each. (2) knows nothing of classmaps
currently, and doesn't need to. For now, just add comment.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
v3- drop __outvar as promising magic it doesnt have
---
include/linux/dynamic_debug.h | 1 -
lib/dynamic_debug.c | 62 ++++++++++++++++++-----------------
2 files changed, 32 insertions(+), 31 deletions(-)
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index ac199293d203..e458d4b838ac 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -83,7 +83,6 @@ enum class_map_type {
};
struct ddebug_class_map {
- struct list_head link;
struct module *mod;
const char *mod_name; /* needed for builtins */
const char **class_names;
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 621e04b1f28c..85b8d32742ec 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -45,10 +45,11 @@ extern struct ddebug_class_map __start___dyndbg_classes[];
extern struct ddebug_class_map __stop___dyndbg_classes[];
struct ddebug_table {
- struct list_head link, maps;
+ struct list_head link;
const char *mod_name;
- unsigned int num_ddebugs;
struct _ddebug *ddebugs;
+ struct ddebug_class_map *classes;
+ unsigned int num_ddebugs, num_classes;
};
struct ddebug_query {
@@ -148,12 +149,13 @@ static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
}
static struct ddebug_class_map *ddebug_find_valid_class(struct ddebug_table const *dt,
- const char *class_string, int *class_id)
+ const char *class_string,
+ int *class_id)
{
struct ddebug_class_map *map;
- int idx;
+ int i, idx;
- list_for_each_entry(map, &dt->maps, link) {
+ for (map = dt->classes, i = 0; i < dt->num_classes; i++, map++) {
idx = match_string(map->class_names, map->length, class_string);
if (idx >= 0) {
*class_id = idx + map->base;
@@ -164,7 +166,6 @@ static struct ddebug_class_map *ddebug_find_valid_class(struct ddebug_table cons
return NULL;
}
-#define __outvar /* filled by callee */
/*
* Search the tables for _ddebug's which match the given `query' and
* apply the `flags' and `mask' to them. Returns number of matching
@@ -180,7 +181,7 @@ static int ddebug_change(const struct ddebug_query *query,
unsigned int nfound = 0;
struct flagsbuf fbuf, nbuf;
struct ddebug_class_map *map = NULL;
- int __outvar valid_class;
+ int valid_class;
/* search for matching ddebugs */
mutex_lock(&ddebug_lock);
@@ -1122,9 +1123,10 @@ static void *ddebug_proc_next(struct seq_file *m, void *p, loff_t *pos)
static const char *ddebug_class_name(struct ddebug_iter *iter, struct _ddebug *dp)
{
- struct ddebug_class_map *map;
+ struct ddebug_class_map *map = iter->table->classes;
+ int i, nc = iter->table->num_classes;
- list_for_each_entry(map, &iter->table->maps, link)
+ for (i = 0; i < nc; i++, map++)
if (class_in_range(dp->class_id, map))
return map->class_names[dp->class_id - map->base];
@@ -1208,30 +1210,31 @@ static const struct proc_ops proc_fops = {
.proc_write = ddebug_proc_write
};
-static void ddebug_attach_module_classes(struct ddebug_table *dt,
- struct ddebug_class_map *classes,
- int num_classes)
+static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug_info *di)
{
struct ddebug_class_map *cm;
- int i, j, ct = 0;
+ int i, nc = 0;
- for (cm = classes, i = 0; i < num_classes; i++, cm++) {
+ /*
+ * Find this module's classmaps in a subrange/wholerange of
+ * the builtin/modular classmap vector/section. Save the start
+ * and length of the subrange at its edges.
+ */
+ for (cm = di->classes, i = 0; i < di->num_classes; i++, cm++) {
if (!strcmp(cm->mod_name, dt->mod_name)) {
-
- v2pr_info("class[%d]: module:%s base:%d len:%d ty:%d\n", i,
- cm->mod_name, cm->base, cm->length, cm->map_type);
-
- for (j = 0; j < cm->length; j++)
- v3pr_info(" %d: %d %s\n", j + cm->base, j,
- cm->class_names[j]);
-
- list_add(&cm->link, &dt->maps);
- ct++;
+ if (!nc) {
+ v2pr_info("start subrange, class[%d]: module:%s base:%d len:%d ty:%d\n",
+ i, cm->mod_name, cm->base, cm->length, cm->map_type);
+ dt->classes = cm;
+ }
+ nc++;
}
}
- if (ct)
- vpr_info("module:%s attached %d classes\n", dt->mod_name, ct);
+ if (nc) {
+ dt->num_classes = nc;
+ vpr_info("module:%s attached %d classes\n", dt->mod_name, nc);
+ }
}
/*
@@ -1263,10 +1266,9 @@ static int ddebug_add_module(struct _ddebug_info *di, const char *modname)
dt->num_ddebugs = di->num_descs;
INIT_LIST_HEAD(&dt->link);
- INIT_LIST_HEAD(&dt->maps);
if (di->classes && di->num_classes)
- ddebug_attach_module_classes(dt, di->classes, di->num_classes);
+ ddebug_attach_module_classes(dt, di);
mutex_lock(&ddebug_lock);
list_add_tail(&dt->link, &ddebug_tables);
@@ -1379,8 +1381,8 @@ static void ddebug_remove_all_tables(void)
mutex_lock(&ddebug_lock);
while (!list_empty(&ddebug_tables)) {
struct ddebug_table *dt = list_entry(ddebug_tables.next,
- struct ddebug_table,
- link);
+ struct ddebug_table,
+ link);
ddebug_table_free(dt);
}
mutex_unlock(&ddebug_lock);
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 12/54] dyndbg: macrofy a 2-index for-loop pattern
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (10 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 11/54] dyndbg: replace classmap list with a vector Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 13/54] dyndbg, module: make proper substructs in _ddebug_info Jim Cromie
` (41 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
dynamic-debug has several __sections, each with <vecname>,
num_<vecname>, and it iterates over these with a 2-index for-loop.
These loops are fiddly with the 2 names.
We have only 2 such loops now, but are getting more soon; lets
embed/abstract the fiddlyness in the for_subvec() macro, and avoid
repeating it going forward.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
lib/dynamic_debug.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 85b8d32742ec..253eaf0a9bd6 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -128,6 +128,21 @@ do { \
#define v3pr_info(fmt, ...) vnpr_info(3, fmt, ##__VA_ARGS__)
#define v4pr_info(fmt, ...) vnpr_info(4, fmt, ##__VA_ARGS__)
+
+/*
+ * simplify a repeated for-loop pattern walking N steps in a T _vec
+ * member inside a struct _box. It expects int i and T *_sp to be
+ * declared in the caller.
+ * @_i: caller provided counter.
+ * @_sp: cursor into _vec, to examine each item.
+ * @_box: ptr to a struct containing @_vec member
+ * @_vec: name of a sub-struct member in _box, with array-ref and length
+ */
+#define for_subvec(_i, _sp, _box, _vec) \
+ for ((_i) = 0, (_sp) = (_box)->_vec; \
+ (_i) < (_box)->num_##_vec; \
+ (_i)++, (_sp)++)
+
static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
{
/* trim any trailing newlines */
@@ -155,7 +170,7 @@ static struct ddebug_class_map *ddebug_find_valid_class(struct ddebug_table cons
struct ddebug_class_map *map;
int i, idx;
- for (map = dt->classes, i = 0; i < dt->num_classes; i++, map++) {
+ for_subvec(i, map, dt, classes) {
idx = match_string(map->class_names, map->length, class_string);
if (idx >= 0) {
*class_id = idx + map->base;
@@ -1220,8 +1235,7 @@ static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug
* the builtin/modular classmap vector/section. Save the start
* and length of the subrange at its edges.
*/
- for (cm = di->classes, i = 0; i < di->num_classes; i++, cm++) {
-
+ for_subvec(i, cm, di, classes) {
if (!strcmp(cm->mod_name, dt->mod_name)) {
if (!nc) {
v2pr_info("start subrange, class[%d]: module:%s base:%d len:%d ty:%d\n",
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 13/54] dyndbg, module: make proper substructs in _ddebug_info
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (11 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 12/54] dyndbg: macrofy a 2-index for-loop pattern Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-15 9:59 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 14/54] dyndbg: hoist classmap-filter-by-modname up to ddebug_add_module Jim Cromie
` (40 subsequent siblings)
53 siblings, 1 reply; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
recompose struct _ddebug_info, inserting proper sub-structs.
The struct currently has 2 pairs of fields: descs, num_descs and
classes, num_classes. Several for-loops operate on these field pairs,
soon many more will be added.
Looping over these blocks by respective field-pairs is repetitive and
fiddly, differing only by the field-names. Before adding a 3rd
section and compounding the fiddly details problem, make proper
substructs of each section, with the same named fields.
So this patch does:
Adds 3 "vector<T>" structs, each with { <T> *start, int len; }
components, for _ddebug_descriptors, _ddebug_class_maps, and
_ddebug_class_users respectively.
Invariant: These vectors ref a contiguous subrange of __section memory
in builtin/DATA or in loadable modules via mod->dyndbg_info; with
guaranteed life-time for us.
Bundles these 3 vectors (subrange-refs) struct (reformed) _ddebug_info,
where they're __packed to close the paholes introduced otherwise.
The common fields allow improving the for_subvec() macro by dropping
the ugly num_##<T> paste-up.
Also recompose struct ddebug_table to contain a _ddebug_info. This
reinforces its use as a cursor into relevant data for a builtin
module, and access to the full _ddebug state for modules.
NOTES:
Fixup names: section names improved, struct names normalized to
_ddebug_*
struct module contains a _ddebug_info field and module/main.c sets it
up, so that gets adjusted.
The __packed attribute on _ddebug_info and the 3 contained structs
closes the holes otherwise created by the structification (which was
my excuse for not doing it originally).
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
-v2 rework towards front of series
---
include/asm-generic/vmlinux.lds.h | 4 +-
include/linux/dynamic_debug.h | 42 +++++++-----
kernel/module/main.c | 12 ++--
lib/dynamic_debug.c | 108 ++++++++++++++----------------
lib/test_dynamic_debug.c | 2 +-
5 files changed, 88 insertions(+), 80 deletions(-)
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index c9c66089ea2f..f834ad1fb8c4 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -366,8 +366,8 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
*(__tracepoints) \
/* implement dynamic printk debug */ \
. = ALIGN(8); \
- BOUNDED_SECTION_BY(__dyndbg_classes, ___dyndbg_classes) \
- BOUNDED_SECTION_BY(__dyndbg, ___dyndbg) \
+ BOUNDED_SECTION_BY(__dyndbg_class_maps, ___dyndbg_class_maps) \
+ BOUNDED_SECTION_BY(__dyndbg_descriptors, ___dyndbg_descs) \
CODETAG_SECTIONS() \
LIKELY_PROFILE() \
BRANCH_PROFILE() \
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index e458d4b838ac..9d282e2444e1 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -82,7 +82,7 @@ enum class_map_type {
*/
};
-struct ddebug_class_map {
+struct _ddebug_class_map {
struct module *mod;
const char *mod_name; /* needed for builtins */
const char **class_names;
@@ -93,15 +93,15 @@ struct ddebug_class_map {
/**
* DECLARE_DYNDBG_CLASSMAP - declare classnames known by a module
- * @_var: a struct ddebug_class_map, passed to module_param_cb
+ * @_var: a struct _ddebug_class_map, passed to module_param_cb
* @_type: enum class_map_type, chooses bits/verbose, numeric/symbolic
* @_base: offset of 1st class-name. splits .class_id space
* @classes: class-names used to control class'd prdbgs
*/
#define DECLARE_DYNDBG_CLASSMAP(_var, _maptype, _base, ...) \
static const char *_var##_classnames[] = { __VA_ARGS__ }; \
- static struct ddebug_class_map __aligned(8) __used \
- __section("__dyndbg_classes") _var = { \
+ static struct _ddebug_class_map __aligned(8) __used \
+ __section("__dyndbg_class_maps") _var = { \
.mod = THIS_MODULE, \
.mod_name = KBUILD_MODNAME, \
.base = _base, \
@@ -110,21 +110,33 @@ struct ddebug_class_map {
.class_names = _var##_classnames, \
}
-/* encapsulate linker provided built-in (or module) dyndbg data */
+/*
+ * @_ddebug_info: gathers module/builtin dyndbg_* __sections together.
+ * For builtins, it is used as a cursor, with the inner structs
+ * marking sub-vectors of the builtin __sections in DATA.
+ */
+struct _ddebug_descs {
+ struct _ddebug *start;
+ int len;
+} __packed;
+
+struct _ddebug_class_maps {
+ struct _ddebug_class_map *start;
+ int len;
+} __packed;
+
struct _ddebug_info {
- struct _ddebug *descs;
- struct ddebug_class_map *classes;
- unsigned int num_descs;
- unsigned int num_classes;
-};
+ struct _ddebug_descs descs;
+ struct _ddebug_class_maps maps;
+} __packed;
-struct ddebug_class_param {
+struct _ddebug_class_param {
union {
unsigned long *bits;
unsigned long *lvl;
};
char flags[8];
- const struct ddebug_class_map *map;
+ const struct _ddebug_class_map *map;
};
/*
@@ -159,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 = { \
+ __section("__dyndbg_descriptors") name = { \
.modname = KBUILD_MODNAME, \
.function = __func__, \
.filename = __FILE__, \
@@ -242,7 +254,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
* macro.
*/
#define _dynamic_func_call_cls(cls, fmt, func, ...) \
- __dynamic_func_call_cls(__UNIQUE_ID(ddebug), cls, fmt, func, ##__VA_ARGS__)
+ __dynamic_func_call_cls(__UNIQUE_ID(_ddebug), cls, fmt, func, ##__VA_ARGS__)
#define _dynamic_func_call(fmt, func, ...) \
_dynamic_func_call_cls(_DPRINTK_CLASS_DFLT, fmt, func, ##__VA_ARGS__)
@@ -252,7 +264,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
* with precisely the macro's varargs.
*/
#define _dynamic_func_call_cls_no_desc(cls, fmt, func, ...) \
- __dynamic_func_call_cls_no_desc(__UNIQUE_ID(ddebug), cls, fmt, \
+ __dynamic_func_call_cls_no_desc(__UNIQUE_ID(_ddebug), cls, fmt, \
func, ##__VA_ARGS__)
#define _dynamic_func_call_no_desc(fmt, func, ...) \
_dynamic_func_call_cls_no_desc(_DPRINTK_CLASS_DFLT, fmt, \
diff --git a/kernel/module/main.c b/kernel/module/main.c
index 1fb9ad289a6f..b60f728e36ac 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -2621,12 +2621,12 @@ static int find_module_sections(struct module *mod, struct load_info *info)
pr_warn("%s: Ignoring obsolete parameters\n", mod->name);
#ifdef CONFIG_DYNAMIC_DEBUG_CORE
- mod->dyndbg_info.descs = section_objs(info, "__dyndbg",
- sizeof(*mod->dyndbg_info.descs),
- &mod->dyndbg_info.num_descs);
- mod->dyndbg_info.classes = section_objs(info, "__dyndbg_classes",
- sizeof(*mod->dyndbg_info.classes),
- &mod->dyndbg_info.num_classes);
+ mod->dyndbg_info.descs.start = section_objs(info, "__dyndbg_descriptors",
+ sizeof(*mod->dyndbg_info.descs.start),
+ &mod->dyndbg_info.descs.len);
+ mod->dyndbg_info.maps.start = section_objs(info, "__dyndbg_class_maps",
+ sizeof(*mod->dyndbg_info.maps.start),
+ &mod->dyndbg_info.maps.len);
#endif
return 0;
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 253eaf0a9bd6..104cf8abdf33 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -39,17 +39,15 @@
#include <rdma/ib_verbs.h>
-extern struct _ddebug __start___dyndbg[];
-extern struct _ddebug __stop___dyndbg[];
-extern struct ddebug_class_map __start___dyndbg_classes[];
-extern struct ddebug_class_map __stop___dyndbg_classes[];
+extern struct _ddebug __start___dyndbg_descs[];
+extern struct _ddebug __stop___dyndbg_descs[];
+extern struct _ddebug_class_map __start___dyndbg_class_maps[];
+extern struct _ddebug_class_map __stop___dyndbg_class_maps[];
struct ddebug_table {
struct list_head link;
const char *mod_name;
- struct _ddebug *ddebugs;
- struct ddebug_class_map *classes;
- unsigned int num_ddebugs, num_classes;
+ struct _ddebug_info info;
};
struct ddebug_query {
@@ -128,7 +126,6 @@ do { \
#define v3pr_info(fmt, ...) vnpr_info(3, fmt, ##__VA_ARGS__)
#define v4pr_info(fmt, ...) vnpr_info(4, fmt, ##__VA_ARGS__)
-
/*
* simplify a repeated for-loop pattern walking N steps in a T _vec
* member inside a struct _box. It expects int i and T *_sp to be
@@ -139,8 +136,8 @@ do { \
* @_vec: name of a sub-struct member in _box, with array-ref and length
*/
#define for_subvec(_i, _sp, _box, _vec) \
- for ((_i) = 0, (_sp) = (_box)->_vec; \
- (_i) < (_box)->num_##_vec; \
+ for ((_i) = 0, (_sp) = (_box)->_vec.start; \
+ (_i) < (_box)->_vec.len; \
(_i)++, (_sp)++)
static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
@@ -163,14 +160,14 @@ static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
query->first_lineno, query->last_lineno, query->class_string);
}
-static struct ddebug_class_map *ddebug_find_valid_class(struct ddebug_table const *dt,
+static struct _ddebug_class_map *ddebug_find_valid_class(struct ddebug_table const *dt,
const char *class_string,
int *class_id)
{
- struct ddebug_class_map *map;
+ struct _ddebug_class_map *map;
int i, idx;
- for_subvec(i, map, dt, classes) {
+ for_subvec(i, map, &dt->info, maps) {
idx = match_string(map->class_names, map->length, class_string);
if (idx >= 0) {
*class_id = idx + map->base;
@@ -195,7 +192,7 @@ static int ddebug_change(const struct ddebug_query *query,
unsigned int newflags;
unsigned int nfound = 0;
struct flagsbuf fbuf, nbuf;
- struct ddebug_class_map *map = NULL;
+ struct _ddebug_class_map *map = NULL;
int valid_class;
/* search for matching ddebugs */
@@ -216,8 +213,8 @@ static int ddebug_change(const struct ddebug_query *query,
valid_class = _DPRINTK_CLASS_DFLT;
}
- for (i = 0; i < dt->num_ddebugs; i++) {
- struct _ddebug *dp = &dt->ddebugs[i];
+ for (i = 0; i < dt->info.descs.len; i++) {
+ struct _ddebug *dp = &dt->info.descs.start[i];
/* match site against query-class */
if (dp->class_id != valid_class)
@@ -610,14 +607,14 @@ static int ddebug_exec_queries(char *query, const char *modname)
}
/* apply a new class-param setting */
-static int ddebug_apply_class_bitmap(const struct ddebug_class_param *dcp,
+static int ddebug_apply_class_bitmap(const struct _ddebug_class_param *dcp,
const unsigned long *new_bits,
const unsigned long old_bits,
const char *query_modname)
{
#define QUERY_SIZE 128
char query[QUERY_SIZE];
- const struct ddebug_class_map *map = dcp->map;
+ const struct _ddebug_class_map *map = dcp->map;
int matches = 0;
int bi, ct;
@@ -653,8 +650,8 @@ static int ddebug_apply_class_bitmap(const struct ddebug_class_param *dcp,
/* accept comma-separated-list of [+-] classnames */
static int param_set_dyndbg_classnames(const char *instr, const struct kernel_param *kp)
{
- const struct ddebug_class_param *dcp = kp->arg;
- const struct ddebug_class_map *map = dcp->map;
+ const struct _ddebug_class_param *dcp = kp->arg;
+ const struct _ddebug_class_map *map = dcp->map;
unsigned long curr_bits, old_bits;
char *cl_str, *p, *tmp;
int cls_id, totct = 0;
@@ -724,8 +721,8 @@ static int param_set_dyndbg_module_classes(const char *instr,
const struct kernel_param *kp,
const char *mod_name)
{
- const struct ddebug_class_param *dcp = kp->arg;
- const struct ddebug_class_map *map = dcp->map;
+ const struct _ddebug_class_param *dcp = kp->arg;
+ const struct _ddebug_class_map *map = dcp->map;
unsigned long inrep, new_bits, old_bits;
int rc, totct = 0;
@@ -812,8 +809,8 @@ EXPORT_SYMBOL(param_set_dyndbg_classes);
*/
int param_get_dyndbg_classes(char *buffer, const struct kernel_param *kp)
{
- const struct ddebug_class_param *dcp = kp->arg;
- const struct ddebug_class_map *map = dcp->map;
+ const struct _ddebug_class_param *dcp = kp->arg;
+ const struct _ddebug_class_map *map = dcp->map;
switch (map->map_type) {
@@ -1064,8 +1061,8 @@ static struct _ddebug *ddebug_iter_first(struct ddebug_iter *iter)
}
iter->table = list_entry(ddebug_tables.next,
struct ddebug_table, link);
- iter->idx = iter->table->num_ddebugs;
- return &iter->table->ddebugs[--iter->idx];
+ iter->idx = iter->table->info.descs.len;
+ return &iter->table->info.descs.start[--iter->idx];
}
/*
@@ -1086,10 +1083,10 @@ static struct _ddebug *ddebug_iter_next(struct ddebug_iter *iter)
}
iter->table = list_entry(iter->table->link.next,
struct ddebug_table, link);
- iter->idx = iter->table->num_ddebugs;
+ iter->idx = iter->table->info.descs.len;
--iter->idx;
}
- return &iter->table->ddebugs[iter->idx];
+ return &iter->table->info.descs.start[iter->idx];
}
/*
@@ -1136,12 +1133,12 @@ static void *ddebug_proc_next(struct seq_file *m, void *p, loff_t *pos)
#define class_in_range(class_id, map) \
(class_id >= map->base && class_id < map->base + map->length)
-static const char *ddebug_class_name(struct ddebug_iter *iter, struct _ddebug *dp)
+static const char *ddebug_class_name(struct ddebug_table *dt, struct _ddebug *dp)
{
- struct ddebug_class_map *map = iter->table->classes;
- int i, nc = iter->table->num_classes;
+ struct _ddebug_class_map *map;
+ int i;
- for (i = 0; i < nc; i++, map++)
+ for_subvec(i, map, &dt->info, maps)
if (class_in_range(dp->class_id, map))
return map->class_names[dp->class_id - map->base];
@@ -1175,7 +1172,7 @@ static int ddebug_proc_show(struct seq_file *m, void *p)
seq_putc(m, '"');
if (dp->class_id != _DPRINTK_CLASS_DFLT) {
- class = ddebug_class_name(iter, dp);
+ class = ddebug_class_name(iter->table, dp);
if (class)
seq_printf(m, " class:%s", class);
else
@@ -1227,7 +1224,7 @@ static const struct proc_ops proc_fops = {
static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug_info *di)
{
- struct ddebug_class_map *cm;
+ struct _ddebug_class_map *cm;
int i, nc = 0;
/*
@@ -1235,18 +1232,18 @@ static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug
* the builtin/modular classmap vector/section. Save the start
* and length of the subrange at its edges.
*/
- for_subvec(i, cm, di, classes) {
+ for_subvec(i, cm, di, maps) {
if (!strcmp(cm->mod_name, dt->mod_name)) {
if (!nc) {
v2pr_info("start subrange, class[%d]: module:%s base:%d len:%d ty:%d\n",
i, cm->mod_name, cm->base, cm->length, cm->map_type);
- dt->classes = cm;
+ dt->info.maps.start = cm;
}
nc++;
}
}
if (nc) {
- dt->num_classes = nc;
+ dt->info.maps.len = nc;
vpr_info("module:%s attached %d classes\n", dt->mod_name, nc);
}
}
@@ -1259,10 +1256,10 @@ static int ddebug_add_module(struct _ddebug_info *di, const char *modname)
{
struct ddebug_table *dt;
- if (!di->num_descs)
+ if (!di->descs.len)
return 0;
- v3pr_info("add-module: %s %d sites\n", modname, di->num_descs);
+ v3pr_info("add-module: %s %d sites\n", modname, di->descs.len);
dt = kzalloc(sizeof(*dt), GFP_KERNEL);
if (dt == NULL) {
@@ -1276,19 +1273,18 @@ static int ddebug_add_module(struct _ddebug_info *di, const char *modname)
* this struct ddebug_table.
*/
dt->mod_name = modname;
- dt->ddebugs = di->descs;
- dt->num_ddebugs = di->num_descs;
+ dt->info = *di;
INIT_LIST_HEAD(&dt->link);
- if (di->classes && di->num_classes)
+ if (di->maps.len)
ddebug_attach_module_classes(dt, di);
mutex_lock(&ddebug_lock);
list_add_tail(&dt->link, &ddebug_tables);
mutex_unlock(&ddebug_lock);
- vpr_info("%3u debug prints in module %s\n", di->num_descs, modname);
+ vpr_info("%3u debug prints in module %s\n", di->descs.len, modname);
return 0;
}
@@ -1435,10 +1431,10 @@ static int __init dynamic_debug_init(void)
char *cmdline;
struct _ddebug_info di = {
- .descs = __start___dyndbg,
- .classes = __start___dyndbg_classes,
- .num_descs = __stop___dyndbg - __start___dyndbg,
- .num_classes = __stop___dyndbg_classes - __start___dyndbg_classes,
+ .descs.start = __start___dyndbg_descs,
+ .maps.start = __start___dyndbg_class_maps,
+ .descs.len = __stop___dyndbg_descs - __start___dyndbg_descs,
+ .maps.len = __stop___dyndbg_class_maps - __start___dyndbg_class_maps,
};
#ifdef CONFIG_MODULES
@@ -1449,7 +1445,7 @@ static int __init dynamic_debug_init(void)
}
#endif /* CONFIG_MODULES */
- if (&__start___dyndbg == &__stop___dyndbg) {
+ if (&__start___dyndbg_descs == &__stop___dyndbg_descs) {
if (IS_ENABLED(CONFIG_DYNAMIC_DEBUG)) {
pr_warn("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n");
return 1;
@@ -1459,16 +1455,16 @@ static int __init dynamic_debug_init(void)
return 0;
}
- iter = iter_mod_start = __start___dyndbg;
+ iter = iter_mod_start = __start___dyndbg_descs;
modname = iter->modname;
i = mod_sites = mod_ct = 0;
- for (; iter < __stop___dyndbg; iter++, i++, mod_sites++) {
+ for (; iter < __stop___dyndbg_descs; iter++, i++, mod_sites++) {
if (strcmp(modname, iter->modname)) {
mod_ct++;
- di.num_descs = mod_sites;
- di.descs = iter_mod_start;
+ di.descs.len = mod_sites;
+ di.descs.start = iter_mod_start;
ret = ddebug_add_module(&di, modname);
if (ret)
goto out_err;
@@ -1478,8 +1474,8 @@ static int __init dynamic_debug_init(void)
iter_mod_start = iter;
}
}
- di.num_descs = mod_sites;
- di.descs = iter_mod_start;
+ di.descs.len = mod_sites;
+ di.descs.start = iter_mod_start;
ret = ddebug_add_module(&di, modname);
if (ret)
goto out_err;
@@ -1489,8 +1485,8 @@ static int __init dynamic_debug_init(void)
i, mod_ct, (int)((mod_ct * sizeof(struct ddebug_table)) >> 10),
(int)((i * sizeof(struct _ddebug)) >> 10));
- if (di.num_classes)
- v2pr_info(" %d builtin ddebug class-maps\n", di.num_classes);
+ if (di.maps.len)
+ v2pr_info(" %d builtin ddebug class-maps\n", di.maps.len);
/* now that ddebug tables are loaded, process all boot args
* again to find and activate queries given in dyndbg params.
diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
index 396144cf351b..8434f70b51bb 100644
--- a/lib/test_dynamic_debug.c
+++ b/lib/test_dynamic_debug.c
@@ -41,7 +41,7 @@ module_param_cb(do_prints, ¶m_ops_do_prints, NULL, 0600);
*/
#define DD_SYS_WRAP(_model, _flags) \
static unsigned long bits_##_model; \
- static struct ddebug_class_param _flags##_model = { \
+ static struct _ddebug_class_param _flags##_model = { \
.bits = &bits_##_model, \
.flags = #_flags, \
.map = &map_##_model, \
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 14/54] dyndbg: hoist classmap-filter-by-modname up to ddebug_add_module
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (12 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 13/54] dyndbg, module: make proper substructs in _ddebug_info Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-15 10:00 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 15/54] dyndbg: ddebug_table.mod_name down to _ddebug_info Jim Cromie
` (39 subsequent siblings)
53 siblings, 1 reply; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
The body of ddebug_attach_module_classes() is dominated by a
code-block that finds the contiguous subrange of classmaps matching on
modname, and saves it into the ddebug_table's info record.
Implement this block in a macro to accommodate different component
vectors in the "box" (as named in the for_subvec macro).
And hoist its invocation out of ddebug_attach_module_classes() up into
ddebug_add_module(). This moves the filtering step up closer to
dynamic_debug_init(), which effectively does the same for builtin
pr_debug descriptors; segmenting them into subranges by modname.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
lib/dynamic_debug.c | 56 ++++++++++++++++++++++++++-------------------
1 file changed, 32 insertions(+), 24 deletions(-)
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 104cf8abdf33..046c4ffb38f8 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -161,8 +161,8 @@ static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
}
static struct _ddebug_class_map *ddebug_find_valid_class(struct ddebug_table const *dt,
- const char *class_string,
- int *class_id)
+ const char *class_string,
+ int *class_id)
{
struct _ddebug_class_map *map;
int i, idx;
@@ -1224,30 +1224,34 @@ static const struct proc_ops proc_fops = {
static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug_info *di)
{
- struct _ddebug_class_map *cm;
- int i, nc = 0;
-
- /*
- * Find this module's classmaps in a subrange/wholerange of
- * the builtin/modular classmap vector/section. Save the start
- * and length of the subrange at its edges.
- */
- for_subvec(i, cm, di, maps) {
- if (!strcmp(cm->mod_name, dt->mod_name)) {
- if (!nc) {
- v2pr_info("start subrange, class[%d]: module:%s base:%d len:%d ty:%d\n",
- i, cm->mod_name, cm->base, cm->length, cm->map_type);
- dt->info.maps.start = cm;
- }
- nc++;
- }
- }
- if (nc) {
- dt->info.maps.len = nc;
- vpr_info("module:%s attached %d classes\n", dt->mod_name, nc);
- }
+ vpr_info("module:%s attached %d classes\n", dt->mod_name, dt->info.maps.len);
}
+/*
+ * Walk the @_box->@_vec member, over @_vec.start[0..len], and find
+ * the contiguous subrange of elements matching on ->mod_name. Copy
+ * the subrange into @_dst. This depends on vars defd by caller.
+ *
+ * @_i: caller provided counter var, init'd by macro
+ * @_sp: cursor into @_vec.
+ * @_box: contains member named @_vec
+ * @_vec: an array-ref, with: .start .len fields.
+ * @_dst: an array-ref: to remember the module's subrange
+ */
+#define dd_mark_vector_subrange(_i, _dst, _sp, _box, _vec) ({ \
+ int nc = 0; \
+ for_subvec(_i, _sp, _box, _vec) { \
+ if (!strcmp((_sp)->mod_name, (_dst)->mod_name)) { \
+ if (!nc++) \
+ (_dst)->info._vec.start = (_sp); \
+ } else { \
+ if (nc) \
+ break; /* end of consecutive matches */ \
+ } \
+ } \
+ (_dst)->info._vec.len = nc; \
+})
+
/*
* Allocate a new ddebug_table for the given module
* and add it to the global list.
@@ -1255,6 +1259,8 @@ static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug
static int ddebug_add_module(struct _ddebug_info *di, const char *modname)
{
struct ddebug_table *dt;
+ struct _ddebug_class_map *cm;
+ int i;
if (!di->descs.len)
return 0;
@@ -1277,6 +1283,8 @@ static int ddebug_add_module(struct _ddebug_info *di, const char *modname)
INIT_LIST_HEAD(&dt->link);
+ dd_mark_vector_subrange(i, dt, cm, di, maps);
+
if (di->maps.len)
ddebug_attach_module_classes(dt, di);
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 15/54] dyndbg: ddebug_table.mod_name down to _ddebug_info
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (13 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 14/54] dyndbg: hoist classmap-filter-by-modname up to ddebug_add_module Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 16/54] dyndbg-API: remove DD_CLASS_TYPE_(DISJOINT|LEVEL)_NAMES and code Jim Cromie
` (38 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
struct _ddebug_info already has most of dyndbg's info for a module;
push debug_table.mod_name down into it, finishing the encapsulation.
This allows refactoring several callchains, passing &_ddebug_info
instead of &ddebug_table, and hoisting the "&dt->info" deref up.
ddebug_table contains a _ddebug_info member, so its users keep access
to mod_name, just now with "->info." added in.
In static ddebug_add_module(&di), reinforce the cursor-model by
dropping the modname arg, and setting di->mod_name at each caller.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
-v3 more s/dt/di/ internal interface changes
---
include/linux/dynamic_debug.h | 1 +
lib/dynamic_debug.c | 45 ++++++++++++++++++-----------------
2 files changed, 24 insertions(+), 22 deletions(-)
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 9d282e2444e1..f4d1d08cd5a7 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -126,6 +126,7 @@ struct _ddebug_class_maps {
} __packed;
struct _ddebug_info {
+ const char *mod_name;
struct _ddebug_descs descs;
struct _ddebug_class_maps maps;
} __packed;
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 046c4ffb38f8..aff254d39c36 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -46,7 +46,6 @@ extern struct _ddebug_class_map __stop___dyndbg_class_maps[];
struct ddebug_table {
struct list_head link;
- const char *mod_name;
struct _ddebug_info info;
};
@@ -201,7 +200,7 @@ 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(query->module, dt->info.mod_name))
continue;
if (query->class_string) {
@@ -269,7 +268,7 @@ static int ddebug_change(const struct ddebug_query *query,
#endif
v4pr_info("changed %s:%d [%s]%s %s => %s\n",
trim_prefix(dp->filename), dp->lineno,
- dt->mod_name, dp->function,
+ dt->info.mod_name, dp->function,
ddebug_describe_flags(dp->flags, &fbuf),
ddebug_describe_flags(newflags, &nbuf));
dp->flags = newflags;
@@ -1133,12 +1132,12 @@ static void *ddebug_proc_next(struct seq_file *m, void *p, loff_t *pos)
#define class_in_range(class_id, map) \
(class_id >= map->base && class_id < map->base + map->length)
-static const char *ddebug_class_name(struct ddebug_table *dt, struct _ddebug *dp)
+static const char *ddebug_class_name(struct _ddebug_info *di, struct _ddebug *dp)
{
struct _ddebug_class_map *map;
int i;
- for_subvec(i, map, &dt->info, maps)
+ for_subvec(i, map, di, maps)
if (class_in_range(dp->class_id, map))
return map->class_names[dp->class_id - map->base];
@@ -1166,13 +1165,13 @@ static int ddebug_proc_show(struct seq_file *m, void *p)
seq_printf(m, "%s:%u [%s]%s =%s \"",
trim_prefix(dp->filename), dp->lineno,
- iter->table->mod_name, dp->function,
+ iter->table->info.mod_name, dp->function,
ddebug_describe_flags(dp->flags, &flags));
seq_escape_str(m, dp->format, ESCAPE_SPACE, "\t\r\n\"");
seq_putc(m, '"');
if (dp->class_id != _DPRINTK_CLASS_DFLT) {
- class = ddebug_class_name(iter->table, dp);
+ class = ddebug_class_name(&iter->table->info, dp);
if (class)
seq_printf(m, " class:%s", class);
else
@@ -1224,7 +1223,7 @@ static const struct proc_ops proc_fops = {
static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug_info *di)
{
- vpr_info("module:%s attached %d classes\n", dt->mod_name, dt->info.maps.len);
+ vpr_info("module:%s attached %d classes\n", dt->info.mod_name, dt->info.maps.len);
}
/*
@@ -1241,7 +1240,7 @@ static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug
#define dd_mark_vector_subrange(_i, _dst, _sp, _box, _vec) ({ \
int nc = 0; \
for_subvec(_i, _sp, _box, _vec) { \
- if (!strcmp((_sp)->mod_name, (_dst)->mod_name)) { \
+ if (!strcmp((_sp)->mod_name, (_dst)->info.mod_name)) { \
if (!nc++) \
(_dst)->info._vec.start = (_sp); \
} else { \
@@ -1256,7 +1255,7 @@ static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug
* Allocate a new ddebug_table for the given module
* and add it to the global list.
*/
-static int ddebug_add_module(struct _ddebug_info *di, const char *modname)
+static int ddebug_add_module(struct _ddebug_info *di)
{
struct ddebug_table *dt;
struct _ddebug_class_map *cm;
@@ -1265,20 +1264,19 @@ static int ddebug_add_module(struct _ddebug_info *di, const char *modname)
if (!di->descs.len)
return 0;
- v3pr_info("add-module: %s %d sites\n", modname, di->descs.len);
+ v3pr_info("add-module: %s %d sites\n", di->mod_name, di->descs.len);
dt = kzalloc(sizeof(*dt), GFP_KERNEL);
if (dt == NULL) {
- pr_err("error adding module: %s\n", modname);
+ pr_err("error adding module: %s\n", di->mod_name);
return -ENOMEM;
}
/*
- * For built-in modules, name lives in .rodata and is
- * immortal. For loaded modules, name points at the name[]
- * member of struct module, which lives at least as long as
- * this struct ddebug_table.
+ * For built-in modules, name (as supplied in di by its
+ * callers) lives in .rodata and is immortal. For loaded
+ * modules, name points at the name[] member of struct module,
+ * which lives at least as long as this struct ddebug_table.
*/
- dt->mod_name = modname;
dt->info = *di;
INIT_LIST_HEAD(&dt->link);
@@ -1292,7 +1290,7 @@ static int ddebug_add_module(struct _ddebug_info *di, const char *modname)
list_add_tail(&dt->link, &ddebug_tables);
mutex_unlock(&ddebug_lock);
- vpr_info("%3u debug prints in module %s\n", di->descs.len, modname);
+ vpr_info("%3u debug prints in module %s\n", di->descs.len, di->mod_name);
return 0;
}
@@ -1355,7 +1353,7 @@ static int ddebug_remove_module(const char *mod_name)
mutex_lock(&ddebug_lock);
list_for_each_entry_safe(dt, nextdt, &ddebug_tables, link) {
- if (dt->mod_name == mod_name) {
+ if (dt->info.mod_name == mod_name) {
ddebug_table_free(dt);
ret = 0;
break;
@@ -1375,7 +1373,8 @@ static int ddebug_module_notify(struct notifier_block *self, unsigned long val,
switch (val) {
case MODULE_STATE_COMING:
- ret = ddebug_add_module(&mod->dyndbg_info, mod->name);
+ mod->dyndbg_info.mod_name = mod->name;
+ ret = ddebug_add_module(&mod->dyndbg_info);
if (ret)
WARN(1, "Failed to allocate memory: dyndbg may not work properly.\n");
break;
@@ -1473,7 +1472,8 @@ static int __init dynamic_debug_init(void)
mod_ct++;
di.descs.len = mod_sites;
di.descs.start = iter_mod_start;
- ret = ddebug_add_module(&di, modname);
+ di.mod_name = modname;
+ ret = ddebug_add_module(&di);
if (ret)
goto out_err;
@@ -1484,7 +1484,8 @@ static int __init dynamic_debug_init(void)
}
di.descs.len = mod_sites;
di.descs.start = iter_mod_start;
- ret = ddebug_add_module(&di, modname);
+ di.mod_name = modname;
+ ret = ddebug_add_module(&di);
if (ret)
goto out_err;
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 16/54] dyndbg-API: remove DD_CLASS_TYPE_(DISJOINT|LEVEL)_NAMES and code
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (14 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 15/54] dyndbg: ddebug_table.mod_name down to _ddebug_info Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-15 10:00 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 17/54] dyndbg-API: replace DECLARE_DYNDBG_CLASSMAP Jim Cromie
` (37 subsequent siblings)
53 siblings, 1 reply; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
Remove the DD_CLASS_TYPE_*_NAMES classmap types and code.
These 2 classmap types accept class names at the PARAM interface, for
example:
echo +DRM_UT_CORE,-DRM_UT_KMS > /sys/module/drm/parameters/debug_names
The code works, but its only used by test-dynamic-debug, and wasn't
asked for by anyone else, so reduce LOC & test-surface; simplify things.
Also rename enum class_map_type to enum ddebug_class_map_type.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
include/linux/dynamic_debug.h | 23 ++------
lib/dynamic_debug.c | 102 +++-------------------------------
lib/test_dynamic_debug.c | 26 ---------
3 files changed, 14 insertions(+), 137 deletions(-)
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index f4d1d08cd5a7..769f02456c8e 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -58,27 +58,16 @@ struct _ddebug {
#endif
} __attribute__((aligned(8)));
-enum class_map_type {
+enum ddebug_class_map_type {
DD_CLASS_TYPE_DISJOINT_BITS,
/**
- * DD_CLASS_TYPE_DISJOINT_BITS: classes are independent, one per bit.
- * expecting hex input. Built for drm.debug, basis for other types.
+ * DD_CLASS_TYPE_DISJOINT_BITS: classes are independent, mapped to bits[0..N].
+ * Expects hex input. Built for drm.debug, basis for other types.
*/
DD_CLASS_TYPE_LEVEL_NUM,
/**
- * DD_CLASS_TYPE_LEVEL_NUM: input is numeric level, 0-N.
- * N turns on just bits N-1 .. 0, so N=0 turns all bits off.
- */
- DD_CLASS_TYPE_DISJOINT_NAMES,
- /**
- * DD_CLASS_TYPE_DISJOINT_NAMES: input is a CSV of [+-]CLASS_NAMES,
- * classes are independent, like _DISJOINT_BITS.
- */
- DD_CLASS_TYPE_LEVEL_NAMES,
- /**
- * DD_CLASS_TYPE_LEVEL_NAMES: input is a CSV of [+-]CLASS_NAMES,
- * intended for names like: INFO,DEBUG,TRACE, with a module prefix
- * avoid EMERG,ALERT,CRIT,ERR,WARNING: they're not debug
+ * DD_CLASS_TYPE_LEVEL_NUM: input is numeric level, 0..N.
+ * Input N turns on bits 0..N-1
*/
};
@@ -88,7 +77,7 @@ struct _ddebug_class_map {
const char **class_names;
const int length;
const int base; /* index of 1st .class_id, allows split/shared space */
- enum class_map_type map_type;
+ enum ddebug_class_map_type map_type;
};
/**
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index aff254d39c36..a7e1dbb6ead0 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -646,76 +646,6 @@ static int ddebug_apply_class_bitmap(const struct _ddebug_class_param *dcp,
#define CLASSMAP_BITMASK(width) ((1UL << (width)) - 1)
-/* accept comma-separated-list of [+-] classnames */
-static int param_set_dyndbg_classnames(const char *instr, const struct kernel_param *kp)
-{
- const struct _ddebug_class_param *dcp = kp->arg;
- const struct _ddebug_class_map *map = dcp->map;
- unsigned long curr_bits, old_bits;
- char *cl_str, *p, *tmp;
- int cls_id, totct = 0;
- bool wanted;
-
- cl_str = tmp = kstrdup_and_replace(instr, '\n', '\0', GFP_KERNEL);
- if (!tmp)
- return -ENOMEM;
-
- /* start with previously set state-bits, then modify */
- curr_bits = old_bits = *dcp->bits;
- vpr_info("\"%s\" > %s:0x%lx\n", cl_str, KP_NAME(kp), curr_bits);
-
- for (; cl_str; cl_str = p) {
- p = strchr(cl_str, ',');
- if (p)
- *p++ = '\0';
-
- if (*cl_str == '-') {
- wanted = false;
- cl_str++;
- } else {
- wanted = true;
- if (*cl_str == '+')
- cl_str++;
- }
- cls_id = match_string(map->class_names, map->length, cl_str);
- if (cls_id < 0) {
- pr_err("%s unknown to %s\n", cl_str, KP_NAME(kp));
- continue;
- }
-
- /* have one or more valid class_ids of one *_NAMES type */
- switch (map->map_type) {
- case DD_CLASS_TYPE_DISJOINT_NAMES:
- /* the +/- pertains to a single bit */
- if (test_bit(cls_id, &curr_bits) == wanted) {
- v3pr_info("no change on %s\n", cl_str);
- continue;
- }
- curr_bits ^= BIT(cls_id);
- totct += ddebug_apply_class_bitmap(dcp, &curr_bits, *dcp->bits, NULL);
- *dcp->bits = curr_bits;
- v2pr_info("%s: changed bit %d:%s\n", KP_NAME(kp), cls_id,
- map->class_names[cls_id]);
- break;
- case DD_CLASS_TYPE_LEVEL_NAMES:
- /* cls_id = N in 0..max. wanted +/- determines N or N-1 */
- old_bits = CLASSMAP_BITMASK(*dcp->lvl);
- curr_bits = CLASSMAP_BITMASK(cls_id + (wanted ? 1 : 0 ));
-
- totct += ddebug_apply_class_bitmap(dcp, &curr_bits, old_bits, NULL);
- *dcp->lvl = (cls_id + (wanted ? 1 : 0));
- v2pr_info("%s: changed bit-%d: \"%s\" %lx->%lx\n", KP_NAME(kp), cls_id,
- map->class_names[cls_id], old_bits, curr_bits);
- break;
- default:
- pr_err("illegal map-type value %d\n", map->map_type);
- }
- }
- kfree(tmp);
- vpr_info("total matches: %d\n", totct);
- return 0;
-}
-
static int param_set_dyndbg_module_classes(const char *instr,
const struct kernel_param *kp,
const char *mod_name)
@@ -724,29 +654,17 @@ static int param_set_dyndbg_module_classes(const char *instr,
const struct _ddebug_class_map *map = dcp->map;
unsigned long inrep, new_bits, old_bits;
int rc, totct = 0;
-
- switch (map->map_type) {
-
- case DD_CLASS_TYPE_DISJOINT_NAMES:
- case DD_CLASS_TYPE_LEVEL_NAMES:
- /* handle [+-]classnames list separately, we are done here */
- return param_set_dyndbg_classnames(instr, kp);
-
- case DD_CLASS_TYPE_DISJOINT_BITS:
- case DD_CLASS_TYPE_LEVEL_NUM:
- /* numeric input, accept and fall-thru */
- rc = kstrtoul(instr, 0, &inrep);
- if (rc) {
- pr_err("expecting numeric input: %s > %s\n", instr, KP_NAME(kp));
- return -EINVAL;
- }
- break;
- default:
- pr_err("%s: bad map type: %d\n", KP_NAME(kp), map->map_type);
+ char *nl;
+
+ rc = kstrtoul(instr, 0, &inrep);
+ if (rc) {
+ nl = strchr(instr, '\n');
+ if (nl)
+ *nl = '\0';
+ pr_err("expecting numeric input, not: %s > %s\n", instr, KP_NAME(kp));
return -EINVAL;
}
- /* only _BITS,_NUM (numeric) map-types get here */
switch (map->map_type) {
case DD_CLASS_TYPE_DISJOINT_BITS:
/* expect bits. mask and warn if too many */
@@ -812,12 +730,8 @@ int param_get_dyndbg_classes(char *buffer, const struct kernel_param *kp)
const struct _ddebug_class_map *map = dcp->map;
switch (map->map_type) {
-
- case DD_CLASS_TYPE_DISJOINT_NAMES:
case DD_CLASS_TYPE_DISJOINT_BITS:
return scnprintf(buffer, PAGE_SIZE, "0x%lx\n", *dcp->bits);
-
- case DD_CLASS_TYPE_LEVEL_NAMES:
case DD_CLASS_TYPE_LEVEL_NUM:
return scnprintf(buffer, PAGE_SIZE, "%ld\n", *dcp->lvl);
default:
diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
index 8434f70b51bb..9c3e53cd26bd 100644
--- a/lib/test_dynamic_debug.c
+++ b/lib/test_dynamic_debug.c
@@ -74,13 +74,6 @@ DECLARE_DYNDBG_CLASSMAP(map_disjoint_bits, DD_CLASS_TYPE_DISJOINT_BITS, 0,
DD_SYS_WRAP(disjoint_bits, p);
DD_SYS_WRAP(disjoint_bits, T);
-/* symbolic input, independent bits */
-enum cat_disjoint_names { LOW = 10, MID, HI };
-DECLARE_DYNDBG_CLASSMAP(map_disjoint_names, DD_CLASS_TYPE_DISJOINT_NAMES, 10,
- "LOW", "MID", "HI");
-DD_SYS_WRAP(disjoint_names, p);
-DD_SYS_WRAP(disjoint_names, T);
-
/* numeric verbosity, V2 > V1 related */
enum cat_level_num { V0 = 14, V1, V2, V3, V4, V5, V6, V7 };
DECLARE_DYNDBG_CLASSMAP(map_level_num, DD_CLASS_TYPE_LEVEL_NUM, 14,
@@ -88,13 +81,6 @@ DECLARE_DYNDBG_CLASSMAP(map_level_num, DD_CLASS_TYPE_LEVEL_NUM, 14,
DD_SYS_WRAP(level_num, p);
DD_SYS_WRAP(level_num, T);
-/* symbolic verbosity */
-enum cat_level_names { L0 = 22, L1, L2, L3, L4, L5, L6, L7 };
-DECLARE_DYNDBG_CLASSMAP(map_level_names, DD_CLASS_TYPE_LEVEL_NAMES, 22,
- "L0", "L1", "L2", "L3", "L4", "L5", "L6", "L7");
-DD_SYS_WRAP(level_names, p);
-DD_SYS_WRAP(level_names, T);
-
/* stand-in for all pr_debug etc */
#define prdbg(SYM) __pr_debug_cls(SYM, #SYM " msg\n")
@@ -102,10 +88,6 @@ static void do_cats(void)
{
pr_debug("doing categories\n");
- prdbg(LOW);
- prdbg(MID);
- prdbg(HI);
-
prdbg(D2_CORE);
prdbg(D2_DRIVER);
prdbg(D2_KMS);
@@ -129,14 +111,6 @@ static void do_levels(void)
prdbg(V5);
prdbg(V6);
prdbg(V7);
-
- prdbg(L1);
- prdbg(L2);
- prdbg(L3);
- prdbg(L4);
- prdbg(L5);
- prdbg(L6);
- prdbg(L7);
}
static void do_prints(void)
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 17/54] dyndbg-API: replace DECLARE_DYNDBG_CLASSMAP
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (15 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 16/54] dyndbg-API: remove DD_CLASS_TYPE_(DISJOINT|LEVEL)_NAMES and code Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-15 10:01 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 18/54] selftests-dyndbg: add tools/testing/selftests/dynamic_debug/* Jim Cromie
` (36 subsequent siblings)
53 siblings, 1 reply; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie, linux-doc
DECLARE_DYNDBG_CLASSMAP() has a design error; its usage fails a basic
K&R rule: "define once, refer many times".
When DRM_USE_DYNAMIC_DEBUG=y, it is used across DRM core & drivers;
each invocation allocates/inits the classmap understood by that
module. All must match for the modules to respond together when
DRM.debug categories are enabled. This is brittle; a maintenance
foot-gun.
Further, its culpable in the CONFIG_DRM_USE_DYNAMIC_DEBUG=Y
regression; its use in both core & drivers obfuscates the 2 roles, that
caused incomplete initialization when modprobing drivers:
1st drm.ko loads, and dyndbg initializes its DRM.debug callsites, then
a drm-driver loads, but too late for the DRM.debug enablement.
So retire it, replace with 2 macros:
DYNAMIC_DEBUG_CLASSMAP_DEFINE - invoked once from core - drm.ko
DYNAMIC_DEBUG_CLASSMAP_USE - from all drm drivers and helpers.
DYNAMIC_DEBUG_CLASSMAP_DEFINE: this reworks DECLARE_DYNDBG_CLASSMAP,
by dropping the static qualifier on the classmap, and exporting it
instead.
DYNAMIC_DEBUG_CLASSMAP_USE: then refers to the exported var by name:
used from drivers, helper-mods
lets us drop the repetitive "classname" declarations
fixes 2nd-defn problem
creates a ddebug_class_user record in new __dyndbg_class_users section
new section is scanned "differently"
DECLARE_DYNDBG_CLASSMAP is preserved temporarily, to decouple DRM
adaptation work and avoid compile-errs before its done. IOW, DRM gets
these fixes when they commit the adopt-new-api patches.
The DEFINE,USE distinction, and the separate classmap-use record,
allows dyndbg to initialize the driver's & helper's DRM.debug
callsites separately after each is modprobed.
Basically, the classmap init-scan is repeated for classmap-users.
To review, dyndbg's existing __dyndbg_classes[] section does:
. catalogs the module's classmaps
. tells dyndbg about them, allowing >control
. DYNAMIC_DEBUG_CLASSMAP_DEFINE creates section records.
. we rename it to: __dyndbg_class_maps[]
Then this patch adds __dyndbg_class_users[] section:
. catalogs users of classmap definitions elsewhere
. authorizes dyndbg to >control user's class'd prdbgs
. DYNAMIC_DEBUG_CLASSMAP_USE() creates section records.
Now ddebug_add_module(etal) can handle classmap-uses similar to (and
after) classmaps; when a dependent module is loaded, if it has
classmap-uses (to a classmap-def in another module), that module's
kernel params are scanned to find if it has a kparam that is wired to
dyndbg's param-ops, and whose classmap is the one being ref'd.
To support this, theres a few data/header changes:
new struct ddebug_class_user
contains: user-module-name, &classmap-defn
it records drm-driver's use of a classmap in the section, allowing lookup
struct ddebug_info gets 2 new fields for the new sections:
class_users, num_class_users.
set by dynamic_debug_init() for builtins.
or by kernel/module/main:load_info() for loadable modules.
vmlinux.lds.h: new BOUNDED_SECTION for __dyndbg_class_users
dynamic_debug.c has 2 changes in ddebug_add_module(), ddebug_change():
ddebug_add_module()
called ddebug_attach_module_classes()
now calls ddebug_apply_class_maps() & ddebug_apply_class_users()
these both call ddebug_apply_params().
ddebug_apply_params(new fn):
It scans module's/builtin kernel-params, calls ddebug_match_apply_kparam
for each to find any params/sysfs-nodes which may be wired to a classmap.
ddebug_match_apply_kparam(new fn):
1st, it tests the kernel-param.ops is dyndbg's; this guarantees that
the attached arg is a struct ddebug_class_param, which has a ref to
the param's state, and to the classmap defining the param's handling.
2nd, it requires that the classmap ref'd by the kparam is the one
we're called for; modules can use many separate classmaps (as
test_dynamic_debug does).
Then apply the "parent" kparam's setting to the dependent module,
using ddebug_apply_class_bitmap().
ddebug_change(and callees) also gets adjustments:
ddebug_find_valid_class(): This does a search over the module's
classmaps, looking for the class FOO echo'd to >control. So now it
searches over __dyndbg_class_users[] after __dyndbg_classes[].
ddebug_class_name(): return class-names for defined AND used classes.
test_dynamic_debug.c, test_dynamic_debug_submod.c:
This demonstrates the 2 types of classmaps & sysfs-params, following
the 4-part recipe:
1. define an enum for the classmap: DRM.debug has DRM_UT_{CORE,KMS,...}
multiple classes must share 0-62 classid space.
2. DYNAMIC_DEBUG_CLASSMAP_DEFINE(.. DRM_UT_{CORE,KMS,...})
3. DYNAMIC_DEBUG_CLASSMAP_PARAM* (classmap)
4. DYNAMIC_DEBUG_CLASSMAP_USE()
by _submod only, skipping 2,3
Move all the enum declarations together, to better explain how they
share the 0..62 class-id space available to a module (non-overlapping
subranges).
reorg macros 2,3 by name. This gives a tabular format, making it easy
to see the pattern of repetition, and the points of change.
And extend the test to replicate the 2-module (parent & dependent)
scenario which caused the CONFIG_DRM_USE_DYNAMIC_DEBUG=y regression
seen in drm & drivers.
The _submod.c is a 2-line file: #define _SUBMOD, #include parent.
This gives identical complements of prdbgs in parent & _submod, and
thus identical print behavior when all of: >control, >params, and
parent->_submod propagation are working correctly.
It also puts all the parent/_submod declarations together in the same
source, with the new ifdef _SUBMOD block invoking DYNAMIC_DEBUG_CLASSMAP_USE
for the 2 test-interfaces. I think this is clearer.
These 2 modules are both tristate, allowing 3 super/sub combos: Y/Y,
Y/M, M/M (not N/Y, since this is disallowed by dependence).
Y/Y testing exposed a missing __align(8) in the _METADATA macro, which
M/M didn't see because the module-loader memory placement constrains
it instead.
Fixes: aad0214f3026 ("dyndbg: add DECLARE_DYNDBG_CLASSMAP macro")
cc: linux-doc@vger.kernel.org
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
v3-
undo 1.9 simplification of ddebug_find_valid_class()
ddebug_change needs map to see its controlling param
change internal callchains to pass di, not dt
v2 a. building 2 .ko's from 1 source file is weird; add a clear
comment at the top to justify it (basically cloning)
ln 138+ in commit-msg is insufficient.
b. retire "DYNDBG_" name shortening b4 adding _CLASSMAP_* macros.
c. s/dd_class/_ddebug_class/
d. s/\bddebug\b/_$1/g in header: chgs 1 struct and UNIQUE_ID bases
v1.9 - commit-msg tweaks
DRM:CHECK warnings on macros: add parens
extern DEFINEd _var, static classnames
change ddebug_class_user.user_mod_name to .mod_name
simplify ddebug_find_valid_class return val
improve vpr_cm_info msg format
wrap (base) in macro body
move __DYNDBG_CLASSMAP_CHECK above kdoc for DYNDBG_CLASSMAP_DEFINE
v1.8 - split drm parts to separate commits.
preserve DECLARE_DYNDBG_CLASSMAP to decouple DRM, no flag day.
fixup block comment
v1.7 - previous submission-blocking bug:
missing __align(8) in DYNAMIC_DEBUG_DECLARE_METADATA on
ddebug_class_user caused corrupt records, but only for builtin
modules; module loader code probably pinned allocations to the right
alignment naturally, hiding the bug for typical builds.
v6- get rid of WARN_ON_ONCE
v?- fix _var expanded 2x in macro
dyndbg:
This fn formerly returned the map which contained the class (thus
validating it), and as a side-effect set the class-id in an outvar.
But the caller didn't use the map (after checking its not null), only
the valid class-id. So simplify the fn to return the class-id of the
validated classname, or -ENOENT when the queried classname is not
found.
Convey more useful info in the debug-msg: print class-names[0,last],
and [base,+len] instead of the class-type printout, which is almost
always "type:DISJOINT_BITS". And drop ddebug_classmap_typenames,
which is now unused.
[root@v6 b0-dd]# modprobe test_dynamic_debug_submod
[ 18.864962] dyndbg: loaded classmap: test_dynamic_debug [16..24] V0..V7
[ 18.865046] dyndbg: found kp:p_level_num =0x0
[ 18.865048] dyndbg: mapped to: test_dynamic_debug [16..24] V0..V7
[ 18.865164] dyndbg: p_level_num: lvl:0 bits:0x0
[ 18.865217] dyndbg: loaded classmap: test_dynamic_debug [0..10] D2_CORE..D2_DRMRES
[ 18.865297] dyndbg: found kp:p_disjoint_bits =0x0
[ 18.865298] dyndbg: mapped to: test_dynamic_debug [0..10] D2_CORE..D2_DRMRES
[ 18.865424] dyndbg: p_disjoint_bits: classbits: 0x0
[ 18.865472] dyndbg: module:test_dynamic_debug attached 2 classmaps
[ 18.865533] dyndbg: 23 debug prints in module test_dynamic_debug
[ 18.866558] dyndbg: loaded classmap: test_dynamic_debug_submod [16..24] V0..V7
[ 18.866698] dyndbg: found kp:p_level_num =0x0
[ 18.866699] dyndbg: mapped to: test_dynamic_debug_submod [16..24] V0..V7
[ 18.866865] dyndbg: p_level_num: lvl:0 bits:0x0
[ 18.866926] dyndbg: loaded classmap: test_dynamic_debug_submod [0..10] D2_CORE..D2_DRMRES
[ 18.867026] dyndbg: found kp:p_disjoint_bits =0x0
[ 18.867027] dyndbg: mapped to: test_dynamic_debug_submod [0..10] D2_CORE..D2_DRMRES
[ 18.867193] dyndbg: p_disjoint_bits: classbits: 0x0
[ 18.867255] dyndbg: module:test_dynamic_debug_submod attached 2 classmap uses
[ 18.867351] dyndbg: 23 debug prints in module test_dynamic_debug_submod
fixup-test-submod
fixup-test
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
MAINTAINERS | 2 +-
include/asm-generic/vmlinux.lds.h | 1 +
include/linux/dynamic_debug.h | 93 +++++++++++++++++---
kernel/module/main.c | 3 +
lib/Kconfig.debug | 24 ++++--
lib/Makefile | 3 +
lib/dynamic_debug.c | 137 +++++++++++++++++++++++++++---
lib/test_dynamic_debug.c | 132 ++++++++++++++++++++--------
lib/test_dynamic_debug_submod.c | 14 +++
9 files changed, 343 insertions(+), 66 deletions(-)
create mode 100644 lib/test_dynamic_debug_submod.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 00e94bec401e..1c5fcbd9e408 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8139,7 +8139,7 @@ M: Jim Cromie <jim.cromie@gmail.com>
S: Maintained
F: include/linux/dynamic_debug.h
F: lib/dynamic_debug.c
-F: lib/test_dynamic_debug.c
+F: lib/test_dynamic_debug*.c
DYNAMIC INTERRUPT MODERATION
M: Tal Gilboa <talgi@nvidia.com>
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index f834ad1fb8c4..fa382caf2ae2 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -367,6 +367,7 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
/* implement dynamic printk debug */ \
. = ALIGN(8); \
BOUNDED_SECTION_BY(__dyndbg_class_maps, ___dyndbg_class_maps) \
+ BOUNDED_SECTION_BY(__dyndbg_class_users, ___dyndbg_class_users) \
BOUNDED_SECTION_BY(__dyndbg_descriptors, ___dyndbg_descs) \
CODETAG_SECTIONS() \
LIKELY_PROFILE() \
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 769f02456c8e..9af825c84e70 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -71,9 +71,28 @@ enum ddebug_class_map_type {
*/
};
+/*
+ * dyndbg-classmaps are devised to support DRM.debug directly:
+ * 10 enum-vals: DRM_UT_* define the categories
+ * ~23 categorized *_dbg() macros, each passing a DRM_UT_* val as 1st arg
+ * 2 macros below them: drm_dev_dbg, __drm_dbg
+ * ~5000 calls to the categorized macros, across all of drivers/gpu/drm/
+ *
+ * When CONFIG_DRM_USE_DYNAMIC_DEBUG=y, the 2 low macros are redefined
+ * to invoke _dynamic_func_call_cls(). This compiles the category
+ * into each callsite's class_id field, where dyndbg can select on it
+ * and alter a callsite's patch-state, avoiding repeated __drm_debug
+ * checks.
+ *
+ * To make the callsites manageable from the >control file, authors
+ * provide a "classmap" of names to class_ids in use by the module(s),
+ * usually by stringifying the enum-vals. Modules with multiple
+ * classmaps must arrange to share the 0..62 class_id space.
+ */
+
struct _ddebug_class_map {
- struct module *mod;
- const char *mod_name; /* needed for builtins */
+ const struct module *mod; /* NULL for builtins */
+ const char *mod_name;
const char **class_names;
const int length;
const int base; /* index of 1st .class_id, allows split/shared space */
@@ -81,11 +100,34 @@ struct _ddebug_class_map {
};
/**
- * DECLARE_DYNDBG_CLASSMAP - declare classnames known by a module
- * @_var: a struct _ddebug_class_map, passed to module_param_cb
- * @_type: enum class_map_type, chooses bits/verbose, numeric/symbolic
- * @_base: offset of 1st class-name. splits .class_id space
- * @classes: class-names used to control class'd prdbgs
+ * DYNAMIC_DEBUG_CLASSMAP_DEFINE - define debug classes used by a module.
+ * @_var: name of the classmap, exported for other modules coordinated use.
+ * @_mapty: enum ddebug_class_map_type: 0:DISJOINT - independent, 1:LEVEL - v2>v1
+ * @_base: reserve N classids starting at _base, to split 0..62 classid space
+ * @classes: names of the N classes.
+ *
+ * This tells dyndbg what class_ids the module is using: _base..+N, by
+ * mapping names onto them. This qualifies "class NAME" >controls on
+ * the defining module, ignoring unknown names.
+ */
+#define DYNAMIC_DEBUG_CLASSMAP_DEFINE(_var, _mapty, _base, ...) \
+ static const char *_var##_classnames[] = { __VA_ARGS__ }; \
+ extern struct _ddebug_class_map _var; \
+ struct _ddebug_class_map __aligned(8) __used \
+ __section("__dyndbg_class_maps") _var = { \
+ .mod = THIS_MODULE, \
+ .mod_name = KBUILD_MODNAME, \
+ .base = (_base), \
+ .map_type = (_mapty), \
+ .length = ARRAY_SIZE(_var##_classnames), \
+ .class_names = _var##_classnames, \
+ }; \
+ EXPORT_SYMBOL(_var)
+
+/*
+ * XXX: keep this until DRM adapts to use the DEFINE/USE api, it
+ * differs from DYNAMIC_DEBUG_CLASSMAP_DEFINE by the lack of the
+ * extern/EXPORT on the struct init, and cascading thinkos.
*/
#define DECLARE_DYNDBG_CLASSMAP(_var, _maptype, _base, ...) \
static const char *_var##_classnames[] = { __VA_ARGS__ }; \
@@ -99,10 +141,35 @@ struct _ddebug_class_map {
.class_names = _var##_classnames, \
}
+struct _ddebug_class_user {
+ char *mod_name;
+ struct _ddebug_class_map *map;
+};
+
+/**
+ * DYNAMIC_DEBUG_CLASSMAP_USE - refer to a classmap, DEFINEd elsewhere.
+ * @_var: name of the exported classmap var
+ *
+ * This tells dyndbg that the module has prdbgs with classids defined
+ * in the named classmap. This qualifies "class NAME" >controls on
+ * the user module, ignoring unknown names.
+ */
+#define DYNAMIC_DEBUG_CLASSMAP_USE(_var) \
+ DYNAMIC_DEBUG_CLASSMAP_USE_(_var, __UNIQUE_ID(_ddebug_class_user))
+#define DYNAMIC_DEBUG_CLASSMAP_USE_(_var, _uname) \
+ extern struct _ddebug_class_map _var; \
+ static struct _ddebug_class_user __aligned(8) __used \
+ __section("__dyndbg_class_users") _uname = { \
+ .mod_name = KBUILD_MODNAME, \
+ .map = &(_var), \
+ }
+
/*
- * @_ddebug_info: gathers module/builtin dyndbg_* __sections together.
+ * @_ddebug_info: gathers module/builtin __dyndbg_<T> __sections
+ * together, each is a vector: a struct { <T> *addr, int len }.
+ *
* For builtins, it is used as a cursor, with the inner structs
- * marking sub-vectors of the builtin __sections in DATA.
+ * marking sub-vectors of the builtin __sections in DATA_DATA
*/
struct _ddebug_descs {
struct _ddebug *start;
@@ -114,10 +181,16 @@ struct _ddebug_class_maps {
int len;
} __packed;
+struct _ddebug_class_users {
+ struct _ddebug_class_user *start;
+ int len;
+} __packed;
+
struct _ddebug_info {
const char *mod_name;
struct _ddebug_descs descs;
struct _ddebug_class_maps maps;
+ struct _ddebug_class_users users;
} __packed;
struct _ddebug_class_param {
@@ -218,7 +291,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
* (|_no_desc): former gets callsite descriptor as 1st arg (for prdbgs)
*/
#define __dynamic_func_call_cls(id, cls, fmt, func, ...) do { \
- DEFINE_DYNAMIC_DEBUG_METADATA_CLS(id, cls, fmt); \
+ DEFINE_DYNAMIC_DEBUG_METADATA_CLS((id), cls, fmt); \
if (DYNAMIC_DEBUG_BRANCH(id)) \
func(&id, ##__VA_ARGS__); \
} while (0)
diff --git a/kernel/module/main.c b/kernel/module/main.c
index b60f728e36ac..c203b0694f7e 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -2627,6 +2627,9 @@ static int find_module_sections(struct module *mod, struct load_info *info)
mod->dyndbg_info.maps.start = section_objs(info, "__dyndbg_class_maps",
sizeof(*mod->dyndbg_info.maps.start),
&mod->dyndbg_info.maps.len);
+ mod->dyndbg_info.users.start = section_objs(info, "__dyndbg_class_users",
+ sizeof(*mod->dyndbg_info.users.start),
+ &mod->dyndbg_info.users.len);
#endif
return 0;
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 35796c290ca3..91a75f724c1a 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2905,12 +2905,26 @@ config TEST_STATIC_KEYS
If unsure, say N.
config TEST_DYNAMIC_DEBUG
- tristate "Test DYNAMIC_DEBUG"
- depends on DYNAMIC_DEBUG
+ tristate "Build test-dynamic-debug module"
+ depends on DYNAMIC_DEBUG || DYNAMIC_DEBUG_CORE
help
- This module registers a tracer callback to count enabled
- pr_debugs in a 'do_debugging' function, then alters their
- enablements, calls the function, and compares counts.
+ This module exercises/demonstrates dyndbg's classmap API, by
+ creating 2 classes: a DISJOINT classmap (supporting DRM.debug)
+ and a LEVELS/VERBOSE classmap (like verbose2 > verbose1).
+
+ If unsure, say N.
+
+config TEST_DYNAMIC_DEBUG_SUBMOD
+ tristate "Build test-dynamic-debug submodule"
+ default m
+ depends on DYNAMIC_DEBUG || DYNAMIC_DEBUG_CORE
+ depends on TEST_DYNAMIC_DEBUG
+ help
+ This sub-module uses a classmap defined and exported by the
+ parent module, recapitulating drm & driver's shared use of
+ drm.debug to control enabled debug-categories.
+ It is tristate, independent of parent, to allow testing all
+ proper combinations of parent=y/m submod=y/m.
If unsure, say N.
diff --git a/lib/Makefile b/lib/Makefile
index d5cfc7afbbb8..2c344138d990 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -84,6 +84,7 @@ obj-$(CONFIG_TEST_SORT) += test_sort.o
obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o
obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o
obj-$(CONFIG_TEST_DYNAMIC_DEBUG) += test_dynamic_debug.o
+obj-$(CONFIG_TEST_DYNAMIC_DEBUG_SUBMOD) += test_dynamic_debug_submod.o
obj-$(CONFIG_TEST_PRINTF) += test_printf.o
obj-$(CONFIG_TEST_SCANF) += test_scanf.o
@@ -226,6 +227,8 @@ obj-$(CONFIG_ARCH_NEED_CMPXCHG_1_EMU) += cmpxchg-emu.o
obj-$(CONFIG_DYNAMIC_DEBUG_CORE) += dynamic_debug.o
#ensure exported functions have prototypes
CFLAGS_dynamic_debug.o := -DDYNAMIC_DEBUG_MODULE
+CFLAGS_test_dynamic_debug.o := -DDYNAMIC_DEBUG_MODULE
+CFLAGS_test_dynamic_debug_submod.o := -DDYNAMIC_DEBUG_MODULE
obj-$(CONFIG_SYMBOLIC_ERRNAME) += errname.o
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index a7e1dbb6ead0..53e261dbf81e 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -29,6 +29,7 @@
#include <linux/string_helpers.h>
#include <linux/uaccess.h>
#include <linux/dynamic_debug.h>
+
#include <linux/debugfs.h>
#include <linux/slab.h>
#include <linux/jump_label.h>
@@ -43,6 +44,8 @@ extern struct _ddebug __start___dyndbg_descs[];
extern struct _ddebug __stop___dyndbg_descs[];
extern struct _ddebug_class_map __start___dyndbg_class_maps[];
extern struct _ddebug_class_map __stop___dyndbg_class_maps[];
+extern struct _ddebug_class_user __start___dyndbg_class_users[];
+extern struct _ddebug_class_user __stop___dyndbg_class_users[];
struct ddebug_table {
struct list_head link;
@@ -159,20 +162,37 @@ static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
query->first_lineno, query->last_lineno, query->class_string);
}
-static struct _ddebug_class_map *ddebug_find_valid_class(struct ddebug_table const *dt,
- const char *class_string,
- int *class_id)
+#define vpr_di_info(di_p, msg_p, ...) ({ \
+ struct _ddebug_info const *_di = di_p; \
+ v2pr_info(msg_p " module:%s nd:%d nc:%d nu:%d\n", ##__VA_ARGS__, \
+ _di->mod_name, _di->descs.len, _di->maps.len, \
+ _di->users.len); \
+ })
+
+static struct _ddebug_class_map *
+ddebug_find_valid_class(struct _ddebug_info const *di, const char *query_class, int *class_id)
{
struct _ddebug_class_map *map;
+ struct _ddebug_class_user *cli;
int i, idx;
- for_subvec(i, map, &dt->info, maps) {
- idx = match_string(map->class_names, map->length, class_string);
+ for_subvec(i, map, di, maps) {
+ idx = match_string(map->class_names, map->length, query_class);
if (idx >= 0) {
+ vpr_di_info(di, "good-class: %s.%s ", map->mod_name, query_class);
*class_id = idx + map->base;
return map;
}
}
+ for_subvec(i, cli, di, users) {
+ idx = match_string(cli->map->class_names, cli->map->length, query_class);
+ if (idx >= 0) {
+ vpr_di_info(di, "class-ref: %s -> %s.%s ",
+ cli->mod_name, cli->map->mod_name, query_class);
+ *class_id = idx + cli->map->base;
+ return cli->map;
+ }
+ }
*class_id = -ENOENT;
return NULL;
}
@@ -183,8 +203,7 @@ static struct _ddebug_class_map *ddebug_find_valid_class(struct ddebug_table con
* callsites, normally the same as number of changes. If verbose,
* logs the changes. Takes ddebug_lock.
*/
-static int ddebug_change(const struct ddebug_query *query,
- struct flag_settings *modifiers)
+static int ddebug_change(const struct ddebug_query *query, struct flag_settings *modifiers)
{
int i;
struct ddebug_table *dt;
@@ -204,7 +223,8 @@ static int ddebug_change(const struct ddebug_query *query,
continue;
if (query->class_string) {
- map = ddebug_find_valid_class(dt, query->class_string, &valid_class);
+ map = ddebug_find_valid_class(&dt->info, query->class_string,
+ &valid_class);
if (!map)
continue;
} else {
@@ -569,7 +589,7 @@ static int ddebug_exec_query(char *query_string, const char *modname)
/* handle multiple queries in query string, continue on error, return
last error or number of matching callsites. Module name is either
- in param (for boot arg) or perhaps in query string.
+ in the modname arg (for boot args) or perhaps in query string.
*/
static int ddebug_exec_queries(char *query, const char *modname)
{
@@ -700,7 +720,7 @@ static int param_set_dyndbg_module_classes(const char *instr,
/**
* param_set_dyndbg_classes - classmap kparam setter
* @instr: string echo>d to sysfs, input depends on map_type
- * @kp: kp->arg has state: bits/lvl, map, map_type
+ * @kp: kp->arg has state: bits/lvl, classmap, map_type
*
* enable/disable all class'd pr_debugs in the classmap. For LEVEL
* map-types, enforce * relative levels by bitpos.
@@ -737,6 +757,7 @@ int param_get_dyndbg_classes(char *buffer, const struct kernel_param *kp)
default:
return -1;
}
+ return 0;
}
EXPORT_SYMBOL(param_get_dyndbg_classes);
@@ -1049,12 +1070,17 @@ static void *ddebug_proc_next(struct seq_file *m, void *p, loff_t *pos)
static const char *ddebug_class_name(struct _ddebug_info *di, struct _ddebug *dp)
{
struct _ddebug_class_map *map;
+ struct _ddebug_class_user *cli;
int i;
for_subvec(i, map, di, maps)
if (class_in_range(dp->class_id, map))
return map->class_names[dp->class_id - map->base];
+ for_subvec(i, cli, di, users)
+ if (class_in_range(dp->class_id, cli->map))
+ return cli->map->class_names[dp->class_id - cli->map->base];
+
return NULL;
}
@@ -1135,9 +1161,85 @@ static const struct proc_ops proc_fops = {
.proc_write = ddebug_proc_write
};
-static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug_info *di)
+#define vpr_cm_info(cm_p, msg_fmt, ...) ({ \
+ struct _ddebug_class_map const *_cm = cm_p; \
+ v2pr_info(msg_fmt " %s [%d..%d] %s..%s\n", ##__VA_ARGS__, \
+ _cm->mod_name, _cm->base, _cm->base + _cm->length, \
+ _cm->class_names[0], _cm->class_names[_cm->length - 1]); \
+ })
+
+static void ddebug_sync_classbits(const struct kernel_param *kp, const char *modname)
+{
+ const struct _ddebug_class_param *dcp = kp->arg;
+
+ /* clamp initial bitvec, mask off hi-bits */
+ if (*dcp->bits & ~CLASSMAP_BITMASK(dcp->map->length)) {
+ *dcp->bits &= CLASSMAP_BITMASK(dcp->map->length);
+ v2pr_info("preset classbits: %lx\n", *dcp->bits);
+ }
+ /* force class'd prdbgs (in USEr module) to match (DEFINEr module) class-param */
+ ddebug_apply_class_bitmap(dcp, dcp->bits, ~0, modname);
+ ddebug_apply_class_bitmap(dcp, dcp->bits, 0, modname);
+}
+
+static void ddebug_match_apply_kparam(const struct kernel_param *kp,
+ const struct _ddebug_class_map *map,
+ const char *mod_name)
+{
+ struct _ddebug_class_param *dcp;
+
+ if (kp->ops != ¶m_ops_dyndbg_classes)
+ return;
+
+ dcp = (struct _ddebug_class_param *)kp->arg;
+
+ if (map == dcp->map) {
+ v2pr_info(" kp:%s.%s =0x%lx", mod_name, kp->name, *dcp->bits);
+ vpr_cm_info(map, " %s mapped to: ", mod_name);
+ ddebug_sync_classbits(kp, mod_name);
+ }
+}
+
+static void ddebug_apply_params(const struct _ddebug_class_map *cm, const char *mod_name)
+{
+ const struct kernel_param *kp;
+#if IS_ENABLED(CONFIG_MODULES)
+ int i;
+
+ if (cm->mod) {
+ vpr_cm_info(cm, "loaded classmap: %s", mod_name);
+ /* ifdef protects the cm->mod->kp deref */
+ for (i = 0, kp = cm->mod->kp; i < cm->mod->num_kp; i++, kp++)
+ ddebug_match_apply_kparam(kp, cm, mod_name);
+ }
+#endif
+ if (!cm->mod) {
+ vpr_cm_info(cm, "builtin classmap: %s", mod_name);
+ for (kp = __start___param; kp < __stop___param; kp++)
+ ddebug_match_apply_kparam(kp, cm, mod_name);
+ }
+}
+
+static void ddebug_apply_class_maps(const struct _ddebug_info *di)
+{
+ struct _ddebug_class_map *cm;
+ int i;
+
+ for_subvec(i, cm, di, maps)
+ ddebug_apply_params(cm, cm->mod_name);
+
+ vpr_di_info(di, "attached %d classmaps to module: %s ", i, cm->mod_name);
+}
+
+static void ddebug_apply_class_users(const struct _ddebug_info *di)
{
- vpr_info("module:%s attached %d classes\n", dt->info.mod_name, dt->info.maps.len);
+ struct _ddebug_class_user *cli;
+ int i;
+
+ for_subvec(i, cli, di, users)
+ ddebug_apply_params(cli->map, cli->mod_name);
+
+ vpr_di_info(di, "attached %d class-users to module: %s ", i, cli->mod_name);
}
/*
@@ -1173,6 +1275,7 @@ static int ddebug_add_module(struct _ddebug_info *di)
{
struct ddebug_table *dt;
struct _ddebug_class_map *cm;
+ struct _ddebug_class_user *cli;
int i;
if (!di->descs.len)
@@ -1196,14 +1299,18 @@ static int ddebug_add_module(struct _ddebug_info *di)
INIT_LIST_HEAD(&dt->link);
dd_mark_vector_subrange(i, dt, cm, di, maps);
+ dd_mark_vector_subrange(i, dt, cli, di, users);
- if (di->maps.len)
- ddebug_attach_module_classes(dt, di);
+ if (dt->info.maps.len)
+ ddebug_apply_class_maps(&dt->info);
mutex_lock(&ddebug_lock);
list_add_tail(&dt->link, &ddebug_tables);
mutex_unlock(&ddebug_lock);
+ if (dt->info.users.len)
+ ddebug_apply_class_users(&dt->info);
+
vpr_info("%3u debug prints in module %s\n", di->descs.len, di->mod_name);
return 0;
}
@@ -1354,8 +1461,10 @@ static int __init dynamic_debug_init(void)
struct _ddebug_info di = {
.descs.start = __start___dyndbg_descs,
.maps.start = __start___dyndbg_class_maps,
+ .users.start = __start___dyndbg_class_users,
.descs.len = __stop___dyndbg_descs - __start___dyndbg_descs,
.maps.len = __stop___dyndbg_class_maps - __start___dyndbg_class_maps,
+ .users.len = __stop___dyndbg_class_users - __start___dyndbg_class_users,
};
#ifdef CONFIG_MODULES
diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
index 9c3e53cd26bd..1070107f74f1 100644
--- a/lib/test_dynamic_debug.c
+++ b/lib/test_dynamic_debug.c
@@ -6,11 +6,30 @@
* Jim Cromie <jim.cromie@gmail.com>
*/
-#define pr_fmt(fmt) "test_dd: " fmt
+/*
+ * This file is built 2x, also making test_dynamic_debug_submod.ko,
+ * whose 2-line src file #includes this file. This gives us a _submod
+ * clone with identical pr_debugs, without further maintenance.
+ *
+ * If things are working properly, they should operate identically
+ * when printed or adjusted by >control. This eases visual perusal of
+ * the logs, and simplifies testing, by easing the proper accounting
+ * of expectations.
+ *
+ * It also puts both halves of the subsystem _DEFINE & _USE use case
+ * together, and integrates the common ENUM providing both class_ids
+ * and class-names to both _DEFINErs and _USERs. I think this makes
+ * the usage clearer.
+ */
+#if defined(TEST_DYNAMIC_DEBUG_SUBMOD)
+ #define pr_fmt(fmt) "test_dd_submod: " fmt
+#else
+ #define pr_fmt(fmt) "test_dd: " fmt
+#endif
#include <linux/module.h>
-/* run tests by reading or writing sysfs node: do_prints */
+/* re-gen output by reading or writing sysfs node: do_prints */
static void do_prints(void); /* device under test */
static int param_set_do_prints(const char *instr, const struct kernel_param *kp)
@@ -29,24 +48,39 @@ static const struct kernel_param_ops param_ops_do_prints = {
};
module_param_cb(do_prints, ¶m_ops_do_prints, NULL, 0600);
-/*
- * Using the CLASSMAP api:
- * - classmaps must have corresponding enum
- * - enum symbols must match/correlate with class-name strings in the map.
- * - base must equal enum's 1st value
- * - multiple maps must set their base to share the 0-30 class_id space !!
- * (build-bug-on tips welcome)
- * Additionally, here:
- * - tie together sysname, mapname, bitsname, flagsname
- */
-#define DD_SYS_WRAP(_model, _flags) \
- static unsigned long bits_##_model; \
- static struct _ddebug_class_param _flags##_model = { \
+#define CLASSMAP_BITMASK(width, base) (((1UL << (width)) - 1) << (base))
+
+/* sysfs param wrapper, proto-API */
+#define DYNAMIC_DEBUG_CLASSMAP_PARAM_(_model, _flags, _init) \
+ static unsigned long bits_##_model = _init; \
+ static struct _ddebug_class_param _flags##_##_model = { \
.bits = &bits_##_model, \
.flags = #_flags, \
.map = &map_##_model, \
}; \
- module_param_cb(_flags##_##_model, ¶m_ops_dyndbg_classes, &_flags##_model, 0600)
+ module_param_cb(_flags##_##_model, ¶m_ops_dyndbg_classes, \
+ &_flags##_##_model, 0600)
+#ifdef DEBUG
+#define DYNAMIC_DEBUG_CLASSMAP_PARAM(_model, _flags) \
+ DYNAMIC_DEBUG_CLASSMAP_PARAM_(_model, _flags, ~0)
+#else
+#define DYNAMIC_DEBUG_CLASSMAP_PARAM(_model, _flags) \
+ DYNAMIC_DEBUG_CLASSMAP_PARAM_(_model, _flags, 0)
+#endif
+
+/*
+ * Demonstrate/test DISJOINT & LEVEL typed classmaps with a sys-param.
+ *
+ * To comport with DRM debug-category (an int), classmaps map names to
+ * ids (also an int). So a classmap starts with an enum; DRM has enum
+ * debug_category: with DRM_UT_<CORE,DRIVER,KMS,etc>. We use the enum
+ * values as class-ids, and stringified enum-symbols as classnames.
+ *
+ * Modules with multiple CLASSMAPS must have enums with distinct
+ * value-ranges, as arranged below with explicit enum_sym = X inits.
+ * To clarify this sharing, declare the 2 enums now, for the 2
+ * different classmap types
+ */
/* numeric input, independent bits */
enum cat_disjoint_bits {
@@ -60,26 +94,51 @@ enum cat_disjoint_bits {
D2_LEASE,
D2_DP,
D2_DRMRES };
-DECLARE_DYNDBG_CLASSMAP(map_disjoint_bits, DD_CLASS_TYPE_DISJOINT_BITS, 0,
- "D2_CORE",
- "D2_DRIVER",
- "D2_KMS",
- "D2_PRIME",
- "D2_ATOMIC",
- "D2_VBL",
- "D2_STATE",
- "D2_LEASE",
- "D2_DP",
- "D2_DRMRES");
-DD_SYS_WRAP(disjoint_bits, p);
-DD_SYS_WRAP(disjoint_bits, T);
-
-/* numeric verbosity, V2 > V1 related */
-enum cat_level_num { V0 = 14, V1, V2, V3, V4, V5, V6, V7 };
-DECLARE_DYNDBG_CLASSMAP(map_level_num, DD_CLASS_TYPE_LEVEL_NUM, 14,
- "V0", "V1", "V2", "V3", "V4", "V5", "V6", "V7");
-DD_SYS_WRAP(level_num, p);
-DD_SYS_WRAP(level_num, T);
+
+/* numeric verbosity, V2 > V1 related. V0 is > D2_DRM_RES */
+enum cat_level_num { V0 = 16, V1, V2, V3, V4, V5, V6, V7 };
+
+/* recapitulate DRM's multi-classmap setup */
+#if !defined(TEST_DYNAMIC_DEBUG_SUBMOD)
+/*
+ * In single user, or parent / coordinator (drm.ko) modules, define
+ * classmaps on the client enums above, and then declares the PARAMS
+ * ref'g the classmaps. Each is exported.
+ */
+DYNAMIC_DEBUG_CLASSMAP_DEFINE(map_disjoint_bits, DD_CLASS_TYPE_DISJOINT_BITS,
+ D2_CORE,
+ "D2_CORE",
+ "D2_DRIVER",
+ "D2_KMS",
+ "D2_PRIME",
+ "D2_ATOMIC",
+ "D2_VBL",
+ "D2_STATE",
+ "D2_LEASE",
+ "D2_DP",
+ "D2_DRMRES");
+
+DYNAMIC_DEBUG_CLASSMAP_DEFINE(map_level_num, DD_CLASS_TYPE_LEVEL_NUM,
+ V0, "V0", "V1", "V2", "V3", "V4", "V5", "V6", "V7");
+
+/*
+ * now add the sysfs-params
+ */
+
+DYNAMIC_DEBUG_CLASSMAP_PARAM(disjoint_bits, p);
+DYNAMIC_DEBUG_CLASSMAP_PARAM(level_num, p);
+
+#else /* TEST_DYNAMIC_DEBUG_SUBMOD */
+
+/*
+ * in submod/drm-drivers, use the classmaps defined in top/parent
+ * module above.
+ */
+
+DYNAMIC_DEBUG_CLASSMAP_USE(map_disjoint_bits);
+DYNAMIC_DEBUG_CLASSMAP_USE(map_level_num);
+
+#endif
/* stand-in for all pr_debug etc */
#define prdbg(SYM) __pr_debug_cls(SYM, #SYM " msg\n")
@@ -115,6 +174,7 @@ static void do_levels(void)
static void do_prints(void)
{
+ pr_debug("do_prints:\n");
do_cats();
do_levels();
}
diff --git a/lib/test_dynamic_debug_submod.c b/lib/test_dynamic_debug_submod.c
new file mode 100644
index 000000000000..672aabf40160
--- /dev/null
+++ b/lib/test_dynamic_debug_submod.c
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Kernel module for testing dynamic_debug
+ *
+ * Authors:
+ * Jim Cromie <jim.cromie@gmail.com>
+ */
+
+/*
+ * clone the parent, inherit all the properties, for consistency and
+ * simpler accounting in test expectations.
+ */
+#define TEST_DYNAMIC_DEBUG_SUBMOD
+#include "test_dynamic_debug.c"
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 18/54] selftests-dyndbg: add tools/testing/selftests/dynamic_debug/*
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (16 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 17/54] dyndbg-API: replace DECLARE_DYNDBG_CLASSMAP Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-15 10:02 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 19/54] dyndbg: detect class_id reservation conflicts Jim Cromie
` (35 subsequent siblings)
53 siblings, 1 reply; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
Add a selftest script for dynamic-debug. The config requires
CONFIG_TEST_DYNAMIC_DEBUG=m and CONFIG_TEST_DYNAMIC_DEBUG_SUBMOD=m,
which tacitly requires either CONFIG_DYNAMIC_DEBUG=y or
CONFIG_DYNAMIC_DEBUG_CORE=y
ATM this has just basic_tests(), which modify pr_debug() flags in the
builtin params module. This means they're available to manipulate and
observe the effects in "cat control".
This is backported from another feature branch; the support-fns (thx
Lukas) have unused features at the moment, they'll get used shortly.
The script enables simple virtme-ng testing:
[jimc@gandalf b0-ftrace]$ vrun_t
virtme-ng 1.32+115.g07b109d
doing: vng --name v6.14-rc4-60-gd5f48427de0c \
--user root -v -p 4 -a dynamic_debug.verbose=3 V=1 \
-- ../tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
virtme: waiting for virtiofsd to start
..
And add dynamic_debug to TARGETS, so `make run_tests` sees it properly
For the impatient, set TARGETS explicitly:
bash-5.2# make TARGETS=dynamic_debug run_tests
make[1]: ...
TAP version 13
1..1
[ 35.552922] dyndbg: read 3 bytes from userspace
[ 35.553099] dyndbg: query 0: "=_" mod:*
[ 35.553544] dyndbg: processed 1 queries, with 1778 matches, 0 errs
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Co-developed-by: Łukasz Bartosik <ukaszb@chromium.org>
Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
---
-r3 turn off green at end
drop config dep on TEST_DYNAMIC_DEBUG,
since basic-test uses builtin params
- check KCONFIG_CONFIG to avoid silly fails
Several tests are dependent upon config choices. Lets avoid failing
where that is noise.
The KCONFIG_CONFIG var exists to convey the config-file around. If
the var names a file, read it and extract the relevant CONFIG items,
and use them to skip the dependent tests, thus avoiding the fails that
would follow, and the disruption to whatever CI is running these
selftests.
If the envar doesn't name a config-file, ".config" is assumed.
CONFIG_DYNAMIC_DEBUG=y:
basic-tests() and comma-terminator-tests() test for the presence of
the builtin pr_debugs in module/main.c, which I deemed stable and
therefore safe to count. That said, the test fails if only
CONFIG_DYNAMIC_DEBUG_CORE=y is set. It could be rewritten to test
against test-dynamic-debug.ko, but that just trades one config
dependence for another.
CONFIG_TEST_DYNAMIC_DEBUG=m
As written, test_percent_splitting() modprobes test_dynamic_debug,
enables several classes, and count them. It could be re-written to
work for the builtin module also, but builtin test modules are not a
common or desirable build/config.
CONFIG_TEST_DYNAMIC_DEBUG=m && CONFIG_TEST_DYNAMIC_DEBUG_SUBMOD=m
test_mod_submod() recaps the bug found in DRM-CI where drivers werent
enabled by drm.debug=<bits>. It modprobes both test_dynamic_debug &
test_dynamic_debug_submod, so it depends on a loadable modules config.
It could be rewritten to work in a builtin parent config; DRM=y is
common enough to be pertinent, but testing that config also wouldn't
really test anything more fully than all-loadable modules, since they
default together.
generalize-test-env
---
MAINTAINERS | 1 +
tools/testing/selftests/Makefile | 1 +
.../testing/selftests/dynamic_debug/Makefile | 9 +
tools/testing/selftests/dynamic_debug/config | 7 +
.../dynamic_debug/dyndbg_selftest.sh | 257 ++++++++++++++++++
5 files changed, 275 insertions(+)
create mode 100644 tools/testing/selftests/dynamic_debug/Makefile
create mode 100644 tools/testing/selftests/dynamic_debug/config
create mode 100755 tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
diff --git a/MAINTAINERS b/MAINTAINERS
index 1c5fcbd9e408..1192ad6c65c1 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8140,6 +8140,7 @@ S: Maintained
F: include/linux/dynamic_debug.h
F: lib/dynamic_debug.c
F: lib/test_dynamic_debug*.c
+F: tools/testing/selftests/dynamic_debug/*
DYNAMIC INTERRUPT MODERATION
M: Tal Gilboa <talgi@nvidia.com>
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 8daac70c2f9d..b6a323c7f986 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -26,6 +26,7 @@ TARGETS += drivers/net/team
TARGETS += drivers/net/virtio_net
TARGETS += drivers/platform/x86/intel/ifs
TARGETS += dt
+TARGETS += dynamic_debug
TARGETS += efivarfs
TARGETS += exec
TARGETS += fchmodat2
diff --git a/tools/testing/selftests/dynamic_debug/Makefile b/tools/testing/selftests/dynamic_debug/Makefile
new file mode 100644
index 000000000000..6d06fa7f1040
--- /dev/null
+++ b/tools/testing/selftests/dynamic_debug/Makefile
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# borrowed from Makefile for user memory selftests
+
+# No binaries, but make sure arg-less "make" doesn't trigger "run_tests"
+all:
+
+TEST_PROGS := dyndbg_selftest.sh
+
+include ../lib.mk
diff --git a/tools/testing/selftests/dynamic_debug/config b/tools/testing/selftests/dynamic_debug/config
new file mode 100644
index 000000000000..0f906ff53908
--- /dev/null
+++ b/tools/testing/selftests/dynamic_debug/config
@@ -0,0 +1,7 @@
+
+# basic tests ref the builtin params module
+CONFIG_DYNAMIC_DEBUG=m
+
+# more testing is possible with these
+# CONFIG_TEST_DYNAMIC_DEBUG=m
+# CONFIG_TEST_DYNAMIC_DEBUG_SUBMOD=m
diff --git a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
new file mode 100755
index 000000000000..465fad3f392c
--- /dev/null
+++ b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
@@ -0,0 +1,257 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+
+V=${V:=0} # invoke as V=1 $0 for global verbose
+RED="\033[0;31m"
+GREEN="\033[0;32m"
+YELLOW="\033[0;33m"
+BLUE="\033[0;34m"
+MAGENTA="\033[0;35m"
+CYAN="\033[0;36m"
+NC="\033[0;0m"
+error_msg=""
+
+[ -e /proc/dynamic_debug/control ] || {
+ echo -e "${RED}: this test requires CONFIG_DYNAMIC_DEBUG=y ${NC}"
+ exit 0 # nothing to test here, no good reason to fail.
+}
+
+# need info to avoid failures due to untestable configs
+
+[ -f "$KCONFIG_CONFIG" ] || KCONFIG_CONFIG=".config"
+if [ -f "$KCONFIG_CONFIG" ]; then
+ echo "# consulting KCONFIG_CONFIG: $KCONFIG_CONFIG"
+ grep -q "CONFIG_DYNAMIC_DEBUG=y" $KCONFIG_CONFIG ; LACK_DD_BUILTIN=$?
+ grep -q "CONFIG_TEST_DYNAMIC_DEBUG=m" $KCONFIG_CONFIG ; LACK_TMOD=$?
+ grep -q "CONFIG_TEST_DYNAMIC_DEBUG_SUBMOD=m" $KCONFIG_CONFIG ; LACK_TMOD_SUBMOD=$?
+ if [ $V -eq 1 ]; then
+ echo LACK_DD_BUILTIN: $LACK_DD_BUILTIN
+ echo LACK_TMOD: $LACK_TMOD
+ echo LACK_TMOD_SUBMOD: $LACK_TMOD_SUBMOD
+ fi
+else
+ LACK_DD_BUILTIN=0
+ LACK_TMOD=0
+ LACK_TMOD_SUBMOD=0
+fi
+
+function vx () {
+ echo $1 > /sys/module/dynamic_debug/parameters/verbose
+}
+
+function ddgrep () {
+ grep $1 /proc/dynamic_debug/control
+}
+
+function doprints () {
+ cat /sys/module/test_dynamic_debug/parameters/do_prints
+}
+
+function ddcmd () {
+ exp_exit_code=0
+ num_args=$#
+ if [ "${@:$#}" = "pass" ]; then
+ num_args=$#-1
+ elif [ "${@:$#}" = "fail" ]; then
+ num_args=$#-1
+ exp_exit_code=1
+ fi
+ args=${@:1:$num_args}
+ output=$((echo "$args" > /proc/dynamic_debug/control) 2>&1)
+ exit_code=$?
+ error_msg=$(echo $output | cut -d ":" -f 5 | sed -e 's/^[[:space:]]*//')
+ handle_exit_code $BASH_LINENO $FUNCNAME $exit_code $exp_exit_code
+}
+
+function handle_exit_code() {
+ local exp_exit_code=0
+ [ $# == 4 ] && exp_exit_code=$4
+ if [ $3 -ne $exp_exit_code ]; then
+ echo -e "${RED}: $BASH_SOURCE:$1 $2() expected to exit with code $exp_exit_code"
+ [ $3 == 1 ] && echo "Error: '$error_msg'"
+ exit
+ fi
+}
+
+# $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
+# $4 - optional when $3 is set to "-r" then $4 can be used to pass "-v"
+function check_match_ct {
+ pattern="\s$1\s"
+ exp_cnt=0
+
+ [ "$3" == "-r" ] && pattern="$1"
+ let cnt=$(ddgrep "$pattern" | wc -l)
+ if [ $V -eq 1 ] || [ "$3" == "-v" ] || [ "$4" == "-v" ]; then
+ echo -ne "${BLUE}" && ddgrep $pattern && echo -ne "${NC}"
+ fi
+ [ $# -gt 1 ] && exp_cnt=$2
+ if [ $cnt -ne $exp_cnt ]; then
+ echo -e "${RED}: $BASH_SOURCE:$BASH_LINENO check failed expected $exp_cnt on $1, got $cnt"
+ exit
+ else
+ echo ": $cnt matches on $1"
+ fi
+}
+
+# $1 - trace instance name
+# #2 - if > 0 then directory is expected to exist, if <= 0 then otherwise
+# $3 - "-v" for verbose
+function check_trace_instance_dir {
+ if [ -e /sys/kernel/tracing/instances/$1 ]; then
+ if [ "$3" == "-v" ] ; then
+ echo "ls -l /sys/kernel/tracing/instances/$1: "
+ ls -l /sys/kernel/tracing/instances/$1
+ fi
+ if [ $2 -le 0 ]; then
+ echo -e "${RED}: $BASH_SOURCE:$BASH_LINENO error trace instance \
+ '/sys/kernel/tracing/instances/$1' does exist"
+ exit
+ fi
+ else
+ if [ $2 -gt 0 ]; then
+ echo -e "${RED}: $BASH_SOURCE:$BASH_LINENO error trace instance \
+ '/sys/kernel/tracing/instances/$1' does not exist"
+ exit
+ fi
+ fi
+}
+
+function tmark {
+ echo $* > /sys/kernel/tracing/trace_marker
+}
+
+# $1 - trace instance name
+# $2 - line number
+# $3 - if > 0 then the instance is expected to be opened, otherwise
+# the instance is expected to be closed
+function check_trace_instance {
+ output=$(tail -n9 /proc/dynamic_debug/control | grep ": Opened trace instances" \
+ | xargs -n1 | grep $1)
+ if [ "$output" != $1 ] && [ $3 -gt 0 ]; then
+ echo -e "${RED}: $BASH_SOURCE:$2 trace instance $1 is not opened"
+ exit
+ fi
+ if [ "$output" == $1 ] && [ $3 -le 0 ]; then
+ echo -e "${RED}: $BASH_SOURCE:$2 trace instance $1 is not closed"
+ exit
+ fi
+}
+
+function is_trace_instance_opened {
+ check_trace_instance $1 $BASH_LINENO 1
+}
+
+function is_trace_instance_closed {
+ check_trace_instance $1 $BASH_LINENO 0
+}
+
+# $1 - trace instance directory to delete
+# $2 - if > 0 then directory is expected to be deleted successfully, if <= 0 then otherwise
+function del_trace_instance_dir() {
+ exp_exit_code=1
+ [ $2 -gt 0 ] && exp_exit_code=0
+ output=$((rmdir /sys/kernel/debug/tracing/instances/$1) 2>&1)
+ exit_code=$?
+ error_msg=$(echo $output | cut -d ":" -f 3 | sed -e 's/^[[:space:]]*//')
+ handle_exit_code $BASH_LINENO $FUNCNAME $exit_code $exp_exit_code
+}
+
+function error_log_ref {
+ # to show what I got
+ : echo "# error-log-ref: $1"
+ : echo cat \$2
+}
+
+function ifrmmod {
+ lsmod | grep $1 2>&1>/dev/null && rmmod $1
+}
+
+# $1 - text to search for
+function search_trace() {
+ search_trace_name 0 1 $1
+}
+
+# $1 - trace instance name, 0 for global event trace
+# $2 - line number counting from the bottom
+# $3 - text to search for
+function search_trace_name() {
+ if [ "$1" = "0" ]; then
+ buf=$(cat /sys/kernel/debug/tracing/trace)
+ line=$(tail -$2 /sys/kernel/debug/tracing/trace | head -1 | sed -e 's/^[[:space:]]*//')
+ else
+ buf=$(cat /sys/kernel/debug/tracing/instances/$1/trace)
+ line=$(tail -$2 /sys/kernel/debug/tracing/instances/$1/trace | head -1 | \
+ sed -e 's/^[[:space:]]*//')
+ fi
+ if [ $2 = 0 ]; then
+ # whole-buf check
+ output=$(echo $buf | grep "$3")
+ else
+ output=$(echo $line | grep "$3")
+ fi
+ if [ "$output" = "" ]; then
+ echo -e "${RED}: $BASH_SOURCE:$BASH_LINENO search for '$3' failed \
+ in line '$line' or '$buf'"
+ exit
+ fi
+ if [ $V = 1 ]; then
+ echo -e "${MAGENTA}: search_trace_name in $1 found: \n$output \nin:${BLUE} $buf ${NC}"
+ fi
+}
+
+# $1 - error message to check
+function check_err_msg() {
+ if [ "$error_msg" != "$1" ]; then
+ echo -e "${RED}: $BASH_SOURCE:$BASH_LINENO error message '$error_msg' \
+ does not match with '$1'"
+ exit
+ fi
+}
+
+function basic_tests {
+ echo -e "${GREEN}# BASIC_TESTS ${NC}"
+ if [ $LACK_DD_BUILTIN -eq 1 ]; then
+ echo "SKIP"
+ return
+ fi
+ ddcmd =_ # zero everything
+ check_match_ct =p 0
+
+ # module params are builtin to handle boot args
+ check_match_ct '\[params\]' 4 -r
+ ddcmd module params +mpf
+ check_match_ct =pmf 4
+
+ # multi-cmd input, newline separated, with embedded comments
+ cat <<"EOF" > /proc/dynamic_debug/control
+ module params =_ # clear params
+ module params +mf # set flags
+ module params func parse_args +sl # other flags
+EOF
+ check_match_ct =mf 3
+ check_match_ct =mfsl 1
+ ddcmd =_
+}
+
+tests_list=(
+ basic_tests
+)
+
+# Run tests
+
+ifrmmod test_dynamic_debug_submod
+ifrmmod test_dynamic_debug
+
+for test in "${tests_list[@]}"
+do
+ $test
+ echo ""
+done
+echo -en "${GREEN}# Done on: "
+date
+echo -en "${NC}"
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 19/54] dyndbg: detect class_id reservation conflicts
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (17 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 18/54] selftests-dyndbg: add tools/testing/selftests/dynamic_debug/* Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-15 10:03 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 20/54] dyndbg: check DYNAMIC_DEBUG_CLASSMAP_DEFINE args at compile-time Jim Cromie
` (34 subsequent siblings)
53 siblings, 1 reply; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
If a module _DEFINEs + _USEs 2 or more classmaps, it must devise them
to share the per-module 0..62 class-id space; ie their respective
base,+length reservations cannot overlap.
To detect conflicts at modprobe, add ddebug_class_range_overlap(),
call it from ddebug_add_module(), and WARN and return -EINVAL when
they're detected.
test_dynamic_debug.c:
If built with -DFORCE_CLASSID_CONFLICT, the test-modules get 2 bad
DYNDBG_CLASS_DEFINE declarations, into parent and the _submod. These
conflict with one of the good ones in the parent (D2_CORE..etc),
causing the modprobe(s) to warn
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
---
lib/dynamic_debug.c | 29 +++++++++++++++++++++++++++++
lib/test_dynamic_debug.c | 8 ++++++++
2 files changed, 37 insertions(+)
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 53e261dbf81e..56b503af0b31 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -1267,6 +1267,22 @@ static void ddebug_apply_class_users(const struct _ddebug_info *di)
(_dst)->info._vec.len = nc; \
})
+static int __maybe_unused
+ddebug_class_range_overlap(struct _ddebug_class_map *cm,
+ u64 *reserved_ids)
+{
+ u64 range = (((1ULL << cm->length) - 1) << cm->base);
+
+ if (range & *reserved_ids) {
+ pr_err("[%d..%d] on %s conflicts with %llx\n", cm->base,
+ cm->base + cm->length - 1, cm->class_names[0],
+ *reserved_ids);
+ return -EINVAL;
+ }
+ *reserved_ids |= range;
+ return 0;
+}
+
/*
* Allocate a new ddebug_table for the given module
* and add it to the global list.
@@ -1276,6 +1292,7 @@ static int ddebug_add_module(struct _ddebug_info *di)
struct ddebug_table *dt;
struct _ddebug_class_map *cm;
struct _ddebug_class_user *cli;
+ u64 reserved_ids = 0;
int i;
if (!di->descs.len)
@@ -1301,6 +1318,13 @@ static int ddebug_add_module(struct _ddebug_info *di)
dd_mark_vector_subrange(i, dt, cm, di, maps);
dd_mark_vector_subrange(i, dt, cli, di, users);
+ for_subvec(i, cm, &dt->info, maps)
+ if (ddebug_class_range_overlap(cm, &reserved_ids))
+ goto cleanup;
+ for_subvec(i, cli, &dt->info, users)
+ if (ddebug_class_range_overlap(cli->map, &reserved_ids))
+ goto cleanup;
+
if (dt->info.maps.len)
ddebug_apply_class_maps(&dt->info);
@@ -1313,6 +1337,11 @@ static int ddebug_add_module(struct _ddebug_info *di)
vpr_info("%3u debug prints in module %s\n", di->descs.len, di->mod_name);
return 0;
+cleanup:
+ WARN_ONCE("dyndbg multi-classmap conflict in %s\n", di->mod_name);
+ kfree(dt);
+ return -EINVAL;
+
}
/* helper for ddebug_dyndbg_(boot|module)_param_cb */
diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
index 1070107f74f1..e42916b08fd4 100644
--- a/lib/test_dynamic_debug.c
+++ b/lib/test_dynamic_debug.c
@@ -128,6 +128,14 @@ DYNAMIC_DEBUG_CLASSMAP_DEFINE(map_level_num, DD_CLASS_TYPE_LEVEL_NUM,
DYNAMIC_DEBUG_CLASSMAP_PARAM(disjoint_bits, p);
DYNAMIC_DEBUG_CLASSMAP_PARAM(level_num, p);
+#ifdef FORCE_CLASSID_CONFLICT
+/*
+ * Enable with -Dflag on compile to test overlapping class-id range
+ * detection. This should warn on modprobes.
+ */
+DYNDBG_CLASSMAP_DEFINE(classid_range_conflict, 0, D2_CORE + 1, "D3_CORE");
+#endif
+
#else /* TEST_DYNAMIC_DEBUG_SUBMOD */
/*
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 20/54] dyndbg: check DYNAMIC_DEBUG_CLASSMAP_DEFINE args at compile-time
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (18 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 19/54] dyndbg: detect class_id reservation conflicts Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-15 10:04 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 21/54] dyndbg-test: change do_prints testpoint to accept a loopct Jim Cromie
` (33 subsequent siblings)
53 siblings, 1 reply; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
Add __DYNAMIC_DEBUG_CLASSMAP_CHECK to implement the following
arg-checks at compile-time:
0 <= _base < 63
class_names is not empty
class_names[0] is a string
(class_names.length + _base) < 63
These compile-time checks will prevent several misuses; 4 such
examples are added to test_dynamic_debug_submod.ko, and will fail
compilation if -DDD_MACRO_ARGCHECK is added to cflags. This wouldn't
be a useful CONFIG_ item, since it breaks the build.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
v3- $macro_name =~ s/DYNDBG/DYNAMIC_DEBUG/
prev-
- split static-asserts to __DYNDBG_CLASSMAP_CHECK
- move __DYNDBG_CLASSMAP_CHECK above kdoc for DYNDBG_CLASSMAP_DEFINE
silences kernel-doc warnings
---
include/linux/dynamic_debug.h | 9 +++++++++
lib/test_dynamic_debug.c | 11 +++++++++++
2 files changed, 20 insertions(+)
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 9af825c84e70..4941ef2adb46 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -99,6 +99,14 @@ struct _ddebug_class_map {
enum ddebug_class_map_type map_type;
};
+#define __DYNAMIC_DEBUG_CLASSMAP_CHECK(_clnames, _base) \
+ static_assert(((_base) >= 0 && (_base) < _DPRINTK_CLASS_DFLT), \
+ "_base must be in 0..62"); \
+ static_assert(ARRAY_SIZE(_clnames) > 0, \
+ "classnames array size must be > 0"); \
+ static_assert((ARRAY_SIZE(_clnames) + (_base)) < _DPRINTK_CLASS_DFLT, \
+ "_base + classnames.length exceeds range")
+
/**
* DYNAMIC_DEBUG_CLASSMAP_DEFINE - define debug classes used by a module.
* @_var: name of the classmap, exported for other modules coordinated use.
@@ -112,6 +120,7 @@ struct _ddebug_class_map {
*/
#define DYNAMIC_DEBUG_CLASSMAP_DEFINE(_var, _mapty, _base, ...) \
static const char *_var##_classnames[] = { __VA_ARGS__ }; \
+ __DYNAMIC_DEBUG_CLASSMAP_CHECK(_var##_classnames, (_base)); \
extern struct _ddebug_class_map _var; \
struct _ddebug_class_map __aligned(8) __used \
__section("__dyndbg_class_maps") _var = { \
diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
index e42916b08fd4..9f9e3fddd7e6 100644
--- a/lib/test_dynamic_debug.c
+++ b/lib/test_dynamic_debug.c
@@ -146,8 +146,19 @@ DYNDBG_CLASSMAP_DEFINE(classid_range_conflict, 0, D2_CORE + 1, "D3_CORE");
DYNAMIC_DEBUG_CLASSMAP_USE(map_disjoint_bits);
DYNAMIC_DEBUG_CLASSMAP_USE(map_level_num);
+#if defined(DD_MACRO_ARGCHECK)
+/*
+ * Exersize compile-time arg-checks in DYNDBG_CLASSMAP_DEFINE.
+ * These will break compilation.
+ */
+DYNDBG_CLASSMAP_DEFINE(fail_base_neg, 0, -1, "NEGATIVE_BASE_ARG");
+DYNDBG_CLASSMAP_DEFINE(fail_base_big, 0, 100, "TOOBIG_BASE_ARG");
+DYNDBG_CLASSMAP_DEFINE(fail_str_type, 0, 0, 1 /* not a string */);
+DYNDBG_CLASSMAP_DEFINE(fail_emptyclass, 0, 0 /* ,empty */);
#endif
+#endif /* TEST_DYNAMIC_DEBUG_SUBMOD */
+
/* stand-in for all pr_debug etc */
#define prdbg(SYM) __pr_debug_cls(SYM, #SYM " msg\n")
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 21/54] dyndbg-test: change do_prints testpoint to accept a loopct
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (19 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 20/54] dyndbg: check DYNAMIC_DEBUG_CLASSMAP_DEFINE args at compile-time Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-15 10:04 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 22/54] dyndbg-API: promote DYNAMIC_DEBUG_CLASSMAP_PARAM to API Jim Cromie
` (32 subsequent siblings)
53 siblings, 1 reply; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
echo 1000 > /sys/module/test_dynamic_debug/parameters/do_prints
This allows its use as a scriptable load generator, to generate
dynamic-prefix-emits for flag combinations vs undecorated messages.
This will make it easy to assess the cost of the prefixing.
Reading the ./do_prints node also prints messages (once) to the-log.
NB: the count is clamped to 10000, chosen to be notice able, but not
annoying, and not enough to accidentally flood the logs.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
lib/test_dynamic_debug.c | 37 ++++++++++++++++++++++++++-----------
1 file changed, 26 insertions(+), 11 deletions(-)
diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
index 9f9e3fddd7e6..4a3d2612ef60 100644
--- a/lib/test_dynamic_debug.c
+++ b/lib/test_dynamic_debug.c
@@ -29,18 +29,30 @@
#include <linux/module.h>
-/* re-gen output by reading or writing sysfs node: do_prints */
-
-static void do_prints(void); /* device under test */
+/* re-trigger debug output by reading or writing sysfs node: do_prints */
+#define PRINT_CLAMP 10000
+static void do_prints(unsigned int); /* device under test */
static int param_set_do_prints(const char *instr, const struct kernel_param *kp)
{
- do_prints();
+ int rc;
+ unsigned int ct;
+
+ rc = kstrtouint(instr, 0, &ct);
+ if (rc) {
+ pr_err("expecting numeric input, using 1 instead\n");
+ ct = 1;
+ }
+ if (ct > PRINT_CLAMP) {
+ ct = PRINT_CLAMP;
+ pr_info("clamping print-count to %d\n", ct);
+ }
+ do_prints(ct);
return 0;
}
static int param_get_do_prints(char *buffer, const struct kernel_param *kp)
{
- do_prints();
- return scnprintf(buffer, PAGE_SIZE, "did do_prints\n");
+ do_prints(1);
+ return scnprintf(buffer, PAGE_SIZE, "did 1 do_prints\n");
}
static const struct kernel_param_ops param_ops_do_prints = {
.set = param_set_do_prints,
@@ -191,17 +203,20 @@ static void do_levels(void)
prdbg(V7);
}
-static void do_prints(void)
+static void do_prints(unsigned int ct)
{
- pr_debug("do_prints:\n");
- do_cats();
- do_levels();
+ /* maybe clamp this */
+ pr_debug("do-prints %d times:\n", ct);
+ for (; ct; ct--) {
+ do_cats();
+ do_levels();
+ }
}
static int __init test_dynamic_debug_init(void)
{
pr_debug("init start\n");
- do_prints();
+ do_prints(1);
pr_debug("init done\n");
return 0;
}
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 22/54] dyndbg-API: promote DYNAMIC_DEBUG_CLASSMAP_PARAM to API
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (20 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 21/54] dyndbg-test: change do_prints testpoint to accept a loopct Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-15 10:06 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 23/54] dyndbg: treat comma as a token separator Jim Cromie
` (31 subsequent siblings)
53 siblings, 1 reply; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie, linux-doc
move the DYNAMIC_DEBUG_CLASSMAP_PARAM macro from test-dynamic-debug.c into
the header, and refine it, by distinguishing the 2 use cases:
1.DYNAMIC_DEBUG_CLASSMAP_PARAM_REF
for DRM, to pass in extern __drm_debug by name.
dyndbg keeps bits in it, so drm can still use it as before
2.DYNAMIC_DEBUG_CLASSMAP_PARAM
new user (test_dynamic_debug) doesn't need to share state,
decls a static long unsigned int to store the bitvec.
__DYNAMIC_DEBUG_CLASSMAP_PARAM
bottom layer - allocate,init a ddebug-class-param, module-param-cb.
Modify ddebug_sync_classbits() argtype deref inside the fn, to give
access to all kp members.
Also clean up and improve comments in test-code, and add
MODULE_DESCRIPTIONs.
cc: linux-doc@vger.kernel.org
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
-v9
- fixup drm-print.h add PARAM_REF forwarding macros
with DYNAMIC_DEBUG_CLASSMAP_PARAM_REF in the API, add DRM_ variant
---
include/linux/dynamic_debug.h | 38 +++++++++++++++++++++
lib/dynamic_debug.c | 60 ++++++++++++++++++++++-----------
lib/test_dynamic_debug.c | 47 ++++++++++----------------
lib/test_dynamic_debug_submod.c | 9 ++++-
4 files changed, 104 insertions(+), 50 deletions(-)
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 4941ef2adb46..ce221a702f84 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -211,6 +211,44 @@ struct _ddebug_class_param {
const struct _ddebug_class_map *map;
};
+/**
+ * DYNAMIC_DEBUG_CLASSMAP_PARAM - control a ddebug-classmap from a sys-param
+ * @_name: sysfs node name
+ * @_var: name of the classmap var defining the controlled classes/bits
+ * @_flags: flags to be toggled, typically just 'p'
+ *
+ * Creates a sysfs-param to control the classes defined by the
+ * exported classmap, with bits 0..N-1 mapped to the classes named.
+ * This version keeps class-state in a private long int.
+ */
+#define DYNAMIC_DEBUG_CLASSMAP_PARAM(_name, _var, _flags) \
+ static unsigned long _name##_bvec; \
+ __DYNAMIC_DEBUG_CLASSMAP_PARAM(_name, _name##_bvec, _var, _flags)
+
+/**
+ * DYNAMIC_DEBUG_CLASSMAP_PARAM_REF - wrap a classmap with a controlling sys-param
+ * @_name: sysfs node name
+ * @_bits: name of the module's unsigned long bit-vector, ex: __drm_debug
+ * @_var: name of the (exported) classmap var defining the classes/bits
+ * @_flags: flags to be toggled, typically just 'p'
+ *
+ * Creates a sysfs-param to control the classes defined by the
+ * exported clasmap, with bits 0..N-1 mapped to the classes named.
+ * This version keeps class-state in user @_bits. This lets drm check
+ * __drm_debug elsewhere too.
+ */
+#define DYNAMIC_DEBUG_CLASSMAP_PARAM_REF(_name, _bits, _var, _flags) \
+ __DYNAMIC_DEBUG_CLASSMAP_PARAM(_name, _bits, _var, _flags)
+
+#define __DYNAMIC_DEBUG_CLASSMAP_PARAM(_name, _bits, _var, _flags) \
+ static struct _ddebug_class_param _name##_##_flags = { \
+ .bits = &(_bits), \
+ .flags = #_flags, \
+ .map = &(_var), \
+ }; \
+ module_param_cb(_name, ¶m_ops_dyndbg_classes, \
+ &_name##_##_flags, 0600)
+
/*
* pr_debug() and friends are globally enabled or modules have selectively
* enabled them.
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 56b503af0b31..0d603caadef8 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -666,6 +666,30 @@ static int ddebug_apply_class_bitmap(const struct _ddebug_class_param *dcp,
#define CLASSMAP_BITMASK(width) ((1UL << (width)) - 1)
+static void ddebug_class_param_clamp_input(unsigned long *inrep, const struct kernel_param *kp)
+{
+ const struct _ddebug_class_param *dcp = kp->arg;
+ const struct _ddebug_class_map *map = dcp->map;
+
+ switch (map->map_type) {
+ case DD_CLASS_TYPE_DISJOINT_BITS:
+ /* expect bits. mask and warn if too many */
+ if (*inrep & ~CLASSMAP_BITMASK(map->length)) {
+ pr_warn("%s: input: 0x%lx exceeds mask: 0x%lx, masking\n",
+ KP_NAME(kp), *inrep, CLASSMAP_BITMASK(map->length));
+ *inrep &= CLASSMAP_BITMASK(map->length);
+ }
+ break;
+ case DD_CLASS_TYPE_LEVEL_NUM:
+ /* input is bitpos, of highest verbosity to be enabled */
+ if (*inrep > map->length) {
+ pr_warn("%s: level:%ld exceeds max:%d, clamping\n",
+ KP_NAME(kp), *inrep, map->length);
+ *inrep = map->length;
+ }
+ break;
+ }
+}
static int param_set_dyndbg_module_classes(const char *instr,
const struct kernel_param *kp,
const char *mod_name)
@@ -684,26 +708,15 @@ static int param_set_dyndbg_module_classes(const char *instr,
pr_err("expecting numeric input, not: %s > %s\n", instr, KP_NAME(kp));
return -EINVAL;
}
+ ddebug_class_param_clamp_input(&inrep, kp);
switch (map->map_type) {
case DD_CLASS_TYPE_DISJOINT_BITS:
- /* expect bits. mask and warn if too many */
- if (inrep & ~CLASSMAP_BITMASK(map->length)) {
- pr_warn("%s: input: 0x%lx exceeds mask: 0x%lx, masking\n",
- KP_NAME(kp), inrep, CLASSMAP_BITMASK(map->length));
- inrep &= CLASSMAP_BITMASK(map->length);
- }
v2pr_info("bits:0x%lx > %s.%s\n", inrep, mod_name ?: "*", KP_NAME(kp));
totct += ddebug_apply_class_bitmap(dcp, &inrep, *dcp->bits, mod_name);
*dcp->bits = inrep;
break;
case DD_CLASS_TYPE_LEVEL_NUM:
- /* input is bitpos, of highest verbosity to be enabled */
- if (inrep > map->length) {
- pr_warn("%s: level:%ld exceeds max:%d, clamping\n",
- KP_NAME(kp), inrep, map->length);
- inrep = map->length;
- }
old_bits = CLASSMAP_BITMASK(*dcp->lvl);
new_bits = CLASSMAP_BITMASK(inrep);
v2pr_info("lvl:%ld bits:0x%lx > %s\n", inrep, new_bits, KP_NAME(kp));
@@ -1171,15 +1184,24 @@ static const struct proc_ops proc_fops = {
static void ddebug_sync_classbits(const struct kernel_param *kp, const char *modname)
{
const struct _ddebug_class_param *dcp = kp->arg;
+ unsigned long new_bits;
- /* clamp initial bitvec, mask off hi-bits */
- if (*dcp->bits & ~CLASSMAP_BITMASK(dcp->map->length)) {
- *dcp->bits &= CLASSMAP_BITMASK(dcp->map->length);
- v2pr_info("preset classbits: %lx\n", *dcp->bits);
+ ddebug_class_param_clamp_input(dcp->bits, kp);
+
+ switch (dcp->map->map_type) {
+ case DD_CLASS_TYPE_DISJOINT_BITS:
+ v2pr_info(" %s: classbits: 0x%lx\n", KP_NAME(kp), *dcp->bits);
+ ddebug_apply_class_bitmap(dcp, dcp->bits, 0UL, modname);
+ break;
+ case DD_CLASS_TYPE_LEVEL_NUM:
+ new_bits = CLASSMAP_BITMASK(*dcp->lvl);
+ v2pr_info(" %s: lvl:%ld bits:0x%lx\n", KP_NAME(kp), *dcp->lvl, new_bits);
+ ddebug_apply_class_bitmap(dcp, &new_bits, 0UL, modname);
+ break;
+ default:
+ pr_err("bad map type %d\n", dcp->map->map_type);
+ return;
}
- /* force class'd prdbgs (in USEr module) to match (DEFINEr module) class-param */
- ddebug_apply_class_bitmap(dcp, dcp->bits, ~0, modname);
- ddebug_apply_class_bitmap(dcp, dcp->bits, 0, modname);
}
static void ddebug_match_apply_kparam(const struct kernel_param *kp,
diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
index 4a3d2612ef60..78cf5420770a 100644
--- a/lib/test_dynamic_debug.c
+++ b/lib/test_dynamic_debug.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
- * Kernel module for testing dynamic_debug
+ * Kernel module to test/demonstrate dynamic_debug features,
+ * particularly classmaps and their support for subsystems like DRM.
*
* Authors:
* Jim Cromie <jim.cromie@gmail.com>
@@ -62,24 +63,6 @@ module_param_cb(do_prints, ¶m_ops_do_prints, NULL, 0600);
#define CLASSMAP_BITMASK(width, base) (((1UL << (width)) - 1) << (base))
-/* sysfs param wrapper, proto-API */
-#define DYNAMIC_DEBUG_CLASSMAP_PARAM_(_model, _flags, _init) \
- static unsigned long bits_##_model = _init; \
- static struct _ddebug_class_param _flags##_##_model = { \
- .bits = &bits_##_model, \
- .flags = #_flags, \
- .map = &map_##_model, \
- }; \
- module_param_cb(_flags##_##_model, ¶m_ops_dyndbg_classes, \
- &_flags##_##_model, 0600)
-#ifdef DEBUG
-#define DYNAMIC_DEBUG_CLASSMAP_PARAM(_model, _flags) \
- DYNAMIC_DEBUG_CLASSMAP_PARAM_(_model, _flags, ~0)
-#else
-#define DYNAMIC_DEBUG_CLASSMAP_PARAM(_model, _flags) \
- DYNAMIC_DEBUG_CLASSMAP_PARAM_(_model, _flags, 0)
-#endif
-
/*
* Demonstrate/test DISJOINT & LEVEL typed classmaps with a sys-param.
*
@@ -110,12 +93,15 @@ enum cat_disjoint_bits {
/* numeric verbosity, V2 > V1 related. V0 is > D2_DRM_RES */
enum cat_level_num { V0 = 16, V1, V2, V3, V4, V5, V6, V7 };
-/* recapitulate DRM's multi-classmap setup */
+/*
+ * use/demonstrate multi-module-group classmaps, as for DRM
+ */
#if !defined(TEST_DYNAMIC_DEBUG_SUBMOD)
/*
- * In single user, or parent / coordinator (drm.ko) modules, define
- * classmaps on the client enums above, and then declares the PARAMS
- * ref'g the classmaps. Each is exported.
+ * For module-groups of 1+, define classmaps with names (stringified
+ * enum-symbols) copied from above. 1-to-1 mapping is recommended.
+ * The classmap is exported, so that other modules in the group can
+ * link to it and control their prdbgs.
*/
DYNAMIC_DEBUG_CLASSMAP_DEFINE(map_disjoint_bits, DD_CLASS_TYPE_DISJOINT_BITS,
D2_CORE,
@@ -134,11 +120,13 @@ DYNAMIC_DEBUG_CLASSMAP_DEFINE(map_level_num, DD_CLASS_TYPE_LEVEL_NUM,
V0, "V0", "V1", "V2", "V3", "V4", "V5", "V6", "V7");
/*
- * now add the sysfs-params
+ * for use-cases that want it, provide a sysfs-param to set the
+ * classes in the classmap. It is at this interface where the
+ * "v3>v2" property is applied to DD_CLASS_TYPE_LEVEL_NUM inputs.
*/
-DYNAMIC_DEBUG_CLASSMAP_PARAM(disjoint_bits, p);
-DYNAMIC_DEBUG_CLASSMAP_PARAM(level_num, p);
+DYNAMIC_DEBUG_CLASSMAP_PARAM(p_disjoint_bits, map_disjoint_bits, p);
+DYNAMIC_DEBUG_CLASSMAP_PARAM(p_level_num, map_level_num, p);
#ifdef FORCE_CLASSID_CONFLICT
/*
@@ -149,12 +137,10 @@ DYNDBG_CLASSMAP_DEFINE(classid_range_conflict, 0, D2_CORE + 1, "D3_CORE");
#endif
#else /* TEST_DYNAMIC_DEBUG_SUBMOD */
-
/*
- * in submod/drm-drivers, use the classmaps defined in top/parent
- * module above.
+ * the +1 members of a multi-module group refer to the classmap
+ * DEFINEd (and exported) above.
*/
-
DYNAMIC_DEBUG_CLASSMAP_USE(map_disjoint_bits);
DYNAMIC_DEBUG_CLASSMAP_USE(map_level_num);
@@ -229,6 +215,7 @@ static void __exit test_dynamic_debug_exit(void)
module_init(test_dynamic_debug_init);
module_exit(test_dynamic_debug_exit);
+MODULE_DESCRIPTION("test/demonstrate dynamic-debug features");
MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
MODULE_DESCRIPTION("Kernel module for testing dynamic_debug");
MODULE_LICENSE("GPL");
diff --git a/lib/test_dynamic_debug_submod.c b/lib/test_dynamic_debug_submod.c
index 672aabf40160..3adf3925fb86 100644
--- a/lib/test_dynamic_debug_submod.c
+++ b/lib/test_dynamic_debug_submod.c
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * Kernel module for testing dynamic_debug
+ * Kernel module to test/demonstrate dynamic_debug features,
+ * particularly classmaps and their support for subsystems, like DRM,
+ * which defines its drm_debug classmap in drm module, and uses it in
+ * helpers & drivers.
*
* Authors:
* Jim Cromie <jim.cromie@gmail.com>
@@ -12,3 +15,7 @@
*/
#define TEST_DYNAMIC_DEBUG_SUBMOD
#include "test_dynamic_debug.c"
+
+MODULE_DESCRIPTION("test/demonstrate dynamic-debug subsystem support");
+MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
+MODULE_LICENSE("GPL");
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 23/54] dyndbg: treat comma as a token separator
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (21 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 22/54] dyndbg-API: promote DYNAMIC_DEBUG_CLASSMAP_PARAM to API Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-15 10:04 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 24/54] dyndbg: split multi-query strings with % Jim Cromie
` (30 subsequent siblings)
53 siblings, 1 reply; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
Treat comma as a token terminator, just like a space. This allows a
user to avoid quoting hassles when spaces are otherwise needed:
:#> modprobe drm dyndbg=class,DRM_UT_CORE,+p\;class,DRM_UT_KMS,+p
or as a boot arg:
drm.dyndbg=class,DRM_UT_CORE,+p # todo: support multi-query here
Given the many ways a boot-line +args can be assembled and then passed
in/down/around shell based tools, this may allow side-stepping all
sorts of quoting hassles thru those layers.
existing query format:
modprobe test_dynamic_debug dyndbg="class D2_CORE +p"
new format:
modprobe test_dynamic_debug dyndbg=class,D2_CORE,+p
ALSO
selftests-dyndbg: add comma_terminator_tests
New fn validates parsing and effect of queries using combinations of
commas and spaces to delimit the tokens.
It manipulates pr-debugs in builtin module/params, so might have deps
I havent foreseen on odd configurations.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Co-developed-by: Łukasz Bartosik <ukaszb@chromium.org>
Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
---
- skip comma tests if no builtins
-v3 squash in tests and doc
---
.../admin-guide/dynamic-debug-howto.rst | 9 +++++---
lib/dynamic_debug.c | 17 +++++++++++----
.../dynamic_debug/dyndbg_selftest.sh | 21 ++++++++++++++++++-
3 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/Documentation/admin-guide/dynamic-debug-howto.rst b/Documentation/admin-guide/dynamic-debug-howto.rst
index 63a511f2337b..e2dbb5d9b314 100644
--- a/Documentation/admin-guide/dynamic-debug-howto.rst
+++ b/Documentation/admin-guide/dynamic-debug-howto.rst
@@ -78,11 +78,12 @@ Command Language Reference
==========================
At the basic lexical level, a command is a sequence of words separated
-by spaces or tabs. So these are all equivalent::
+by spaces, tabs, or commas. So these are all equivalent::
:#> ddcmd file svcsock.c line 1603 +p
:#> ddcmd "file svcsock.c line 1603 +p"
:#> ddcmd ' file svcsock.c line 1603 +p '
+ :#> ddcmd file,svcsock.c,line,1603,+p
Command submissions are bounded by a write() system call.
Multiple commands can be written together, separated by ``;`` or ``\n``::
@@ -167,9 +168,11 @@ 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::
+ suffix and with ``-`` changed to ``_``.
- module sunrpc
+ Examples::
+
+ module,sunrpc # with ',' as token separator
module nfsd
module drm* # both drm, drm_kms_helper
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 0d603caadef8..5737f1b4eba8 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -299,6 +299,14 @@ static int ddebug_change(const struct ddebug_query *query, struct flag_settings
return nfound;
}
+static char *skip_spaces_and_commas(const char *str)
+{
+ str = skip_spaces(str);
+ while (*str == ',')
+ str = skip_spaces(++str);
+ return (char *)str;
+}
+
/*
* Split the buffer `buf' into space-separated words.
* Handles simple " and ' quoting, i.e. without nested,
@@ -312,8 +320,8 @@ static int ddebug_tokenize(char *buf, char *words[], int maxwords)
while (*buf) {
char *end;
- /* Skip leading whitespace */
- buf = skip_spaces(buf);
+ /* Skip leading whitespace and comma */
+ buf = skip_spaces_and_commas(buf);
if (!*buf)
break; /* oh, it was trailing whitespace */
if (*buf == '#')
@@ -329,7 +337,7 @@ static int ddebug_tokenize(char *buf, char *words[], int maxwords)
return -EINVAL; /* unclosed quote */
}
} else {
- for (end = buf; *end && !isspace(*end); end++)
+ for (end = buf; *end && !isspace(*end) && *end != ','; end++)
;
if (end == buf) {
pr_err("parse err after word:%d=%s\n", nwords,
@@ -601,7 +609,8 @@ static int ddebug_exec_queries(char *query, const char *modname)
if (split)
*split++ = '\0';
- query = skip_spaces(query);
+ query = skip_spaces_and_commas(query);
+
if (!query || !*query || *query == '#')
continue;
diff --git a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
index 465fad3f392c..c7bf521f36ee 100755
--- a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
+++ b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
@@ -216,7 +216,7 @@ function check_err_msg() {
function basic_tests {
echo -e "${GREEN}# BASIC_TESTS ${NC}"
if [ $LACK_DD_BUILTIN -eq 1 ]; then
- echo "SKIP"
+ echo "SKIP - test requires params, which is a builtin module"
return
fi
ddcmd =_ # zero everything
@@ -238,8 +238,27 @@ EOF
ddcmd =_
}
+function comma_terminator_tests {
+ echo -e "${GREEN}# COMMA_TERMINATOR_TESTS ${NC}"
+ if [ $LACK_DD_BUILTIN -eq 1 ]; then
+ echo "SKIP - test requires params, which is a builtin module"
+ return
+ fi
+ # try combos of spaces & commas
+ check_match_ct '\[params\]' 4 -r
+ ddcmd module,params,=_ # commas as spaces
+ ddcmd module,params,+mpf # turn on module's pr-debugs
+ check_match_ct =pmf 4
+ ddcmd ,module ,, , params, -p
+ check_match_ct =mf 4
+ ddcmd " , module ,,, , params, -m" #
+ check_match_ct =f 4
+ ddcmd =_
+}
+
tests_list=(
basic_tests
+ comma_terminator_tests
)
# Run tests
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 24/54] dyndbg: split multi-query strings with %
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (22 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 23/54] dyndbg: treat comma as a token separator Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 25/54] selftests-dyndbg: add test_mod_submod Jim Cromie
` (29 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
Since commit
85f7f6c0edb8 ("dynamic_debug: process multiple debug-queries on a line")
Multi-query commands have been allowed:
modprobe drm dyndbg="class DRM_UT_CORE +p; class DRM_UT_KMS +p"
modprobe drm dyndbg=<<EOX
class DRM_UT_CORE +p
class DRM_UT_KMS +p
EOX
More recently, the need for quoting was avoided by treating a comma
like a space/token-terminator:
modprobe drm dyndbg=class,DRM_UT_CORE,+p\;class,DRM_UT_KMS,+p
That works, but it needs the escaped semicolon, which is a shell
special-char (one of the bash control operators), so it is brittle
when passed in/down/around scripts. In particular, it fails when
passed to vng (virtme-ng).
So this patch adds '%' to the existing ';' and '\n' multi-command
separators, which is more shell-friendly, so you can more fully avoid
quoting and escaping hassles.
NOTE: it does break format matching on '%' patterns:
bash-5.2# ddcmd 'format "find-me: %foo" +p'
[ 203.900581] dyndbg: read 26 bytes from userspace
[ 203.900883] dyndbg: query 0: "format "find-me: " mod:*
[ 203.901118] dyndbg: unclosed quote: find-me:
[ 203.901355] dyndbg: tokenize failed
[ 203.901529] dyndbg: query 1: "foo" +p" mod:*
[ 203.901957] dyndbg: split into words: "foo"" "+p"
[ 203.902243] dyndbg: op='+' flags=0x1 maskp=0xffffffff
[ 203.902458] dyndbg: expecting pairs of match-spec <value>
[ 203.902703] dyndbg: query parse failed
[ 203.902871] dyndbg: processed 2 queries, with 0 matches, 2 errs
bash: echo: write error: Invalid argument
The '%' splits the input into 2 queries, and both fail. Given the
limited utility of matching against the working parts of a format
string "foo: %d bar %s", nothing is actually lost here.
selftests-dyndbg: test_percent_splitting
This does basic testing of classmaps using '%' separated
multi-queries. It modprobes test_dynamic_debug with several classes
enabled, and counts to verify that the expected sites show the
enablement in the control file.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
-v3 squash feature, test, doc together
gate new test, which needs test-dynamic-debug.ko
test-percent-escape
---
.../admin-guide/dynamic-debug-howto.rst | 8 ++++---
lib/dynamic_debug.c | 2 +-
.../dynamic_debug/dyndbg_selftest.sh | 24 +++++++++++++++++++
3 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/Documentation/admin-guide/dynamic-debug-howto.rst b/Documentation/admin-guide/dynamic-debug-howto.rst
index e2dbb5d9b314..1ceadf4f28f9 100644
--- a/Documentation/admin-guide/dynamic-debug-howto.rst
+++ b/Documentation/admin-guide/dynamic-debug-howto.rst
@@ -85,10 +85,12 @@ by spaces, tabs, or commas. So these are all equivalent::
:#> ddcmd ' file svcsock.c line 1603 +p '
:#> ddcmd file,svcsock.c,line,1603,+p
-Command submissions are bounded by a write() system call.
-Multiple commands can be written together, separated by ``;`` or ``\n``::
+Command submissions are bounded by a write() system call. Multiple
+commands can be written together, separated by ``%``, ``;`` or ``\n``::
- :#> ddcmd "func pnpacpi_get_resources +p; func pnp_assign_mem +p"
+ :#> ddcmd func foo +p % func bar +p
+ :#> ddcmd func foo +p \; func bar +p
+ :#> ddcmd "func foo +p ; func bar +p"
:#> ddcmd <<"EOC"
func pnpacpi_get_resources +p
func pnp_assign_mem +p
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 5737f1b4eba8..7a60088a1b5c 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -605,7 +605,7 @@ static int ddebug_exec_queries(char *query, const char *modname)
int i, errs = 0, exitcode = 0, rc, nfound = 0;
for (i = 0; query; query = split) {
- split = strpbrk(query, ";\n");
+ split = strpbrk(query, "%;\n");
if (split)
*split++ = '\0';
diff --git a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
index c7bf521f36ee..513f6cb1db1d 100755
--- a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
+++ b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
@@ -256,9 +256,33 @@ function comma_terminator_tests {
ddcmd =_
}
+function test_percent_splitting {
+ echo -e "${GREEN}# TEST_PERCENT_SPLITTING - multi-command splitting on % ${NC}"
+ if [ $LACK_TMOD -eq 1 ]; then
+ echo "SKIP - test requires test-dynamic-debug.ko"
+ return
+ fi
+ ifrmmod test_dynamic_debug_submod
+ ifrmmod test_dynamic_debug
+ ddcmd =_
+ modprobe test_dynamic_debug dyndbg=class,D2_CORE,+pf%class,D2_KMS,+pt%class,D2_ATOMIC,+pm
+ check_match_ct =pf 1
+ check_match_ct =pt 1
+ check_match_ct =pm 1
+ check_match_ct test_dynamic_debug 23 -r
+ # add flags to those callsites
+ ddcmd class,D2_CORE,+mf%class,D2_KMS,+lt%class,D2_ATOMIC,+ml
+ check_match_ct =pmf 1
+ check_match_ct =plt 1
+ check_match_ct =pml 1
+ check_match_ct test_dynamic_debug 23 -r
+ ifrmmod test_dynamic_debug
+}
+
tests_list=(
basic_tests
comma_terminator_tests
+ test_percent_splitting
)
# Run tests
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 25/54] selftests-dyndbg: add test_mod_submod
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (23 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 24/54] dyndbg: split multi-query strings with % Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 26/54] dyndbg: change __dynamic_func_call_cls* macros into expressions Jim Cromie
` (28 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
This new test-fn runs 3 module/submodule modprobe scenarios, variously
using both the generic dyndbg=<queries> modprobe arg, and the
test-module's classmap-params to manipulate the test-mod*'s pr_debugs.
In all cases, the current flag-settings are counted and tested vs
expectations.
The 3rd scenario recapitulates the DRM_USE_DYNAMIC_DEBUG=y failure.
1. 2 modprobes (super then sub), with separate dyndbg=class-settings
check module specific flag settings
2. modprobe submod, supermod is auto-loaded
set supermod class-params
check expected enablements in super & submod
3. modprobe super, with param=setting (like drm.debug=0x1ef)
modprobe submod
validate submod's class'd pr_debugs get properly enabled
The test uses multi-queries, with both commas and percents (to avoid
spaces and quoting). This is the main reason the test wasn't earlier
in the patchset, closer to the classmap patches its validating.
With some tedium, the tests could be refactored to split out early
tests which avoid multi-cmds, and test only the class-params.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
r3 - skip test if LACK_TMOD
older
drop -v used in test_mod_submod(). V=1 does it for whole test
ifrmmod at test end (Lukasz)
test-mod-tmod
---
.../dynamic_debug/dyndbg_selftest.sh | 73 +++++++++++++++++++
1 file changed, 73 insertions(+)
diff --git a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
index 513f6cb1db1d..09937dca3056 100755
--- a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
+++ b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
@@ -279,10 +279,83 @@ function test_percent_splitting {
ifrmmod test_dynamic_debug
}
+function test_mod_submod {
+ echo -e "${GREEN}# TEST_MOD_SUBMOD ${NC}"
+ if [ $LACK_TMOD -eq 1 ]; then
+ echo "SKIP - test requires test-dynamic-debug.ko"
+ return
+ fi
+ ifrmmod test_dynamic_debug_submod
+ ifrmmod test_dynamic_debug
+ ddcmd =_
+
+ # modprobe with class enablements
+ modprobe test_dynamic_debug \
+ dyndbg=class,D2_CORE,+pf%class,D2_KMS,+pt%class,D2_ATOMIC,+pm
+
+ check_match_ct '\[test_dynamic_debug\]' 23 -r
+ check_match_ct =pf 1
+ check_match_ct =pt 1
+ check_match_ct =pm 1
+
+ modprobe test_dynamic_debug_submod
+ check_match_ct test_dynamic_debug_submod 23 -r
+ check_match_ct '\[test_dynamic_debug\]' 23 -r
+ check_match_ct test_dynamic_debug 46 -r
+
+ # no enablements propagate here
+ check_match_ct =pf 1
+ check_match_ct =pt 1
+ check_match_ct =pm 1
+
+ # change classes again, this time submod too
+ ddcmd class,D2_CORE,+mf%class,D2_KMS,+lt%class,D2_ATOMIC,+ml "# add some prefixes"
+ check_match_ct =pmf 1
+ check_match_ct =plt 1
+ check_match_ct =pml 1
+ # submod changed too
+ check_match_ct =mf 1
+ check_match_ct =lt 1
+ check_match_ct =ml 1
+
+ # now work the classmap-params
+ # fresh start, to clear all above flags (test-fn limits)
+ ifrmmod test_dynamic_debug_submod
+ ifrmmod test_dynamic_debug
+ modprobe test_dynamic_debug_submod # get supermod too
+
+ echo 1 > /sys/module/test_dynamic_debug/parameters/p_disjoint_bits
+ echo 4 > /sys/module/test_dynamic_debug/parameters/p_level_num
+ # 2 mods * ( V1-3 + D2_CORE )
+ check_match_ct =p 8
+ echo 3 > /sys/module/test_dynamic_debug/parameters/p_disjoint_bits
+ echo 0 > /sys/module/test_dynamic_debug/parameters/p_level_num
+ # 2 mods * ( D2_CORE, D2_DRIVER )
+ check_match_ct =p 4
+ echo 0x16 > /sys/module/test_dynamic_debug/parameters/p_disjoint_bits
+ echo 0 > /sys/module/test_dynamic_debug/parameters/p_level_num
+ # 2 mods * ( D2_DRIVER, D2_KMS, D2_ATOMIC )
+ check_match_ct =p 6
+
+ # recap DRM_USE_DYNAMIC_DEBUG regression
+ ifrmmod test_dynamic_debug_submod
+ ifrmmod test_dynamic_debug
+ # set super-mod params
+ modprobe test_dynamic_debug p_disjoint_bits=0x16 p_level_num=5
+ check_match_ct =p 7
+ modprobe test_dynamic_debug_submod
+ # see them picked up by submod
+ check_match_ct =p 14
+ ifrmmod test_dynamic_debug_submod
+ ifrmmod test_dynamic_debug
+}
+
tests_list=(
basic_tests
+ # these require test_dynamic_debug*.ko
comma_terminator_tests
test_percent_splitting
+ test_mod_submod
)
# Run tests
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 26/54] dyndbg: change __dynamic_func_call_cls* macros into expressions
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (24 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 25/54] selftests-dyndbg: add test_mod_submod Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-15 10:06 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 27/54] dyndbg: drop "protection" of class'd pr_debugs from legacy queries Jim Cromie
` (27 subsequent siblings)
53 siblings, 1 reply; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
The Xe driver's XE_IOCTL_DBG macro calls drm_dbg() from inside an if
(expression). This breaks when CONFIG_DRM_USE_DYNAMIC_DEBUG=y because
the invoked macro has a do-while-0 wrapper.
if (cond && (drm_dbg("expr-form"),1)) {
... do some more stuff
}
Fix for this usage by changing __dynamic_func_call_cls{,_no_desc}
macros into expressions, by replacing the do-while-0s with a ({ })
wrapper. In the common usage, the trailing ';' converts the
expression into a statement.
drm_dbg("statement form");
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
---
include/linux/dynamic_debug.h | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index ce221a702f84..2d87cca27544 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -337,20 +337,20 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
* (|_cls): adds in _DPRINT_CLASS_DFLT as needed
* (|_no_desc): former gets callsite descriptor as 1st arg (for prdbgs)
*/
-#define __dynamic_func_call_cls(id, cls, fmt, func, ...) do { \
- DEFINE_DYNAMIC_DEBUG_METADATA_CLS((id), cls, fmt); \
+#define __dynamic_func_call_cls(id, cls, fmt, func, ...) ({ \
+ DEFINE_DYNAMIC_DEBUG_METADATA_CLS(id, cls, fmt); \
if (DYNAMIC_DEBUG_BRANCH(id)) \
- func(&id, ##__VA_ARGS__); \
-} while (0)
+ func(&(id), ##__VA_ARGS__); \
+})
#define __dynamic_func_call(id, fmt, func, ...) \
__dynamic_func_call_cls(id, _DPRINTK_CLASS_DFLT, fmt, \
func, ##__VA_ARGS__)
-#define __dynamic_func_call_cls_no_desc(id, cls, fmt, func, ...) do { \
+#define __dynamic_func_call_cls_no_desc(id, cls, fmt, func, ...) ({ \
DEFINE_DYNAMIC_DEBUG_METADATA_CLS(id, cls, fmt); \
if (DYNAMIC_DEBUG_BRANCH(id)) \
func(__VA_ARGS__); \
-} while (0)
+})
#define __dynamic_func_call_no_desc(id, fmt, func, ...) \
__dynamic_func_call_cls_no_desc(id, _DPRINTK_CLASS_DFLT, \
fmt, func, ##__VA_ARGS__)
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 27/54] dyndbg: drop "protection" of class'd pr_debugs from legacy queries
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (25 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 26/54] dyndbg: change __dynamic_func_call_cls* macros into expressions Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-15 10:06 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 28/54] dyndbg: restore classmap protection when theres a controlling_param Jim Cromie
` (26 subsequent siblings)
53 siblings, 1 reply; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
Current classmap code protects class'd pr_debugs from unintended
changes by "legacy" unclassed queries:
# this doesn't disable all of DRM_UT_* categories
echo "-p" > /proc/dynamic_debug/control
# name the class to change it - protective but tedious
echo "class DRM_UT_CORE +p" > /proc/dynamic_debug/control
# or do it the (old school) subsystem way
echo 1 > /sys/module/drm/parameters/debug
This "name the class to change it" behavior gave a modicum of
protection to classmap users (ie DRM) so their debug settings aren't
trivially and unintentionally altered underneath them.
And by "symmetry", if they're not picked by "class FOO", then they're
excluded from adjustment. This allowed all previously conceived
queries to work the way they always had; ie select the same set of
pr_debugs, despite the inclusion of whole new classes of pr_debugs.
That had 2 downsides:
1. "name the class to change it" means that every class must be
individually modified, quickly becoming long-winded and tedious to
adjust all the classes in a map via >control.
2. It made the class keyword special in some sense; the other keywords
skip only on explicit mismatch, otherwise the code falls thru to
adjust the pr-debug site.
So this patch reverts to the traditional view, it drops protection of
classes from default/legacy queries.
But it also refactors the skip/continue choice to allow the module
defining the classmap to protect its classes from unintended
alterations by legacy/class-less queries.
Next:
Author choice: use of DYNAMIC_DEBUG_CLASSMAP_PARAM() means they want
the drm.debug style control point. We should presume they want it to
reflect whats set underneath, with only "class FOO" qualified queries
changing the callsites beneath.
CC: jbaron@akamai.com
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
--
v3- s/slctd_/selected_/
pitch the PARAM control of protection.
---
lib/dynamic_debug.c | 31 +++++++++++++++++++++++--------
1 file changed, 23 insertions(+), 8 deletions(-)
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 7a60088a1b5c..54f462cf41b0 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -197,6 +197,17 @@ ddebug_find_valid_class(struct _ddebug_info const *di, const char *query_class,
return NULL;
}
+/*
+ * classmaps-v1 protected classes from changes by legacy commands
+ * (those selecting _DPRINTK_CLASS_DFLT by omission), v2 undoes that
+ * special treatment. State so explicitly. Later we could give
+ * modules the choice to protect their classes or to keep v2 behavior.
+ */
+static inline bool ddebug_client_module_protects_classes(const struct ddebug_table *dt)
+{
+ return false;
+}
+
/*
* Search the tables for _ddebug's which match the given `query' and
* apply the `flags' and `mask' to them. Returns number of matching
@@ -211,7 +222,7 @@ static int ddebug_change(const struct ddebug_query *query, struct flag_settings
unsigned int nfound = 0;
struct flagsbuf fbuf, nbuf;
struct _ddebug_class_map *map = NULL;
- int valid_class;
+ int selected_class;
/* search for matching ddebugs */
mutex_lock(&ddebug_lock);
@@ -224,21 +235,25 @@ static int ddebug_change(const struct ddebug_query *query, struct flag_settings
if (query->class_string) {
map = ddebug_find_valid_class(&dt->info, query->class_string,
- &valid_class);
+ &selected_class);
if (!map)
continue;
} else {
- /* constrain query, do not touch class'd callsites */
- valid_class = _DPRINTK_CLASS_DFLT;
+ selected_class = _DPRINTK_CLASS_DFLT;
}
for (i = 0; i < dt->info.descs.len; i++) {
struct _ddebug *dp = &dt->info.descs.start[i];
- /* match site against query-class */
- if (dp->class_id != valid_class)
- continue;
-
+ if (dp->class_id != selected_class) {
+ if (query->class_string)
+ /* site.class != given class */
+ continue;
+ /* legacy query, class'd site */
+ else if (ddebug_client_module_protects_classes(dt))
+ continue;
+ /* allow change on class'd pr_debug */
+ }
/* match against the source filename */
if (query->filename &&
!match_wildcard(query->filename, dp->filename) &&
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 28/54] dyndbg: restore classmap protection when theres a controlling_param
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (26 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 27/54] dyndbg: drop "protection" of class'd pr_debugs from legacy queries Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-06-20 14:41 ` Sean Paul
2025-04-02 17:41 ` [PATCH v3 29/54] docs/dyndbg: add classmap info to howto Jim Cromie
` (25 subsequent siblings)
53 siblings, 1 reply; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
DRM has always had /sys/module/drm/parameters/debug (ie drm.debug).
Without dyndbg, this is their only control point. One could presume
they like it - in any case its a system/user interface, ie ABI.
With dyndbg enabled, drm calls DYNAMIC_DEBUG_CLASSMAP_PARAM() to
create the drm.debug kparam, wired to our param-handler, which writes
a "class FOO" query for each bit in the classmap. Since no new
interface was ever contemplated, this is using >control.
Since drm.debug is ABI, we should not allow class-less queries to
alter our implementation of its settings.
This patch provides that protection, *only* when theres a PARAM. This
is the user, expressing their wish for easy control of their entire
classmap. They also wish to trust its settings.
Classes without a PARAM are unprotected, allowing admins their
shortcuts. No such use-cases exist yet.
Anyway, this patch does:
1. adds struct _ddebug_class_map.controlling_param
2. set it in ddebug_match_apply_kparam(), during modprobe/init,
when options like drm.debug are handled.
3. ddebug_class_has_param() checks .controlling_param
4. ddebug_class_wants_protection() macro renames 3.
5. ddebug_change() calls 4 when needed.
IE when applying a class-less query to a class'd pr_debug / drm_dbg_<T>
Historical Summary:
-v0 - before classmaps. no special case keywords
-v1 - "class DEFAULT" is assumed if not mentioned.
this protects classes from class-less queries
-v2.pre-this-patch - protection macro'd to false
-v2.with-this-patch - sysfs knob decides
-v2.speculative - module decides wrt classmap protection
seems unneeded now, TBD
NOTE: protection is only against class-less queries, explicit "class
FOO" adjustments are allowed (that is the mechanism).
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
v3 - new patch
---
include/linux/dynamic_debug.h | 3 +-
lib/dynamic_debug.c | 55 ++++++++++++++++++++++++++---------
2 files changed, 44 insertions(+), 14 deletions(-)
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 2d87cca27544..d34a44ff961a 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -89,8 +89,9 @@ enum ddebug_class_map_type {
* usually by stringifying the enum-vals. Modules with multiple
* classmaps must arrange to share the 0..62 class_id space.
*/
-
+struct _ddebug_class_param;
struct _ddebug_class_map {
+ struct _ddebug_class_param *controlling_param;
const struct module *mod; /* NULL for builtins */
const char *mod_name;
const char **class_names;
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 54f462cf41b0..3eb4a8abeb33 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -198,16 +198,26 @@ ddebug_find_valid_class(struct _ddebug_info const *di, const char *query_class,
}
/*
- * classmaps-v1 protected classes from changes by legacy commands
- * (those selecting _DPRINTK_CLASS_DFLT by omission), v2 undoes that
- * special treatment. State so explicitly. Later we could give
- * modules the choice to protect their classes or to keep v2 behavior.
+ * classmaps-V1 protected classes from changes by legacy commands
+ * (those selecting _DPRINTK_CLASS_DFLT by omission). This had the
+ * downside that saying "class FOO" for every change can get tedious.
+ *
+ * V2 is smarter, it protects class-maps if the defining module also
+ * calls DYNAMIC_DEBUG_CLASSMAP_PARAM to create a sysfs parameter.
+ * Since they want the knob, we should assume they intend to use it
+ * (in preference to "class FOO +p" >control), and want to trust its
+ * settings.
+ * This gives protection when its useful, and not when its just tedious.
*/
-static inline bool ddebug_client_module_protects_classes(const struct ddebug_table *dt)
+static inline bool ddebug_class_has_param(const struct _ddebug_class_map *map)
{
- return false;
+ return !!(map->controlling_param);
}
+/* re-framed as a policy choice */
+#define ddebug_class_wants_protection(map) \
+ ddebug_class_has_param(map)
+
/*
* Search the tables for _ddebug's which match the given `query' and
* apply the `flags' and `mask' to them. Returns number of matching
@@ -250,7 +260,7 @@ static int ddebug_change(const struct ddebug_query *query, struct flag_settings
/* site.class != given class */
continue;
/* legacy query, class'd site */
- else if (ddebug_client_module_protects_classes(dt))
+ else if (ddebug_class_wants_protection(map))
continue;
/* allow change on class'd pr_debug */
}
@@ -650,6 +660,7 @@ static int ddebug_exec_queries(char *query, const char *modname)
}
/* apply a new class-param setting */
+
static int ddebug_apply_class_bitmap(const struct _ddebug_class_param *dcp,
const unsigned long *new_bits,
const unsigned long old_bits,
@@ -1228,25 +1239,36 @@ static void ddebug_sync_classbits(const struct kernel_param *kp, const char *mod
}
}
-static void ddebug_match_apply_kparam(const struct kernel_param *kp,
- const struct _ddebug_class_map *map,
- const char *mod_name)
+static struct _ddebug_class_param *
+ddebug_get_classmap_kparam(const struct kernel_param *kp,
+ const struct _ddebug_class_map *map)
{
struct _ddebug_class_param *dcp;
if (kp->ops != ¶m_ops_dyndbg_classes)
- return;
+ return false;
dcp = (struct _ddebug_class_param *)kp->arg;
- if (map == dcp->map) {
+ return (map == dcp->map)
+ ? dcp : (struct _ddebug_class_param *)NULL;
+}
+
+static void ddebug_match_apply_kparam(const struct kernel_param *kp,
+ struct _ddebug_class_map *map,
+ const char *mod_name)
+{
+ struct _ddebug_class_param *dcp = ddebug_get_classmap_kparam(kp, map);
+
+ if (dcp) {
+ map->controlling_param = dcp;
v2pr_info(" kp:%s.%s =0x%lx", mod_name, kp->name, *dcp->bits);
vpr_cm_info(map, " %s mapped to: ", mod_name);
ddebug_sync_classbits(kp, mod_name);
}
}
-static void ddebug_apply_params(const struct _ddebug_class_map *cm, const char *mod_name)
+static void ddebug_apply_params(struct _ddebug_class_map *cm, const char *mod_name)
{
const struct kernel_param *kp;
#if IS_ENABLED(CONFIG_MODULES)
@@ -1266,6 +1288,13 @@ static void ddebug_apply_params(const struct _ddebug_class_map *cm, const char *
}
}
+/*
+ * called from add_module, ie early. it can find controlling kparams,
+ * which can/does? enable protection of this classmap from class-less
+ * queries, on the grounds that the user created the kparam, means to
+ * use it, and expects it to reflect reality. We should oblige him,
+ * and protect those classmaps from classless "-p" changes.
+ */
static void ddebug_apply_class_maps(const struct _ddebug_info *di)
{
struct _ddebug_class_map *cm;
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 29/54] docs/dyndbg: add classmap info to howto
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (27 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 28/54] dyndbg: restore classmap protection when theres a controlling_param Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-15 10:06 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 30/54] drm: use correct ccflags-y spelling Jim Cromie
` (24 subsequent siblings)
53 siblings, 1 reply; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie, linux-doc
Describe the 3 API macros providing dynamic_debug's classmaps
DYNDBG_CLASSMAP_DEFINE - create & export a classmap
DYNDBG_CLASSMAP_USE - refer to exported map
DYNDBG_CLASSMAP_PARAM - bind control param to the classmap
DYNDBG_CLASSMAP_PARAM_REF + use module's storage - __drm_debug
TBD: some of this might be over-specification, or just over-talked.
NB: The _DEFINE & _USE model makes the user dependent on the definer,
just like EXPORT_SYMBOL(__drm_debug) already does.
cc: linux-doc@vger.kernel.org
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
v3- rework protection around PARAM
v0.5 adjustments per Randy Dunlap
v0.7 checkpatch fixes
v0.8 more
v0.9 rewords
fixup-howto
---
.../admin-guide/dynamic-debug-howto.rst | 93 +++++++++++++++++++
1 file changed, 93 insertions(+)
diff --git a/Documentation/admin-guide/dynamic-debug-howto.rst b/Documentation/admin-guide/dynamic-debug-howto.rst
index 1ceadf4f28f9..5eb4ae3b2f27 100644
--- a/Documentation/admin-guide/dynamic-debug-howto.rst
+++ b/Documentation/admin-guide/dynamic-debug-howto.rst
@@ -394,3 +394,96 @@ just a shortcut for ``print_hex_dump(KERN_DEBUG)``.
For ``print_hex_dump_debug()``/``print_hex_dump_bytes()``, format string is
its ``prefix_str`` argument, if it is constant string; or ``hexdump``
in case ``prefix_str`` is built dynamically.
+
+Dynamic Debug classmaps
+=======================
+
+The "class" keyword selects prdbgs based on author supplied,
+domain-oriented names. This complements the nested-scope keywords:
+module, file, function, line.
+
+The main difference from the others: classes must be named to be
+changed. This protects them from generic overwrite:
+
+ # IOW this cannot undo any DRM.debug settings
+ :#> ddcmd -p
+
+This protection is needed in order to honor the ABI, settings done
+there must be respected:
+
+ :#> echo 0x1ff > /sys/module/drm/parameters/debug
+
+So each class must be enabled individually (no wildcards):
+
+ :#> ddcmd class DRM_UT_CORE +p
+ :#> ddcmd class DRM_UT_KMS +p
+ # or more selectively
+ :#> ddcmd class DRM_UT_CORE module drm +p
+
+That makes direct >control wordy and annoying, but it is a secondary
+interface; it is not intended to replace the ABI, just slide in
+underneath and reimplement it.
+
+However, since the param is the ABI, if a classmap DEFINEr doesn't
+also add a _CLASSMAP_PARAM, there is no ABI, and no protection is
+needed. In that case, class'd prdbgs would be enabled/disabled by
+legacy (class-less) queries.
+
+
+Dynamic Debug Classmap API
+==========================
+
+DRM.debug is built upon:
+ ABI in /sys/module/drm/parameters/debug
+ the bits set all DRM_UT_* together
+ ~23 categorized api macros: drm_dbg_<T>()
+ all calling drm_{,dev}dbg(DRM_UT_*, ....)
+ ~5000 calls to the api macros across drivers/gpu/drm/*
+
+The const short ints are good for optimizing compilers; a primary
+classmaps design goal was to preserve those opporunities for
+optimization. So basically .classid === category.
+
+Then we use the drm_categories DRM_UT_* enum for both the classnames
+(stringified enum symbols) and their numeric values.
+
+Its expected that future users will also use an enum-defined
+categorization scheme like DRM's, and dyndbg can be adapted under them
+similarly.
+
+DYNAMIC_DEBUG_CLASSMAP_DEFINE(var,type,_base,classnames) - this maps
+classnames (a list of strings) onto class-ids consecutively, starting
+at _base, it also maps the names onto CLASSMAP_PARAM bits 0..N.
+
+DYNAMIC_DEBUG_CLASSMAP_USE(var) - modules call this to refer to the
+var _DEFINEd elsewhere (and exported).
+
+Classmaps are opt-in: modules invoke _DEFINE or _USE to authorize
+dyndbg to update those classes. "class FOO" queries are validated
+against the classes, this finds the classid to alter; classes are not
+directly selectable by their classid.
+
+There are 2 types of classmaps:
+
+ DD_CLASS_TYPE_DISJOINT_BITS: classes are independent, like DRM.debug
+ DD_CLASS_TYPE_LEVEL_NUM: classes are relative, ordered (V3 > V2)
+
+DYNAMIC_DEBUG_CLASSMAP_PARAM - modelled after module_param_cb, it
+refers to a DEFINEd classmap, and associates it to the param's
+data-store. This state is then applied to DEFINEr and USEr modules
+when they're modprobed.
+
+The PARAM interface also enforces the DD_CLASS_TYPE_LEVEL_NUM relation
+amongst the contained classnames; all classes are independent in the
+control parser itself; there is no implied meaning in names like "V4".
+
+Modules or module-groups (drm & drivers) can define multiple
+classmaps, as long as they (all the classmaps) share the limited 0..62
+per-module-group _class_id range, without overlap. If a module
+encounters a conflict between 2 classmaps its USEing, we can extend
+the _USE macro with an offset to allow avoiding the conflicting range.
+
+``#define DEBUG`` will enable all pr_debugs in scope, including any
+class'd ones. This won't be reflected in the PARAM readback value,
+but the class'd pr_debug callsites can be forced off by toggling the
+classmap-kparam all-on then all-off.
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 30/54] drm: use correct ccflags-y spelling
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (28 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 29/54] docs/dyndbg: add classmap info to howto Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 31/54] drm-dyndbg: adapt drm core to use dyndbg classmaps-v2 Jim Cromie
` (23 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
Incorrectly spelled CFLAGS- failed to add -DDYNAMIC_DEBUG_MODULE,
which disabled dynamic-debug in modules built with:
CONFIG_DYNAMIC_DEBUG=n # 1
CONFIG_DYNAMIC_DEBUG_CORE=y # 2
CONFIG_DRM_USE_DYNAMIC_DEBUG=y # 3
NB: this adds the flag (when 3) more often than strictly needed;
modules built with CONFIG_DYNAMIC_DEBUG=y (!1) don't need the flag.
Fixes: 84ec67288c10 ("drm_print: wrap drm_*_dbg in dyndbg descriptor factory macro")
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
drivers/gpu/drm/Makefile | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 19fb370fbc56..704f94efc804 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -3,7 +3,8 @@
# Makefile for the drm device driver. This driver provides support for the
# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
-CFLAGS-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) += -DDYNAMIC_DEBUG_MODULE
+ccflags-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) += -DDYNAMIC_DEBUG_MODULE
+subdir-ccflags-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) += -DDYNAMIC_DEBUG_MODULE
# Unconditionally enable W=1 warnings locally
# --- begin copy-paste W=1 warnings from scripts/Makefile.extrawarn
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 31/54] drm-dyndbg: adapt drm core to use dyndbg classmaps-v2
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (29 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 30/54] drm: use correct ccflags-y spelling Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 32/54] drm-dyndbg: adapt DRM to invoke DYNAMIC_DEBUG_CLASSMAP_PARAM Jim Cromie
` (22 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
dyndbg's CLASSMAP-v1 api was broken; DECLARE_DYNDBG_CLASSMAP tried to
do too much. Its replaced by DRM_CLASSMAP_DEFINE, which creates &
EXPORTs a classmap (in DRM core), and DRM_CLASSMAP_USE which refers to
the classmap defined elsewhere.
The drivers still use DECLARE_DYNDBG_CLASSMAP for now, so they still
redundantly re-declare the classmap, but we can convert the drivers
later to DYNDBG_CLASSMAP_USE
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
this ignores a checkpatch
WARNING: Argument 'name' is not used in function-like macro
#70: FILE: include/drm/drm_print.h:148:
+#define DRM_CLASSMAP_USE(name)
the macro is empty, and correct. only 1 arg is expected.
---
drivers/gpu/drm/drm_print.c | 25 +++++++++++++------------
include/drm/drm_print.h | 8 ++++++++
2 files changed, 21 insertions(+), 12 deletions(-)
diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c
index 79517bd4418f..a3b70d104afa 100644
--- a/drivers/gpu/drm/drm_print.c
+++ b/drivers/gpu/drm/drm_print.c
@@ -55,18 +55,19 @@ MODULE_PARM_DESC(debug, "Enable debug output, where each bit enables a debug cat
#if !defined(CONFIG_DRM_USE_DYNAMIC_DEBUG)
module_param_named(debug, __drm_debug, ulong, 0600);
#else
-/* classnames must match vals of enum drm_debug_category */
-DECLARE_DYNDBG_CLASSMAP(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS, 0,
- "DRM_UT_CORE",
- "DRM_UT_DRIVER",
- "DRM_UT_KMS",
- "DRM_UT_PRIME",
- "DRM_UT_ATOMIC",
- "DRM_UT_VBL",
- "DRM_UT_STATE",
- "DRM_UT_LEASE",
- "DRM_UT_DP",
- "DRM_UT_DRMRES");
+/* classnames must match value-symbols of enum drm_debug_category */
+DRM_CLASSMAP_DEFINE(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS,
+ DRM_UT_CORE,
+ "DRM_UT_CORE",
+ "DRM_UT_DRIVER",
+ "DRM_UT_KMS",
+ "DRM_UT_PRIME",
+ "DRM_UT_ATOMIC",
+ "DRM_UT_VBL",
+ "DRM_UT_STATE",
+ "DRM_UT_LEASE",
+ "DRM_UT_DP",
+ "DRM_UT_DRMRES");
static struct ddebug_class_param drm_debug_bitmap = {
.bits = &__drm_debug,
diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h
index 9732f514566d..e86ebb716b4c 100644
--- a/include/drm/drm_print.h
+++ b/include/drm/drm_print.h
@@ -141,6 +141,14 @@ enum drm_debug_category {
DRM_UT_DRMRES
};
+#ifdef CONFIG_DRM_USE_DYNAMIC_DEBUG
+#define DRM_CLASSMAP_DEFINE(...) DYNAMIC_DEBUG_CLASSMAP_DEFINE(__VA_ARGS__)
+#define DRM_CLASSMAP_USE(name) DYNAMIC_DEBUG_CLASSMAP_USE(name)
+#else
+#define DRM_CLASSMAP_DEFINE(...)
+#define DRM_CLASSMAP_USE(name)
+#endif
+
static inline bool drm_debug_enabled_raw(enum drm_debug_category category)
{
return unlikely(__drm_debug & BIT(category));
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 32/54] drm-dyndbg: adapt DRM to invoke DYNAMIC_DEBUG_CLASSMAP_PARAM
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (30 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 31/54] drm-dyndbg: adapt drm core to use dyndbg classmaps-v2 Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 33/54] drm-print: fix config-dependent unused variable Jim Cromie
` (21 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
Invoke DYNAMIC_DEBUG_CLASSMAP_PARAM to hook drm.debug (__drm_debug) to the
DRM_UT_* classmap, replacing the ad-hoc wiring previously doing it.
Add DRM_CLASSMAP_* adapter macros to selectively use
DYNAMIC_DEBUG_CLASSMAP_* when DRM_USE_DYNAMIC_DEBUG=y is configured.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
drivers/gpu/drm/drm_print.c | 8 ++------
include/drm/drm_print.h | 4 ++++
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c
index a3b70d104afa..46d53fe30204 100644
--- a/drivers/gpu/drm/drm_print.c
+++ b/drivers/gpu/drm/drm_print.c
@@ -69,12 +69,8 @@ DRM_CLASSMAP_DEFINE(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS,
"DRM_UT_DP",
"DRM_UT_DRMRES");
-static struct ddebug_class_param drm_debug_bitmap = {
- .bits = &__drm_debug,
- .flags = "p",
- .map = &drm_debug_classes,
-};
-module_param_cb(debug, ¶m_ops_dyndbg_classes, &drm_debug_bitmap, 0600);
+DRM_CLASSMAP_PARAM_REF(debug, __drm_debug, drm_debug_classes, p);
+
#endif
void __drm_puts_coredump(struct drm_printer *p, const char *str)
diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h
index e86ebb716b4c..8758449491b8 100644
--- a/include/drm/drm_print.h
+++ b/include/drm/drm_print.h
@@ -144,9 +144,13 @@ enum drm_debug_category {
#ifdef CONFIG_DRM_USE_DYNAMIC_DEBUG
#define DRM_CLASSMAP_DEFINE(...) DYNAMIC_DEBUG_CLASSMAP_DEFINE(__VA_ARGS__)
#define DRM_CLASSMAP_USE(name) DYNAMIC_DEBUG_CLASSMAP_USE(name)
+#define DRM_CLASSMAP_PARAM_REF(...) DYNAMIC_DEBUG_CLASSMAP_PARAM_REF(__VA_ARGS__)
+#define DRM_CLASSMAP_PARAM(...) DYNAMIC_DEBUG_CLASSMAP_PARAM(__VA_ARGS__)
#else
#define DRM_CLASSMAP_DEFINE(...)
#define DRM_CLASSMAP_USE(name)
+#define DRM_CLASSMAP_PARAM_REF(...)
+#define DRM_CLASSMAP_PARAM(...)
#endif
static inline bool drm_debug_enabled_raw(enum drm_debug_category category)
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 33/54] drm-print: fix config-dependent unused variable
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (31 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 32/54] drm-dyndbg: adapt DRM to invoke DYNAMIC_DEBUG_CLASSMAP_PARAM Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 34/54] drm-dyndbg: DRM_CLASSMAP_USE in amdgpu driver Jim Cromie
` (20 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
With CONFIG_DRM_USE_DYNAMIC_DEBUG=y, __drm_printfn_dbg() gets an
unused variable warning/error on 'category', even though the usage
follows immediately, in drm_debug_enabled(category).
For static-key optimized dyndbg, the macro doesn't actually check the
category var, since the static-key patches in the proper state. The
compiler evidently sees this lack of reference and complains.
So this drops the local var and refs the field directly in the
macro-call, which avoids the warning/error.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
drivers/gpu/drm/drm_print.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c
index 46d53fe30204..41ad11247b48 100644
--- a/drivers/gpu/drm/drm_print.c
+++ b/drivers/gpu/drm/drm_print.c
@@ -212,9 +212,8 @@ void __drm_printfn_dbg(struct drm_printer *p, struct va_format *vaf)
{
const struct drm_device *drm = p->arg;
const struct device *dev = drm ? drm->dev : NULL;
- enum drm_debug_category category = p->category;
- if (!__drm_debug_enabled(category))
+ if (!__drm_debug_enabled(p->category))
return;
__drm_dev_vprintk(dev, KERN_DEBUG, p->origin, p->prefix, vaf);
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 34/54] drm-dyndbg: DRM_CLASSMAP_USE in amdgpu driver
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (32 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 33/54] drm-print: fix config-dependent unused variable Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 35/54] drm-dyndbg: DRM_CLASSMAP_USE in i915 driver Jim Cromie
` (19 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
Following the dyndbg-api-fix, replace DECLARE_DYNDBG_CLASSMAP with
DRM_CLASSMAP_USE. This refs the defined & exported classmap, rather
than re-declaring it redundantly, and error-prone-ly.
This resolves the appearance of "class:_UNKNOWN_" in the control file
for the driver's drm_dbg()s.
Fixes: f158936b60a7 ("drm: POC drm on dyndbg - use in core, 2 helpers, 3 drivers.")
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index c0ddbe7d6f0b..e1367f66c4d2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -234,17 +234,7 @@ int amdgpu_wbrf = -1;
int amdgpu_damage_clips = -1; /* auto */
int amdgpu_umsch_mm_fwlog;
-DECLARE_DYNDBG_CLASSMAP(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS, 0,
- "DRM_UT_CORE",
- "DRM_UT_DRIVER",
- "DRM_UT_KMS",
- "DRM_UT_PRIME",
- "DRM_UT_ATOMIC",
- "DRM_UT_VBL",
- "DRM_UT_STATE",
- "DRM_UT_LEASE",
- "DRM_UT_DP",
- "DRM_UT_DRMRES");
+DRM_CLASSMAP_USE(drm_debug_classes);
struct amdgpu_mgpu_info mgpu_info = {
.mutex = __MUTEX_INITIALIZER(mgpu_info.mutex),
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 35/54] drm-dyndbg: DRM_CLASSMAP_USE in i915 driver
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (33 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 34/54] drm-dyndbg: DRM_CLASSMAP_USE in amdgpu driver Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 36/54] drm-dyndbg: DRM_CLASSMAP_USE in drm_crtc_helper Jim Cromie
` (18 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
Following the dyndbg-api-fix, replace DECLARE_DYNDBG_CLASSMAP with
DRM_CLASSMAP_USE. This refs the defined & exported classmap, rather
than re-declaring it redundantly, and error-prone-ly.
This resolves the appearance of "class:_UNKNOWN_" in the control file
for the driver's drm_dbg()s.
Fixes: f158936b60a7 ("drm: POC drm on dyndbg - use in core, 2 helpers, 3 drivers.")
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
drivers/gpu/drm/i915/i915_params.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_params.c b/drivers/gpu/drm/i915/i915_params.c
index 37746dd619fd..2dc0e2c06e09 100644
--- a/drivers/gpu/drm/i915/i915_params.c
+++ b/drivers/gpu/drm/i915/i915_params.c
@@ -29,17 +29,7 @@
#include "i915_params.h"
#include "i915_drv.h"
-DECLARE_DYNDBG_CLASSMAP(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS, 0,
- "DRM_UT_CORE",
- "DRM_UT_DRIVER",
- "DRM_UT_KMS",
- "DRM_UT_PRIME",
- "DRM_UT_ATOMIC",
- "DRM_UT_VBL",
- "DRM_UT_STATE",
- "DRM_UT_LEASE",
- "DRM_UT_DP",
- "DRM_UT_DRMRES");
+DRM_CLASSMAP_USE(drm_debug_classes);
#define i915_param_named(name, T, perm, desc) \
module_param_named(name, i915_modparams.name, T, perm); \
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 36/54] drm-dyndbg: DRM_CLASSMAP_USE in drm_crtc_helper
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (34 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 35/54] drm-dyndbg: DRM_CLASSMAP_USE in i915 driver Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 37/54] drm-dyndbg: DRM_CLASSMAP_USE in drm_dp_helper Jim Cromie
` (17 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
Following the dyndbg-api-fix, replace DECLARE_DYNDBG_CLASSMAP with
DRM_CLASSMAP_USE. This refs the defined & exported classmap, rather
than re-declaring it redundantly, and error-prone-ly.
This resolves the appearance of "class:_UNKNOWN_" in the control file
for the driver's drm_dbg()s.
Fixes: f158936b60a7 ("drm: POC drm on dyndbg - use in core, 2 helpers, 3 drivers.")
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
drivers/gpu/drm/drm_crtc_helper.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
index 0955f1c385dd..1d08d759f238 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -50,17 +50,7 @@
#include "drm_crtc_helper_internal.h"
-DECLARE_DYNDBG_CLASSMAP(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS, 0,
- "DRM_UT_CORE",
- "DRM_UT_DRIVER",
- "DRM_UT_KMS",
- "DRM_UT_PRIME",
- "DRM_UT_ATOMIC",
- "DRM_UT_VBL",
- "DRM_UT_STATE",
- "DRM_UT_LEASE",
- "DRM_UT_DP",
- "DRM_UT_DRMRES");
+DRM_CLASSMAP_USE(drm_debug_classes);
/**
* DOC: overview
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 37/54] drm-dyndbg: DRM_CLASSMAP_USE in drm_dp_helper
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (35 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 36/54] drm-dyndbg: DRM_CLASSMAP_USE in drm_crtc_helper Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 38/54] drm-dyndbg: DRM_CLASSMAP_USE in nouveau Jim Cromie
` (16 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
Following the dyndbg-api-fix, replace DECLARE_DYNDBG_CLASSMAP with
DRM_CLASSMAP_USE. This refs the defined & exported classmap, rather
than re-declaring it redundantly, and error-prone-ly.
This resolves the appearance of "class:_UNKNOWN_" in the control file
for the driver's drm_dbg()s.
Fixes: f158936b60a7 ("drm: POC drm on dyndbg - use in core, 2 helpers, 3 drivers.")
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
drivers/gpu/drm/display/drm_dp_helper.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/drivers/gpu/drm/display/drm_dp_helper.c b/drivers/gpu/drm/display/drm_dp_helper.c
index 61c7c2c588c6..68ba17eb2541 100644
--- a/drivers/gpu/drm/display/drm_dp_helper.c
+++ b/drivers/gpu/drm/display/drm_dp_helper.c
@@ -43,17 +43,7 @@
#include "drm_dp_helper_internal.h"
-DECLARE_DYNDBG_CLASSMAP(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS, 0,
- "DRM_UT_CORE",
- "DRM_UT_DRIVER",
- "DRM_UT_KMS",
- "DRM_UT_PRIME",
- "DRM_UT_ATOMIC",
- "DRM_UT_VBL",
- "DRM_UT_STATE",
- "DRM_UT_LEASE",
- "DRM_UT_DP",
- "DRM_UT_DRMRES");
+DRM_CLASSMAP_USE(drm_debug_classes);
struct dp_aux_backlight {
struct backlight_device *base;
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 38/54] drm-dyndbg: DRM_CLASSMAP_USE in nouveau
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (36 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 37/54] drm-dyndbg: DRM_CLASSMAP_USE in drm_dp_helper Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 39/54] drm-dyndbg: add DRM_CLASSMAP_USE to Xe driver Jim Cromie
` (15 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
Following the dyndbg-api-fix, replace DECLARE_DYNDBG_CLASSMAP with
DRM_CLASSMAP_USE. This refs the defined & exported classmap, rather
than re-declaring it redundantly, and error-prone-ly.
This resolves the appearance of "class:_UNKNOWN_" in the control file
for the driver's drm_dbg()s.
Fixes: f158936b60a7 ("drm: POC drm on dyndbg - use in core, 2 helpers, 3 drivers.")
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
drivers/gpu/drm/nouveau/nouveau_drm.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c
index 5664c4c71faf..bdecd27efabf 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
@@ -74,17 +74,7 @@
#include "nouveau_uvmm.h"
#include "nouveau_sched.h"
-DECLARE_DYNDBG_CLASSMAP(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS, 0,
- "DRM_UT_CORE",
- "DRM_UT_DRIVER",
- "DRM_UT_KMS",
- "DRM_UT_PRIME",
- "DRM_UT_ATOMIC",
- "DRM_UT_VBL",
- "DRM_UT_STATE",
- "DRM_UT_LEASE",
- "DRM_UT_DP",
- "DRM_UT_DRMRES");
+DRM_CLASSMAP_USE(drm_debug_classes);
MODULE_PARM_DESC(config, "option string to pass to driver core");
static char *nouveau_config;
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 39/54] drm-dyndbg: add DRM_CLASSMAP_USE to Xe driver
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (37 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 38/54] drm-dyndbg: DRM_CLASSMAP_USE in nouveau Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 40/54] drm-dyndbg: add DRM_CLASSMAP_USE to virtio_gpu Jim Cromie
` (14 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
Invoke DRM_CLASSMAP_USE from xe_drm_client.c. When built with
CONFIG_DRM_USE_DYNAMIC_DEBUG=y, this tells dydnbg that Xe has
drm.debug callsites.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
drivers/gpu/drm/xe/xe_drm_client.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/xe/xe_drm_client.c b/drivers/gpu/drm/xe/xe_drm_client.c
index 2d4874d2b922..756dba5c88f8 100644
--- a/drivers/gpu/drm/xe/xe_drm_client.c
+++ b/drivers/gpu/drm/xe/xe_drm_client.c
@@ -21,6 +21,8 @@
#include "xe_pm.h"
#include "xe_trace.h"
+DRM_CLASSMAP_USE(drm_debug_classes);
+
/**
* DOC: DRM Client usage stats
*
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 40/54] drm-dyndbg: add DRM_CLASSMAP_USE to virtio_gpu
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (38 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 39/54] drm-dyndbg: add DRM_CLASSMAP_USE to Xe driver Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 41/54] drm-dyndbg: add DRM_CLASSMAP_USE to simpledrm Jim Cromie
` (13 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
virtio_gpu has 10 DRM_UT_CORE debugs, make them controllable when
CONFIG_DRM_USE_DYNAMIC_DEBUG=y by telling dyndbg that the module has
class'd debugs.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
drivers/gpu/drm/virtio/virtgpu_drv.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.c b/drivers/gpu/drm/virtio/virtgpu_drv.c
index 6a67c6297d58..3bc4e6694fc2 100644
--- a/drivers/gpu/drm/virtio/virtgpu_drv.c
+++ b/drivers/gpu/drm/virtio/virtgpu_drv.c
@@ -45,6 +45,8 @@ static const struct drm_driver driver;
static int virtio_gpu_modeset = -1;
+DRM_CLASSMAP_USE(drm_debug_classes);
+
MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
module_param_named(modeset, virtio_gpu_modeset, int, 0400);
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 41/54] drm-dyndbg: add DRM_CLASSMAP_USE to simpledrm
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (39 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 40/54] drm-dyndbg: add DRM_CLASSMAP_USE to virtio_gpu Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 42/54] drm-dyndbg: add DRM_CLASSMAP_USE to bochs Jim Cromie
` (12 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
tiny/simpledrm has 3 DRM_UT_DRIVER debugs, make them controllable when
CONFIG_DRM_USE_DYNAMIC_DEBUG=y by telling dyndbg that the module has
class'd debugs.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
drivers/gpu/drm/tiny/simpledrm.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/tiny/simpledrm.c b/drivers/gpu/drm/tiny/simpledrm.c
index 5d9ab8adf800..bcf2cccac0ec 100644
--- a/drivers/gpu/drm/tiny/simpledrm.c
+++ b/drivers/gpu/drm/tiny/simpledrm.c
@@ -34,6 +34,8 @@
#define DRIVER_MAJOR 1
#define DRIVER_MINOR 0
+DRM_CLASSMAP_USE(drm_debug_classes);
+
/*
* Helpers for simplefb
*/
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 42/54] drm-dyndbg: add DRM_CLASSMAP_USE to bochs
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (40 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 41/54] drm-dyndbg: add DRM_CLASSMAP_USE to simpledrm Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 43/54] drm-dyndbg: add DRM_CLASSMAP_USE to etnaviv Jim Cromie
` (11 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
tiny/bochs has 5 DRM_UT_* debugs, make them controllable when
CONFIG_DRM_USE_DYNAMIC_DEBUG=y by telling dyndbg that the module has
class'd debugs.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
drivers/gpu/drm/tiny/bochs.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/tiny/bochs.c b/drivers/gpu/drm/tiny/bochs.c
index 8706763af8fb..dbcc8ba70dfa 100644
--- a/drivers/gpu/drm/tiny/bochs.c
+++ b/drivers/gpu/drm/tiny/bochs.c
@@ -59,6 +59,8 @@ static int bochs_modeset = -1;
static int defx = 1024;
static int defy = 768;
+DRM_CLASSMAP_USE(drm_debug_classes);
+
module_param_named(modeset, bochs_modeset, int, 0444);
MODULE_PARM_DESC(modeset, "enable/disable kernel modesetting");
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 43/54] drm-dyndbg: add DRM_CLASSMAP_USE to etnaviv
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (41 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 42/54] drm-dyndbg: add DRM_CLASSMAP_USE to bochs Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 44/54] drm-dyndbg: add DRM_CLASSMAP_USE to gma500 driver Jim Cromie
` (10 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
etnaviv has 5 DRM_UT_CORE debugs, make them controllable when
CONFIG_DRM_USE_DYNAMIC_DEBUG=y by telling dyndbg that the module has
class'd debugs as well as plain-old pr_debug()s
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
drivers/gpu/drm/etnaviv/etnaviv_drv.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c
index 3e91747ed339..70759b7d338f 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c
@@ -25,6 +25,8 @@
#include "etnaviv_mmu.h"
#include "etnaviv_perfmon.h"
+DRM_CLASSMAP_USE(drm_debug_classes);
+
/*
* DRM operations:
*/
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 44/54] drm-dyndbg: add DRM_CLASSMAP_USE to gma500 driver
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (42 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 43/54] drm-dyndbg: add DRM_CLASSMAP_USE to etnaviv Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 45/54] drm-dyndbg: add DRM_CLASSMAP_USE to radeon Jim Cromie
` (9 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
The gma500 has 126 DRM_UT_* debugs, make them controllable when
CONFIG_DRM_USE_DYNAMIC_DEBUG=y by telling dyndbg that the module has
class'd debugs.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
drivers/gpu/drm/gma500/psb_drv.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/gma500/psb_drv.c b/drivers/gpu/drm/gma500/psb_drv.c
index 85d3557c2eb9..dc72388ed08d 100644
--- a/drivers/gpu/drm/gma500/psb_drv.c
+++ b/drivers/gpu/drm/gma500/psb_drv.c
@@ -40,6 +40,8 @@
static const struct drm_driver driver;
static int psb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
+DRM_CLASSMAP_USE(drm_debug_classes);
+
/*
* The table below contains a mapping of the PCI vendor ID and the PCI Device ID
* to the different groups of PowerVR 5-series chip designs
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 45/54] drm-dyndbg: add DRM_CLASSMAP_USE to radeon
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (43 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 44/54] drm-dyndbg: add DRM_CLASSMAP_USE to gma500 driver Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 46/54] drm-dyndbg: add DRM_CLASSMAP_USE to vmwgfx driver Jim Cromie
` (8 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
radeon has some DRM_UT_* debugs, make them controllable when
CONFIG_DRM_USE_DYNAMIC_DEBUG=y by telling dyndbg about its use of
the class'd debugs.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
drivers/gpu/drm/radeon/radeon_drv.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c
index 267f082bc430..6eaac728e966 100644
--- a/drivers/gpu/drm/radeon/radeon_drv.c
+++ b/drivers/gpu/drm/radeon/radeon_drv.c
@@ -253,6 +253,8 @@ static const struct pci_device_id pciidlist[] = {
};
MODULE_DEVICE_TABLE(pci, pciidlist);
+DRM_CLASSMAP_USE(drm_debug_classes);
+
static const struct drm_driver kms_driver;
static int radeon_pci_probe(struct pci_dev *pdev,
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 46/54] drm-dyndbg: add DRM_CLASSMAP_USE to vmwgfx driver
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (44 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 45/54] drm-dyndbg: add DRM_CLASSMAP_USE to radeon Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 47/54] drm-dyndbg: add DRM_CLASSMAP_USE to vkms driver Jim Cromie
` (7 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
The vmwgfx driver has a number of DRM_UT_* debugs, make them
controllable when CONFIG_DRM_USE_DYNAMIC_DEBUG=y by telling dyndbg
that the module uses them.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 0f32471c8533..2b4f862fe5d4 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -279,6 +279,8 @@ static int vmw_probe(struct pci_dev *, const struct pci_device_id *);
static int vmwgfx_pm_notifier(struct notifier_block *nb, unsigned long val,
void *ptr);
+DRM_CLASSMAP_USE(drm_debug_classes);
+
MODULE_PARM_DESC(restrict_iommu, "Try to limit IOMMU usage for TTM pages");
module_param_named(restrict_iommu, vmw_restrict_iommu, int, 0600);
MODULE_PARM_DESC(force_coherent, "Force coherent TTM pages");
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 47/54] drm-dyndbg: add DRM_CLASSMAP_USE to vkms driver
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (45 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 46/54] drm-dyndbg: add DRM_CLASSMAP_USE to vmwgfx driver Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 48/54] drm-dyndbg: add DRM_CLASSMAP_USE to udl driver Jim Cromie
` (6 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
The vkms driver has a number of DRM_UT_* debugs, make them
controllable when CONFIG_DRM_USE_DYNAMIC_DEBUG=y by telling dyndbg
that the module uses them.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
drivers/gpu/drm/vkms/vkms_drv.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
index e0409aba9349..4b9da64661fb 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.c
+++ b/drivers/gpu/drm/vkms/vkms_drv.c
@@ -39,6 +39,8 @@
static struct vkms_config *default_config;
+DRM_CLASSMAP_USE(drm_debug_classes);
+
static bool enable_cursor = true;
module_param_named(enable_cursor, enable_cursor, bool, 0444);
MODULE_PARM_DESC(enable_cursor, "Enable/Disable cursor support");
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 48/54] drm-dyndbg: add DRM_CLASSMAP_USE to udl driver
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (46 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 47/54] drm-dyndbg: add DRM_CLASSMAP_USE to vkms driver Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 49/54] drm-dyndbg: add DRM_CLASSMAP_USE to mgag200 driver Jim Cromie
` (5 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
The udl driver has a number of DRM_UT_* debugs, make them
controllable when CONFIG_DRM_USE_DYNAMIC_DEBUG=y by telling dyndbg
that the module uses them.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
drivers/gpu/drm/udl/udl_main.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/udl/udl_main.c b/drivers/gpu/drm/udl/udl_main.c
index 3ebe2ce55dfd..ba57c14454e5 100644
--- a/drivers/gpu/drm/udl/udl_main.c
+++ b/drivers/gpu/drm/udl/udl_main.c
@@ -19,6 +19,8 @@
#define NR_USB_REQUEST_CHANNEL 0x12
+DRM_CLASSMAP_USE(drm_debug_classes);
+
#define MAX_TRANSFER (PAGE_SIZE*16 - BULK_SIZE)
#define WRITES_IN_FLIGHT (20)
#define MAX_VENDOR_DESCRIPTOR_SIZE 256
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 49/54] drm-dyndbg: add DRM_CLASSMAP_USE to mgag200 driver
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (47 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 48/54] drm-dyndbg: add DRM_CLASSMAP_USE to udl driver Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 50/54] drm-dyndbg: add DRM_CLASSMAP_USE to the gud driver Jim Cromie
` (4 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
The mgag200 driver has a number of DRM_UT_* debugs, make them
controllable when CONFIG_DRM_USE_DYNAMIC_DEBUG=y by telling dyndbg
that the module uses them.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
drivers/gpu/drm/mgag200/mgag200_drv.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.c b/drivers/gpu/drm/mgag200/mgag200_drv.c
index 069fdd2dc8f6..5b6ec1550da3 100644
--- a/drivers/gpu/drm/mgag200/mgag200_drv.c
+++ b/drivers/gpu/drm/mgag200/mgag200_drv.c
@@ -27,6 +27,8 @@ static int mgag200_modeset = -1;
MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
module_param_named(modeset, mgag200_modeset, int, 0400);
+DRM_CLASSMAP_USE(drm_debug_classes);
+
int mgag200_init_pci_options(struct pci_dev *pdev, u32 option, u32 option2)
{
struct device *dev = &pdev->dev;
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 50/54] drm-dyndbg: add DRM_CLASSMAP_USE to the gud driver
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (48 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 49/54] drm-dyndbg: add DRM_CLASSMAP_USE to mgag200 driver Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 51/54] drm-dyndbg: add DRM_CLASSMAP_USE to the qxl driver Jim Cromie
` (3 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
The gud driver has a number of DRM_UT_* debugs, make them
controllable when CONFIG_DRM_USE_DYNAMIC_DEBUG=y by telling dyndbg
that the module uses them.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
drivers/gpu/drm/gud/gud_drv.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/gud/gud_drv.c b/drivers/gpu/drm/gud/gud_drv.c
index cb405771d6e2..3843c0e47169 100644
--- a/drivers/gpu/drm/gud/gud_drv.c
+++ b/drivers/gpu/drm/gud/gud_drv.c
@@ -32,6 +32,8 @@
#include "gud_internal.h"
+DRM_CLASSMAP_USE(drm_debug_classes);
+
/* Only used internally */
static const struct drm_format_info gud_drm_format_r1 = {
.format = GUD_DRM_FORMAT_R1,
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 51/54] drm-dyndbg: add DRM_CLASSMAP_USE to the qxl driver
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (49 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 50/54] drm-dyndbg: add DRM_CLASSMAP_USE to the gud driver Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 52/54] drm-dyndbg: add DRM_CLASSMAP_USE to the drm_gem_shmem_helper driver Jim Cromie
` (2 subsequent siblings)
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
The qxl driver has a number of DRM_UT_* debugs, make them
controllable when CONFIG_DRM_USE_DYNAMIC_DEBUG=y by telling dyndbg
that the module uses them.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
drivers/gpu/drm/qxl/qxl_drv.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/qxl/qxl_drv.c b/drivers/gpu/drm/qxl/qxl_drv.c
index 417061ae59eb..c18577a3153d 100644
--- a/drivers/gpu/drm/qxl/qxl_drv.c
+++ b/drivers/gpu/drm/qxl/qxl_drv.c
@@ -66,6 +66,8 @@ module_param_named(modeset, qxl_modeset, int, 0400);
MODULE_PARM_DESC(num_heads, "Number of virtual crtcs to expose (default 4)");
module_param_named(num_heads, qxl_num_crtc, int, 0400);
+DRM_CLASSMAP_USE(drm_debug_classes);
+
static struct drm_driver qxl_driver;
static struct pci_driver qxl_pci_driver;
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 52/54] drm-dyndbg: add DRM_CLASSMAP_USE to the drm_gem_shmem_helper driver
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (50 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 51/54] drm-dyndbg: add DRM_CLASSMAP_USE to the qxl driver Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-02 17:41 ` [PATCH v3 53/54] drm: restore CONFIG_DRM_USE_DYNAMIC_DEBUG un-BROKEN Jim Cromie
2025-04-02 17:41 ` [PATCH v3 54/54] drm: RFC - make drm_dyndbg_user.o for drm-*_helpers, drivers Jim Cromie
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
The drm_gem_shmem_helper driver has a number of DRM_UT_* debugs, make
them controllable when CONFIG_DRM_USE_DYNAMIC_DEBUG=y by telling
dyndbg that the module uses them.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
drivers/gpu/drm/drm_gem_shmem_helper.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
index 5ab351409312..481d18561688 100644
--- a/drivers/gpu/drm/drm_gem_shmem_helper.c
+++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
@@ -23,6 +23,7 @@
#include <drm/drm_print.h>
MODULE_IMPORT_NS("DMA_BUF");
+DRM_CLASSMAP_USE(drm_debug_classes);
/**
* DOC: overview
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 53/54] drm: restore CONFIG_DRM_USE_DYNAMIC_DEBUG un-BROKEN
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (51 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 52/54] drm-dyndbg: add DRM_CLASSMAP_USE to the drm_gem_shmem_helper driver Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
2025-04-15 10:00 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 54/54] drm: RFC - make drm_dyndbg_user.o for drm-*_helpers, drivers Jim Cromie
53 siblings, 1 reply; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
Time for some thorough CI.
Also, the previous 18 patches could perhaps be replaced by a single
invocation of DYNDBG_CLASSMAP_USE, from a C-file linked into all drm
drivers & helpers. I didn't find such a file, nor a drm-client
linkage item in the Makefile.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
drivers/gpu/drm/Kconfig | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index fbef3f471bd0..c7d6adbe17eb 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -53,8 +53,7 @@ config DRM_DEBUG_MM
config DRM_USE_DYNAMIC_DEBUG
bool "use dynamic debug to implement drm.debug"
- default n
- depends on BROKEN
+ default y
depends on DRM
depends on DYNAMIC_DEBUG || DYNAMIC_DEBUG_CORE
depends on JUMP_LABEL
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v3 54/54] drm: RFC - make drm_dyndbg_user.o for drm-*_helpers, drivers
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
` (52 preceding siblings ...)
2025-04-02 17:41 ` [PATCH v3 53/54] drm: restore CONFIG_DRM_USE_DYNAMIC_DEBUG un-BROKEN Jim Cromie
@ 2025-04-02 17:41 ` Jim Cromie
53 siblings, 0 replies; 81+ messages in thread
From: Jim Cromie @ 2025-04-02 17:41 UTC (permalink / raw)
To: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, Jim Cromie
Add new drm_dyndbg_user.c with a single call to
DYNDBG_CLASSMAP_USE(drm_debug_classes). This creates a _class_user
record (and a linkage dependency).
If a driver adds this object to its Makefile target, it gets the
record, which authorizes dyndbg to enable the module's class'd
pr_debugs, such as DRMs <category>_dbg() macros.
So Id like to automatically inject this object into drivers. I tried
subdir-objs-y, but thats not a thing.
In drm/Makefile:
Add object dependency to drm_*_helper-y targets:
$targ-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) += drm_dyndbg_user.o
Attempt a foreach:
to add $driver-y += ../drm_dyndbg_user.o
this appears to be a train-wreck for impl reasons, but it describes a
want/need reasonably well. It might not be a good maintainble idea.
Explicitly adding to radeon/Makefile worked:
$radeon-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) += ../drm_dyndbg_user.o
But doing this is just as per-module as just adding the _USE()
explicitly to the main .c file, which is less magical than make-fu.
Also, it appears to cause make && make rebuilds.
and try to link it to helpers and everything
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
drivers/gpu/drm/Makefile | 9 +++++++++
drivers/gpu/drm/drm_dyndbg_user.c | 11 +++++++++++
2 files changed, 20 insertions(+)
create mode 100644 drivers/gpu/drm/drm_dyndbg_user.c
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 704f94efc804..1adb5a262180 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -74,10 +74,12 @@ drm-y := \
drm_vblank_work.o \
drm_vma_manager.o \
drm_writeback.o
+
drm-$(CONFIG_DRM_CLIENT) += \
drm_client.o \
drm_client_event.o \
drm_client_modeset.o
+
drm-$(CONFIG_DRM_LIB_RANDOM) += lib/drm_random.o
drm-$(CONFIG_COMPAT) += drm_ioc32.o
drm-$(CONFIG_DRM_PANEL) += drm_panel.o
@@ -111,20 +113,25 @@ obj-$(CONFIG_DRM_BUDDY) += drm_buddy.o
drm_dma_helper-y := drm_gem_dma_helper.o
drm_dma_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fbdev_dma.o
drm_dma_helper-$(CONFIG_DRM_KMS_HELPER) += drm_fb_dma_helper.o
+drm_dma_helper-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) += drm_dyndbg_user.o
obj-$(CONFIG_DRM_GEM_DMA_HELPER) += drm_dma_helper.o
drm_shmem_helper-y := drm_gem_shmem_helper.o
drm_shmem_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fbdev_shmem.o
+drm_shmem_helper-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) += drm_dyndbg_user.o
obj-$(CONFIG_DRM_GEM_SHMEM_HELPER) += drm_shmem_helper.o
drm_suballoc_helper-y := drm_suballoc.o
+drm_suballoc_helper-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) += drm_dyndbg_user.o
obj-$(CONFIG_DRM_SUBALLOC_HELPER) += drm_suballoc_helper.o
drm_vram_helper-y := drm_gem_vram_helper.o
+drm_vram_helper-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) += drm_dyndbg_user.o
obj-$(CONFIG_DRM_VRAM_HELPER) += drm_vram_helper.o
drm_ttm_helper-y := drm_gem_ttm_helper.o
drm_ttm_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fbdev_ttm.o
+drm_ttm_helper-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) += drm_dyndbg_user.o
obj-$(CONFIG_DRM_TTM_HELPER) += drm_ttm_helper.o
#
@@ -149,11 +156,13 @@ drm_kms_helper-y := \
drm_simple_kms_helper.o
drm_kms_helper-$(CONFIG_DRM_PANEL_BRIDGE) += bridge/panel.o
drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
+drm_kms_helper-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) += drm_dyndbg_user.o
obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o
#
# Drivers and the rest
#
+subdir-obj-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) += drm_dyndbg_user.o
obj-y += tests/
diff --git a/drivers/gpu/drm/drm_dyndbg_user.c b/drivers/gpu/drm/drm_dyndbg_user.c
new file mode 100644
index 000000000000..9e4aa87d4b58
--- /dev/null
+++ b/drivers/gpu/drm/drm_dyndbg_user.c
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "drm/drm_print.h"
+/*
+ * if DRM_USE_DYNAMIC_DEBBUG:
+ * DYNDBG_CLASSMAP_USE(drm_debug_classes);
+ *
+ * dyndbg classmaps are opt-in, so modules which call drm:_*_dbg must
+ * link this to authorize dyndbg to change the static-keys underneath.
+ */
+DRM_CLASSMAP_USE(drm_debug_classes);
--
2.49.0
^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v3 01/54] vmlinux.lds.h: fixup HEADERED_SECTION{,_BY} macros
2025-04-02 17:41 ` [PATCH v3 01/54] vmlinux.lds.h: fixup HEADERED_SECTION{,_BY} macros Jim Cromie
@ 2025-04-15 9:59 ` Louis Chauvet
0 siblings, 0 replies; 81+ messages in thread
From: Louis Chauvet @ 2025-04-15 9:59 UTC (permalink / raw)
To: Jim Cromie, jbaron, gregkh, ukaszb, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala
Hi Jim,
Thanks a lot for this v3!
Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> commit 1d926e259d8f ("vmlinux.lds.h: add HEADERED_SECTION_* macros")
>
> I flubbed the defn of the outer 2 macros; they missed the extra arg
> needed: _front/_hdr. Fix it now, before anyone notices.
I don't see any usage of this change in the series. Is it related to it?
If no, can you make this a separate series, it is already difficult to
review the dyndbg part without unrelated noise?
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
> ---
> include/asm-generic/vmlinux.lds.h | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> index 0d5b186abee8..c9c66089ea2f 100644
> --- a/include/asm-generic/vmlinux.lds.h
> +++ b/include/asm-generic/vmlinux.lds.h
> @@ -219,10 +219,11 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
> KEEP(*(.gnu.linkonce.##_sec_)) \
> BOUNDED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_)
>
> -#define HEADERED_SECTION_BY(_sec_, _label_) \
> - HEADERED_SECTION_PRE_LABEL(_sec_, _label_, __start, __stop)
> +#define HEADERED_SECTION_BY(_sec_, _label_, _front) \
> + HEADERED_SECTION_PRE_LABEL(_sec_, _label_, __start, __stop, _front)
>
> -#define HEADERED_SECTION(_sec) HEADERED_SECTION_BY(_sec, _sec)
> +#define HEADERED_SECTION(_sec, _front) \
> + HEADERED_SECTION_BY(_sec, _sec, _front)
>
> #ifdef CONFIG_TRACE_BRANCH_PROFILING
> #define LIKELY_PROFILE() \
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 02/54] docs/dyndbg: update examples \012 to \n
2025-04-02 17:41 ` [PATCH v3 02/54] docs/dyndbg: update examples \012 to \n Jim Cromie
@ 2025-04-15 9:59 ` Louis Chauvet
0 siblings, 0 replies; 81+ messages in thread
From: Louis Chauvet @ 2025-04-15 9:59 UTC (permalink / raw)
To: Jim Cromie, jbaron, gregkh, ukaszb, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala
Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> commit 47ea6f99d06e ("dyndbg: use ESCAPE_SPACE for cat control")
> changed the control-file to display format strings with "\n" rather
> than "\012". Update the docs to match the new reality.
Hi,
I don't know what is the process for dyndbg and how much review you
need, but what are your thoughts on applying 02..09 as soon it is
possible to reduce the size of the series?
Thanks,
Louis Chauvet
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
> Tested-by: Louis Chauvet<louis.chauvet@bootlin.com>
> ---
> -v2 fix missed \012's
> ---
> .../admin-guide/dynamic-debug-howto.rst | 20 +++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/Documentation/admin-guide/dynamic-debug-howto.rst b/Documentation/admin-guide/dynamic-debug-howto.rst
> index 7c036590cd07..4ac18c0a1d95 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\012
> - init/main.c:1218 [main]initcall_blacklisted =_ "initcall %s blacklisted\012"
> - init/main.c:1424 [main]run_init_process =_ " with arguments:\012"
> - init/main.c:1426 [main]run_init_process =_ " %s\012"
> - init/main.c:1427 [main]run_init_process =_ " with environment:\012"
> - init/main.c:1429 [main]run_init_process =_ " %s\012"
> + 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"
>
> 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:\012"
> - init/main.c:1426 [main]run_init_process =p " %s\012"
> - init/main.c:1427 [main]run_init_process =p " with environment:\012"
> - init/main.c:1429 [main]run_init_process =p " %s\012"
> + 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"
>
> Error messages go to console/syslog::
>
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 11/54] dyndbg: replace classmap list with a vector
2025-04-02 17:41 ` [PATCH v3 11/54] dyndbg: replace classmap list with a vector Jim Cromie
@ 2025-04-15 9:59 ` Louis Chauvet
0 siblings, 0 replies; 81+ messages in thread
From: Louis Chauvet @ 2025-04-15 9:59 UTC (permalink / raw)
To: Jim Cromie, jbaron, gregkh, ukaszb, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala
Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> Classmaps are stored in an elf section/array, but currently are
> individually list-linked onto dyndbg's per-module ddebug_table for
> operation. This is unnecessary.
>
> Just like dyndbg's descriptors, classes are packed in compile order;
> so even with many builtin modules employing multiple classmaps, each
> modules' maps are packed contiguously, and can be treated as a
> array-start-address & array-length.
>
> So this drops the whole list building operation done in
> ddebug_attach_module_classes(), and removes the list-head members.
> The "select-by-modname" condition is reused to find the start,end of
> the subrange.
>
> NOTE: This "filter-by-modname" on classmaps should really be done in
> ddebug_add_module(1); ie at least one step closer to ddebug_init(2),
> which already splits up pr-debug descriptors into subranges by
> modname, then calls (1) on each. (2) knows nothing of classmaps
> currently, and doesn't need to. For now, just add comment.
>
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> ---
> v3- drop __outvar as promising magic it doesnt have
> ---
> include/linux/dynamic_debug.h | 1 -
> lib/dynamic_debug.c | 62 ++++++++++++++++++-----------------
> 2 files changed, 32 insertions(+), 31 deletions(-)
>
> diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
> index ac199293d203..e458d4b838ac 100644
> --- a/include/linux/dynamic_debug.h
> +++ b/include/linux/dynamic_debug.h
> @@ -83,7 +83,6 @@ enum class_map_type {
> };
>
> struct ddebug_class_map {
> - struct list_head link;
> struct module *mod;
> const char *mod_name; /* needed for builtins */
> const char **class_names;
> diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
> index 621e04b1f28c..85b8d32742ec 100644
> --- a/lib/dynamic_debug.c
> +++ b/lib/dynamic_debug.c
> @@ -45,10 +45,11 @@ extern struct ddebug_class_map __start___dyndbg_classes[];
> extern struct ddebug_class_map __stop___dyndbg_classes[];
>
> struct ddebug_table {
> - struct list_head link, maps;
> + struct list_head link;
> const char *mod_name;
> - unsigned int num_ddebugs;
> struct _ddebug *ddebugs;
> + struct ddebug_class_map *classes;
> + unsigned int num_ddebugs, num_classes;
> };
>
> struct ddebug_query {
> @@ -148,12 +149,13 @@ static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
> }
>
> static struct ddebug_class_map *ddebug_find_valid_class(struct ddebug_table const *dt,
> - const char *class_string, int *class_id)
> + const char *class_string,
> + int *class_id)
> {
> struct ddebug_class_map *map;
> - int idx;
> + int i, idx;
>
> - list_for_each_entry(map, &dt->maps, link) {
> + for (map = dt->classes, i = 0; i < dt->num_classes; i++, map++) {
> idx = match_string(map->class_names, map->length, class_string);
> if (idx >= 0) {
> *class_id = idx + map->base;
> @@ -164,7 +166,6 @@ static struct ddebug_class_map *ddebug_find_valid_class(struct ddebug_table cons
> return NULL;
> }
>
> -#define __outvar /* filled by callee */
> /*
> * Search the tables for _ddebug's which match the given `query' and
> * apply the `flags' and `mask' to them. Returns number of matching
> @@ -180,7 +181,7 @@ static int ddebug_change(const struct ddebug_query *query,
> unsigned int nfound = 0;
> struct flagsbuf fbuf, nbuf;
> struct ddebug_class_map *map = NULL;
> - int __outvar valid_class;
> + int valid_class;
>
> /* search for matching ddebugs */
> mutex_lock(&ddebug_lock);
> @@ -1122,9 +1123,10 @@ static void *ddebug_proc_next(struct seq_file *m, void *p, loff_t *pos)
>
> static const char *ddebug_class_name(struct ddebug_iter *iter, struct _ddebug *dp)
> {
> - struct ddebug_class_map *map;
> + struct ddebug_class_map *map = iter->table->classes;
> + int i, nc = iter->table->num_classes;
>
> - list_for_each_entry(map, &iter->table->maps, link)
> + for (i = 0; i < nc; i++, map++)
> if (class_in_range(dp->class_id, map))
> return map->class_names[dp->class_id - map->base];
>
> @@ -1208,30 +1210,31 @@ static const struct proc_ops proc_fops = {
> .proc_write = ddebug_proc_write
> };
>
> -static void ddebug_attach_module_classes(struct ddebug_table *dt,
> - struct ddebug_class_map *classes,
> - int num_classes)
> +static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug_info *di)
> {
> struct ddebug_class_map *cm;
> - int i, j, ct = 0;
> + int i, nc = 0;
>
> - for (cm = classes, i = 0; i < num_classes; i++, cm++) {
> + /*
> + * Find this module's classmaps in a subrange/wholerange of
> + * the builtin/modular classmap vector/section. Save the start
> + * and length of the subrange at its edges.
> + */
> + for (cm = di->classes, i = 0; i < di->num_classes; i++, cm++) {
>
> if (!strcmp(cm->mod_name, dt->mod_name)) {
> -
> - v2pr_info("class[%d]: module:%s base:%d len:%d ty:%d\n", i,
> - cm->mod_name, cm->base, cm->length, cm->map_type);
> -
> - for (j = 0; j < cm->length; j++)
> - v3pr_info(" %d: %d %s\n", j + cm->base, j,
> - cm->class_names[j]);
> -
> - list_add(&cm->link, &dt->maps);
> - ct++;
> + if (!nc) {
> + v2pr_info("start subrange, class[%d]: module:%s base:%d len:%d ty:%d\n",
> + i, cm->mod_name, cm->base, cm->length, cm->map_type);
I think the log change belongs to patch 08 (reduce verbose/debug clutter).
With or without this:
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
> + dt->classes = cm;
> + }
> + nc++;
> }
> }
> - if (ct)
> - vpr_info("module:%s attached %d classes\n", dt->mod_name, ct);
> + if (nc) {
> + dt->num_classes = nc;
> + vpr_info("module:%s attached %d classes\n", dt->mod_name, nc);
> + }
> }
>
> /*
> @@ -1263,10 +1266,9 @@ static int ddebug_add_module(struct _ddebug_info *di, const char *modname)
> dt->num_ddebugs = di->num_descs;
>
> INIT_LIST_HEAD(&dt->link);
> - INIT_LIST_HEAD(&dt->maps);
>
> if (di->classes && di->num_classes)
> - ddebug_attach_module_classes(dt, di->classes, di->num_classes);
> + ddebug_attach_module_classes(dt, di);
>
> mutex_lock(&ddebug_lock);
> list_add_tail(&dt->link, &ddebug_tables);
> @@ -1379,8 +1381,8 @@ static void ddebug_remove_all_tables(void)
> mutex_lock(&ddebug_lock);
> while (!list_empty(&ddebug_tables)) {
> struct ddebug_table *dt = list_entry(ddebug_tables.next,
> - struct ddebug_table,
> - link);
> + struct ddebug_table,
> + link);
> ddebug_table_free(dt);
> }
> mutex_unlock(&ddebug_lock);
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 13/54] dyndbg, module: make proper substructs in _ddebug_info
2025-04-02 17:41 ` [PATCH v3 13/54] dyndbg, module: make proper substructs in _ddebug_info Jim Cromie
@ 2025-04-15 9:59 ` Louis Chauvet
0 siblings, 0 replies; 81+ messages in thread
From: Louis Chauvet @ 2025-04-15 9:59 UTC (permalink / raw)
To: Jim Cromie, jbaron, gregkh, ukaszb, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala
Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> recompose struct _ddebug_info, inserting proper sub-structs.
>
> The struct currently has 2 pairs of fields: descs, num_descs and
> classes, num_classes. Several for-loops operate on these field pairs,
> soon many more will be added.
>
> Looping over these blocks by respective field-pairs is repetitive and
> fiddly, differing only by the field-names. Before adding a 3rd
> section and compounding the fiddly details problem, make proper
> substructs of each section, with the same named fields.
>
> So this patch does:
>
> Adds 3 "vector<T>" structs, each with { <T> *start, int len; }
> components, for _ddebug_descriptors, _ddebug_class_maps, and
> _ddebug_class_users respectively.
>
> Invariant: These vectors ref a contiguous subrange of __section memory
> in builtin/DATA or in loadable modules via mod->dyndbg_info; with
> guaranteed life-time for us.
>
> Bundles these 3 vectors (subrange-refs) struct (reformed) _ddebug_info,
> where they're __packed to close the paholes introduced otherwise.
>
> The common fields allow improving the for_subvec() macro by dropping
> the ugly num_##<T> paste-up.
>
> Also recompose struct ddebug_table to contain a _ddebug_info. This
> reinforces its use as a cursor into relevant data for a builtin
> module, and access to the full _ddebug state for modules.
>
> NOTES:
>
> Fixup names: section names improved, struct names normalized to
> _ddebug_*
>
> struct module contains a _ddebug_info field and module/main.c sets it
> up, so that gets adjusted.
>
> The __packed attribute on _ddebug_info and the 3 contained structs
> closes the holes otherwise created by the structification (which was
> my excuse for not doing it originally).
>
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> ---
> -v2 rework towards front of series
> ---
> include/asm-generic/vmlinux.lds.h | 4 +-
> include/linux/dynamic_debug.h | 42 +++++++-----
> kernel/module/main.c | 12 ++--
> lib/dynamic_debug.c | 108 ++++++++++++++----------------
> lib/test_dynamic_debug.c | 2 +-
> 5 files changed, 88 insertions(+), 80 deletions(-)
>
> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> index c9c66089ea2f..f834ad1fb8c4 100644
> --- a/include/asm-generic/vmlinux.lds.h
> +++ b/include/asm-generic/vmlinux.lds.h
> @@ -366,8 +366,8 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
> *(__tracepoints) \
> /* implement dynamic printk debug */ \
> . = ALIGN(8); \
> - BOUNDED_SECTION_BY(__dyndbg_classes, ___dyndbg_classes) \
> - BOUNDED_SECTION_BY(__dyndbg, ___dyndbg) \
> + BOUNDED_SECTION_BY(__dyndbg_class_maps, ___dyndbg_class_maps) \
> + BOUNDED_SECTION_BY(__dyndbg_descriptors, ___dyndbg_descs) \
> CODETAG_SECTIONS() \
> LIKELY_PROFILE() \
> BRANCH_PROFILE() \
> diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
> index e458d4b838ac..9d282e2444e1 100644
> --- a/include/linux/dynamic_debug.h
> +++ b/include/linux/dynamic_debug.h
> @@ -82,7 +82,7 @@ enum class_map_type {
> */
> };
>
> -struct ddebug_class_map {
> +struct _ddebug_class_map {
> struct module *mod;
> const char *mod_name; /* needed for builtins */
> const char **class_names;
> @@ -93,15 +93,15 @@ struct ddebug_class_map {
>
> /**
> * DECLARE_DYNDBG_CLASSMAP - declare classnames known by a module
> - * @_var: a struct ddebug_class_map, passed to module_param_cb
> + * @_var: a struct _ddebug_class_map, passed to module_param_cb
> * @_type: enum class_map_type, chooses bits/verbose, numeric/symbolic
> * @_base: offset of 1st class-name. splits .class_id space
> * @classes: class-names used to control class'd prdbgs
> */
> #define DECLARE_DYNDBG_CLASSMAP(_var, _maptype, _base, ...) \
> static const char *_var##_classnames[] = { __VA_ARGS__ }; \
> - static struct ddebug_class_map __aligned(8) __used \
> - __section("__dyndbg_classes") _var = { \
> + static struct _ddebug_class_map __aligned(8) __used \
> + __section("__dyndbg_class_maps") _var = { \
> .mod = THIS_MODULE, \
> .mod_name = KBUILD_MODNAME, \
> .base = _base, \
> @@ -110,21 +110,33 @@ struct ddebug_class_map {
> .class_names = _var##_classnames, \
> }
>
> -/* encapsulate linker provided built-in (or module) dyndbg data */
> +/*
> + * @_ddebug_info: gathers module/builtin dyndbg_* __sections together.
> + * For builtins, it is used as a cursor, with the inner structs
> + * marking sub-vectors of the builtin __sections in DATA.
> + */
> +struct _ddebug_descs {
> + struct _ddebug *start;
> + int len;
> +} __packed;
> +
> +struct _ddebug_class_maps {
> + struct _ddebug_class_map *start;
> + int len;
> +} __packed;
> +
> struct _ddebug_info {
> - struct _ddebug *descs;
> - struct ddebug_class_map *classes;
> - unsigned int num_descs;
> - unsigned int num_classes;
> -};
> + struct _ddebug_descs descs;
> + struct _ddebug_class_maps maps;
> +} __packed;
>
> -struct ddebug_class_param {
> +struct _ddebug_class_param {
> union {
> unsigned long *bits;
> unsigned long *lvl;
> };
> char flags[8];
> - const struct ddebug_class_map *map;
> + const struct _ddebug_class_map *map;
> };
>
> /*
> @@ -159,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 = { \
> + __section("__dyndbg_descriptors") name = { \
> .modname = KBUILD_MODNAME, \
> .function = __func__, \
> .filename = __FILE__, \
> @@ -242,7 +254,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
> * macro.
> */
> #define _dynamic_func_call_cls(cls, fmt, func, ...) \
> - __dynamic_func_call_cls(__UNIQUE_ID(ddebug), cls, fmt, func, ##__VA_ARGS__)
> + __dynamic_func_call_cls(__UNIQUE_ID(_ddebug), cls, fmt, func, ##__VA_ARGS__)
> #define _dynamic_func_call(fmt, func, ...) \
> _dynamic_func_call_cls(_DPRINTK_CLASS_DFLT, fmt, func, ##__VA_ARGS__)
>
> @@ -252,7 +264,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
> * with precisely the macro's varargs.
> */
> #define _dynamic_func_call_cls_no_desc(cls, fmt, func, ...) \
> - __dynamic_func_call_cls_no_desc(__UNIQUE_ID(ddebug), cls, fmt, \
> + __dynamic_func_call_cls_no_desc(__UNIQUE_ID(_ddebug), cls, fmt, \
> func, ##__VA_ARGS__)
> #define _dynamic_func_call_no_desc(fmt, func, ...) \
> _dynamic_func_call_cls_no_desc(_DPRINTK_CLASS_DFLT, fmt, \
> diff --git a/kernel/module/main.c b/kernel/module/main.c
> index 1fb9ad289a6f..b60f728e36ac 100644
> --- a/kernel/module/main.c
> +++ b/kernel/module/main.c
> @@ -2621,12 +2621,12 @@ static int find_module_sections(struct module *mod, struct load_info *info)
> pr_warn("%s: Ignoring obsolete parameters\n", mod->name);
>
> #ifdef CONFIG_DYNAMIC_DEBUG_CORE
> - mod->dyndbg_info.descs = section_objs(info, "__dyndbg",
> - sizeof(*mod->dyndbg_info.descs),
> - &mod->dyndbg_info.num_descs);
> - mod->dyndbg_info.classes = section_objs(info, "__dyndbg_classes",
> - sizeof(*mod->dyndbg_info.classes),
> - &mod->dyndbg_info.num_classes);
> + mod->dyndbg_info.descs.start = section_objs(info, "__dyndbg_descriptors",
> + sizeof(*mod->dyndbg_info.descs.start),
> + &mod->dyndbg_info.descs.len);
> + mod->dyndbg_info.maps.start = section_objs(info, "__dyndbg_class_maps",
> + sizeof(*mod->dyndbg_info.maps.start),
> + &mod->dyndbg_info.maps.len);
> #endif
>
> return 0;
> diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
> index 253eaf0a9bd6..104cf8abdf33 100644
> --- a/lib/dynamic_debug.c
> +++ b/lib/dynamic_debug.c
> @@ -39,17 +39,15 @@
>
> #include <rdma/ib_verbs.h>
>
> -extern struct _ddebug __start___dyndbg[];
> -extern struct _ddebug __stop___dyndbg[];
> -extern struct ddebug_class_map __start___dyndbg_classes[];
> -extern struct ddebug_class_map __stop___dyndbg_classes[];
> +extern struct _ddebug __start___dyndbg_descs[];
> +extern struct _ddebug __stop___dyndbg_descs[];
> +extern struct _ddebug_class_map __start___dyndbg_class_maps[];
> +extern struct _ddebug_class_map __stop___dyndbg_class_maps[];
>
> struct ddebug_table {
> struct list_head link;
> const char *mod_name;
> - struct _ddebug *ddebugs;
> - struct ddebug_class_map *classes;
> - unsigned int num_ddebugs, num_classes;
> + struct _ddebug_info info;
> };
>
> struct ddebug_query {
> @@ -128,7 +126,6 @@ do { \
> #define v3pr_info(fmt, ...) vnpr_info(3, fmt, ##__VA_ARGS__)
> #define v4pr_info(fmt, ...) vnpr_info(4, fmt, ##__VA_ARGS__)
>
> -
> /*
> * simplify a repeated for-loop pattern walking N steps in a T _vec
> * member inside a struct _box. It expects int i and T *_sp to be
> @@ -139,8 +136,8 @@ do { \
> * @_vec: name of a sub-struct member in _box, with array-ref and length
> */
> #define for_subvec(_i, _sp, _box, _vec) \
> - for ((_i) = 0, (_sp) = (_box)->_vec; \
> - (_i) < (_box)->num_##_vec; \
> + for ((_i) = 0, (_sp) = (_box)->_vec.start; \
> + (_i) < (_box)->_vec.len; \
> (_i)++, (_sp)++)
>
> static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
> @@ -163,14 +160,14 @@ static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
> query->first_lineno, query->last_lineno, query->class_string);
> }
>
> -static struct ddebug_class_map *ddebug_find_valid_class(struct ddebug_table const *dt,
> +static struct _ddebug_class_map *ddebug_find_valid_class(struct ddebug_table const *dt,
> const char *class_string,
> int *class_id)
> {
> - struct ddebug_class_map *map;
> + struct _ddebug_class_map *map;
> int i, idx;
>
> - for_subvec(i, map, dt, classes) {
> + for_subvec(i, map, &dt->info, maps) {
> idx = match_string(map->class_names, map->length, class_string);
> if (idx >= 0) {
> *class_id = idx + map->base;
> @@ -195,7 +192,7 @@ static int ddebug_change(const struct ddebug_query *query,
> unsigned int newflags;
> unsigned int nfound = 0;
> struct flagsbuf fbuf, nbuf;
> - struct ddebug_class_map *map = NULL;
> + struct _ddebug_class_map *map = NULL;
> int valid_class;
>
> /* search for matching ddebugs */
> @@ -216,8 +213,8 @@ static int ddebug_change(const struct ddebug_query *query,
> valid_class = _DPRINTK_CLASS_DFLT;
> }
>
> - for (i = 0; i < dt->num_ddebugs; i++) {
> - struct _ddebug *dp = &dt->ddebugs[i];
> + for (i = 0; i < dt->info.descs.len; i++) {
> + struct _ddebug *dp = &dt->info.descs.start[i];
>
> /* match site against query-class */
> if (dp->class_id != valid_class)
> @@ -610,14 +607,14 @@ static int ddebug_exec_queries(char *query, const char *modname)
> }
>
> /* apply a new class-param setting */
> -static int ddebug_apply_class_bitmap(const struct ddebug_class_param *dcp,
> +static int ddebug_apply_class_bitmap(const struct _ddebug_class_param *dcp,
> const unsigned long *new_bits,
> const unsigned long old_bits,
> const char *query_modname)
> {
> #define QUERY_SIZE 128
> char query[QUERY_SIZE];
> - const struct ddebug_class_map *map = dcp->map;
> + const struct _ddebug_class_map *map = dcp->map;
> int matches = 0;
> int bi, ct;
>
> @@ -653,8 +650,8 @@ static int ddebug_apply_class_bitmap(const struct ddebug_class_param *dcp,
> /* accept comma-separated-list of [+-] classnames */
> static int param_set_dyndbg_classnames(const char *instr, const struct kernel_param *kp)
> {
> - const struct ddebug_class_param *dcp = kp->arg;
> - const struct ddebug_class_map *map = dcp->map;
> + const struct _ddebug_class_param *dcp = kp->arg;
> + const struct _ddebug_class_map *map = dcp->map;
> unsigned long curr_bits, old_bits;
> char *cl_str, *p, *tmp;
> int cls_id, totct = 0;
> @@ -724,8 +721,8 @@ static int param_set_dyndbg_module_classes(const char *instr,
> const struct kernel_param *kp,
> const char *mod_name)
> {
> - const struct ddebug_class_param *dcp = kp->arg;
> - const struct ddebug_class_map *map = dcp->map;
> + const struct _ddebug_class_param *dcp = kp->arg;
> + const struct _ddebug_class_map *map = dcp->map;
> unsigned long inrep, new_bits, old_bits;
> int rc, totct = 0;
>
> @@ -812,8 +809,8 @@ EXPORT_SYMBOL(param_set_dyndbg_classes);
> */
> int param_get_dyndbg_classes(char *buffer, const struct kernel_param *kp)
> {
> - const struct ddebug_class_param *dcp = kp->arg;
> - const struct ddebug_class_map *map = dcp->map;
> + const struct _ddebug_class_param *dcp = kp->arg;
> + const struct _ddebug_class_map *map = dcp->map;
>
> switch (map->map_type) {
>
> @@ -1064,8 +1061,8 @@ static struct _ddebug *ddebug_iter_first(struct ddebug_iter *iter)
> }
> iter->table = list_entry(ddebug_tables.next,
> struct ddebug_table, link);
> - iter->idx = iter->table->num_ddebugs;
> - return &iter->table->ddebugs[--iter->idx];
> + iter->idx = iter->table->info.descs.len;
> + return &iter->table->info.descs.start[--iter->idx];
> }
>
> /*
> @@ -1086,10 +1083,10 @@ static struct _ddebug *ddebug_iter_next(struct ddebug_iter *iter)
> }
> iter->table = list_entry(iter->table->link.next,
> struct ddebug_table, link);
> - iter->idx = iter->table->num_ddebugs;
> + iter->idx = iter->table->info.descs.len;
> --iter->idx;
> }
> - return &iter->table->ddebugs[iter->idx];
> + return &iter->table->info.descs.start[iter->idx];
> }
>
> /*
> @@ -1136,12 +1133,12 @@ static void *ddebug_proc_next(struct seq_file *m, void *p, loff_t *pos)
> #define class_in_range(class_id, map) \
> (class_id >= map->base && class_id < map->base + map->length)
>
> -static const char *ddebug_class_name(struct ddebug_iter *iter, struct _ddebug *dp)
> +static const char *ddebug_class_name(struct ddebug_table *dt, struct _ddebug *dp)
> {
> - struct ddebug_class_map *map = iter->table->classes;
> - int i, nc = iter->table->num_classes;
> + struct _ddebug_class_map *map;
> + int i;
>
> - for (i = 0; i < nc; i++, map++)
> + for_subvec(i, map, &dt->info, maps)
> if (class_in_range(dp->class_id, map))
> return map->class_names[dp->class_id - map->base];
>
> @@ -1175,7 +1172,7 @@ static int ddebug_proc_show(struct seq_file *m, void *p)
> seq_putc(m, '"');
>
> if (dp->class_id != _DPRINTK_CLASS_DFLT) {
> - class = ddebug_class_name(iter, dp);
> + class = ddebug_class_name(iter->table, dp);
> if (class)
> seq_printf(m, " class:%s", class);
> else
> @@ -1227,7 +1224,7 @@ static const struct proc_ops proc_fops = {
>
> static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug_info *di)
> {
> - struct ddebug_class_map *cm;
> + struct _ddebug_class_map *cm;
> int i, nc = 0;
>
> /*
> @@ -1235,18 +1232,18 @@ static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug
> * the builtin/modular classmap vector/section. Save the start
> * and length of the subrange at its edges.
> */
> - for_subvec(i, cm, di, classes) {
> + for_subvec(i, cm, di, maps) {
> if (!strcmp(cm->mod_name, dt->mod_name)) {
> if (!nc) {
> v2pr_info("start subrange, class[%d]: module:%s base:%d len:%d ty:%d\n",
> i, cm->mod_name, cm->base, cm->length, cm->map_type);
> - dt->classes = cm;
> + dt->info.maps.start = cm;
> }
> nc++;
> }
> }
> if (nc) {
> - dt->num_classes = nc;
> + dt->info.maps.len = nc;
> vpr_info("module:%s attached %d classes\n", dt->mod_name, nc);
> }
> }
> @@ -1259,10 +1256,10 @@ static int ddebug_add_module(struct _ddebug_info *di, const char *modname)
> {
> struct ddebug_table *dt;
>
> - if (!di->num_descs)
> + if (!di->descs.len)
> return 0;
>
> - v3pr_info("add-module: %s %d sites\n", modname, di->num_descs);
> + v3pr_info("add-module: %s %d sites\n", modname, di->descs.len);
>
> dt = kzalloc(sizeof(*dt), GFP_KERNEL);
> if (dt == NULL) {
> @@ -1276,19 +1273,18 @@ static int ddebug_add_module(struct _ddebug_info *di, const char *modname)
> * this struct ddebug_table.
> */
> dt->mod_name = modname;
> - dt->ddebugs = di->descs;
> - dt->num_ddebugs = di->num_descs;
> + dt->info = *di;
>
> INIT_LIST_HEAD(&dt->link);
>
> - if (di->classes && di->num_classes)
> + if (di->maps.len)
> ddebug_attach_module_classes(dt, di);
>
> mutex_lock(&ddebug_lock);
> list_add_tail(&dt->link, &ddebug_tables);
> mutex_unlock(&ddebug_lock);
>
> - vpr_info("%3u debug prints in module %s\n", di->num_descs, modname);
> + vpr_info("%3u debug prints in module %s\n", di->descs.len, modname);
> return 0;
> }
>
> @@ -1435,10 +1431,10 @@ static int __init dynamic_debug_init(void)
> char *cmdline;
>
> struct _ddebug_info di = {
> - .descs = __start___dyndbg,
> - .classes = __start___dyndbg_classes,
> - .num_descs = __stop___dyndbg - __start___dyndbg,
> - .num_classes = __stop___dyndbg_classes - __start___dyndbg_classes,
> + .descs.start = __start___dyndbg_descs,
> + .maps.start = __start___dyndbg_class_maps,
> + .descs.len = __stop___dyndbg_descs - __start___dyndbg_descs,
> + .maps.len = __stop___dyndbg_class_maps - __start___dyndbg_class_maps,
> };
>
> #ifdef CONFIG_MODULES
> @@ -1449,7 +1445,7 @@ static int __init dynamic_debug_init(void)
> }
> #endif /* CONFIG_MODULES */
>
> - if (&__start___dyndbg == &__stop___dyndbg) {
> + if (&__start___dyndbg_descs == &__stop___dyndbg_descs) {
> if (IS_ENABLED(CONFIG_DYNAMIC_DEBUG)) {
> pr_warn("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n");
> return 1;
> @@ -1459,16 +1455,16 @@ static int __init dynamic_debug_init(void)
> return 0;
> }
>
> - iter = iter_mod_start = __start___dyndbg;
> + iter = iter_mod_start = __start___dyndbg_descs;
> modname = iter->modname;
> i = mod_sites = mod_ct = 0;
>
> - for (; iter < __stop___dyndbg; iter++, i++, mod_sites++) {
> + for (; iter < __stop___dyndbg_descs; iter++, i++, mod_sites++) {
>
> if (strcmp(modname, iter->modname)) {
> mod_ct++;
> - di.num_descs = mod_sites;
> - di.descs = iter_mod_start;
> + di.descs.len = mod_sites;
> + di.descs.start = iter_mod_start;
> ret = ddebug_add_module(&di, modname);
> if (ret)
> goto out_err;
> @@ -1478,8 +1474,8 @@ static int __init dynamic_debug_init(void)
> iter_mod_start = iter;
> }
> }
> - di.num_descs = mod_sites;
> - di.descs = iter_mod_start;
> + di.descs.len = mod_sites;
> + di.descs.start = iter_mod_start;
> ret = ddebug_add_module(&di, modname);
> if (ret)
> goto out_err;
> @@ -1489,8 +1485,8 @@ static int __init dynamic_debug_init(void)
> i, mod_ct, (int)((mod_ct * sizeof(struct ddebug_table)) >> 10),
> (int)((i * sizeof(struct _ddebug)) >> 10));
>
> - if (di.num_classes)
> - v2pr_info(" %d builtin ddebug class-maps\n", di.num_classes);
> + if (di.maps.len)
> + v2pr_info(" %d builtin ddebug class-maps\n", di.maps.len);
>
> /* now that ddebug tables are loaded, process all boot args
> * again to find and activate queries given in dyndbg params.
> diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
> index 396144cf351b..8434f70b51bb 100644
> --- a/lib/test_dynamic_debug.c
> +++ b/lib/test_dynamic_debug.c
> @@ -41,7 +41,7 @@ module_param_cb(do_prints, ¶m_ops_do_prints, NULL, 0600);
> */
> #define DD_SYS_WRAP(_model, _flags) \
> static unsigned long bits_##_model; \
> - static struct ddebug_class_param _flags##_model = { \
> + static struct _ddebug_class_param _flags##_model = { \
> .bits = &bits_##_model, \
> .flags = #_flags, \
> .map = &map_##_model, \
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 53/54] drm: restore CONFIG_DRM_USE_DYNAMIC_DEBUG un-BROKEN
2025-04-02 17:41 ` [PATCH v3 53/54] drm: restore CONFIG_DRM_USE_DYNAMIC_DEBUG un-BROKEN Jim Cromie
@ 2025-04-15 10:00 ` Louis Chauvet
0 siblings, 0 replies; 81+ messages in thread
From: Louis Chauvet @ 2025-04-15 10:00 UTC (permalink / raw)
To: Jim Cromie, jbaron, gregkh, ukaszb, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala
Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> Time for some thorough CI.
>
> Also, the previous 18 patches could perhaps be replaced by a single
> invocation of DYNDBG_CLASSMAP_USE, from a C-file linked into all drm
> drivers & helpers. I didn't find such a file, nor a drm-client
> linkage item in the Makefile.
>
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
Since [1] this patch does not apply on drm-misc-next, but the fix is
easy, just move the change to the correct file.
[1]:
https://patchwork.freedesktop.org/patch/msgid/20250324092633.49746-2-tvrtko.ursulin@igalia.com
> ---
> drivers/gpu/drm/Kconfig | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
> index fbef3f471bd0..c7d6adbe17eb 100644
> --- a/drivers/gpu/drm/Kconfig
> +++ b/drivers/gpu/drm/Kconfig
> @@ -53,8 +53,7 @@ config DRM_DEBUG_MM
>
> config DRM_USE_DYNAMIC_DEBUG
> bool "use dynamic debug to implement drm.debug"
> - default n
> - depends on BROKEN
> + default y
> depends on DRM
> depends on DYNAMIC_DEBUG || DYNAMIC_DEBUG_CORE
> depends on JUMP_LABEL
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 14/54] dyndbg: hoist classmap-filter-by-modname up to ddebug_add_module
2025-04-02 17:41 ` [PATCH v3 14/54] dyndbg: hoist classmap-filter-by-modname up to ddebug_add_module Jim Cromie
@ 2025-04-15 10:00 ` Louis Chauvet
0 siblings, 0 replies; 81+ messages in thread
From: Louis Chauvet @ 2025-04-15 10:00 UTC (permalink / raw)
To: Jim Cromie, jbaron, gregkh, ukaszb, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala
Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> The body of ddebug_attach_module_classes() is dominated by a
> code-block that finds the contiguous subrange of classmaps matching on
> modname, and saves it into the ddebug_table's info record.
>
> Implement this block in a macro to accommodate different component
> vectors in the "box" (as named in the for_subvec macro).
>
> And hoist its invocation out of ddebug_attach_module_classes() up into
> ddebug_add_module(). This moves the filtering step up closer to
> dynamic_debug_init(), which effectively does the same for builtin
> pr_debug descriptors; segmenting them into subranges by modname.
>
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> ---
> lib/dynamic_debug.c | 56 ++++++++++++++++++++++++++-------------------
> 1 file changed, 32 insertions(+), 24 deletions(-)
>
> diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
> index 104cf8abdf33..046c4ffb38f8 100644
> --- a/lib/dynamic_debug.c
> +++ b/lib/dynamic_debug.c
> @@ -161,8 +161,8 @@ static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
> }
>
> static struct _ddebug_class_map *ddebug_find_valid_class(struct ddebug_table const *dt,
> - const char *class_string,
> - int *class_id)
> + const char *class_string,
> + int *class_id)
> {
> struct _ddebug_class_map *map;
> int i, idx;
> @@ -1224,30 +1224,34 @@ static const struct proc_ops proc_fops = {
>
> static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug_info *di)
> {
> - struct _ddebug_class_map *cm;
> - int i, nc = 0;
> -
> - /*
> - * Find this module's classmaps in a subrange/wholerange of
> - * the builtin/modular classmap vector/section. Save the start
> - * and length of the subrange at its edges.
> - */
> - for_subvec(i, cm, di, maps) {
> - if (!strcmp(cm->mod_name, dt->mod_name)) {
> - if (!nc) {
> - v2pr_info("start subrange, class[%d]: module:%s base:%d len:%d ty:%d\n",
> - i, cm->mod_name, cm->base, cm->length, cm->map_type);
> - dt->info.maps.start = cm;
> - }
> - nc++;
> - }
> - }
> - if (nc) {
> - dt->info.maps.len = nc;
> - vpr_info("module:%s attached %d classes\n", dt->mod_name, nc);
> - }
> + vpr_info("module:%s attached %d classes\n", dt->mod_name, dt->info.maps.len);
> }
>
> +/*
> + * Walk the @_box->@_vec member, over @_vec.start[0..len], and find
> + * the contiguous subrange of elements matching on ->mod_name. Copy
> + * the subrange into @_dst. This depends on vars defd by caller.
> + *
> + * @_i: caller provided counter var, init'd by macro
> + * @_sp: cursor into @_vec.
> + * @_box: contains member named @_vec
> + * @_vec: an array-ref, with: .start .len fields.
> + * @_dst: an array-ref: to remember the module's subrange
_dst must contains a member info which contains a member named @_vec.
Can you specify this in the documentation?
Nitpick: Can you use the same order in documentation and macro definition?
> + */
> +#define dd_mark_vector_subrange(_i, _dst, _sp, _box, _vec) ({ \
> + int nc = 0; \
> + for_subvec(_i, _sp, _box, _vec) { \
> + if (!strcmp((_sp)->mod_name, (_dst)->mod_name)) { \
> + if (!nc++) \
> + (_dst)->info._vec.start = (_sp); \
> + } else { \
> + if (nc) \
> + break; /* end of consecutive matches */ \
> + } \
> + } \
> + (_dst)->info._vec.len = nc; \
> +})
> +
> /*
> * Allocate a new ddebug_table for the given module
> * and add it to the global list.
> @@ -1255,6 +1259,8 @@ static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug
> static int ddebug_add_module(struct _ddebug_info *di, const char *modname)
> {
> struct ddebug_table *dt;
> + struct _ddebug_class_map *cm;
> + int i;
>
> if (!di->descs.len)
> return 0;
> @@ -1277,6 +1283,8 @@ static int ddebug_add_module(struct _ddebug_info *di, const char *modname)
>
> INIT_LIST_HEAD(&dt->link);
>
> + dd_mark_vector_subrange(i, dt, cm, di, maps);
> +
> if (di->maps.len)
> ddebug_attach_module_classes(dt, di);
>
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 16/54] dyndbg-API: remove DD_CLASS_TYPE_(DISJOINT|LEVEL)_NAMES and code
2025-04-02 17:41 ` [PATCH v3 16/54] dyndbg-API: remove DD_CLASS_TYPE_(DISJOINT|LEVEL)_NAMES and code Jim Cromie
@ 2025-04-15 10:00 ` Louis Chauvet
0 siblings, 0 replies; 81+ messages in thread
From: Louis Chauvet @ 2025-04-15 10:00 UTC (permalink / raw)
To: Jim Cromie, jbaron, gregkh, ukaszb, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala
Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> Remove the DD_CLASS_TYPE_*_NAMES classmap types and code.
>
> These 2 classmap types accept class names at the PARAM interface, for
> example:
>
> echo +DRM_UT_CORE,-DRM_UT_KMS > /sys/module/drm/parameters/debug_names
>
> The code works, but its only used by test-dynamic-debug, and wasn't
> asked for by anyone else, so reduce LOC & test-surface; simplify things.
>
> Also rename enum class_map_type to enum ddebug_class_map_type.
>
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
> ---
> include/linux/dynamic_debug.h | 23 ++------
> lib/dynamic_debug.c | 102 +++-------------------------------
> lib/test_dynamic_debug.c | 26 ---------
> 3 files changed, 14 insertions(+), 137 deletions(-)
>
> diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
> index f4d1d08cd5a7..769f02456c8e 100644
> --- a/include/linux/dynamic_debug.h
> +++ b/include/linux/dynamic_debug.h
> @@ -58,27 +58,16 @@ struct _ddebug {
> #endif
> } __attribute__((aligned(8)));
>
> -enum class_map_type {
> +enum ddebug_class_map_type {
> DD_CLASS_TYPE_DISJOINT_BITS,
> /**
> - * DD_CLASS_TYPE_DISJOINT_BITS: classes are independent, one per bit.
> - * expecting hex input. Built for drm.debug, basis for other types.
> + * DD_CLASS_TYPE_DISJOINT_BITS: classes are independent, mapped to bits[0..N].
> + * Expects hex input. Built for drm.debug, basis for other types.
> */
> DD_CLASS_TYPE_LEVEL_NUM,
> /**
> - * DD_CLASS_TYPE_LEVEL_NUM: input is numeric level, 0-N.
> - * N turns on just bits N-1 .. 0, so N=0 turns all bits off.
> - */
> - DD_CLASS_TYPE_DISJOINT_NAMES,
> - /**
> - * DD_CLASS_TYPE_DISJOINT_NAMES: input is a CSV of [+-]CLASS_NAMES,
> - * classes are independent, like _DISJOINT_BITS.
> - */
> - DD_CLASS_TYPE_LEVEL_NAMES,
> - /**
> - * DD_CLASS_TYPE_LEVEL_NAMES: input is a CSV of [+-]CLASS_NAMES,
> - * intended for names like: INFO,DEBUG,TRACE, with a module prefix
> - * avoid EMERG,ALERT,CRIT,ERR,WARNING: they're not debug
> + * DD_CLASS_TYPE_LEVEL_NUM: input is numeric level, 0..N.
> + * Input N turns on bits 0..N-1
> */
> };
>
> @@ -88,7 +77,7 @@ struct _ddebug_class_map {
> const char **class_names;
> const int length;
> const int base; /* index of 1st .class_id, allows split/shared space */
> - enum class_map_type map_type;
> + enum ddebug_class_map_type map_type;
> };
>
> /**
> diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
> index aff254d39c36..a7e1dbb6ead0 100644
> --- a/lib/dynamic_debug.c
> +++ b/lib/dynamic_debug.c
> @@ -646,76 +646,6 @@ static int ddebug_apply_class_bitmap(const struct _ddebug_class_param *dcp,
>
> #define CLASSMAP_BITMASK(width) ((1UL << (width)) - 1)
>
> -/* accept comma-separated-list of [+-] classnames */
> -static int param_set_dyndbg_classnames(const char *instr, const struct kernel_param *kp)
> -{
> - const struct _ddebug_class_param *dcp = kp->arg;
> - const struct _ddebug_class_map *map = dcp->map;
> - unsigned long curr_bits, old_bits;
> - char *cl_str, *p, *tmp;
> - int cls_id, totct = 0;
> - bool wanted;
> -
> - cl_str = tmp = kstrdup_and_replace(instr, '\n', '\0', GFP_KERNEL);
> - if (!tmp)
> - return -ENOMEM;
> -
> - /* start with previously set state-bits, then modify */
> - curr_bits = old_bits = *dcp->bits;
> - vpr_info("\"%s\" > %s:0x%lx\n", cl_str, KP_NAME(kp), curr_bits);
> -
> - for (; cl_str; cl_str = p) {
> - p = strchr(cl_str, ',');
> - if (p)
> - *p++ = '\0';
> -
> - if (*cl_str == '-') {
> - wanted = false;
> - cl_str++;
> - } else {
> - wanted = true;
> - if (*cl_str == '+')
> - cl_str++;
> - }
> - cls_id = match_string(map->class_names, map->length, cl_str);
> - if (cls_id < 0) {
> - pr_err("%s unknown to %s\n", cl_str, KP_NAME(kp));
> - continue;
> - }
> -
> - /* have one or more valid class_ids of one *_NAMES type */
> - switch (map->map_type) {
> - case DD_CLASS_TYPE_DISJOINT_NAMES:
> - /* the +/- pertains to a single bit */
> - if (test_bit(cls_id, &curr_bits) == wanted) {
> - v3pr_info("no change on %s\n", cl_str);
> - continue;
> - }
> - curr_bits ^= BIT(cls_id);
> - totct += ddebug_apply_class_bitmap(dcp, &curr_bits, *dcp->bits, NULL);
> - *dcp->bits = curr_bits;
> - v2pr_info("%s: changed bit %d:%s\n", KP_NAME(kp), cls_id,
> - map->class_names[cls_id]);
> - break;
> - case DD_CLASS_TYPE_LEVEL_NAMES:
> - /* cls_id = N in 0..max. wanted +/- determines N or N-1 */
> - old_bits = CLASSMAP_BITMASK(*dcp->lvl);
> - curr_bits = CLASSMAP_BITMASK(cls_id + (wanted ? 1 : 0 ));
> -
> - totct += ddebug_apply_class_bitmap(dcp, &curr_bits, old_bits, NULL);
> - *dcp->lvl = (cls_id + (wanted ? 1 : 0));
> - v2pr_info("%s: changed bit-%d: \"%s\" %lx->%lx\n", KP_NAME(kp), cls_id,
> - map->class_names[cls_id], old_bits, curr_bits);
> - break;
> - default:
> - pr_err("illegal map-type value %d\n", map->map_type);
> - }
> - }
> - kfree(tmp);
> - vpr_info("total matches: %d\n", totct);
> - return 0;
> -}
> -
> static int param_set_dyndbg_module_classes(const char *instr,
> const struct kernel_param *kp,
> const char *mod_name)
> @@ -724,29 +654,17 @@ static int param_set_dyndbg_module_classes(const char *instr,
> const struct _ddebug_class_map *map = dcp->map;
> unsigned long inrep, new_bits, old_bits;
> int rc, totct = 0;
> -
> - switch (map->map_type) {
> -
> - case DD_CLASS_TYPE_DISJOINT_NAMES:
> - case DD_CLASS_TYPE_LEVEL_NAMES:
> - /* handle [+-]classnames list separately, we are done here */
> - return param_set_dyndbg_classnames(instr, kp);
> -
> - case DD_CLASS_TYPE_DISJOINT_BITS:
> - case DD_CLASS_TYPE_LEVEL_NUM:
> - /* numeric input, accept and fall-thru */
> - rc = kstrtoul(instr, 0, &inrep);
> - if (rc) {
> - pr_err("expecting numeric input: %s > %s\n", instr, KP_NAME(kp));
> - return -EINVAL;
> - }
> - break;
> - default:
> - pr_err("%s: bad map type: %d\n", KP_NAME(kp), map->map_type);
> + char *nl;
> +
> + rc = kstrtoul(instr, 0, &inrep);
> + if (rc) {
> + nl = strchr(instr, '\n');
> + if (nl)
> + *nl = '\0';
> + pr_err("expecting numeric input, not: %s > %s\n", instr, KP_NAME(kp));
> return -EINVAL;
> }
>
> - /* only _BITS,_NUM (numeric) map-types get here */
> switch (map->map_type) {
> case DD_CLASS_TYPE_DISJOINT_BITS:
> /* expect bits. mask and warn if too many */
> @@ -812,12 +730,8 @@ int param_get_dyndbg_classes(char *buffer, const struct kernel_param *kp)
> const struct _ddebug_class_map *map = dcp->map;
>
> switch (map->map_type) {
> -
> - case DD_CLASS_TYPE_DISJOINT_NAMES:
> case DD_CLASS_TYPE_DISJOINT_BITS:
> return scnprintf(buffer, PAGE_SIZE, "0x%lx\n", *dcp->bits);
> -
> - case DD_CLASS_TYPE_LEVEL_NAMES:
> case DD_CLASS_TYPE_LEVEL_NUM:
> return scnprintf(buffer, PAGE_SIZE, "%ld\n", *dcp->lvl);
> default:
> diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
> index 8434f70b51bb..9c3e53cd26bd 100644
> --- a/lib/test_dynamic_debug.c
> +++ b/lib/test_dynamic_debug.c
> @@ -74,13 +74,6 @@ DECLARE_DYNDBG_CLASSMAP(map_disjoint_bits, DD_CLASS_TYPE_DISJOINT_BITS, 0,
> DD_SYS_WRAP(disjoint_bits, p);
> DD_SYS_WRAP(disjoint_bits, T);
>
> -/* symbolic input, independent bits */
> -enum cat_disjoint_names { LOW = 10, MID, HI };
> -DECLARE_DYNDBG_CLASSMAP(map_disjoint_names, DD_CLASS_TYPE_DISJOINT_NAMES, 10,
> - "LOW", "MID", "HI");
> -DD_SYS_WRAP(disjoint_names, p);
> -DD_SYS_WRAP(disjoint_names, T);
> -
> /* numeric verbosity, V2 > V1 related */
> enum cat_level_num { V0 = 14, V1, V2, V3, V4, V5, V6, V7 };
> DECLARE_DYNDBG_CLASSMAP(map_level_num, DD_CLASS_TYPE_LEVEL_NUM, 14,
> @@ -88,13 +81,6 @@ DECLARE_DYNDBG_CLASSMAP(map_level_num, DD_CLASS_TYPE_LEVEL_NUM, 14,
> DD_SYS_WRAP(level_num, p);
> DD_SYS_WRAP(level_num, T);
>
> -/* symbolic verbosity */
> -enum cat_level_names { L0 = 22, L1, L2, L3, L4, L5, L6, L7 };
> -DECLARE_DYNDBG_CLASSMAP(map_level_names, DD_CLASS_TYPE_LEVEL_NAMES, 22,
> - "L0", "L1", "L2", "L3", "L4", "L5", "L6", "L7");
> -DD_SYS_WRAP(level_names, p);
> -DD_SYS_WRAP(level_names, T);
> -
> /* stand-in for all pr_debug etc */
> #define prdbg(SYM) __pr_debug_cls(SYM, #SYM " msg\n")
>
> @@ -102,10 +88,6 @@ static void do_cats(void)
> {
> pr_debug("doing categories\n");
>
> - prdbg(LOW);
> - prdbg(MID);
> - prdbg(HI);
> -
> prdbg(D2_CORE);
> prdbg(D2_DRIVER);
> prdbg(D2_KMS);
> @@ -129,14 +111,6 @@ static void do_levels(void)
> prdbg(V5);
> prdbg(V6);
> prdbg(V7);
> -
> - prdbg(L1);
> - prdbg(L2);
> - prdbg(L3);
> - prdbg(L4);
> - prdbg(L5);
> - prdbg(L6);
> - prdbg(L7);
> }
>
> static void do_prints(void)
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 17/54] dyndbg-API: replace DECLARE_DYNDBG_CLASSMAP
2025-04-02 17:41 ` [PATCH v3 17/54] dyndbg-API: replace DECLARE_DYNDBG_CLASSMAP Jim Cromie
@ 2025-04-15 10:01 ` Louis Chauvet
2025-04-15 19:38 ` jim.cromie
0 siblings, 1 reply; 81+ messages in thread
From: Louis Chauvet @ 2025-04-15 10:01 UTC (permalink / raw)
To: Jim Cromie, jbaron, gregkh, ukaszb, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, linux-doc
Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> DECLARE_DYNDBG_CLASSMAP() has a design error; its usage fails a basic
> K&R rule: "define once, refer many times".
>
> When DRM_USE_DYNAMIC_DEBUG=y, it is used across DRM core & drivers;
> each invocation allocates/inits the classmap understood by that
> module. All must match for the modules to respond together when
> DRM.debug categories are enabled. This is brittle; a maintenance
> foot-gun.
>
> Further, its culpable in the CONFIG_DRM_USE_DYNAMIC_DEBUG=Y
> regression; its use in both core & drivers obfuscates the 2 roles, that
> caused incomplete initialization when modprobing drivers:
>
> 1st drm.ko loads, and dyndbg initializes its DRM.debug callsites, then
> a drm-driver loads, but too late for the DRM.debug enablement.
>
> So retire it, replace with 2 macros:
> DYNAMIC_DEBUG_CLASSMAP_DEFINE - invoked once from core - drm.ko
> DYNAMIC_DEBUG_CLASSMAP_USE - from all drm drivers and helpers.
>
> DYNAMIC_DEBUG_CLASSMAP_DEFINE: this reworks DECLARE_DYNDBG_CLASSMAP,
> by dropping the static qualifier on the classmap, and exporting it
> instead.
>
> DYNAMIC_DEBUG_CLASSMAP_USE: then refers to the exported var by name:
> used from drivers, helper-mods
> lets us drop the repetitive "classname" declarations
> fixes 2nd-defn problem
> creates a ddebug_class_user record in new __dyndbg_class_users section
> new section is scanned "differently"
>
> DECLARE_DYNDBG_CLASSMAP is preserved temporarily, to decouple DRM
> adaptation work and avoid compile-errs before its done. IOW, DRM gets
> these fixes when they commit the adopt-new-api patches.
>
> The DEFINE,USE distinction, and the separate classmap-use record,
> allows dyndbg to initialize the driver's & helper's DRM.debug
> callsites separately after each is modprobed.
>
> Basically, the classmap init-scan is repeated for classmap-users.
>
> To review, dyndbg's existing __dyndbg_classes[] section does:
>
> . catalogs the module's classmaps
> . tells dyndbg about them, allowing >control
> . DYNAMIC_DEBUG_CLASSMAP_DEFINE creates section records.
> . we rename it to: __dyndbg_class_maps[]
>
> Then this patch adds __dyndbg_class_users[] section:
>
> . catalogs users of classmap definitions elsewhere
> . authorizes dyndbg to >control user's class'd prdbgs
> . DYNAMIC_DEBUG_CLASSMAP_USE() creates section records.
>
> Now ddebug_add_module(etal) can handle classmap-uses similar to (and
> after) classmaps; when a dependent module is loaded, if it has
> classmap-uses (to a classmap-def in another module), that module's
> kernel params are scanned to find if it has a kparam that is wired to
> dyndbg's param-ops, and whose classmap is the one being ref'd.
>
> To support this, theres a few data/header changes:
>
> new struct ddebug_class_user
> contains: user-module-name, &classmap-defn
> it records drm-driver's use of a classmap in the section, allowing lookup
>
> struct ddebug_info gets 2 new fields for the new sections:
> class_users, num_class_users.
> set by dynamic_debug_init() for builtins.
> or by kernel/module/main:load_info() for loadable modules.
>
> vmlinux.lds.h: new BOUNDED_SECTION for __dyndbg_class_users
>
> dynamic_debug.c has 2 changes in ddebug_add_module(), ddebug_change():
>
> ddebug_add_module()
> called ddebug_attach_module_classes()
> now calls ddebug_apply_class_maps() & ddebug_apply_class_users()
> these both call ddebug_apply_params().
>
> ddebug_apply_params(new fn):
>
> It scans module's/builtin kernel-params, calls ddebug_match_apply_kparam
> for each to find any params/sysfs-nodes which may be wired to a classmap.
>
> ddebug_match_apply_kparam(new fn):
>
> 1st, it tests the kernel-param.ops is dyndbg's; this guarantees that
> the attached arg is a struct ddebug_class_param, which has a ref to
> the param's state, and to the classmap defining the param's handling.
>
> 2nd, it requires that the classmap ref'd by the kparam is the one
> we're called for; modules can use many separate classmaps (as
> test_dynamic_debug does).
>
> Then apply the "parent" kparam's setting to the dependent module,
> using ddebug_apply_class_bitmap().
>
> ddebug_change(and callees) also gets adjustments:
>
> ddebug_find_valid_class(): This does a search over the module's
> classmaps, looking for the class FOO echo'd to >control. So now it
> searches over __dyndbg_class_users[] after __dyndbg_classes[].
>
> ddebug_class_name(): return class-names for defined AND used classes.
>
> test_dynamic_debug.c, test_dynamic_debug_submod.c:
>
> This demonstrates the 2 types of classmaps & sysfs-params, following
> the 4-part recipe:
>
> 1. define an enum for the classmap: DRM.debug has DRM_UT_{CORE,KMS,...}
> multiple classes must share 0-62 classid space.
> 2. DYNAMIC_DEBUG_CLASSMAP_DEFINE(.. DRM_UT_{CORE,KMS,...})
> 3. DYNAMIC_DEBUG_CLASSMAP_PARAM* (classmap)
> 4. DYNAMIC_DEBUG_CLASSMAP_USE()
> by _submod only, skipping 2,3
>
> Move all the enum declarations together, to better explain how they
> share the 0..62 class-id space available to a module (non-overlapping
> subranges).
>
> reorg macros 2,3 by name. This gives a tabular format, making it easy
> to see the pattern of repetition, and the points of change.
>
> And extend the test to replicate the 2-module (parent & dependent)
> scenario which caused the CONFIG_DRM_USE_DYNAMIC_DEBUG=y regression
> seen in drm & drivers.
>
> The _submod.c is a 2-line file: #define _SUBMOD, #include parent.
>
> This gives identical complements of prdbgs in parent & _submod, and
> thus identical print behavior when all of: >control, >params, and
> parent->_submod propagation are working correctly.
>
> It also puts all the parent/_submod declarations together in the same
> source, with the new ifdef _SUBMOD block invoking DYNAMIC_DEBUG_CLASSMAP_USE
> for the 2 test-interfaces. I think this is clearer.
>
> These 2 modules are both tristate, allowing 3 super/sub combos: Y/Y,
> Y/M, M/M (not N/Y, since this is disallowed by dependence).
>
> Y/Y testing exposed a missing __align(8) in the _METADATA macro, which
> M/M didn't see because the module-loader memory placement constrains
> it instead.
>
> Fixes: aad0214f3026 ("dyndbg: add DECLARE_DYNDBG_CLASSMAP macro")
> cc: linux-doc@vger.kernel.org
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> ---
> v3-
> undo 1.9 simplification of ddebug_find_valid_class()
> ddebug_change needs map to see its controlling param
> change internal callchains to pass di, not dt
>
> v2 a. building 2 .ko's from 1 source file is weird; add a clear
> comment at the top to justify it (basically cloning)
> ln 138+ in commit-msg is insufficient.
>
> b. retire "DYNDBG_" name shortening b4 adding _CLASSMAP_* macros.
> c. s/dd_class/_ddebug_class/
> d. s/\bddebug\b/_$1/g in header: chgs 1 struct and UNIQUE_ID bases
>
> v1.9 - commit-msg tweaks
> DRM:CHECK warnings on macros: add parens
> extern DEFINEd _var, static classnames
> change ddebug_class_user.user_mod_name to .mod_name
> simplify ddebug_find_valid_class return val
> improve vpr_cm_info msg format
> wrap (base) in macro body
> move __DYNDBG_CLASSMAP_CHECK above kdoc for DYNDBG_CLASSMAP_DEFINE
>
> v1.8 - split drm parts to separate commits.
> preserve DECLARE_DYNDBG_CLASSMAP to decouple DRM, no flag day.
> fixup block comment
>
> v1.7 - previous submission-blocking bug:
>
> missing __align(8) in DYNAMIC_DEBUG_DECLARE_METADATA on
> ddebug_class_user caused corrupt records, but only for builtin
> modules; module loader code probably pinned allocations to the right
> alignment naturally, hiding the bug for typical builds.
>
> v6- get rid of WARN_ON_ONCE
> v?- fix _var expanded 2x in macro
>
> dyndbg:
>
> This fn formerly returned the map which contained the class (thus
> validating it), and as a side-effect set the class-id in an outvar.
>
> But the caller didn't use the map (after checking its not null), only
> the valid class-id. So simplify the fn to return the class-id of the
> validated classname, or -ENOENT when the queried classname is not
> found.
>
> Convey more useful info in the debug-msg: print class-names[0,last],
> and [base,+len] instead of the class-type printout, which is almost
> always "type:DISJOINT_BITS". And drop ddebug_classmap_typenames,
> which is now unused.
>
> [root@v6 b0-dd]# modprobe test_dynamic_debug_submod
> [ 18.864962] dyndbg: loaded classmap: test_dynamic_debug [16..24] V0..V7
> [ 18.865046] dyndbg: found kp:p_level_num =0x0
> [ 18.865048] dyndbg: mapped to: test_dynamic_debug [16..24] V0..V7
> [ 18.865164] dyndbg: p_level_num: lvl:0 bits:0x0
> [ 18.865217] dyndbg: loaded classmap: test_dynamic_debug [0..10] D2_CORE..D2_DRMRES
> [ 18.865297] dyndbg: found kp:p_disjoint_bits =0x0
> [ 18.865298] dyndbg: mapped to: test_dynamic_debug [0..10] D2_CORE..D2_DRMRES
> [ 18.865424] dyndbg: p_disjoint_bits: classbits: 0x0
> [ 18.865472] dyndbg: module:test_dynamic_debug attached 2 classmaps
> [ 18.865533] dyndbg: 23 debug prints in module test_dynamic_debug
> [ 18.866558] dyndbg: loaded classmap: test_dynamic_debug_submod [16..24] V0..V7
> [ 18.866698] dyndbg: found kp:p_level_num =0x0
> [ 18.866699] dyndbg: mapped to: test_dynamic_debug_submod [16..24] V0..V7
> [ 18.866865] dyndbg: p_level_num: lvl:0 bits:0x0
> [ 18.866926] dyndbg: loaded classmap: test_dynamic_debug_submod [0..10] D2_CORE..D2_DRMRES
> [ 18.867026] dyndbg: found kp:p_disjoint_bits =0x0
> [ 18.867027] dyndbg: mapped to: test_dynamic_debug_submod [0..10] D2_CORE..D2_DRMRES
> [ 18.867193] dyndbg: p_disjoint_bits: classbits: 0x0
> [ 18.867255] dyndbg: module:test_dynamic_debug_submod attached 2 classmap uses
> [ 18.867351] dyndbg: 23 debug prints in module test_dynamic_debug_submod
>
> fixup-test-submod
>
> fixup-test
>
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> ---
> MAINTAINERS | 2 +-
> include/asm-generic/vmlinux.lds.h | 1 +
> include/linux/dynamic_debug.h | 93 +++++++++++++++++---
> kernel/module/main.c | 3 +
> lib/Kconfig.debug | 24 ++++--
> lib/Makefile | 3 +
> lib/dynamic_debug.c | 137 +++++++++++++++++++++++++++---
> lib/test_dynamic_debug.c | 132 ++++++++++++++++++++--------
> lib/test_dynamic_debug_submod.c | 14 +++
> 9 files changed, 343 insertions(+), 66 deletions(-)
> create mode 100644 lib/test_dynamic_debug_submod.c
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 00e94bec401e..1c5fcbd9e408 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -8139,7 +8139,7 @@ M: Jim Cromie <jim.cromie@gmail.com>
> S: Maintained
> F: include/linux/dynamic_debug.h
> F: lib/dynamic_debug.c
> -F: lib/test_dynamic_debug.c
> +F: lib/test_dynamic_debug*.c
>
> DYNAMIC INTERRUPT MODERATION
> M: Tal Gilboa <talgi@nvidia.com>
> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> index f834ad1fb8c4..fa382caf2ae2 100644
> --- a/include/asm-generic/vmlinux.lds.h
> +++ b/include/asm-generic/vmlinux.lds.h
> @@ -367,6 +367,7 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
> /* implement dynamic printk debug */ \
> . = ALIGN(8); \
> BOUNDED_SECTION_BY(__dyndbg_class_maps, ___dyndbg_class_maps) \
> + BOUNDED_SECTION_BY(__dyndbg_class_users, ___dyndbg_class_users) \
> BOUNDED_SECTION_BY(__dyndbg_descriptors, ___dyndbg_descs) \
> CODETAG_SECTIONS() \
> LIKELY_PROFILE() \
> diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
> index 769f02456c8e..9af825c84e70 100644
> --- a/include/linux/dynamic_debug.h
> +++ b/include/linux/dynamic_debug.h
> @@ -71,9 +71,28 @@ enum ddebug_class_map_type {
> */
> };
>
> +/*
> + * dyndbg-classmaps are devised to support DRM.debug directly:
> + * 10 enum-vals: DRM_UT_* define the categories
> + * ~23 categorized *_dbg() macros, each passing a DRM_UT_* val as 1st arg
> + * 2 macros below them: drm_dev_dbg, __drm_dbg
> + * ~5000 calls to the categorized macros, across all of drivers/gpu/drm/
> + *
> + * When CONFIG_DRM_USE_DYNAMIC_DEBUG=y, the 2 low macros are redefined
> + * to invoke _dynamic_func_call_cls(). This compiles the category
> + * into each callsite's class_id field, where dyndbg can select on it
> + * and alter a callsite's patch-state, avoiding repeated __drm_debug
> + * checks.
> + *
> + * To make the callsites manageable from the >control file, authors
> + * provide a "classmap" of names to class_ids in use by the module(s),
> + * usually by stringifying the enum-vals. Modules with multiple
> + * classmaps must arrange to share the 0..62 class_id space.
> + */
> +
> struct _ddebug_class_map {
> - struct module *mod;
> - const char *mod_name; /* needed for builtins */
> + const struct module *mod; /* NULL for builtins */
> + const char *mod_name;
> const char **class_names;
> const int length;
> const int base; /* index of 1st .class_id, allows split/shared space */
> @@ -81,11 +100,34 @@ struct _ddebug_class_map {
> };
>
> /**
> - * DECLARE_DYNDBG_CLASSMAP - declare classnames known by a module
> - * @_var: a struct _ddebug_class_map, passed to module_param_cb
> - * @_type: enum class_map_type, chooses bits/verbose, numeric/symbolic
> - * @_base: offset of 1st class-name. splits .class_id space
> - * @classes: class-names used to control class'd prdbgs
> + * DYNAMIC_DEBUG_CLASSMAP_DEFINE - define debug classes used by a module.
> + * @_var: name of the classmap, exported for other modules coordinated use.
> + * @_mapty: enum ddebug_class_map_type: 0:DISJOINT - independent, 1:LEVEL - v2>v1
> + * @_base: reserve N classids starting at _base, to split 0..62 classid space
> + * @classes: names of the N classes.
> + *
> + * This tells dyndbg what class_ids the module is using: _base..+N, by
> + * mapping names onto them. This qualifies "class NAME" >controls on
> + * the defining module, ignoring unknown names.
> + */
> +#define DYNAMIC_DEBUG_CLASSMAP_DEFINE(_var, _mapty, _base, ...) \
> + static const char *_var##_classnames[] = { __VA_ARGS__ }; \
> + extern struct _ddebug_class_map _var; \
> + struct _ddebug_class_map __aligned(8) __used \
> + __section("__dyndbg_class_maps") _var = { \
> + .mod = THIS_MODULE, \
> + .mod_name = KBUILD_MODNAME, \
> + .base = (_base), \
> + .map_type = (_mapty), \
> + .length = ARRAY_SIZE(_var##_classnames), \
> + .class_names = _var##_classnames, \
> + }; \
> + EXPORT_SYMBOL(_var)
> +
> +/*
> + * XXX: keep this until DRM adapts to use the DEFINE/USE api, it
> + * differs from DYNAMIC_DEBUG_CLASSMAP_DEFINE by the lack of the
> + * extern/EXPORT on the struct init, and cascading thinkos.
> */
> #define DECLARE_DYNDBG_CLASSMAP(_var, _maptype, _base, ...) \
> static const char *_var##_classnames[] = { __VA_ARGS__ }; \
> @@ -99,10 +141,35 @@ struct _ddebug_class_map {
> .class_names = _var##_classnames, \
> }
>
> +struct _ddebug_class_user {
> + char *mod_name;
> + struct _ddebug_class_map *map;
> +};
> +
> +/**
> + * DYNAMIC_DEBUG_CLASSMAP_USE - refer to a classmap, DEFINEd elsewhere.
> + * @_var: name of the exported classmap var
> + *
> + * This tells dyndbg that the module has prdbgs with classids defined
> + * in the named classmap. This qualifies "class NAME" >controls on
> + * the user module, ignoring unknown names.
> + */
> +#define DYNAMIC_DEBUG_CLASSMAP_USE(_var) \
> + DYNAMIC_DEBUG_CLASSMAP_USE_(_var, __UNIQUE_ID(_ddebug_class_user))
> +#define DYNAMIC_DEBUG_CLASSMAP_USE_(_var, _uname) \
> + extern struct _ddebug_class_map _var; \
> + static struct _ddebug_class_user __aligned(8) __used \
> + __section("__dyndbg_class_users") _uname = { \
> + .mod_name = KBUILD_MODNAME, \
> + .map = &(_var), \
> + }
> +
> /*
> - * @_ddebug_info: gathers module/builtin dyndbg_* __sections together.
> + * @_ddebug_info: gathers module/builtin __dyndbg_<T> __sections
> + * together, each is a vector: a struct { <T> *addr, int len }.
> + *
> * For builtins, it is used as a cursor, with the inner structs
> - * marking sub-vectors of the builtin __sections in DATA.
> + * marking sub-vectors of the builtin __sections in DATA_DATA
DATA_DATA? Is it a typo?
With this confirmed:
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
> */
> struct _ddebug_descs {
> struct _ddebug *start;
> @@ -114,10 +181,16 @@ struct _ddebug_class_maps {
> int len;
> } __packed;
>
> +struct _ddebug_class_users {
> + struct _ddebug_class_user *start;
> + int len;
> +} __packed;
> +
> struct _ddebug_info {
> const char *mod_name;
> struct _ddebug_descs descs;
> struct _ddebug_class_maps maps;
> + struct _ddebug_class_users users;
> } __packed;
>
> struct _ddebug_class_param {
> @@ -218,7 +291,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
> * (|_no_desc): former gets callsite descriptor as 1st arg (for prdbgs)
> */
> #define __dynamic_func_call_cls(id, cls, fmt, func, ...) do { \
> - DEFINE_DYNAMIC_DEBUG_METADATA_CLS(id, cls, fmt); \
> + DEFINE_DYNAMIC_DEBUG_METADATA_CLS((id), cls, fmt); \
> if (DYNAMIC_DEBUG_BRANCH(id)) \
> func(&id, ##__VA_ARGS__); \
> } while (0)
> diff --git a/kernel/module/main.c b/kernel/module/main.c
> index b60f728e36ac..c203b0694f7e 100644
> --- a/kernel/module/main.c
> +++ b/kernel/module/main.c
> @@ -2627,6 +2627,9 @@ static int find_module_sections(struct module *mod, struct load_info *info)
> mod->dyndbg_info.maps.start = section_objs(info, "__dyndbg_class_maps",
> sizeof(*mod->dyndbg_info.maps.start),
> &mod->dyndbg_info.maps.len);
> + mod->dyndbg_info.users.start = section_objs(info, "__dyndbg_class_users",
> + sizeof(*mod->dyndbg_info.users.start),
> + &mod->dyndbg_info.users.len);
> #endif
>
> return 0;
> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> index 35796c290ca3..91a75f724c1a 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -2905,12 +2905,26 @@ config TEST_STATIC_KEYS
> If unsure, say N.
>
> config TEST_DYNAMIC_DEBUG
> - tristate "Test DYNAMIC_DEBUG"
> - depends on DYNAMIC_DEBUG
> + tristate "Build test-dynamic-debug module"
> + depends on DYNAMIC_DEBUG || DYNAMIC_DEBUG_CORE
> help
> - This module registers a tracer callback to count enabled
> - pr_debugs in a 'do_debugging' function, then alters their
> - enablements, calls the function, and compares counts.
> + This module exercises/demonstrates dyndbg's classmap API, by
> + creating 2 classes: a DISJOINT classmap (supporting DRM.debug)
> + and a LEVELS/VERBOSE classmap (like verbose2 > verbose1).
> +
> + If unsure, say N.
> +
> +config TEST_DYNAMIC_DEBUG_SUBMOD
> + tristate "Build test-dynamic-debug submodule"
> + default m
> + depends on DYNAMIC_DEBUG || DYNAMIC_DEBUG_CORE
> + depends on TEST_DYNAMIC_DEBUG
> + help
> + This sub-module uses a classmap defined and exported by the
> + parent module, recapitulating drm & driver's shared use of
> + drm.debug to control enabled debug-categories.
> + It is tristate, independent of parent, to allow testing all
> + proper combinations of parent=y/m submod=y/m.
>
> If unsure, say N.
>
> diff --git a/lib/Makefile b/lib/Makefile
> index d5cfc7afbbb8..2c344138d990 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -84,6 +84,7 @@ obj-$(CONFIG_TEST_SORT) += test_sort.o
> obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o
> obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o
> obj-$(CONFIG_TEST_DYNAMIC_DEBUG) += test_dynamic_debug.o
> +obj-$(CONFIG_TEST_DYNAMIC_DEBUG_SUBMOD) += test_dynamic_debug_submod.o
> obj-$(CONFIG_TEST_PRINTF) += test_printf.o
> obj-$(CONFIG_TEST_SCANF) += test_scanf.o
>
> @@ -226,6 +227,8 @@ obj-$(CONFIG_ARCH_NEED_CMPXCHG_1_EMU) += cmpxchg-emu.o
> obj-$(CONFIG_DYNAMIC_DEBUG_CORE) += dynamic_debug.o
> #ensure exported functions have prototypes
> CFLAGS_dynamic_debug.o := -DDYNAMIC_DEBUG_MODULE
> +CFLAGS_test_dynamic_debug.o := -DDYNAMIC_DEBUG_MODULE
> +CFLAGS_test_dynamic_debug_submod.o := -DDYNAMIC_DEBUG_MODULE
>
> obj-$(CONFIG_SYMBOLIC_ERRNAME) += errname.o
>
> diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
> index a7e1dbb6ead0..53e261dbf81e 100644
> --- a/lib/dynamic_debug.c
> +++ b/lib/dynamic_debug.c
> @@ -29,6 +29,7 @@
> #include <linux/string_helpers.h>
> #include <linux/uaccess.h>
> #include <linux/dynamic_debug.h>
> +
> #include <linux/debugfs.h>
> #include <linux/slab.h>
> #include <linux/jump_label.h>
> @@ -43,6 +44,8 @@ extern struct _ddebug __start___dyndbg_descs[];
> extern struct _ddebug __stop___dyndbg_descs[];
> extern struct _ddebug_class_map __start___dyndbg_class_maps[];
> extern struct _ddebug_class_map __stop___dyndbg_class_maps[];
> +extern struct _ddebug_class_user __start___dyndbg_class_users[];
> +extern struct _ddebug_class_user __stop___dyndbg_class_users[];
>
> struct ddebug_table {
> struct list_head link;
> @@ -159,20 +162,37 @@ static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
> query->first_lineno, query->last_lineno, query->class_string);
> }
>
> -static struct _ddebug_class_map *ddebug_find_valid_class(struct ddebug_table const *dt,
> - const char *class_string,
> - int *class_id)
> +#define vpr_di_info(di_p, msg_p, ...) ({ \
> + struct _ddebug_info const *_di = di_p; \
> + v2pr_info(msg_p " module:%s nd:%d nc:%d nu:%d\n", ##__VA_ARGS__, \
> + _di->mod_name, _di->descs.len, _di->maps.len, \
> + _di->users.len); \
> + })
> +
> +static struct _ddebug_class_map *
> +ddebug_find_valid_class(struct _ddebug_info const *di, const char *query_class, int *class_id)
> {
> struct _ddebug_class_map *map;
> + struct _ddebug_class_user *cli;
> int i, idx;
>
> - for_subvec(i, map, &dt->info, maps) {
> - idx = match_string(map->class_names, map->length, class_string);
> + for_subvec(i, map, di, maps) {
> + idx = match_string(map->class_names, map->length, query_class);
> if (idx >= 0) {
> + vpr_di_info(di, "good-class: %s.%s ", map->mod_name, query_class);
> *class_id = idx + map->base;
> return map;
> }
> }
> + for_subvec(i, cli, di, users) {
> + idx = match_string(cli->map->class_names, cli->map->length, query_class);
> + if (idx >= 0) {
> + vpr_di_info(di, "class-ref: %s -> %s.%s ",
> + cli->mod_name, cli->map->mod_name, query_class);
> + *class_id = idx + cli->map->base;
> + return cli->map;
> + }
> + }
> *class_id = -ENOENT;
> return NULL;
> }
> @@ -183,8 +203,7 @@ static struct _ddebug_class_map *ddebug_find_valid_class(struct ddebug_table con
> * callsites, normally the same as number of changes. If verbose,
> * logs the changes. Takes ddebug_lock.
> */
> -static int ddebug_change(const struct ddebug_query *query,
> - struct flag_settings *modifiers)
> +static int ddebug_change(const struct ddebug_query *query, struct flag_settings *modifiers)
> {
> int i;
> struct ddebug_table *dt;
> @@ -204,7 +223,8 @@ static int ddebug_change(const struct ddebug_query *query,
> continue;
>
> if (query->class_string) {
> - map = ddebug_find_valid_class(dt, query->class_string, &valid_class);
> + map = ddebug_find_valid_class(&dt->info, query->class_string,
> + &valid_class);
> if (!map)
> continue;
> } else {
> @@ -569,7 +589,7 @@ static int ddebug_exec_query(char *query_string, const char *modname)
>
> /* handle multiple queries in query string, continue on error, return
> last error or number of matching callsites. Module name is either
> - in param (for boot arg) or perhaps in query string.
> + in the modname arg (for boot args) or perhaps in query string.
> */
> static int ddebug_exec_queries(char *query, const char *modname)
> {
> @@ -700,7 +720,7 @@ static int param_set_dyndbg_module_classes(const char *instr,
> /**
> * param_set_dyndbg_classes - classmap kparam setter
> * @instr: string echo>d to sysfs, input depends on map_type
> - * @kp: kp->arg has state: bits/lvl, map, map_type
> + * @kp: kp->arg has state: bits/lvl, classmap, map_type
> *
> * enable/disable all class'd pr_debugs in the classmap. For LEVEL
> * map-types, enforce * relative levels by bitpos.
> @@ -737,6 +757,7 @@ int param_get_dyndbg_classes(char *buffer, const struct kernel_param *kp)
> default:
> return -1;
> }
> + return 0;
> }
> EXPORT_SYMBOL(param_get_dyndbg_classes);
>
> @@ -1049,12 +1070,17 @@ static void *ddebug_proc_next(struct seq_file *m, void *p, loff_t *pos)
> static const char *ddebug_class_name(struct _ddebug_info *di, struct _ddebug *dp)
> {
> struct _ddebug_class_map *map;
> + struct _ddebug_class_user *cli;
> int i;
>
> for_subvec(i, map, di, maps)
> if (class_in_range(dp->class_id, map))
> return map->class_names[dp->class_id - map->base];
>
> + for_subvec(i, cli, di, users)
> + if (class_in_range(dp->class_id, cli->map))
> + return cli->map->class_names[dp->class_id - cli->map->base];
> +
> return NULL;
> }
>
> @@ -1135,9 +1161,85 @@ static const struct proc_ops proc_fops = {
> .proc_write = ddebug_proc_write
> };
>
> -static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug_info *di)
> +#define vpr_cm_info(cm_p, msg_fmt, ...) ({ \
> + struct _ddebug_class_map const *_cm = cm_p; \
> + v2pr_info(msg_fmt " %s [%d..%d] %s..%s\n", ##__VA_ARGS__, \
> + _cm->mod_name, _cm->base, _cm->base + _cm->length, \
> + _cm->class_names[0], _cm->class_names[_cm->length - 1]); \
> + })
> +
> +static void ddebug_sync_classbits(const struct kernel_param *kp, const char *modname)
> +{
> + const struct _ddebug_class_param *dcp = kp->arg;
> +
> + /* clamp initial bitvec, mask off hi-bits */
> + if (*dcp->bits & ~CLASSMAP_BITMASK(dcp->map->length)) {
> + *dcp->bits &= CLASSMAP_BITMASK(dcp->map->length);
> + v2pr_info("preset classbits: %lx\n", *dcp->bits);
> + }
> + /* force class'd prdbgs (in USEr module) to match (DEFINEr module) class-param */
> + ddebug_apply_class_bitmap(dcp, dcp->bits, ~0, modname);
> + ddebug_apply_class_bitmap(dcp, dcp->bits, 0, modname);
> +}
> +
> +static void ddebug_match_apply_kparam(const struct kernel_param *kp,
> + const struct _ddebug_class_map *map,
> + const char *mod_name)
> +{
> + struct _ddebug_class_param *dcp;
> +
> + if (kp->ops != ¶m_ops_dyndbg_classes)
> + return;
> +
> + dcp = (struct _ddebug_class_param *)kp->arg;
> +
> + if (map == dcp->map) {
> + v2pr_info(" kp:%s.%s =0x%lx", mod_name, kp->name, *dcp->bits);
> + vpr_cm_info(map, " %s mapped to: ", mod_name);
> + ddebug_sync_classbits(kp, mod_name);
> + }
> +}
> +
> +static void ddebug_apply_params(const struct _ddebug_class_map *cm, const char *mod_name)
> +{
> + const struct kernel_param *kp;
> +#if IS_ENABLED(CONFIG_MODULES)
> + int i;
> +
> + if (cm->mod) {
> + vpr_cm_info(cm, "loaded classmap: %s", mod_name);
> + /* ifdef protects the cm->mod->kp deref */
> + for (i = 0, kp = cm->mod->kp; i < cm->mod->num_kp; i++, kp++)
> + ddebug_match_apply_kparam(kp, cm, mod_name);
> + }
> +#endif
> + if (!cm->mod) {
> + vpr_cm_info(cm, "builtin classmap: %s", mod_name);
> + for (kp = __start___param; kp < __stop___param; kp++)
> + ddebug_match_apply_kparam(kp, cm, mod_name);
> + }
> +}
> +
> +static void ddebug_apply_class_maps(const struct _ddebug_info *di)
> +{
> + struct _ddebug_class_map *cm;
> + int i;
> +
> + for_subvec(i, cm, di, maps)
> + ddebug_apply_params(cm, cm->mod_name);
> +
> + vpr_di_info(di, "attached %d classmaps to module: %s ", i, cm->mod_name);
> +}
> +
> +static void ddebug_apply_class_users(const struct _ddebug_info *di)
> {
> - vpr_info("module:%s attached %d classes\n", dt->info.mod_name, dt->info.maps.len);
> + struct _ddebug_class_user *cli;
> + int i;
> +
> + for_subvec(i, cli, di, users)
> + ddebug_apply_params(cli->map, cli->mod_name);
> +
> + vpr_di_info(di, "attached %d class-users to module: %s ", i, cli->mod_name);
> }
>
> /*
> @@ -1173,6 +1275,7 @@ static int ddebug_add_module(struct _ddebug_info *di)
> {
> struct ddebug_table *dt;
> struct _ddebug_class_map *cm;
> + struct _ddebug_class_user *cli;
> int i;
>
> if (!di->descs.len)
> @@ -1196,14 +1299,18 @@ static int ddebug_add_module(struct _ddebug_info *di)
> INIT_LIST_HEAD(&dt->link);
>
> dd_mark_vector_subrange(i, dt, cm, di, maps);
> + dd_mark_vector_subrange(i, dt, cli, di, users);
>
> - if (di->maps.len)
> - ddebug_attach_module_classes(dt, di);
> + if (dt->info.maps.len)
> + ddebug_apply_class_maps(&dt->info);
>
> mutex_lock(&ddebug_lock);
> list_add_tail(&dt->link, &ddebug_tables);
> mutex_unlock(&ddebug_lock);
>
> + if (dt->info.users.len)
> + ddebug_apply_class_users(&dt->info);
> +
> vpr_info("%3u debug prints in module %s\n", di->descs.len, di->mod_name);
> return 0;
> }
> @@ -1354,8 +1461,10 @@ static int __init dynamic_debug_init(void)
> struct _ddebug_info di = {
> .descs.start = __start___dyndbg_descs,
> .maps.start = __start___dyndbg_class_maps,
> + .users.start = __start___dyndbg_class_users,
> .descs.len = __stop___dyndbg_descs - __start___dyndbg_descs,
> .maps.len = __stop___dyndbg_class_maps - __start___dyndbg_class_maps,
> + .users.len = __stop___dyndbg_class_users - __start___dyndbg_class_users,
> };
>
> #ifdef CONFIG_MODULES
> diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
> index 9c3e53cd26bd..1070107f74f1 100644
> --- a/lib/test_dynamic_debug.c
> +++ b/lib/test_dynamic_debug.c
> @@ -6,11 +6,30 @@
> * Jim Cromie <jim.cromie@gmail.com>
> */
>
> -#define pr_fmt(fmt) "test_dd: " fmt
> +/*
> + * This file is built 2x, also making test_dynamic_debug_submod.ko,
> + * whose 2-line src file #includes this file. This gives us a _submod
> + * clone with identical pr_debugs, without further maintenance.
> + *
> + * If things are working properly, they should operate identically
> + * when printed or adjusted by >control. This eases visual perusal of
> + * the logs, and simplifies testing, by easing the proper accounting
> + * of expectations.
> + *
> + * It also puts both halves of the subsystem _DEFINE & _USE use case
> + * together, and integrates the common ENUM providing both class_ids
> + * and class-names to both _DEFINErs and _USERs. I think this makes
> + * the usage clearer.
> + */
> +#if defined(TEST_DYNAMIC_DEBUG_SUBMOD)
> + #define pr_fmt(fmt) "test_dd_submod: " fmt
> +#else
> + #define pr_fmt(fmt) "test_dd: " fmt
> +#endif
>
> #include <linux/module.h>
>
> -/* run tests by reading or writing sysfs node: do_prints */
> +/* re-gen output by reading or writing sysfs node: do_prints */
>
> static void do_prints(void); /* device under test */
> static int param_set_do_prints(const char *instr, const struct kernel_param *kp)
> @@ -29,24 +48,39 @@ static const struct kernel_param_ops param_ops_do_prints = {
> };
> module_param_cb(do_prints, ¶m_ops_do_prints, NULL, 0600);
>
> -/*
> - * Using the CLASSMAP api:
> - * - classmaps must have corresponding enum
> - * - enum symbols must match/correlate with class-name strings in the map.
> - * - base must equal enum's 1st value
> - * - multiple maps must set their base to share the 0-30 class_id space !!
> - * (build-bug-on tips welcome)
> - * Additionally, here:
> - * - tie together sysname, mapname, bitsname, flagsname
> - */
> -#define DD_SYS_WRAP(_model, _flags) \
> - static unsigned long bits_##_model; \
> - static struct _ddebug_class_param _flags##_model = { \
> +#define CLASSMAP_BITMASK(width, base) (((1UL << (width)) - 1) << (base))
> +
> +/* sysfs param wrapper, proto-API */
> +#define DYNAMIC_DEBUG_CLASSMAP_PARAM_(_model, _flags, _init) \
> + static unsigned long bits_##_model = _init; \
> + static struct _ddebug_class_param _flags##_##_model = { \
> .bits = &bits_##_model, \
> .flags = #_flags, \
> .map = &map_##_model, \
> }; \
> - module_param_cb(_flags##_##_model, ¶m_ops_dyndbg_classes, &_flags##_model, 0600)
> + module_param_cb(_flags##_##_model, ¶m_ops_dyndbg_classes, \
> + &_flags##_##_model, 0600)
> +#ifdef DEBUG
> +#define DYNAMIC_DEBUG_CLASSMAP_PARAM(_model, _flags) \
> + DYNAMIC_DEBUG_CLASSMAP_PARAM_(_model, _flags, ~0)
> +#else
> +#define DYNAMIC_DEBUG_CLASSMAP_PARAM(_model, _flags) \
> + DYNAMIC_DEBUG_CLASSMAP_PARAM_(_model, _flags, 0)
> +#endif
> +
> +/*
> + * Demonstrate/test DISJOINT & LEVEL typed classmaps with a sys-param.
> + *
> + * To comport with DRM debug-category (an int), classmaps map names to
> + * ids (also an int). So a classmap starts with an enum; DRM has enum
> + * debug_category: with DRM_UT_<CORE,DRIVER,KMS,etc>. We use the enum
> + * values as class-ids, and stringified enum-symbols as classnames.
> + *
> + * Modules with multiple CLASSMAPS must have enums with distinct
> + * value-ranges, as arranged below with explicit enum_sym = X inits.
> + * To clarify this sharing, declare the 2 enums now, for the 2
> + * different classmap types
> + */
>
> /* numeric input, independent bits */
> enum cat_disjoint_bits {
> @@ -60,26 +94,51 @@ enum cat_disjoint_bits {
> D2_LEASE,
> D2_DP,
> D2_DRMRES };
> -DECLARE_DYNDBG_CLASSMAP(map_disjoint_bits, DD_CLASS_TYPE_DISJOINT_BITS, 0,
> - "D2_CORE",
> - "D2_DRIVER",
> - "D2_KMS",
> - "D2_PRIME",
> - "D2_ATOMIC",
> - "D2_VBL",
> - "D2_STATE",
> - "D2_LEASE",
> - "D2_DP",
> - "D2_DRMRES");
> -DD_SYS_WRAP(disjoint_bits, p);
> -DD_SYS_WRAP(disjoint_bits, T);
> -
> -/* numeric verbosity, V2 > V1 related */
> -enum cat_level_num { V0 = 14, V1, V2, V3, V4, V5, V6, V7 };
> -DECLARE_DYNDBG_CLASSMAP(map_level_num, DD_CLASS_TYPE_LEVEL_NUM, 14,
> - "V0", "V1", "V2", "V3", "V4", "V5", "V6", "V7");
> -DD_SYS_WRAP(level_num, p);
> -DD_SYS_WRAP(level_num, T);
> +
> +/* numeric verbosity, V2 > V1 related. V0 is > D2_DRM_RES */
> +enum cat_level_num { V0 = 16, V1, V2, V3, V4, V5, V6, V7 };
> +
> +/* recapitulate DRM's multi-classmap setup */
> +#if !defined(TEST_DYNAMIC_DEBUG_SUBMOD)
> +/*
> + * In single user, or parent / coordinator (drm.ko) modules, define
> + * classmaps on the client enums above, and then declares the PARAMS
> + * ref'g the classmaps. Each is exported.
> + */
> +DYNAMIC_DEBUG_CLASSMAP_DEFINE(map_disjoint_bits, DD_CLASS_TYPE_DISJOINT_BITS,
> + D2_CORE,
> + "D2_CORE",
> + "D2_DRIVER",
> + "D2_KMS",
> + "D2_PRIME",
> + "D2_ATOMIC",
> + "D2_VBL",
> + "D2_STATE",
> + "D2_LEASE",
> + "D2_DP",
> + "D2_DRMRES");
> +
> +DYNAMIC_DEBUG_CLASSMAP_DEFINE(map_level_num, DD_CLASS_TYPE_LEVEL_NUM,
> + V0, "V0", "V1", "V2", "V3", "V4", "V5", "V6", "V7");
> +
> +/*
> + * now add the sysfs-params
> + */
> +
> +DYNAMIC_DEBUG_CLASSMAP_PARAM(disjoint_bits, p);
> +DYNAMIC_DEBUG_CLASSMAP_PARAM(level_num, p);
> +
> +#else /* TEST_DYNAMIC_DEBUG_SUBMOD */
> +
> +/*
> + * in submod/drm-drivers, use the classmaps defined in top/parent
> + * module above.
> + */
> +
> +DYNAMIC_DEBUG_CLASSMAP_USE(map_disjoint_bits);
> +DYNAMIC_DEBUG_CLASSMAP_USE(map_level_num);
> +
> +#endif
>
> /* stand-in for all pr_debug etc */
> #define prdbg(SYM) __pr_debug_cls(SYM, #SYM " msg\n")
> @@ -115,6 +174,7 @@ static void do_levels(void)
>
> static void do_prints(void)
> {
> + pr_debug("do_prints:\n");
> do_cats();
> do_levels();
> }
> diff --git a/lib/test_dynamic_debug_submod.c b/lib/test_dynamic_debug_submod.c
> new file mode 100644
> index 000000000000..672aabf40160
> --- /dev/null
> +++ b/lib/test_dynamic_debug_submod.c
> @@ -0,0 +1,14 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Kernel module for testing dynamic_debug
> + *
> + * Authors:
> + * Jim Cromie <jim.cromie@gmail.com>
> + */
> +
> +/*
> + * clone the parent, inherit all the properties, for consistency and
> + * simpler accounting in test expectations.
> + */
> +#define TEST_DYNAMIC_DEBUG_SUBMOD
> +#include "test_dynamic_debug.c"
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 18/54] selftests-dyndbg: add tools/testing/selftests/dynamic_debug/*
2025-04-02 17:41 ` [PATCH v3 18/54] selftests-dyndbg: add tools/testing/selftests/dynamic_debug/* Jim Cromie
@ 2025-04-15 10:02 ` Louis Chauvet
2025-04-15 19:46 ` jim.cromie
0 siblings, 1 reply; 81+ messages in thread
From: Louis Chauvet @ 2025-04-15 10:02 UTC (permalink / raw)
To: Jim Cromie, jbaron, gregkh, ukaszb, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala
Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> Add a selftest script for dynamic-debug. The config requires
> CONFIG_TEST_DYNAMIC_DEBUG=m and CONFIG_TEST_DYNAMIC_DEBUG_SUBMOD=m,
> which tacitly requires either CONFIG_DYNAMIC_DEBUG=y or
> CONFIG_DYNAMIC_DEBUG_CORE=y
>
> ATM this has just basic_tests(), which modify pr_debug() flags in the
> builtin params module. This means they're available to manipulate and
> observe the effects in "cat control".
>
> This is backported from another feature branch; the support-fns (thx
> Lukas) have unused features at the moment, they'll get used shortly.
>
> The script enables simple virtme-ng testing:
>
> [jimc@gandalf b0-ftrace]$ vrun_t
> virtme-ng 1.32+115.g07b109d
> doing: vng --name v6.14-rc4-60-gd5f48427de0c \
> --user root -v -p 4 -a dynamic_debug.verbose=3 V=1 \
> -- ../tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
> virtme: waiting for virtiofsd to start
> ..
>
> And add dynamic_debug to TARGETS, so `make run_tests` sees it properly
>
> For the impatient, set TARGETS explicitly:
>
> bash-5.2# make TARGETS=dynamic_debug run_tests
> make[1]: ...
> TAP version 13
> 1..1
> [ 35.552922] dyndbg: read 3 bytes from userspace
> [ 35.553099] dyndbg: query 0: "=_" mod:*
> [ 35.553544] dyndbg: processed 1 queries, with 1778 matches, 0 errs
>
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> Co-developed-by: Łukasz Bartosik <ukaszb@chromium.org>
> Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
> ---
> -r3 turn off green at end
> drop config dep on TEST_DYNAMIC_DEBUG,
> since basic-test uses builtin params
>
> - check KCONFIG_CONFIG to avoid silly fails
>
> Several tests are dependent upon config choices. Lets avoid failing
> where that is noise.
>
> The KCONFIG_CONFIG var exists to convey the config-file around. If
> the var names a file, read it and extract the relevant CONFIG items,
> and use them to skip the dependent tests, thus avoiding the fails that
> would follow, and the disruption to whatever CI is running these
> selftests.
>
> If the envar doesn't name a config-file, ".config" is assumed.
>
> CONFIG_DYNAMIC_DEBUG=y:
>
> basic-tests() and comma-terminator-tests() test for the presence of
> the builtin pr_debugs in module/main.c, which I deemed stable and
> therefore safe to count. That said, the test fails if only
> CONFIG_DYNAMIC_DEBUG_CORE=y is set. It could be rewritten to test
> against test-dynamic-debug.ko, but that just trades one config
> dependence for another.
>
> CONFIG_TEST_DYNAMIC_DEBUG=m
>
> As written, test_percent_splitting() modprobes test_dynamic_debug,
> enables several classes, and count them. It could be re-written to
> work for the builtin module also, but builtin test modules are not a
> common or desirable build/config.
>
> CONFIG_TEST_DYNAMIC_DEBUG=m && CONFIG_TEST_DYNAMIC_DEBUG_SUBMOD=m
>
> test_mod_submod() recaps the bug found in DRM-CI where drivers werent
> enabled by drm.debug=<bits>. It modprobes both test_dynamic_debug &
> test_dynamic_debug_submod, so it depends on a loadable modules config.
>
> It could be rewritten to work in a builtin parent config; DRM=y is
> common enough to be pertinent, but testing that config also wouldn't
> really test anything more fully than all-loadable modules, since they
> default together.
>
> generalize-test-env
> ---
> MAINTAINERS | 1 +
> tools/testing/selftests/Makefile | 1 +
> .../testing/selftests/dynamic_debug/Makefile | 9 +
> tools/testing/selftests/dynamic_debug/config | 7 +
> .../dynamic_debug/dyndbg_selftest.sh | 257 ++++++++++++++++++
> 5 files changed, 275 insertions(+)
> create mode 100644 tools/testing/selftests/dynamic_debug/Makefile
> create mode 100644 tools/testing/selftests/dynamic_debug/config
> create mode 100755 tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 1c5fcbd9e408..1192ad6c65c1 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -8140,6 +8140,7 @@ S: Maintained
> F: include/linux/dynamic_debug.h
> F: lib/dynamic_debug.c
> F: lib/test_dynamic_debug*.c
> +F: tools/testing/selftests/dynamic_debug/*
>
> DYNAMIC INTERRUPT MODERATION
> M: Tal Gilboa <talgi@nvidia.com>
> diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
> index 8daac70c2f9d..b6a323c7f986 100644
> --- a/tools/testing/selftests/Makefile
> +++ b/tools/testing/selftests/Makefile
> @@ -26,6 +26,7 @@ TARGETS += drivers/net/team
> TARGETS += drivers/net/virtio_net
> TARGETS += drivers/platform/x86/intel/ifs
> TARGETS += dt
> +TARGETS += dynamic_debug
> TARGETS += efivarfs
> TARGETS += exec
> TARGETS += fchmodat2
> diff --git a/tools/testing/selftests/dynamic_debug/Makefile b/tools/testing/selftests/dynamic_debug/Makefile
> new file mode 100644
> index 000000000000..6d06fa7f1040
> --- /dev/null
> +++ b/tools/testing/selftests/dynamic_debug/Makefile
> @@ -0,0 +1,9 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +# borrowed from Makefile for user memory selftests
> +
> +# No binaries, but make sure arg-less "make" doesn't trigger "run_tests"
> +all:
> +
> +TEST_PROGS := dyndbg_selftest.sh
> +
> +include ../lib.mk
> diff --git a/tools/testing/selftests/dynamic_debug/config b/tools/testing/selftests/dynamic_debug/config
> new file mode 100644
> index 000000000000..0f906ff53908
> --- /dev/null
> +++ b/tools/testing/selftests/dynamic_debug/config
> @@ -0,0 +1,7 @@
> +
> +# basic tests ref the builtin params module
> +CONFIG_DYNAMIC_DEBUG=m
> +
> +# more testing is possible with these
> +# CONFIG_TEST_DYNAMIC_DEBUG=m
> +# CONFIG_TEST_DYNAMIC_DEBUG_SUBMOD=m
> diff --git a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
> new file mode 100755
> index 000000000000..465fad3f392c
> --- /dev/null
> +++ b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
> @@ -0,0 +1,257 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0-only
> +
> +V=${V:=0} # invoke as V=1 $0 for global verbose
> +RED="\033[0;31m"
> +GREEN="\033[0;32m"
> +YELLOW="\033[0;33m"
> +BLUE="\033[0;34m"
> +MAGENTA="\033[0;35m"
> +CYAN="\033[0;36m"
> +NC="\033[0;0m"
> +error_msg=""
> +
> +[ -e /proc/dynamic_debug/control ] || {
> + echo -e "${RED}: this test requires CONFIG_DYNAMIC_DEBUG=y ${NC}"
> + exit 0 # nothing to test here, no good reason to fail.
> +}
> +
> +# need info to avoid failures due to untestable configs
> +
> +[ -f "$KCONFIG_CONFIG" ] || KCONFIG_CONFIG=".config"
> +if [ -f "$KCONFIG_CONFIG" ]; then
> + echo "# consulting KCONFIG_CONFIG: $KCONFIG_CONFIG"
> + grep -q "CONFIG_DYNAMIC_DEBUG=y" $KCONFIG_CONFIG ; LACK_DD_BUILTIN=$?
> + grep -q "CONFIG_TEST_DYNAMIC_DEBUG=m" $KCONFIG_CONFIG ; LACK_TMOD=$?
> + grep -q "CONFIG_TEST_DYNAMIC_DEBUG_SUBMOD=m" $KCONFIG_CONFIG ; LACK_TMOD_SUBMOD=$?
> + if [ $V -eq 1 ]; then
> + echo LACK_DD_BUILTIN: $LACK_DD_BUILTIN
> + echo LACK_TMOD: $LACK_TMOD
> + echo LACK_TMOD_SUBMOD: $LACK_TMOD_SUBMOD
> + fi
> +else
> + LACK_DD_BUILTIN=0
> + LACK_TMOD=0
> + LACK_TMOD_SUBMOD=0
> +fi
Nitpick for the sh file: is it normal to have inconsistent indenting ?(4
space, tabs, 8 spaces)
> +function vx () {
> + echo $1 > /sys/module/dynamic_debug/parameters/verbose
> +}
> +
> +function ddgrep () {
> + grep $1 /proc/dynamic_debug/control
> +}
> +
> +function doprints () {
> + cat /sys/module/test_dynamic_debug/parameters/do_prints
> +}
> +
> +function ddcmd () {
> + exp_exit_code=0
> + num_args=$#
> + if [ "${@:$#}" = "pass" ]; then
> + num_args=$#-1
> + elif [ "${@:$#}" = "fail" ]; then
> + num_args=$#-1
> + exp_exit_code=1
> + fi
> + args=${@:1:$num_args}
> + output=$((echo "$args" > /proc/dynamic_debug/control) 2>&1)
> + exit_code=$?
> + error_msg=$(echo $output | cut -d ":" -f 5 | sed -e 's/^[[:space:]]*//')
> + handle_exit_code $BASH_LINENO $FUNCNAME $exit_code $exp_exit_code
> +}
> +
> +function handle_exit_code() {
> + local exp_exit_code=0
> + [ $# == 4 ] && exp_exit_code=$4
> + if [ $3 -ne $exp_exit_code ]; then
> + echo -e "${RED}: $BASH_SOURCE:$1 $2() expected to exit with code $exp_exit_code"
> + [ $3 == 1 ] && echo "Error: '$error_msg'"
> + exit
> + fi
> +}
> +
> +# $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
> +# $4 - optional when $3 is set to "-r" then $4 can be used to pass "-v"
> +function check_match_ct {
> + pattern="\s$1\s"
> + exp_cnt=0
> +
> + [ "$3" == "-r" ] && pattern="$1"
> + let cnt=$(ddgrep "$pattern" | wc -l)
> + if [ $V -eq 1 ] || [ "$3" == "-v" ] || [ "$4" == "-v" ]; then
> + echo -ne "${BLUE}" && ddgrep $pattern && echo -ne "${NC}"
> + fi
> + [ $# -gt 1 ] && exp_cnt=$2
> + if [ $cnt -ne $exp_cnt ]; then
> + echo -e "${RED}: $BASH_SOURCE:$BASH_LINENO check failed expected $exp_cnt on $1, got $cnt"
> + exit
> + else
> + echo ": $cnt matches on $1"
> + fi
> +}
> +
> +# $1 - trace instance name
> +# #2 - if > 0 then directory is expected to exist, if <= 0 then otherwise
> +# $3 - "-v" for verbose
> +function check_trace_instance_dir {
> + if [ -e /sys/kernel/tracing/instances/$1 ]; then
> + if [ "$3" == "-v" ] ; then
> + echo "ls -l /sys/kernel/tracing/instances/$1: "
> + ls -l /sys/kernel/tracing/instances/$1
> + fi
> + if [ $2 -le 0 ]; then
> + echo -e "${RED}: $BASH_SOURCE:$BASH_LINENO error trace instance \
> + '/sys/kernel/tracing/instances/$1' does exist"
> + exit
> + fi
> + else
> + if [ $2 -gt 0 ]; then
> + echo -e "${RED}: $BASH_SOURCE:$BASH_LINENO error trace instance \
> + '/sys/kernel/tracing/instances/$1' does not exist"
> + exit
> + fi
> + fi
> +}
> +
> +function tmark {
> + echo $* > /sys/kernel/tracing/trace_marker
> +}
> +
> +# $1 - trace instance name
> +# $2 - line number
> +# $3 - if > 0 then the instance is expected to be opened, otherwise
> +# the instance is expected to be closed
> +function check_trace_instance {
> + output=$(tail -n9 /proc/dynamic_debug/control | grep ": Opened trace instances" \
> + | xargs -n1 | grep $1)
> + if [ "$output" != $1 ] && [ $3 -gt 0 ]; then
> + echo -e "${RED}: $BASH_SOURCE:$2 trace instance $1 is not opened"
> + exit
> + fi
> + if [ "$output" == $1 ] && [ $3 -le 0 ]; then
> + echo -e "${RED}: $BASH_SOURCE:$2 trace instance $1 is not closed"
> + exit
> + fi
> +}
> +
> +function is_trace_instance_opened {
> + check_trace_instance $1 $BASH_LINENO 1
> +}
> +
> +function is_trace_instance_closed {
> + check_trace_instance $1 $BASH_LINENO 0
> +}
> +
> +# $1 - trace instance directory to delete
> +# $2 - if > 0 then directory is expected to be deleted successfully, if <= 0 then otherwise
> +function del_trace_instance_dir() {
> + exp_exit_code=1
> + [ $2 -gt 0 ] && exp_exit_code=0
> + output=$((rmdir /sys/kernel/debug/tracing/instances/$1) 2>&1)
> + exit_code=$?
> + error_msg=$(echo $output | cut -d ":" -f 3 | sed -e 's/^[[:space:]]*//')
> + handle_exit_code $BASH_LINENO $FUNCNAME $exit_code $exp_exit_code
> +}
> +
> +function error_log_ref {
> + # to show what I got
> + : echo "# error-log-ref: $1"
> + : echo cat \$2
> +}
> +
> +function ifrmmod {
> + lsmod | grep $1 2>&1>/dev/null && rmmod $1
> +}
> +
> +# $1 - text to search for
> +function search_trace() {
> + search_trace_name 0 1 $1
> +}
> +
> +# $1 - trace instance name, 0 for global event trace
> +# $2 - line number counting from the bottom
> +# $3 - text to search for
> +function search_trace_name() {
> + if [ "$1" = "0" ]; then
> + buf=$(cat /sys/kernel/debug/tracing/trace)
> + line=$(tail -$2 /sys/kernel/debug/tracing/trace | head -1 | sed -e 's/^[[:space:]]*//')
> + else
> + buf=$(cat /sys/kernel/debug/tracing/instances/$1/trace)
> + line=$(tail -$2 /sys/kernel/debug/tracing/instances/$1/trace | head -1 | \
> + sed -e 's/^[[:space:]]*//')
> + fi
> + if [ $2 = 0 ]; then
> + # whole-buf check
> + output=$(echo $buf | grep "$3")
> + else
> + output=$(echo $line | grep "$3")
> + fi
> + if [ "$output" = "" ]; then
> + echo -e "${RED}: $BASH_SOURCE:$BASH_LINENO search for '$3' failed \
> + in line '$line' or '$buf'"
> + exit
> + fi
> + if [ $V = 1 ]; then
> + echo -e "${MAGENTA}: search_trace_name in $1 found: \n$output \nin:${BLUE} $buf ${NC}"
> + fi
> +}
> +
> +# $1 - error message to check
> +function check_err_msg() {
> + if [ "$error_msg" != "$1" ]; then
> + echo -e "${RED}: $BASH_SOURCE:$BASH_LINENO error message '$error_msg' \
> + does not match with '$1'"
> + exit
> + fi
> +}
> +
> +function basic_tests {
> + echo -e "${GREEN}# BASIC_TESTS ${NC}"
> + if [ $LACK_DD_BUILTIN -eq 1 ]; then
> + echo "SKIP"
> + return
> + fi
> + ddcmd =_ # zero everything
> + check_match_ct =p 0
> +
> + # module params are builtin to handle boot args
> + check_match_ct '\[params\]' 4 -r
> + ddcmd module params +mpf
> + check_match_ct =pmf 4
> +
> + # multi-cmd input, newline separated, with embedded comments
> + cat <<"EOF" > /proc/dynamic_debug/control
> + module params =_ # clear params
> + module params +mf # set flags
> + module params func parse_args +sl # other flags
> +EOF
> + check_match_ct =mf 3
> + check_match_ct =mfsl 1
> + ddcmd =_
> +}
> +
> +tests_list=(
> + basic_tests
> +)
> +
> +# Run tests
> +
> +ifrmmod test_dynamic_debug_submod
> +ifrmmod test_dynamic_debug
> +
> +for test in "${tests_list[@]}"
> +do
> + $test
> + echo ""
> +done
> +echo -en "${GREEN}# Done on: "
> +date
> +echo -en "${NC}"
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 19/54] dyndbg: detect class_id reservation conflicts
2025-04-02 17:41 ` [PATCH v3 19/54] dyndbg: detect class_id reservation conflicts Jim Cromie
@ 2025-04-15 10:03 ` Louis Chauvet
0 siblings, 0 replies; 81+ messages in thread
From: Louis Chauvet @ 2025-04-15 10:03 UTC (permalink / raw)
To: Jim Cromie, jbaron, gregkh, ukaszb, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala
Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> If a module _DEFINEs + _USEs 2 or more classmaps, it must devise them
> to share the per-module 0..62 class-id space; ie their respective
> base,+length reservations cannot overlap.
>
> To detect conflicts at modprobe, add ddebug_class_range_overlap(),
> call it from ddebug_add_module(), and WARN and return -EINVAL when
> they're detected.
>
> test_dynamic_debug.c:
>
> If built with -DFORCE_CLASSID_CONFLICT, the test-modules get 2 bad
> DYNDBG_CLASS_DEFINE declarations, into parent and the _submod. These
> conflict with one of the good ones in the parent (D2_CORE..etc),
> causing the modprobe(s) to warn
>
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
> ---
> ---
> lib/dynamic_debug.c | 29 +++++++++++++++++++++++++++++
> lib/test_dynamic_debug.c | 8 ++++++++
> 2 files changed, 37 insertions(+)
>
> diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
> index 53e261dbf81e..56b503af0b31 100644
> --- a/lib/dynamic_debug.c
> +++ b/lib/dynamic_debug.c
> @@ -1267,6 +1267,22 @@ static void ddebug_apply_class_users(const struct _ddebug_info *di)
> (_dst)->info._vec.len = nc; \
> })
>
> +static int __maybe_unused
> +ddebug_class_range_overlap(struct _ddebug_class_map *cm,
> + u64 *reserved_ids)
> +{
> + u64 range = (((1ULL << cm->length) - 1) << cm->base);
> +
> + if (range & *reserved_ids) {
> + pr_err("[%d..%d] on %s conflicts with %llx\n", cm->base,
> + cm->base + cm->length - 1, cm->class_names[0],
> + *reserved_ids);
> + return -EINVAL;
> + }
> + *reserved_ids |= range;
> + return 0;
> +}
> +
> /*
> * Allocate a new ddebug_table for the given module
> * and add it to the global list.
> @@ -1276,6 +1292,7 @@ static int ddebug_add_module(struct _ddebug_info *di)
> struct ddebug_table *dt;
> struct _ddebug_class_map *cm;
> struct _ddebug_class_user *cli;
> + u64 reserved_ids = 0;
> int i;
>
> if (!di->descs.len)
> @@ -1301,6 +1318,13 @@ static int ddebug_add_module(struct _ddebug_info *di)
> dd_mark_vector_subrange(i, dt, cm, di, maps);
> dd_mark_vector_subrange(i, dt, cli, di, users);
>
> + for_subvec(i, cm, &dt->info, maps)
> + if (ddebug_class_range_overlap(cm, &reserved_ids))
> + goto cleanup;
> + for_subvec(i, cli, &dt->info, users)
> + if (ddebug_class_range_overlap(cli->map, &reserved_ids))
> + goto cleanup;
> +
> if (dt->info.maps.len)
> ddebug_apply_class_maps(&dt->info);
>
> @@ -1313,6 +1337,11 @@ static int ddebug_add_module(struct _ddebug_info *di)
>
> vpr_info("%3u debug prints in module %s\n", di->descs.len, di->mod_name);
> return 0;
> +cleanup:
> + WARN_ONCE("dyndbg multi-classmap conflict in %s\n", di->mod_name);
> + kfree(dt);
> + return -EINVAL;
> +
> }
>
> /* helper for ddebug_dyndbg_(boot|module)_param_cb */
> diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
> index 1070107f74f1..e42916b08fd4 100644
> --- a/lib/test_dynamic_debug.c
> +++ b/lib/test_dynamic_debug.c
> @@ -128,6 +128,14 @@ DYNAMIC_DEBUG_CLASSMAP_DEFINE(map_level_num, DD_CLASS_TYPE_LEVEL_NUM,
> DYNAMIC_DEBUG_CLASSMAP_PARAM(disjoint_bits, p);
> DYNAMIC_DEBUG_CLASSMAP_PARAM(level_num, p);
>
> +#ifdef FORCE_CLASSID_CONFLICT
> +/*
> + * Enable with -Dflag on compile to test overlapping class-id range
> + * detection. This should warn on modprobes.
> + */
> +DYNDBG_CLASSMAP_DEFINE(classid_range_conflict, 0, D2_CORE + 1, "D3_CORE");
> +#endif
> +
> #else /* TEST_DYNAMIC_DEBUG_SUBMOD */
>
> /*
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 20/54] dyndbg: check DYNAMIC_DEBUG_CLASSMAP_DEFINE args at compile-time
2025-04-02 17:41 ` [PATCH v3 20/54] dyndbg: check DYNAMIC_DEBUG_CLASSMAP_DEFINE args at compile-time Jim Cromie
@ 2025-04-15 10:04 ` Louis Chauvet
2025-04-15 19:54 ` jim.cromie
0 siblings, 1 reply; 81+ messages in thread
From: Louis Chauvet @ 2025-04-15 10:04 UTC (permalink / raw)
To: Jim Cromie, jbaron, gregkh, ukaszb, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala
Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> Add __DYNAMIC_DEBUG_CLASSMAP_CHECK to implement the following
> arg-checks at compile-time:
>
> 0 <= _base < 63
> class_names is not empty
> class_names[0] is a string
I don't see where this is checked, did I miss something?
> (class_names.length + _base) < 63
>
> These compile-time checks will prevent several misuses; 4 such
> examples are added to test_dynamic_debug_submod.ko, and will fail
> compilation if -DDD_MACRO_ARGCHECK is added to cflags. This wouldn't
> be a useful CONFIG_ item, since it breaks the build.
>
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> ---
> v3- $macro_name =~ s/DYNDBG/DYNAMIC_DEBUG/
>
> prev-
> - split static-asserts to __DYNDBG_CLASSMAP_CHECK
> - move __DYNDBG_CLASSMAP_CHECK above kdoc for DYNDBG_CLASSMAP_DEFINE
> silences kernel-doc warnings
> ---
> include/linux/dynamic_debug.h | 9 +++++++++
> lib/test_dynamic_debug.c | 11 +++++++++++
> 2 files changed, 20 insertions(+)
>
> diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
> index 9af825c84e70..4941ef2adb46 100644
> --- a/include/linux/dynamic_debug.h
> +++ b/include/linux/dynamic_debug.h
> @@ -99,6 +99,14 @@ struct _ddebug_class_map {
> enum ddebug_class_map_type map_type;
> };
>
> +#define __DYNAMIC_DEBUG_CLASSMAP_CHECK(_clnames, _base) \
> + static_assert(((_base) >= 0 && (_base) < _DPRINTK_CLASS_DFLT), \
> + "_base must be in 0..62"); \
> + static_assert(ARRAY_SIZE(_clnames) > 0, \
> + "classnames array size must be > 0"); \
> + static_assert((ARRAY_SIZE(_clnames) + (_base)) < _DPRINTK_CLASS_DFLT, \
> + "_base + classnames.length exceeds range")
> +
> /**
> * DYNAMIC_DEBUG_CLASSMAP_DEFINE - define debug classes used by a module.
> * @_var: name of the classmap, exported for other modules coordinated use.
> @@ -112,6 +120,7 @@ struct _ddebug_class_map {
> */
> #define DYNAMIC_DEBUG_CLASSMAP_DEFINE(_var, _mapty, _base, ...) \
> static const char *_var##_classnames[] = { __VA_ARGS__ }; \
Or maybe it was already enforced by this, but in this case the commit
message contains too much checks.
> + __DYNAMIC_DEBUG_CLASSMAP_CHECK(_var##_classnames, (_base)); \
> extern struct _ddebug_class_map _var; \
> struct _ddebug_class_map __aligned(8) __used \
> __section("__dyndbg_class_maps") _var = { \
> diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
> index e42916b08fd4..9f9e3fddd7e6 100644
> --- a/lib/test_dynamic_debug.c
> +++ b/lib/test_dynamic_debug.c
> @@ -146,8 +146,19 @@ DYNDBG_CLASSMAP_DEFINE(classid_range_conflict, 0, D2_CORE + 1, "D3_CORE");
> DYNAMIC_DEBUG_CLASSMAP_USE(map_disjoint_bits);
> DYNAMIC_DEBUG_CLASSMAP_USE(map_level_num);
>
> +#if defined(DD_MACRO_ARGCHECK)
> +/*
> + * Exersize compile-time arg-checks in DYNDBG_CLASSMAP_DEFINE.
> + * These will break compilation.
> + */
> +DYNDBG_CLASSMAP_DEFINE(fail_base_neg, 0, -1, "NEGATIVE_BASE_ARG");
> +DYNDBG_CLASSMAP_DEFINE(fail_base_big, 0, 100, "TOOBIG_BASE_ARG");
> +DYNDBG_CLASSMAP_DEFINE(fail_str_type, 0, 0, 1 /* not a string */);
> +DYNDBG_CLASSMAP_DEFINE(fail_emptyclass, 0, 0 /* ,empty */);
> #endif
>
> +#endif /* TEST_DYNAMIC_DEBUG_SUBMOD */
> +
> /* stand-in for all pr_debug etc */
> #define prdbg(SYM) __pr_debug_cls(SYM, #SYM " msg\n")
>
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 21/54] dyndbg-test: change do_prints testpoint to accept a loopct
2025-04-02 17:41 ` [PATCH v3 21/54] dyndbg-test: change do_prints testpoint to accept a loopct Jim Cromie
@ 2025-04-15 10:04 ` Louis Chauvet
2025-04-15 20:15 ` jim.cromie
0 siblings, 1 reply; 81+ messages in thread
From: Louis Chauvet @ 2025-04-15 10:04 UTC (permalink / raw)
To: Jim Cromie, jbaron, gregkh, ukaszb, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala
Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> echo 1000 > /sys/module/test_dynamic_debug/parameters/do_prints
>
> This allows its use as a scriptable load generator, to generate
> dynamic-prefix-emits for flag combinations vs undecorated messages.
> This will make it easy to assess the cost of the prefixing.
>
> Reading the ./do_prints node also prints messages (once) to the-log.
>
> NB: the count is clamped to 10000, chosen to be notice able, but not
> annoying, and not enough to accidentally flood the logs.
>
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
I think this could be in a separate series / merged independently to
reduce the size of this series.
> ---
> lib/test_dynamic_debug.c | 37 ++++++++++++++++++++++++++-----------
> 1 file changed, 26 insertions(+), 11 deletions(-)
>
> diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
> index 9f9e3fddd7e6..4a3d2612ef60 100644
> --- a/lib/test_dynamic_debug.c
> +++ b/lib/test_dynamic_debug.c
> @@ -29,18 +29,30 @@
>
> #include <linux/module.h>
>
> -/* re-gen output by reading or writing sysfs node: do_prints */
> -
> -static void do_prints(void); /* device under test */
> +/* re-trigger debug output by reading or writing sysfs node: do_prints */
> +#define PRINT_CLAMP 10000
> +static void do_prints(unsigned int); /* device under test */
> static int param_set_do_prints(const char *instr, const struct kernel_param *kp)
> {
> - do_prints();
> + int rc;
> + unsigned int ct;
> +
> + rc = kstrtouint(instr, 0, &ct);
> + if (rc) {
> + pr_err("expecting numeric input, using 1 instead\n");
> + ct = 1;
> + }
> + if (ct > PRINT_CLAMP) {
> + ct = PRINT_CLAMP;
> + pr_info("clamping print-count to %d\n", ct);
> + }
> + do_prints(ct);
> return 0;
> }
> static int param_get_do_prints(char *buffer, const struct kernel_param *kp)
> {
> - do_prints();
> - return scnprintf(buffer, PAGE_SIZE, "did do_prints\n");
> + do_prints(1);
> + return scnprintf(buffer, PAGE_SIZE, "did 1 do_prints\n");
> }
> static const struct kernel_param_ops param_ops_do_prints = {
> .set = param_set_do_prints,
> @@ -191,17 +203,20 @@ static void do_levels(void)
> prdbg(V7);
> }
>
> -static void do_prints(void)
> +static void do_prints(unsigned int ct)
> {
> - pr_debug("do_prints:\n");
> - do_cats();
> - do_levels();
> + /* maybe clamp this */
> + pr_debug("do-prints %d times:\n", ct);
> + for (; ct; ct--) {
> + do_cats();
> + do_levels();
> + }
> }
>
> static int __init test_dynamic_debug_init(void)
> {
> pr_debug("init start\n");
> - do_prints();
> + do_prints(1);
> pr_debug("init done\n");
> return 0;
> }
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 23/54] dyndbg: treat comma as a token separator
2025-04-02 17:41 ` [PATCH v3 23/54] dyndbg: treat comma as a token separator Jim Cromie
@ 2025-04-15 10:04 ` Louis Chauvet
2025-04-15 20:17 ` jim.cromie
0 siblings, 1 reply; 81+ messages in thread
From: Louis Chauvet @ 2025-04-15 10:04 UTC (permalink / raw)
To: Jim Cromie, jbaron, gregkh, ukaszb, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala
Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> Treat comma as a token terminator, just like a space. This allows a
> user to avoid quoting hassles when spaces are otherwise needed:
>
> :#> modprobe drm dyndbg=class,DRM_UT_CORE,+p\;class,DRM_UT_KMS,+p
>
> or as a boot arg:
>
> drm.dyndbg=class,DRM_UT_CORE,+p # todo: support multi-query here
>
> Given the many ways a boot-line +args can be assembled and then passed
> in/down/around shell based tools, this may allow side-stepping all
> sorts of quoting hassles thru those layers.
>
> existing query format:
>
> modprobe test_dynamic_debug dyndbg="class D2_CORE +p"
>
> new format:
>
> modprobe test_dynamic_debug dyndbg=class,D2_CORE,+p
>
> ALSO
>
> selftests-dyndbg: add comma_terminator_tests
>
> New fn validates parsing and effect of queries using combinations of
> commas and spaces to delimit the tokens.
>
> It manipulates pr-debugs in builtin module/params, so might have deps
> I havent foreseen on odd configurations.
>
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> Co-developed-by: Łukasz Bartosik <ukaszb@chromium.org>
> Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
> ---
> - skip comma tests if no builtins
> -v3 squash in tests and doc
> ---
> .../admin-guide/dynamic-debug-howto.rst | 9 +++++---
> lib/dynamic_debug.c | 17 +++++++++++----
> .../dynamic_debug/dyndbg_selftest.sh | 21 ++++++++++++++++++-
> 3 files changed, 39 insertions(+), 8 deletions(-)
>
> diff --git a/Documentation/admin-guide/dynamic-debug-howto.rst b/Documentation/admin-guide/dynamic-debug-howto.rst
> index 63a511f2337b..e2dbb5d9b314 100644
> --- a/Documentation/admin-guide/dynamic-debug-howto.rst
> +++ b/Documentation/admin-guide/dynamic-debug-howto.rst
> @@ -78,11 +78,12 @@ Command Language Reference
> ==========================
>
> At the basic lexical level, a command is a sequence of words separated
> -by spaces or tabs. So these are all equivalent::
> +by spaces, tabs, or commas. So these are all equivalent::
>
> :#> ddcmd file svcsock.c line 1603 +p
> :#> ddcmd "file svcsock.c line 1603 +p"
> :#> ddcmd ' file svcsock.c line 1603 +p '
> + :#> ddcmd file,svcsock.c,line,1603,+p
>
> Command submissions are bounded by a write() system call.
> Multiple commands can be written together, separated by ``;`` or ``\n``::
> @@ -167,9 +168,11 @@ 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::
> + suffix and with ``-`` changed to ``_``.
>
> - module sunrpc
> + Examples::
> +
> + module,sunrpc # with ',' as token separator
> module nfsd
> module drm* # both drm, drm_kms_helper
>
> diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
> index 0d603caadef8..5737f1b4eba8 100644
> --- a/lib/dynamic_debug.c
> +++ b/lib/dynamic_debug.c
> @@ -299,6 +299,14 @@ static int ddebug_change(const struct ddebug_query *query, struct flag_settings
> return nfound;
> }
>
> +static char *skip_spaces_and_commas(const char *str)
> +{
> + str = skip_spaces(str);
> + while (*str == ',')
> + str = skip_spaces(++str);
> + return (char *)str;
> +}
> +
> /*
> * Split the buffer `buf' into space-separated words.
> * Handles simple " and ' quoting, i.e. without nested,
> @@ -312,8 +320,8 @@ static int ddebug_tokenize(char *buf, char *words[], int maxwords)
> while (*buf) {
> char *end;
>
> - /* Skip leading whitespace */
> - buf = skip_spaces(buf);
> + /* Skip leading whitespace and comma */
> + buf = skip_spaces_and_commas(buf);
> if (!*buf)
> break; /* oh, it was trailing whitespace */
> if (*buf == '#')
> @@ -329,7 +337,7 @@ static int ddebug_tokenize(char *buf, char *words[], int maxwords)
> return -EINVAL; /* unclosed quote */
> }
> } else {
> - for (end = buf; *end && !isspace(*end); end++)
> + for (end = buf; *end && !isspace(*end) && *end != ','; end++)
> ;
Why don't you use the skip_spaces_and_commas here?
> if (end == buf) {
> pr_err("parse err after word:%d=%s\n", nwords,
> @@ -601,7 +609,8 @@ static int ddebug_exec_queries(char *query, const char *modname)
> if (split)
> *split++ = '\0';
>
> - query = skip_spaces(query);
> + query = skip_spaces_and_commas(query);
> +
> if (!query || !*query || *query == '#')
> continue;
>
> diff --git a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
> index 465fad3f392c..c7bf521f36ee 100755
> --- a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
> +++ b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
> @@ -216,7 +216,7 @@ function check_err_msg() {
> function basic_tests {
> echo -e "${GREEN}# BASIC_TESTS ${NC}"
> if [ $LACK_DD_BUILTIN -eq 1 ]; then
> - echo "SKIP"
> + echo "SKIP - test requires params, which is a builtin module"
> return
> fi
> ddcmd =_ # zero everything
> @@ -238,8 +238,27 @@ EOF
> ddcmd =_
> }
>
> +function comma_terminator_tests {
> + echo -e "${GREEN}# COMMA_TERMINATOR_TESTS ${NC}"
> + if [ $LACK_DD_BUILTIN -eq 1 ]; then
> + echo "SKIP - test requires params, which is a builtin module"
> + return
> + fi
> + # try combos of spaces & commas
> + check_match_ct '\[params\]' 4 -r
> + ddcmd module,params,=_ # commas as spaces
> + ddcmd module,params,+mpf # turn on module's pr-debugs
> + check_match_ct =pmf 4
> + ddcmd ,module ,, , params, -p
> + check_match_ct =mf 4
> + ddcmd " , module ,,, , params, -m" #
> + check_match_ct =f 4
> + ddcmd =_
> +}
> +
> tests_list=(
> basic_tests
> + comma_terminator_tests
> )
>
> # Run tests
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 22/54] dyndbg-API: promote DYNAMIC_DEBUG_CLASSMAP_PARAM to API
2025-04-02 17:41 ` [PATCH v3 22/54] dyndbg-API: promote DYNAMIC_DEBUG_CLASSMAP_PARAM to API Jim Cromie
@ 2025-04-15 10:06 ` Louis Chauvet
0 siblings, 0 replies; 81+ messages in thread
From: Louis Chauvet @ 2025-04-15 10:06 UTC (permalink / raw)
To: Jim Cromie, jbaron, gregkh, ukaszb, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, linux-doc
Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> move the DYNAMIC_DEBUG_CLASSMAP_PARAM macro from test-dynamic-debug.c into
> the header, and refine it, by distinguishing the 2 use cases:
>
> 1.DYNAMIC_DEBUG_CLASSMAP_PARAM_REF
> for DRM, to pass in extern __drm_debug by name.
> dyndbg keeps bits in it, so drm can still use it as before
>
> 2.DYNAMIC_DEBUG_CLASSMAP_PARAM
> new user (test_dynamic_debug) doesn't need to share state,
> decls a static long unsigned int to store the bitvec.
>
> __DYNAMIC_DEBUG_CLASSMAP_PARAM
> bottom layer - allocate,init a ddebug-class-param, module-param-cb.
>
> Modify ddebug_sync_classbits() argtype deref inside the fn, to give
> access to all kp members.
>
> Also clean up and improve comments in test-code, and add
> MODULE_DESCRIPTIONs.
>
> cc: linux-doc@vger.kernel.org
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> ---
>
> -v9
> - fixup drm-print.h add PARAM_REF forwarding macros
> with DYNAMIC_DEBUG_CLASSMAP_PARAM_REF in the API, add DRM_ variant
> ---
> include/linux/dynamic_debug.h | 38 +++++++++++++++++++++
> lib/dynamic_debug.c | 60 ++++++++++++++++++++++-----------
> lib/test_dynamic_debug.c | 47 ++++++++++----------------
> lib/test_dynamic_debug_submod.c | 9 ++++-
> 4 files changed, 104 insertions(+), 50 deletions(-)
>
> diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
> index 4941ef2adb46..ce221a702f84 100644
> --- a/include/linux/dynamic_debug.h
> +++ b/include/linux/dynamic_debug.h
> @@ -211,6 +211,44 @@ struct _ddebug_class_param {
> const struct _ddebug_class_map *map;
> };
>
> +/**
> + * DYNAMIC_DEBUG_CLASSMAP_PARAM - control a ddebug-classmap from a sys-param
> + * @_name: sysfs node name
> + * @_var: name of the classmap var defining the controlled classes/bits
> + * @_flags: flags to be toggled, typically just 'p'
> + *
> + * Creates a sysfs-param to control the classes defined by the
> + * exported classmap, with bits 0..N-1 mapped to the classes named.
> + * This version keeps class-state in a private long int.
> + */
> +#define DYNAMIC_DEBUG_CLASSMAP_PARAM(_name, _var, _flags) \
> + static unsigned long _name##_bvec; \
> + __DYNAMIC_DEBUG_CLASSMAP_PARAM(_name, _name##_bvec, _var, _flags)
> +
> +/**
> + * DYNAMIC_DEBUG_CLASSMAP_PARAM_REF - wrap a classmap with a controlling sys-param
> + * @_name: sysfs node name
> + * @_bits: name of the module's unsigned long bit-vector, ex: __drm_debug
> + * @_var: name of the (exported) classmap var defining the classes/bits
> + * @_flags: flags to be toggled, typically just 'p'
> + *
> + * Creates a sysfs-param to control the classes defined by the
> + * exported clasmap, with bits 0..N-1 mapped to the classes named.
> + * This version keeps class-state in user @_bits. This lets drm check
> + * __drm_debug elsewhere too.
> + */
> +#define DYNAMIC_DEBUG_CLASSMAP_PARAM_REF(_name, _bits, _var, _flags) \
> + __DYNAMIC_DEBUG_CLASSMAP_PARAM(_name, _bits, _var, _flags)
> +
> +#define __DYNAMIC_DEBUG_CLASSMAP_PARAM(_name, _bits, _var, _flags) \
> + static struct _ddebug_class_param _name##_##_flags = { \
> + .bits = &(_bits), \
> + .flags = #_flags, \
> + .map = &(_var), \
> + }; \
> + module_param_cb(_name, ¶m_ops_dyndbg_classes, \
> + &_name##_##_flags, 0600)
> +
> /*
> * pr_debug() and friends are globally enabled or modules have selectively
> * enabled them.
> diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
> index 56b503af0b31..0d603caadef8 100644
> --- a/lib/dynamic_debug.c
> +++ b/lib/dynamic_debug.c
> @@ -666,6 +666,30 @@ static int ddebug_apply_class_bitmap(const struct _ddebug_class_param *dcp,
>
> #define CLASSMAP_BITMASK(width) ((1UL << (width)) - 1)
>
> +static void ddebug_class_param_clamp_input(unsigned long *inrep, const struct kernel_param *kp)
> +{
> + const struct _ddebug_class_param *dcp = kp->arg;
> + const struct _ddebug_class_map *map = dcp->map;
> +
> + switch (map->map_type) {
> + case DD_CLASS_TYPE_DISJOINT_BITS:
> + /* expect bits. mask and warn if too many */
> + if (*inrep & ~CLASSMAP_BITMASK(map->length)) {
> + pr_warn("%s: input: 0x%lx exceeds mask: 0x%lx, masking\n",
> + KP_NAME(kp), *inrep, CLASSMAP_BITMASK(map->length));
> + *inrep &= CLASSMAP_BITMASK(map->length);
> + }
> + break;
> + case DD_CLASS_TYPE_LEVEL_NUM:
> + /* input is bitpos, of highest verbosity to be enabled */
> + if (*inrep > map->length) {
> + pr_warn("%s: level:%ld exceeds max:%d, clamping\n",
> + KP_NAME(kp), *inrep, map->length);
> + *inrep = map->length;
> + }
> + break;
> + }
> +}
> static int param_set_dyndbg_module_classes(const char *instr,
> const struct kernel_param *kp,
> const char *mod_name)
> @@ -684,26 +708,15 @@ static int param_set_dyndbg_module_classes(const char *instr,
> pr_err("expecting numeric input, not: %s > %s\n", instr, KP_NAME(kp));
> return -EINVAL;
> }
> + ddebug_class_param_clamp_input(&inrep, kp);
>
> switch (map->map_type) {
> case DD_CLASS_TYPE_DISJOINT_BITS:
> - /* expect bits. mask and warn if too many */
> - if (inrep & ~CLASSMAP_BITMASK(map->length)) {
> - pr_warn("%s: input: 0x%lx exceeds mask: 0x%lx, masking\n",
> - KP_NAME(kp), inrep, CLASSMAP_BITMASK(map->length));
> - inrep &= CLASSMAP_BITMASK(map->length);
> - }
> v2pr_info("bits:0x%lx > %s.%s\n", inrep, mod_name ?: "*", KP_NAME(kp));
> totct += ddebug_apply_class_bitmap(dcp, &inrep, *dcp->bits, mod_name);
> *dcp->bits = inrep;
> break;
> case DD_CLASS_TYPE_LEVEL_NUM:
> - /* input is bitpos, of highest verbosity to be enabled */
> - if (inrep > map->length) {
> - pr_warn("%s: level:%ld exceeds max:%d, clamping\n",
> - KP_NAME(kp), inrep, map->length);
> - inrep = map->length;
> - }
> old_bits = CLASSMAP_BITMASK(*dcp->lvl);
> new_bits = CLASSMAP_BITMASK(inrep);
> v2pr_info("lvl:%ld bits:0x%lx > %s\n", inrep, new_bits, KP_NAME(kp));
> @@ -1171,15 +1184,24 @@ static const struct proc_ops proc_fops = {
> static void ddebug_sync_classbits(const struct kernel_param *kp, const char *modname)
> {
> const struct _ddebug_class_param *dcp = kp->arg;
> + unsigned long new_bits;
>
> - /* clamp initial bitvec, mask off hi-bits */
> - if (*dcp->bits & ~CLASSMAP_BITMASK(dcp->map->length)) {
> - *dcp->bits &= CLASSMAP_BITMASK(dcp->map->length);
> - v2pr_info("preset classbits: %lx\n", *dcp->bits);
> + ddebug_class_param_clamp_input(dcp->bits, kp);
> +
> + switch (dcp->map->map_type) {
> + case DD_CLASS_TYPE_DISJOINT_BITS:
> + v2pr_info(" %s: classbits: 0x%lx\n", KP_NAME(kp), *dcp->bits);
> + ddebug_apply_class_bitmap(dcp, dcp->bits, 0UL, modname);
> + break;
> + case DD_CLASS_TYPE_LEVEL_NUM:
> + new_bits = CLASSMAP_BITMASK(*dcp->lvl);
> + v2pr_info(" %s: lvl:%ld bits:0x%lx\n", KP_NAME(kp), *dcp->lvl, new_bits);
> + ddebug_apply_class_bitmap(dcp, &new_bits, 0UL, modname);
> + break;
> + default:
> + pr_err("bad map type %d\n", dcp->map->map_type);
> + return;
> }
> - /* force class'd prdbgs (in USEr module) to match (DEFINEr module) class-param */
> - ddebug_apply_class_bitmap(dcp, dcp->bits, ~0, modname);
No need to do this before applying the bitmap?
> - ddebug_apply_class_bitmap(dcp, dcp->bits, 0, modname);
> }
>
> static void ddebug_match_apply_kparam(const struct kernel_param *kp,
> diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
> index 4a3d2612ef60..78cf5420770a 100644
> --- a/lib/test_dynamic_debug.c
> +++ b/lib/test_dynamic_debug.c
> @@ -1,6 +1,7 @@
> // SPDX-License-Identifier: GPL-2.0-only
> /*
> - * Kernel module for testing dynamic_debug
> + * Kernel module to test/demonstrate dynamic_debug features,
> + * particularly classmaps and their support for subsystems like DRM.
> *
> * Authors:
> * Jim Cromie <jim.cromie@gmail.com>
> @@ -62,24 +63,6 @@ module_param_cb(do_prints, ¶m_ops_do_prints, NULL, 0600);
>
> #define CLASSMAP_BITMASK(width, base) (((1UL << (width)) - 1) << (base))
>
> -/* sysfs param wrapper, proto-API */
> -#define DYNAMIC_DEBUG_CLASSMAP_PARAM_(_model, _flags, _init) \
> - static unsigned long bits_##_model = _init; \
> - static struct _ddebug_class_param _flags##_##_model = { \
> - .bits = &bits_##_model, \
> - .flags = #_flags, \
> - .map = &map_##_model, \
> - }; \
> - module_param_cb(_flags##_##_model, ¶m_ops_dyndbg_classes, \
> - &_flags##_##_model, 0600)
> -#ifdef DEBUG
> -#define DYNAMIC_DEBUG_CLASSMAP_PARAM(_model, _flags) \
> - DYNAMIC_DEBUG_CLASSMAP_PARAM_(_model, _flags, ~0)
> -#else
> -#define DYNAMIC_DEBUG_CLASSMAP_PARAM(_model, _flags) \
> - DYNAMIC_DEBUG_CLASSMAP_PARAM_(_model, _flags, 0)
> -#endif
> -
> /*
> * Demonstrate/test DISJOINT & LEVEL typed classmaps with a sys-param.
> *
> @@ -110,12 +93,15 @@ enum cat_disjoint_bits {
> /* numeric verbosity, V2 > V1 related. V0 is > D2_DRM_RES */
> enum cat_level_num { V0 = 16, V1, V2, V3, V4, V5, V6, V7 };
>
> -/* recapitulate DRM's multi-classmap setup */
> +/*
> + * use/demonstrate multi-module-group classmaps, as for DRM
> + */
> #if !defined(TEST_DYNAMIC_DEBUG_SUBMOD)
> /*
> - * In single user, or parent / coordinator (drm.ko) modules, define
> - * classmaps on the client enums above, and then declares the PARAMS
> - * ref'g the classmaps. Each is exported.
> + * For module-groups of 1+, define classmaps with names (stringified
> + * enum-symbols) copied from above. 1-to-1 mapping is recommended.
> + * The classmap is exported, so that other modules in the group can
> + * link to it and control their prdbgs.
> */
> DYNAMIC_DEBUG_CLASSMAP_DEFINE(map_disjoint_bits, DD_CLASS_TYPE_DISJOINT_BITS,
> D2_CORE,
> @@ -134,11 +120,13 @@ DYNAMIC_DEBUG_CLASSMAP_DEFINE(map_level_num, DD_CLASS_TYPE_LEVEL_NUM,
> V0, "V0", "V1", "V2", "V3", "V4", "V5", "V6", "V7");
>
> /*
> - * now add the sysfs-params
> + * for use-cases that want it, provide a sysfs-param to set the
> + * classes in the classmap. It is at this interface where the
> + * "v3>v2" property is applied to DD_CLASS_TYPE_LEVEL_NUM inputs.
> */
>
> -DYNAMIC_DEBUG_CLASSMAP_PARAM(disjoint_bits, p);
> -DYNAMIC_DEBUG_CLASSMAP_PARAM(level_num, p);
> +DYNAMIC_DEBUG_CLASSMAP_PARAM(p_disjoint_bits, map_disjoint_bits, p);
> +DYNAMIC_DEBUG_CLASSMAP_PARAM(p_level_num, map_level_num, p);
>
> #ifdef FORCE_CLASSID_CONFLICT
> /*
> @@ -149,12 +137,10 @@ DYNDBG_CLASSMAP_DEFINE(classid_range_conflict, 0, D2_CORE + 1, "D3_CORE");
> #endif
>
> #else /* TEST_DYNAMIC_DEBUG_SUBMOD */
> -
> /*
> - * in submod/drm-drivers, use the classmaps defined in top/parent
> - * module above.
> + * the +1 members of a multi-module group refer to the classmap
> + * DEFINEd (and exported) above.
> */
> -
> DYNAMIC_DEBUG_CLASSMAP_USE(map_disjoint_bits);
> DYNAMIC_DEBUG_CLASSMAP_USE(map_level_num);
>
> @@ -229,6 +215,7 @@ static void __exit test_dynamic_debug_exit(void)
> module_init(test_dynamic_debug_init);
> module_exit(test_dynamic_debug_exit);
>
> +MODULE_DESCRIPTION("test/demonstrate dynamic-debug features");
> MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
> MODULE_DESCRIPTION("Kernel module for testing dynamic_debug");
> MODULE_LICENSE("GPL");
> diff --git a/lib/test_dynamic_debug_submod.c b/lib/test_dynamic_debug_submod.c
> index 672aabf40160..3adf3925fb86 100644
> --- a/lib/test_dynamic_debug_submod.c
> +++ b/lib/test_dynamic_debug_submod.c
> @@ -1,6 +1,9 @@
> // SPDX-License-Identifier: GPL-2.0
> /*
> - * Kernel module for testing dynamic_debug
> + * Kernel module to test/demonstrate dynamic_debug features,
> + * particularly classmaps and their support for subsystems, like DRM,
> + * which defines its drm_debug classmap in drm module, and uses it in
> + * helpers & drivers.
> *
> * Authors:
> * Jim Cromie <jim.cromie@gmail.com>
> @@ -12,3 +15,7 @@
> */
> #define TEST_DYNAMIC_DEBUG_SUBMOD
> #include "test_dynamic_debug.c"
> +
> +MODULE_DESCRIPTION("test/demonstrate dynamic-debug subsystem support");
> +MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
> +MODULE_LICENSE("GPL");
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 26/54] dyndbg: change __dynamic_func_call_cls* macros into expressions
2025-04-02 17:41 ` [PATCH v3 26/54] dyndbg: change __dynamic_func_call_cls* macros into expressions Jim Cromie
@ 2025-04-15 10:06 ` Louis Chauvet
2025-04-15 22:49 ` jim.cromie
0 siblings, 1 reply; 81+ messages in thread
From: Louis Chauvet @ 2025-04-15 10:06 UTC (permalink / raw)
To: Jim Cromie, jbaron, gregkh, ukaszb, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala
Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> The Xe driver's XE_IOCTL_DBG macro calls drm_dbg() from inside an if
> (expression). This breaks when CONFIG_DRM_USE_DYNAMIC_DEBUG=y because
> the invoked macro has a do-while-0 wrapper.
>
> if (cond && (drm_dbg("expr-form"),1)) {
> ... do some more stuff
> }
>
> Fix for this usage by changing __dynamic_func_call_cls{,_no_desc}
> macros into expressions, by replacing the do-while-0s with a ({ })
> wrapper. In the common usage, the trailing ';' converts the
> expression into a statement.
>
> drm_dbg("statement form");
>
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> ---
> ---
> include/linux/dynamic_debug.h | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
> index ce221a702f84..2d87cca27544 100644
> --- a/include/linux/dynamic_debug.h
> +++ b/include/linux/dynamic_debug.h
> @@ -337,20 +337,20 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
> * (|_cls): adds in _DPRINT_CLASS_DFLT as needed
> * (|_no_desc): former gets callsite descriptor as 1st arg (for prdbgs)
> */
> -#define __dynamic_func_call_cls(id, cls, fmt, func, ...) do { \
> - DEFINE_DYNAMIC_DEBUG_METADATA_CLS((id), cls, fmt); \
> +#define __dynamic_func_call_cls(id, cls, fmt, func, ...) ({ \
> + DEFINE_DYNAMIC_DEBUG_METADATA_CLS(id, cls, fmt); \
You remove the protection around id here.
> if (DYNAMIC_DEBUG_BRANCH(id)) \
> - func(&id, ##__VA_ARGS__); \
> -} while (0)
> + func(&(id), ##__VA_ARGS__); \
But you add the protection here.
I think in macro it is better to be defensive, so I expect to have ()
everywhere (except places where it breaks the compilation).
> +})
> #define __dynamic_func_call(id, fmt, func, ...) \
> __dynamic_func_call_cls(id, _DPRINTK_CLASS_DFLT, fmt, \
> func, ##__VA_ARGS__)
>
> -#define __dynamic_func_call_cls_no_desc(id, cls, fmt, func, ...) do { \
> +#define __dynamic_func_call_cls_no_desc(id, cls, fmt, func, ...) ({ \
> DEFINE_DYNAMIC_DEBUG_METADATA_CLS(id, cls, fmt); \
> if (DYNAMIC_DEBUG_BRANCH(id)) \
> func(__VA_ARGS__); \
> -} while (0)
> +})
> #define __dynamic_func_call_no_desc(id, fmt, func, ...) \
> __dynamic_func_call_cls_no_desc(id, _DPRINTK_CLASS_DFLT, \
> fmt, func, ##__VA_ARGS__)
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 29/54] docs/dyndbg: add classmap info to howto
2025-04-02 17:41 ` [PATCH v3 29/54] docs/dyndbg: add classmap info to howto Jim Cromie
@ 2025-04-15 10:06 ` Louis Chauvet
0 siblings, 0 replies; 81+ messages in thread
From: Louis Chauvet @ 2025-04-15 10:06 UTC (permalink / raw)
To: Jim Cromie, jbaron, gregkh, ukaszb, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala, linux-doc
Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> Describe the 3 API macros providing dynamic_debug's classmaps
>
> DYNDBG_CLASSMAP_DEFINE - create & export a classmap
> DYNDBG_CLASSMAP_USE - refer to exported map
> DYNDBG_CLASSMAP_PARAM - bind control param to the classmap
> DYNDBG_CLASSMAP_PARAM_REF + use module's storage - __drm_debug
>
> TBD: some of this might be over-specification, or just over-talked.
>
> NB: The _DEFINE & _USE model makes the user dependent on the definer,
> just like EXPORT_SYMBOL(__drm_debug) already does.
>
> cc: linux-doc@vger.kernel.org
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> ---
> v3- rework protection around PARAM
>
> v0.5 adjustments per Randy Dunlap
> v0.7 checkpatch fixes
> v0.8 more
> v0.9 rewords
>
> fixup-howto
> ---
> .../admin-guide/dynamic-debug-howto.rst | 93 +++++++++++++++++++
> 1 file changed, 93 insertions(+)
>
> diff --git a/Documentation/admin-guide/dynamic-debug-howto.rst b/Documentation/admin-guide/dynamic-debug-howto.rst
> index 1ceadf4f28f9..5eb4ae3b2f27 100644
> --- a/Documentation/admin-guide/dynamic-debug-howto.rst
> +++ b/Documentation/admin-guide/dynamic-debug-howto.rst
> @@ -394,3 +394,96 @@ just a shortcut for ``print_hex_dump(KERN_DEBUG)``.
> For ``print_hex_dump_debug()``/``print_hex_dump_bytes()``, format string is
> its ``prefix_str`` argument, if it is constant string; or ``hexdump``
> in case ``prefix_str`` is built dynamically.
> +
> +Dynamic Debug classmaps
> +=======================
> +
> +The "class" keyword selects prdbgs based on author supplied,
> +domain-oriented names. This complements the nested-scope keywords:
> +module, file, function, line.
> +
> +The main difference from the others: classes must be named to be
> +changed. This protects them from generic overwrite:
> +
> + # IOW this cannot undo any DRM.debug settings
> + :#> ddcmd -p
Can you also clarify this in the Controlling dynamic debug Behaviour? At
least something like "Some printk may not be affected by >control
because of classmaps, see Dynamic Debug classmaps for more information".
Or maybe integrate this section just after/inside Controlling dynamic
debug Behaviour. So a user is not surprised if his command does not have
the expected effect.
> +
> +This protection is needed in order to honor the ABI, settings done
> +there must be respected:
> +
> + :#> echo 0x1ff > /sys/module/drm/parameters/debug
> +
> +So each class must be enabled individually (no wildcards):
> +
> + :#> ddcmd class DRM_UT_CORE +p
> + :#> ddcmd class DRM_UT_KMS +p
> + # or more selectively
> + :#> ddcmd class DRM_UT_CORE module drm +p
> +
> +That makes direct >control wordy and annoying, but it is a secondary
> +interface; it is not intended to replace the ABI, just slide in
> +underneath and reimplement it.
> +
> +However, since the param is the ABI, if a classmap DEFINEr doesn't
> +also add a _CLASSMAP_PARAM, there is no ABI, and no protection is
> +needed. In that case, class'd prdbgs would be enabled/disabled by
> +legacy (class-less) queries.
Very clear, thanks!
> +
> +Dynamic Debug Classmap API
> +==========================
> +
> +DRM.debug is built upon:
> + ABI in /sys/module/drm/parameters/debug
> + the bits set all DRM_UT_* together
> + ~23 categorized api macros: drm_dbg_<T>()
> + all calling drm_{,dev}dbg(DRM_UT_*, ....)
> + ~5000 calls to the api macros across drivers/gpu/drm/*
> +
> +The const short ints are good for optimizing compilers; a primary
> +classmaps design goal was to preserve those opporunities for
> +optimization. So basically .classid === category.
> +
> +Then we use the drm_categories DRM_UT_* enum for both the classnames
> +(stringified enum symbols) and their numeric values.
> +
> +Its expected that future users will also use an enum-defined
> +categorization scheme like DRM's, and dyndbg can be adapted under them
> +similarly.
> +
> +DYNAMIC_DEBUG_CLASSMAP_DEFINE(var,type,_base,classnames) - this maps
> +classnames (a list of strings) onto class-ids consecutively, starting
> +at _base, it also maps the names onto CLASSMAP_PARAM bits 0..N.
> +
> +DYNAMIC_DEBUG_CLASSMAP_USE(var) - modules call this to refer to the
> +var _DEFINEd elsewhere (and exported).
> +
> +Classmaps are opt-in: modules invoke _DEFINE or _USE to authorize
> +dyndbg to update those classes. "class FOO" queries are validated
> +against the classes, this finds the classid to alter; classes are not
> +directly selectable by their classid.
> +
> +There are 2 types of classmaps:
> +
> + DD_CLASS_TYPE_DISJOINT_BITS: classes are independent, like DRM.debug
> + DD_CLASS_TYPE_LEVEL_NUM: classes are relative, ordered (V3 > V2)
> +
> +DYNAMIC_DEBUG_CLASSMAP_PARAM - modelled after module_param_cb, it
> +refers to a DEFINEd classmap, and associates it to the param's
> +data-store. This state is then applied to DEFINEr and USEr modules
> +when they're modprobed.
> +
> +The PARAM interface also enforces the DD_CLASS_TYPE_LEVEL_NUM relation
> +amongst the contained classnames; all classes are independent in the
> +control parser itself; there is no implied meaning in names like "V4".
> +
> +Modules or module-groups (drm & drivers) can define multiple
> +classmaps, as long as they (all the classmaps) share the limited 0..62
> +per-module-group _class_id range, without overlap. If a module
> +encounters a conflict between 2 classmaps its USEing, we can extend
> +the _USE macro with an offset to allow avoiding the conflicting range.
> +
> +``#define DEBUG`` will enable all pr_debugs in scope, including any
> +class'd ones. This won't be reflected in the PARAM readback value,
> +but the class'd pr_debug callsites can be forced off by toggling the
> +classmap-kparam all-on then all-off.
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 27/54] dyndbg: drop "protection" of class'd pr_debugs from legacy queries
2025-04-02 17:41 ` [PATCH v3 27/54] dyndbg: drop "protection" of class'd pr_debugs from legacy queries Jim Cromie
@ 2025-04-15 10:06 ` Louis Chauvet
0 siblings, 0 replies; 81+ messages in thread
From: Louis Chauvet @ 2025-04-15 10:06 UTC (permalink / raw)
To: Jim Cromie, jbaron, gregkh, ukaszb, linux-kernel
Cc: dri-devel, amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter,
tvrtko.ursulin, jani.nikula, ville.syrjala
Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> Current classmap code protects class'd pr_debugs from unintended
> changes by "legacy" unclassed queries:
>
> # this doesn't disable all of DRM_UT_* categories
> echo "-p" > /proc/dynamic_debug/control
>
> # name the class to change it - protective but tedious
> echo "class DRM_UT_CORE +p" > /proc/dynamic_debug/control
>
> # or do it the (old school) subsystem way
> echo 1 > /sys/module/drm/parameters/debug
>
> This "name the class to change it" behavior gave a modicum of
> protection to classmap users (ie DRM) so their debug settings aren't
> trivially and unintentionally altered underneath them.
>
> And by "symmetry", if they're not picked by "class FOO", then they're
> excluded from adjustment. This allowed all previously conceived
> queries to work the way they always had; ie select the same set of
> pr_debugs, despite the inclusion of whole new classes of pr_debugs.
>
> That had 2 downsides:
>
> 1. "name the class to change it" means that every class must be
> individually modified, quickly becoming long-winded and tedious to
> adjust all the classes in a map via >control.
>
> 2. It made the class keyword special in some sense; the other keywords
> skip only on explicit mismatch, otherwise the code falls thru to
> adjust the pr-debug site.
>
> So this patch reverts to the traditional view, it drops protection of
> classes from default/legacy queries.
>
> But it also refactors the skip/continue choice to allow the module
> defining the classmap to protect its classes from unintended
> alterations by legacy/class-less queries.
>
> Next:
>
> Author choice: use of DYNAMIC_DEBUG_CLASSMAP_PARAM() means they want
> the drm.debug style control point. We should presume they want it to
> reflect whats set underneath, with only "class FOO" qualified queries
> changing the callsites beneath.
This explanation is way better, thanks a lot! It is way easier to
understand this protection.
I continue to think that this "protect its classes from unintended
alterations" is not a good user api. But it is not a blocking point for
me, so I would like to get the point of view from other people (mainly
from DRM, they are the first users).
With or without this modification:
Acked-by: Louis Chauvet <louis.chauvet@bootlin.com>
> CC: jbaron@akamai.com
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> --
> v3- s/slctd_/selected_/
> pitch the PARAM control of protection.
> ---
> lib/dynamic_debug.c | 31 +++++++++++++++++++++++--------
> 1 file changed, 23 insertions(+), 8 deletions(-)
>
> diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
> index 7a60088a1b5c..54f462cf41b0 100644
> --- a/lib/dynamic_debug.c
> +++ b/lib/dynamic_debug.c
> @@ -197,6 +197,17 @@ ddebug_find_valid_class(struct _ddebug_info const *di, const char *query_class,
> return NULL;
> }
>
> +/*
> + * classmaps-v1 protected classes from changes by legacy commands
> + * (those selecting _DPRINTK_CLASS_DFLT by omission), v2 undoes that
> + * special treatment. State so explicitly. Later we could give
> + * modules the choice to protect their classes or to keep v2 behavior.
> + */
> +static inline bool ddebug_client_module_protects_classes(const struct ddebug_table *dt)
> +{
> + return false;
> +}
> +
> /*
> * Search the tables for _ddebug's which match the given `query' and
> * apply the `flags' and `mask' to them. Returns number of matching
> @@ -211,7 +222,7 @@ static int ddebug_change(const struct ddebug_query *query, struct flag_settings
> unsigned int nfound = 0;
> struct flagsbuf fbuf, nbuf;
> struct _ddebug_class_map *map = NULL;
> - int valid_class;
> + int selected_class;
>
> /* search for matching ddebugs */
> mutex_lock(&ddebug_lock);
> @@ -224,21 +235,25 @@ static int ddebug_change(const struct ddebug_query *query, struct flag_settings
>
> if (query->class_string) {
> map = ddebug_find_valid_class(&dt->info, query->class_string,
> - &valid_class);
> + &selected_class);
> if (!map)
> continue;
> } else {
> - /* constrain query, do not touch class'd callsites */
> - valid_class = _DPRINTK_CLASS_DFLT;
> + selected_class = _DPRINTK_CLASS_DFLT;
> }
>
> for (i = 0; i < dt->info.descs.len; i++) {
> struct _ddebug *dp = &dt->info.descs.start[i];
>
> - /* match site against query-class */
> - if (dp->class_id != valid_class)
> - continue;
> -
> + if (dp->class_id != selected_class) {
> + if (query->class_string)
> + /* site.class != given class */
> + continue;
> + /* legacy query, class'd site */
> + else if (ddebug_client_module_protects_classes(dt))
> + continue;
> + /* allow change on class'd pr_debug */
> + }
> /* match against the source filename */
> if (query->filename &&
> !match_wildcard(query->filename, dp->filename) &&
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 17/54] dyndbg-API: replace DECLARE_DYNDBG_CLASSMAP
2025-04-15 10:01 ` Louis Chauvet
@ 2025-04-15 19:38 ` jim.cromie
0 siblings, 0 replies; 81+ messages in thread
From: jim.cromie @ 2025-04-15 19:38 UTC (permalink / raw)
To: Louis Chauvet
Cc: jbaron, gregkh, ukaszb, linux-kernel, dri-devel, amd-gfx,
intel-gvt-dev, intel-gfx, daniel.vetter, tvrtko.ursulin,
jani.nikula, ville.syrjala, linux-doc
On Tue, Apr 15, 2025 at 4:01 AM Louis Chauvet <louis.chauvet@bootlin.com> wrote:
>
>
>
> Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> > DECLARE_DYNDBG_CLASSMAP() has a design error; its usage fails a basic
> > K&R rule: "define once, refer many times".
> >
> > When DRM_USE_DYNAMIC_DEBUG=y, it is used across DRM core & drivers;
> > each invocation allocates/inits the classmap understood by that
> > module. All must match for the modules to respond together when
> > DRM.debug categories are enabled. This is brittle; a maintenance
> > foot-gun.
> >
> > Further, its culpable in the CONFIG_DRM_USE_DYNAMIC_DEBUG=Y
> > regression; its use in both core & drivers obfuscates the 2 roles, that
> > caused incomplete initialization when modprobing drivers:
> >
> > 1st drm.ko loads, and dyndbg initializes its DRM.debug callsites, then
> > a drm-driver loads, but too late for the DRM.debug enablement.
> >
> > So retire it, replace with 2 macros:
> > DYNAMIC_DEBUG_CLASSMAP_DEFINE - invoked once from core - drm.ko
> > DYNAMIC_DEBUG_CLASSMAP_USE - from all drm drivers and helpers.
> >
> > DYNAMIC_DEBUG_CLASSMAP_DEFINE: this reworks DECLARE_DYNDBG_CLASSMAP,
> > by dropping the static qualifier on the classmap, and exporting it
> > instead.
> >
> > DYNAMIC_DEBUG_CLASSMAP_USE: then refers to the exported var by name:
> > used from drivers, helper-mods
> > lets us drop the repetitive "classname" declarations
> > fixes 2nd-defn problem
> > creates a ddebug_class_user record in new __dyndbg_class_users section
> > new section is scanned "differently"
> >
> > DECLARE_DYNDBG_CLASSMAP is preserved temporarily, to decouple DRM
> > adaptation work and avoid compile-errs before its done. IOW, DRM gets
> > these fixes when they commit the adopt-new-api patches.
> >
> > The DEFINE,USE distinction, and the separate classmap-use record,
> > allows dyndbg to initialize the driver's & helper's DRM.debug
> > callsites separately after each is modprobed.
> >
> > Basically, the classmap init-scan is repeated for classmap-users.
> >
> > To review, dyndbg's existing __dyndbg_classes[] section does:
> >
> > . catalogs the module's classmaps
> > . tells dyndbg about them, allowing >control
> > . DYNAMIC_DEBUG_CLASSMAP_DEFINE creates section records.
> > . we rename it to: __dyndbg_class_maps[]
> >
> > Then this patch adds __dyndbg_class_users[] section:
> >
> > . catalogs users of classmap definitions elsewhere
> > . authorizes dyndbg to >control user's class'd prdbgs
> > . DYNAMIC_DEBUG_CLASSMAP_USE() creates section records.
> >
> > Now ddebug_add_module(etal) can handle classmap-uses similar to (and
> > after) classmaps; when a dependent module is loaded, if it has
> > classmap-uses (to a classmap-def in another module), that module's
> > kernel params are scanned to find if it has a kparam that is wired to
> > dyndbg's param-ops, and whose classmap is the one being ref'd.
> >
> > To support this, theres a few data/header changes:
> >
> > new struct ddebug_class_user
> > contains: user-module-name, &classmap-defn
> > it records drm-driver's use of a classmap in the section, allowing lookup
> >
> > struct ddebug_info gets 2 new fields for the new sections:
> > class_users, num_class_users.
> > set by dynamic_debug_init() for builtins.
> > or by kernel/module/main:load_info() for loadable modules.
> >
> > vmlinux.lds.h: new BOUNDED_SECTION for __dyndbg_class_users
> >
> > dynamic_debug.c has 2 changes in ddebug_add_module(), ddebug_change():
> >
> > ddebug_add_module()
> > called ddebug_attach_module_classes()
> > now calls ddebug_apply_class_maps() & ddebug_apply_class_users()
> > these both call ddebug_apply_params().
> >
> > ddebug_apply_params(new fn):
> >
> > It scans module's/builtin kernel-params, calls ddebug_match_apply_kparam
> > for each to find any params/sysfs-nodes which may be wired to a classmap.
> >
> > ddebug_match_apply_kparam(new fn):
> >
> > 1st, it tests the kernel-param.ops is dyndbg's; this guarantees that
> > the attached arg is a struct ddebug_class_param, which has a ref to
> > the param's state, and to the classmap defining the param's handling.
> >
> > 2nd, it requires that the classmap ref'd by the kparam is the one
> > we're called for; modules can use many separate classmaps (as
> > test_dynamic_debug does).
> >
> > Then apply the "parent" kparam's setting to the dependent module,
> > using ddebug_apply_class_bitmap().
> >
> > ddebug_change(and callees) also gets adjustments:
> >
> > ddebug_find_valid_class(): This does a search over the module's
> > classmaps, looking for the class FOO echo'd to >control. So now it
> > searches over __dyndbg_class_users[] after __dyndbg_classes[].
> >
> > ddebug_class_name(): return class-names for defined AND used classes.
> >
> > test_dynamic_debug.c, test_dynamic_debug_submod.c:
> >
> > This demonstrates the 2 types of classmaps & sysfs-params, following
> > the 4-part recipe:
> >
> > 1. define an enum for the classmap: DRM.debug has DRM_UT_{CORE,KMS,...}
> > multiple classes must share 0-62 classid space.
> > 2. DYNAMIC_DEBUG_CLASSMAP_DEFINE(.. DRM_UT_{CORE,KMS,...})
> > 3. DYNAMIC_DEBUG_CLASSMAP_PARAM* (classmap)
> > 4. DYNAMIC_DEBUG_CLASSMAP_USE()
> > by _submod only, skipping 2,3
> >
> > Move all the enum declarations together, to better explain how they
> > share the 0..62 class-id space available to a module (non-overlapping
> > subranges).
> >
> > reorg macros 2,3 by name. This gives a tabular format, making it easy
> > to see the pattern of repetition, and the points of change.
> >
> > And extend the test to replicate the 2-module (parent & dependent)
> > scenario which caused the CONFIG_DRM_USE_DYNAMIC_DEBUG=y regression
> > seen in drm & drivers.
> >
> > The _submod.c is a 2-line file: #define _SUBMOD, #include parent.
> >
> > This gives identical complements of prdbgs in parent & _submod, and
> > thus identical print behavior when all of: >control, >params, and
> > parent->_submod propagation are working correctly.
> >
> > It also puts all the parent/_submod declarations together in the same
> > source, with the new ifdef _SUBMOD block invoking DYNAMIC_DEBUG_CLASSMAP_USE
> > for the 2 test-interfaces. I think this is clearer.
> >
> > These 2 modules are both tristate, allowing 3 super/sub combos: Y/Y,
> > Y/M, M/M (not N/Y, since this is disallowed by dependence).
> >
> > Y/Y testing exposed a missing __align(8) in the _METADATA macro, which
> > M/M didn't see because the module-loader memory placement constrains
> > it instead.
> >
> > Fixes: aad0214f3026 ("dyndbg: add DECLARE_DYNDBG_CLASSMAP macro")
> > cc: linux-doc@vger.kernel.org
> > Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> > ---
> > v3-
> > undo 1.9 simplification of ddebug_find_valid_class()
> > ddebug_change needs map to see its controlling param
> > change internal callchains to pass di, not dt
> >
> > v2 a. building 2 .ko's from 1 source file is weird; add a clear
> > comment at the top to justify it (basically cloning)
> > ln 138+ in commit-msg is insufficient.
> >
> > b. retire "DYNDBG_" name shortening b4 adding _CLASSMAP_* macros.
> > c. s/dd_class/_ddebug_class/
> > d. s/\bddebug\b/_$1/g in header: chgs 1 struct and UNIQUE_ID bases
> >
> > v1.9 - commit-msg tweaks
> > DRM:CHECK warnings on macros: add parens
> > extern DEFINEd _var, static classnames
> > change ddebug_class_user.user_mod_name to .mod_name
> > simplify ddebug_find_valid_class return val
> > improve vpr_cm_info msg format
> > wrap (base) in macro body
> > move __DYNDBG_CLASSMAP_CHECK above kdoc for DYNDBG_CLASSMAP_DEFINE
> >
> > v1.8 - split drm parts to separate commits.
> > preserve DECLARE_DYNDBG_CLASSMAP to decouple DRM, no flag day.
> > fixup block comment
> >
> > v1.7 - previous submission-blocking bug:
> >
> > missing __align(8) in DYNAMIC_DEBUG_DECLARE_METADATA on
> > ddebug_class_user caused corrupt records, but only for builtin
> > modules; module loader code probably pinned allocations to the right
> > alignment naturally, hiding the bug for typical builds.
> >
> > v6- get rid of WARN_ON_ONCE
> > v?- fix _var expanded 2x in macro
> >
> > dyndbg:
> >
> > This fn formerly returned the map which contained the class (thus
> > validating it), and as a side-effect set the class-id in an outvar.
> >
> > But the caller didn't use the map (after checking its not null), only
> > the valid class-id. So simplify the fn to return the class-id of the
> > validated classname, or -ENOENT when the queried classname is not
> > found.
> >
> > Convey more useful info in the debug-msg: print class-names[0,last],
> > and [base,+len] instead of the class-type printout, which is almost
> > always "type:DISJOINT_BITS". And drop ddebug_classmap_typenames,
> > which is now unused.
> >
> > [root@v6 b0-dd]# modprobe test_dynamic_debug_submod
> > [ 18.864962] dyndbg: loaded classmap: test_dynamic_debug [16..24] V0..V7
> > [ 18.865046] dyndbg: found kp:p_level_num =0x0
> > [ 18.865048] dyndbg: mapped to: test_dynamic_debug [16..24] V0..V7
> > [ 18.865164] dyndbg: p_level_num: lvl:0 bits:0x0
> > [ 18.865217] dyndbg: loaded classmap: test_dynamic_debug [0..10] D2_CORE..D2_DRMRES
> > [ 18.865297] dyndbg: found kp:p_disjoint_bits =0x0
> > [ 18.865298] dyndbg: mapped to: test_dynamic_debug [0..10] D2_CORE..D2_DRMRES
> > [ 18.865424] dyndbg: p_disjoint_bits: classbits: 0x0
> > [ 18.865472] dyndbg: module:test_dynamic_debug attached 2 classmaps
> > [ 18.865533] dyndbg: 23 debug prints in module test_dynamic_debug
> > [ 18.866558] dyndbg: loaded classmap: test_dynamic_debug_submod [16..24] V0..V7
> > [ 18.866698] dyndbg: found kp:p_level_num =0x0
> > [ 18.866699] dyndbg: mapped to: test_dynamic_debug_submod [16..24] V0..V7
> > [ 18.866865] dyndbg: p_level_num: lvl:0 bits:0x0
> > [ 18.866926] dyndbg: loaded classmap: test_dynamic_debug_submod [0..10] D2_CORE..D2_DRMRES
> > [ 18.867026] dyndbg: found kp:p_disjoint_bits =0x0
> > [ 18.867027] dyndbg: mapped to: test_dynamic_debug_submod [0..10] D2_CORE..D2_DRMRES
> > [ 18.867193] dyndbg: p_disjoint_bits: classbits: 0x0
> > [ 18.867255] dyndbg: module:test_dynamic_debug_submod attached 2 classmap uses
> > [ 18.867351] dyndbg: 23 debug prints in module test_dynamic_debug_submod
> >
> > fixup-test-submod
> >
> > fixup-test
> >
> > Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> > ---
> > MAINTAINERS | 2 +-
> > include/asm-generic/vmlinux.lds.h | 1 +
> > include/linux/dynamic_debug.h | 93 +++++++++++++++++---
> > kernel/module/main.c | 3 +
> > lib/Kconfig.debug | 24 ++++--
> > lib/Makefile | 3 +
> > lib/dynamic_debug.c | 137 +++++++++++++++++++++++++++---
> > lib/test_dynamic_debug.c | 132 ++++++++++++++++++++--------
> > lib/test_dynamic_debug_submod.c | 14 +++
> > 9 files changed, 343 insertions(+), 66 deletions(-)
> > create mode 100644 lib/test_dynamic_debug_submod.c
> >
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index 00e94bec401e..1c5fcbd9e408 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -8139,7 +8139,7 @@ M: Jim Cromie <jim.cromie@gmail.com>
> > S: Maintained
> > F: include/linux/dynamic_debug.h
> > F: lib/dynamic_debug.c
> > -F: lib/test_dynamic_debug.c
> > +F: lib/test_dynamic_debug*.c
> >
> > DYNAMIC INTERRUPT MODERATION
> > M: Tal Gilboa <talgi@nvidia.com>
> > diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> > index f834ad1fb8c4..fa382caf2ae2 100644
> > --- a/include/asm-generic/vmlinux.lds.h
> > +++ b/include/asm-generic/vmlinux.lds.h
> > @@ -367,6 +367,7 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
> > /* implement dynamic printk debug */ \
> > . = ALIGN(8); \
> > BOUNDED_SECTION_BY(__dyndbg_class_maps, ___dyndbg_class_maps) \
> > + BOUNDED_SECTION_BY(__dyndbg_class_users, ___dyndbg_class_users) \
> > BOUNDED_SECTION_BY(__dyndbg_descriptors, ___dyndbg_descs) \
> > CODETAG_SECTIONS() \
> > LIKELY_PROFILE() \
> > diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
> > index 769f02456c8e..9af825c84e70 100644
> > --- a/include/linux/dynamic_debug.h
> > +++ b/include/linux/dynamic_debug.h
> > @@ -71,9 +71,28 @@ enum ddebug_class_map_type {
> > */
> > };
> >
> > +/*
> > + * dyndbg-classmaps are devised to support DRM.debug directly:
> > + * 10 enum-vals: DRM_UT_* define the categories
> > + * ~23 categorized *_dbg() macros, each passing a DRM_UT_* val as 1st arg
> > + * 2 macros below them: drm_dev_dbg, __drm_dbg
> > + * ~5000 calls to the categorized macros, across all of drivers/gpu/drm/
> > + *
> > + * When CONFIG_DRM_USE_DYNAMIC_DEBUG=y, the 2 low macros are redefined
> > + * to invoke _dynamic_func_call_cls(). This compiles the category
> > + * into each callsite's class_id field, where dyndbg can select on it
> > + * and alter a callsite's patch-state, avoiding repeated __drm_debug
> > + * checks.
> > + *
> > + * To make the callsites manageable from the >control file, authors
> > + * provide a "classmap" of names to class_ids in use by the module(s),
> > + * usually by stringifying the enum-vals. Modules with multiple
> > + * classmaps must arrange to share the 0..62 class_id space.
> > + */
> > +
> > struct _ddebug_class_map {
> > - struct module *mod;
> > - const char *mod_name; /* needed for builtins */
> > + const struct module *mod; /* NULL for builtins */
> > + const char *mod_name;
> > const char **class_names;
> > const int length;
> > const int base; /* index of 1st .class_id, allows split/shared space */
> > @@ -81,11 +100,34 @@ struct _ddebug_class_map {
> > };
> >
> > /**
> > - * DECLARE_DYNDBG_CLASSMAP - declare classnames known by a module
> > - * @_var: a struct _ddebug_class_map, passed to module_param_cb
> > - * @_type: enum class_map_type, chooses bits/verbose, numeric/symbolic
> > - * @_base: offset of 1st class-name. splits .class_id space
> > - * @classes: class-names used to control class'd prdbgs
> > + * DYNAMIC_DEBUG_CLASSMAP_DEFINE - define debug classes used by a module.
> > + * @_var: name of the classmap, exported for other modules coordinated use.
> > + * @_mapty: enum ddebug_class_map_type: 0:DISJOINT - independent, 1:LEVEL - v2>v1
> > + * @_base: reserve N classids starting at _base, to split 0..62 classid space
> > + * @classes: names of the N classes.
> > + *
> > + * This tells dyndbg what class_ids the module is using: _base..+N, by
> > + * mapping names onto them. This qualifies "class NAME" >controls on
> > + * the defining module, ignoring unknown names.
> > + */
> > +#define DYNAMIC_DEBUG_CLASSMAP_DEFINE(_var, _mapty, _base, ...) \
> > + static const char *_var##_classnames[] = { __VA_ARGS__ }; \
> > + extern struct _ddebug_class_map _var; \
> > + struct _ddebug_class_map __aligned(8) __used \
> > + __section("__dyndbg_class_maps") _var = { \
> > + .mod = THIS_MODULE, \
> > + .mod_name = KBUILD_MODNAME, \
> > + .base = (_base), \
> > + .map_type = (_mapty), \
> > + .length = ARRAY_SIZE(_var##_classnames), \
> > + .class_names = _var##_classnames, \
> > + }; \
> > + EXPORT_SYMBOL(_var)
> > +
> > +/*
> > + * XXX: keep this until DRM adapts to use the DEFINE/USE api, it
> > + * differs from DYNAMIC_DEBUG_CLASSMAP_DEFINE by the lack of the
> > + * extern/EXPORT on the struct init, and cascading thinkos.
> > */
> > #define DECLARE_DYNDBG_CLASSMAP(_var, _maptype, _base, ...) \
> > static const char *_var##_classnames[] = { __VA_ARGS__ }; \
> > @@ -99,10 +141,35 @@ struct _ddebug_class_map {
> > .class_names = _var##_classnames, \
> > }
> >
> > +struct _ddebug_class_user {
> > + char *mod_name;
> > + struct _ddebug_class_map *map;
> > +};
> > +
> > +/**
> > + * DYNAMIC_DEBUG_CLASSMAP_USE - refer to a classmap, DEFINEd elsewhere.
> > + * @_var: name of the exported classmap var
> > + *
> > + * This tells dyndbg that the module has prdbgs with classids defined
> > + * in the named classmap. This qualifies "class NAME" >controls on
> > + * the user module, ignoring unknown names.
> > + */
> > +#define DYNAMIC_DEBUG_CLASSMAP_USE(_var) \
> > + DYNAMIC_DEBUG_CLASSMAP_USE_(_var, __UNIQUE_ID(_ddebug_class_user))
> > +#define DYNAMIC_DEBUG_CLASSMAP_USE_(_var, _uname) \
> > + extern struct _ddebug_class_map _var; \
> > + static struct _ddebug_class_user __aligned(8) __used \
> > + __section("__dyndbg_class_users") _uname = { \
> > + .mod_name = KBUILD_MODNAME, \
> > + .map = &(_var), \
> > + }
> > +
> > /*
> > - * @_ddebug_info: gathers module/builtin dyndbg_* __sections together.
> > + * @_ddebug_info: gathers module/builtin __dyndbg_<T> __sections
> > + * together, each is a vector: a struct { <T> *addr, int len }.
> > + *
> > * For builtins, it is used as a cursor, with the inner structs
> > - * marking sub-vectors of the builtin __sections in DATA.
> > + * marking sub-vectors of the builtin __sections in DATA_DATA
>
> DATA_DATA? Is it a typo?
>
No, its the actual name of the macro in vmlinux.lds.h
include/asm-generic/vmlinux.lds.h
355:#define DATA_DATA \
1155: DATA_DATA \
I chose it thinking it was much more specific than just DATA
but it is also used repeatedly elsewhere (as part of symbol-names)
drivers/accel/habanalabs/include/gaudi2/asic_reg/dcore0_sync_mngr_objs_masks.h
42:#define DCORE0_SYNC_MNGR_OBJS_MON_PAY_DATA_DATA_SHIFT 0
43:#define DCORE0_SYNC_MNGR_OBJS_MON_PAY_DATA_DATA_MASK 0xFFFFFFFF
drivers/accel/habanalabs/include/goya/asic_reg/tpc0_eml_cfg_masks.h
245:#define TPC0_EML_CFG_DBG_SPDATA_DATA_SHIFT 0
246:#define TPC0_EML_CFG_DBG_SPDATA_DATA_MASK
0xFFFFFFFF
267:#define TPC0_EML_CFG_DBG_AXIHBWDATA_DATA_SHIFT 0
268:#define TPC0_EML_CFG_DBG_AXIHBWDATA_DATA_MASK
0xFFFFFFFF
285:#define TPC0_EML_CFG_DBG_AXILBWDATA_DATA_SHIFT 0
286:#define TPC0_EML_CFG_DBG_AXILBWDATA_DATA_MASK
0xFFFFFFFF
> With this confirmed:
> Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
>
> > */
> > struct _ddebug_descs {
> > struct _ddebug *start;
> > @@ -114,10 +181,16 @@ struct _ddebug_class_maps {
> > int len;
> > } __packed;
> >
> > +struct _ddebug_class_users {
> > + struct _ddebug_class_user *start;
> > + int len;
> > +} __packed;
> > +
> > struct _ddebug_info {
> > const char *mod_name;
> > struct _ddebug_descs descs;
> > struct _ddebug_class_maps maps;
> > + struct _ddebug_class_users users;
> > } __packed;
> >
> > struct _ddebug_class_param {
> > @@ -218,7 +291,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
> > * (|_no_desc): former gets callsite descriptor as 1st arg (for prdbgs)
> > */
> > #define __dynamic_func_call_cls(id, cls, fmt, func, ...) do { \
> > - DEFINE_DYNAMIC_DEBUG_METADATA_CLS(id, cls, fmt); \
> > + DEFINE_DYNAMIC_DEBUG_METADATA_CLS((id), cls, fmt); \
> > if (DYNAMIC_DEBUG_BRANCH(id)) \
> > func(&id, ##__VA_ARGS__); \
> > } while (0)
> > diff --git a/kernel/module/main.c b/kernel/module/main.c
> > index b60f728e36ac..c203b0694f7e 100644
> > --- a/kernel/module/main.c
> > +++ b/kernel/module/main.c
> > @@ -2627,6 +2627,9 @@ static int find_module_sections(struct module *mod, struct load_info *info)
> > mod->dyndbg_info.maps.start = section_objs(info, "__dyndbg_class_maps",
> > sizeof(*mod->dyndbg_info.maps.start),
> > &mod->dyndbg_info.maps.len);
> > + mod->dyndbg_info.users.start = section_objs(info, "__dyndbg_class_users",
> > + sizeof(*mod->dyndbg_info.users.start),
> > + &mod->dyndbg_info.users.len);
> > #endif
> >
> > return 0;
> > diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> > index 35796c290ca3..91a75f724c1a 100644
> > --- a/lib/Kconfig.debug
> > +++ b/lib/Kconfig.debug
> > @@ -2905,12 +2905,26 @@ config TEST_STATIC_KEYS
> > If unsure, say N.
> >
> > config TEST_DYNAMIC_DEBUG
> > - tristate "Test DYNAMIC_DEBUG"
> > - depends on DYNAMIC_DEBUG
> > + tristate "Build test-dynamic-debug module"
> > + depends on DYNAMIC_DEBUG || DYNAMIC_DEBUG_CORE
> > help
> > - This module registers a tracer callback to count enabled
> > - pr_debugs in a 'do_debugging' function, then alters their
> > - enablements, calls the function, and compares counts.
> > + This module exercises/demonstrates dyndbg's classmap API, by
> > + creating 2 classes: a DISJOINT classmap (supporting DRM.debug)
> > + and a LEVELS/VERBOSE classmap (like verbose2 > verbose1).
> > +
> > + If unsure, say N.
> > +
> > +config TEST_DYNAMIC_DEBUG_SUBMOD
> > + tristate "Build test-dynamic-debug submodule"
> > + default m
> > + depends on DYNAMIC_DEBUG || DYNAMIC_DEBUG_CORE
> > + depends on TEST_DYNAMIC_DEBUG
> > + help
> > + This sub-module uses a classmap defined and exported by the
> > + parent module, recapitulating drm & driver's shared use of
> > + drm.debug to control enabled debug-categories.
> > + It is tristate, independent of parent, to allow testing all
> > + proper combinations of parent=y/m submod=y/m.
> >
> > If unsure, say N.
> >
> > diff --git a/lib/Makefile b/lib/Makefile
> > index d5cfc7afbbb8..2c344138d990 100644
> > --- a/lib/Makefile
> > +++ b/lib/Makefile
> > @@ -84,6 +84,7 @@ obj-$(CONFIG_TEST_SORT) += test_sort.o
> > obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o
> > obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o
> > obj-$(CONFIG_TEST_DYNAMIC_DEBUG) += test_dynamic_debug.o
> > +obj-$(CONFIG_TEST_DYNAMIC_DEBUG_SUBMOD) += test_dynamic_debug_submod.o
> > obj-$(CONFIG_TEST_PRINTF) += test_printf.o
> > obj-$(CONFIG_TEST_SCANF) += test_scanf.o
> >
> > @@ -226,6 +227,8 @@ obj-$(CONFIG_ARCH_NEED_CMPXCHG_1_EMU) += cmpxchg-emu.o
> > obj-$(CONFIG_DYNAMIC_DEBUG_CORE) += dynamic_debug.o
> > #ensure exported functions have prototypes
> > CFLAGS_dynamic_debug.o := -DDYNAMIC_DEBUG_MODULE
> > +CFLAGS_test_dynamic_debug.o := -DDYNAMIC_DEBUG_MODULE
> > +CFLAGS_test_dynamic_debug_submod.o := -DDYNAMIC_DEBUG_MODULE
> >
> > obj-$(CONFIG_SYMBOLIC_ERRNAME) += errname.o
> >
> > diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
> > index a7e1dbb6ead0..53e261dbf81e 100644
> > --- a/lib/dynamic_debug.c
> > +++ b/lib/dynamic_debug.c
> > @@ -29,6 +29,7 @@
> > #include <linux/string_helpers.h>
> > #include <linux/uaccess.h>
> > #include <linux/dynamic_debug.h>
> > +
> > #include <linux/debugfs.h>
> > #include <linux/slab.h>
> > #include <linux/jump_label.h>
> > @@ -43,6 +44,8 @@ extern struct _ddebug __start___dyndbg_descs[];
> > extern struct _ddebug __stop___dyndbg_descs[];
> > extern struct _ddebug_class_map __start___dyndbg_class_maps[];
> > extern struct _ddebug_class_map __stop___dyndbg_class_maps[];
> > +extern struct _ddebug_class_user __start___dyndbg_class_users[];
> > +extern struct _ddebug_class_user __stop___dyndbg_class_users[];
> >
> > struct ddebug_table {
> > struct list_head link;
> > @@ -159,20 +162,37 @@ static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
> > query->first_lineno, query->last_lineno, query->class_string);
> > }
> >
> > -static struct _ddebug_class_map *ddebug_find_valid_class(struct ddebug_table const *dt,
> > - const char *class_string,
> > - int *class_id)
> > +#define vpr_di_info(di_p, msg_p, ...) ({ \
> > + struct _ddebug_info const *_di = di_p; \
> > + v2pr_info(msg_p " module:%s nd:%d nc:%d nu:%d\n", ##__VA_ARGS__, \
> > + _di->mod_name, _di->descs.len, _di->maps.len, \
> > + _di->users.len); \
> > + })
> > +
> > +static struct _ddebug_class_map *
> > +ddebug_find_valid_class(struct _ddebug_info const *di, const char *query_class, int *class_id)
> > {
> > struct _ddebug_class_map *map;
> > + struct _ddebug_class_user *cli;
> > int i, idx;
> >
> > - for_subvec(i, map, &dt->info, maps) {
> > - idx = match_string(map->class_names, map->length, class_string);
> > + for_subvec(i, map, di, maps) {
> > + idx = match_string(map->class_names, map->length, query_class);
> > if (idx >= 0) {
> > + vpr_di_info(di, "good-class: %s.%s ", map->mod_name, query_class);
> > *class_id = idx + map->base;
> > return map;
> > }
> > }
> > + for_subvec(i, cli, di, users) {
> > + idx = match_string(cli->map->class_names, cli->map->length, query_class);
> > + if (idx >= 0) {
> > + vpr_di_info(di, "class-ref: %s -> %s.%s ",
> > + cli->mod_name, cli->map->mod_name, query_class);
> > + *class_id = idx + cli->map->base;
> > + return cli->map;
> > + }
> > + }
> > *class_id = -ENOENT;
> > return NULL;
> > }
> > @@ -183,8 +203,7 @@ static struct _ddebug_class_map *ddebug_find_valid_class(struct ddebug_table con
> > * callsites, normally the same as number of changes. If verbose,
> > * logs the changes. Takes ddebug_lock.
> > */
> > -static int ddebug_change(const struct ddebug_query *query,
> > - struct flag_settings *modifiers)
> > +static int ddebug_change(const struct ddebug_query *query, struct flag_settings *modifiers)
> > {
> > int i;
> > struct ddebug_table *dt;
> > @@ -204,7 +223,8 @@ static int ddebug_change(const struct ddebug_query *query,
> > continue;
> >
> > if (query->class_string) {
> > - map = ddebug_find_valid_class(dt, query->class_string, &valid_class);
> > + map = ddebug_find_valid_class(&dt->info, query->class_string,
> > + &valid_class);
> > if (!map)
> > continue;
> > } else {
> > @@ -569,7 +589,7 @@ static int ddebug_exec_query(char *query_string, const char *modname)
> >
> > /* handle multiple queries in query string, continue on error, return
> > last error or number of matching callsites. Module name is either
> > - in param (for boot arg) or perhaps in query string.
> > + in the modname arg (for boot args) or perhaps in query string.
> > */
> > static int ddebug_exec_queries(char *query, const char *modname)
> > {
> > @@ -700,7 +720,7 @@ static int param_set_dyndbg_module_classes(const char *instr,
> > /**
> > * param_set_dyndbg_classes - classmap kparam setter
> > * @instr: string echo>d to sysfs, input depends on map_type
> > - * @kp: kp->arg has state: bits/lvl, map, map_type
> > + * @kp: kp->arg has state: bits/lvl, classmap, map_type
> > *
> > * enable/disable all class'd pr_debugs in the classmap. For LEVEL
> > * map-types, enforce * relative levels by bitpos.
> > @@ -737,6 +757,7 @@ int param_get_dyndbg_classes(char *buffer, const struct kernel_param *kp)
> > default:
> > return -1;
> > }
> > + return 0;
> > }
> > EXPORT_SYMBOL(param_get_dyndbg_classes);
> >
> > @@ -1049,12 +1070,17 @@ static void *ddebug_proc_next(struct seq_file *m, void *p, loff_t *pos)
> > static const char *ddebug_class_name(struct _ddebug_info *di, struct _ddebug *dp)
> > {
> > struct _ddebug_class_map *map;
> > + struct _ddebug_class_user *cli;
> > int i;
> >
> > for_subvec(i, map, di, maps)
> > if (class_in_range(dp->class_id, map))
> > return map->class_names[dp->class_id - map->base];
> >
> > + for_subvec(i, cli, di, users)
> > + if (class_in_range(dp->class_id, cli->map))
> > + return cli->map->class_names[dp->class_id - cli->map->base];
> > +
> > return NULL;
> > }
> >
> > @@ -1135,9 +1161,85 @@ static const struct proc_ops proc_fops = {
> > .proc_write = ddebug_proc_write
> > };
> >
> > -static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug_info *di)
> > +#define vpr_cm_info(cm_p, msg_fmt, ...) ({ \
> > + struct _ddebug_class_map const *_cm = cm_p; \
> > + v2pr_info(msg_fmt " %s [%d..%d] %s..%s\n", ##__VA_ARGS__, \
> > + _cm->mod_name, _cm->base, _cm->base + _cm->length, \
> > + _cm->class_names[0], _cm->class_names[_cm->length - 1]); \
> > + })
> > +
> > +static void ddebug_sync_classbits(const struct kernel_param *kp, const char *modname)
> > +{
> > + const struct _ddebug_class_param *dcp = kp->arg;
> > +
> > + /* clamp initial bitvec, mask off hi-bits */
> > + if (*dcp->bits & ~CLASSMAP_BITMASK(dcp->map->length)) {
> > + *dcp->bits &= CLASSMAP_BITMASK(dcp->map->length);
> > + v2pr_info("preset classbits: %lx\n", *dcp->bits);
> > + }
> > + /* force class'd prdbgs (in USEr module) to match (DEFINEr module) class-param */
> > + ddebug_apply_class_bitmap(dcp, dcp->bits, ~0, modname);
> > + ddebug_apply_class_bitmap(dcp, dcp->bits, 0, modname);
> > +}
> > +
> > +static void ddebug_match_apply_kparam(const struct kernel_param *kp,
> > + const struct _ddebug_class_map *map,
> > + const char *mod_name)
> > +{
> > + struct _ddebug_class_param *dcp;
> > +
> > + if (kp->ops != ¶m_ops_dyndbg_classes)
> > + return;
> > +
> > + dcp = (struct _ddebug_class_param *)kp->arg;
> > +
> > + if (map == dcp->map) {
> > + v2pr_info(" kp:%s.%s =0x%lx", mod_name, kp->name, *dcp->bits);
> > + vpr_cm_info(map, " %s mapped to: ", mod_name);
> > + ddebug_sync_classbits(kp, mod_name);
> > + }
> > +}
> > +
> > +static void ddebug_apply_params(const struct _ddebug_class_map *cm, const char *mod_name)
> > +{
> > + const struct kernel_param *kp;
> > +#if IS_ENABLED(CONFIG_MODULES)
> > + int i;
> > +
> > + if (cm->mod) {
> > + vpr_cm_info(cm, "loaded classmap: %s", mod_name);
> > + /* ifdef protects the cm->mod->kp deref */
> > + for (i = 0, kp = cm->mod->kp; i < cm->mod->num_kp; i++, kp++)
> > + ddebug_match_apply_kparam(kp, cm, mod_name);
> > + }
> > +#endif
> > + if (!cm->mod) {
> > + vpr_cm_info(cm, "builtin classmap: %s", mod_name);
> > + for (kp = __start___param; kp < __stop___param; kp++)
> > + ddebug_match_apply_kparam(kp, cm, mod_name);
> > + }
> > +}
> > +
> > +static void ddebug_apply_class_maps(const struct _ddebug_info *di)
> > +{
> > + struct _ddebug_class_map *cm;
> > + int i;
> > +
> > + for_subvec(i, cm, di, maps)
> > + ddebug_apply_params(cm, cm->mod_name);
> > +
> > + vpr_di_info(di, "attached %d classmaps to module: %s ", i, cm->mod_name);
> > +}
> > +
> > +static void ddebug_apply_class_users(const struct _ddebug_info *di)
> > {
> > - vpr_info("module:%s attached %d classes\n", dt->info.mod_name, dt->info.maps.len);
> > + struct _ddebug_class_user *cli;
> > + int i;
> > +
> > + for_subvec(i, cli, di, users)
> > + ddebug_apply_params(cli->map, cli->mod_name);
> > +
> > + vpr_di_info(di, "attached %d class-users to module: %s ", i, cli->mod_name);
> > }
> >
> > /*
> > @@ -1173,6 +1275,7 @@ static int ddebug_add_module(struct _ddebug_info *di)
> > {
> > struct ddebug_table *dt;
> > struct _ddebug_class_map *cm;
> > + struct _ddebug_class_user *cli;
> > int i;
> >
> > if (!di->descs.len)
> > @@ -1196,14 +1299,18 @@ static int ddebug_add_module(struct _ddebug_info *di)
> > INIT_LIST_HEAD(&dt->link);
> >
> > dd_mark_vector_subrange(i, dt, cm, di, maps);
> > + dd_mark_vector_subrange(i, dt, cli, di, users);
> >
> > - if (di->maps.len)
> > - ddebug_attach_module_classes(dt, di);
> > + if (dt->info.maps.len)
> > + ddebug_apply_class_maps(&dt->info);
> >
> > mutex_lock(&ddebug_lock);
> > list_add_tail(&dt->link, &ddebug_tables);
> > mutex_unlock(&ddebug_lock);
> >
> > + if (dt->info.users.len)
> > + ddebug_apply_class_users(&dt->info);
> > +
> > vpr_info("%3u debug prints in module %s\n", di->descs.len, di->mod_name);
> > return 0;
> > }
> > @@ -1354,8 +1461,10 @@ static int __init dynamic_debug_init(void)
> > struct _ddebug_info di = {
> > .descs.start = __start___dyndbg_descs,
> > .maps.start = __start___dyndbg_class_maps,
> > + .users.start = __start___dyndbg_class_users,
> > .descs.len = __stop___dyndbg_descs - __start___dyndbg_descs,
> > .maps.len = __stop___dyndbg_class_maps - __start___dyndbg_class_maps,
> > + .users.len = __stop___dyndbg_class_users - __start___dyndbg_class_users,
> > };
> >
> > #ifdef CONFIG_MODULES
> > diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
> > index 9c3e53cd26bd..1070107f74f1 100644
> > --- a/lib/test_dynamic_debug.c
> > +++ b/lib/test_dynamic_debug.c
> > @@ -6,11 +6,30 @@
> > * Jim Cromie <jim.cromie@gmail.com>
> > */
> >
> > -#define pr_fmt(fmt) "test_dd: " fmt
> > +/*
> > + * This file is built 2x, also making test_dynamic_debug_submod.ko,
> > + * whose 2-line src file #includes this file. This gives us a _submod
> > + * clone with identical pr_debugs, without further maintenance.
> > + *
> > + * If things are working properly, they should operate identically
> > + * when printed or adjusted by >control. This eases visual perusal of
> > + * the logs, and simplifies testing, by easing the proper accounting
> > + * of expectations.
> > + *
> > + * It also puts both halves of the subsystem _DEFINE & _USE use case
> > + * together, and integrates the common ENUM providing both class_ids
> > + * and class-names to both _DEFINErs and _USERs. I think this makes
> > + * the usage clearer.
> > + */
> > +#if defined(TEST_DYNAMIC_DEBUG_SUBMOD)
> > + #define pr_fmt(fmt) "test_dd_submod: " fmt
> > +#else
> > + #define pr_fmt(fmt) "test_dd: " fmt
> > +#endif
> >
> > #include <linux/module.h>
> >
> > -/* run tests by reading or writing sysfs node: do_prints */
> > +/* re-gen output by reading or writing sysfs node: do_prints */
> >
> > static void do_prints(void); /* device under test */
> > static int param_set_do_prints(const char *instr, const struct kernel_param *kp)
> > @@ -29,24 +48,39 @@ static const struct kernel_param_ops param_ops_do_prints = {
> > };
> > module_param_cb(do_prints, ¶m_ops_do_prints, NULL, 0600);
> >
> > -/*
> > - * Using the CLASSMAP api:
> > - * - classmaps must have corresponding enum
> > - * - enum symbols must match/correlate with class-name strings in the map.
> > - * - base must equal enum's 1st value
> > - * - multiple maps must set their base to share the 0-30 class_id space !!
> > - * (build-bug-on tips welcome)
> > - * Additionally, here:
> > - * - tie together sysname, mapname, bitsname, flagsname
> > - */
> > -#define DD_SYS_WRAP(_model, _flags) \
> > - static unsigned long bits_##_model; \
> > - static struct _ddebug_class_param _flags##_model = { \
> > +#define CLASSMAP_BITMASK(width, base) (((1UL << (width)) - 1) << (base))
> > +
> > +/* sysfs param wrapper, proto-API */
> > +#define DYNAMIC_DEBUG_CLASSMAP_PARAM_(_model, _flags, _init) \
> > + static unsigned long bits_##_model = _init; \
> > + static struct _ddebug_class_param _flags##_##_model = { \
> > .bits = &bits_##_model, \
> > .flags = #_flags, \
> > .map = &map_##_model, \
> > }; \
> > - module_param_cb(_flags##_##_model, ¶m_ops_dyndbg_classes, &_flags##_model, 0600)
> > + module_param_cb(_flags##_##_model, ¶m_ops_dyndbg_classes, \
> > + &_flags##_##_model, 0600)
> > +#ifdef DEBUG
> > +#define DYNAMIC_DEBUG_CLASSMAP_PARAM(_model, _flags) \
> > + DYNAMIC_DEBUG_CLASSMAP_PARAM_(_model, _flags, ~0)
> > +#else
> > +#define DYNAMIC_DEBUG_CLASSMAP_PARAM(_model, _flags) \
> > + DYNAMIC_DEBUG_CLASSMAP_PARAM_(_model, _flags, 0)
> > +#endif
> > +
> > +/*
> > + * Demonstrate/test DISJOINT & LEVEL typed classmaps with a sys-param.
> > + *
> > + * To comport with DRM debug-category (an int), classmaps map names to
> > + * ids (also an int). So a classmap starts with an enum; DRM has enum
> > + * debug_category: with DRM_UT_<CORE,DRIVER,KMS,etc>. We use the enum
> > + * values as class-ids, and stringified enum-symbols as classnames.
> > + *
> > + * Modules with multiple CLASSMAPS must have enums with distinct
> > + * value-ranges, as arranged below with explicit enum_sym = X inits.
> > + * To clarify this sharing, declare the 2 enums now, for the 2
> > + * different classmap types
> > + */
> >
> > /* numeric input, independent bits */
> > enum cat_disjoint_bits {
> > @@ -60,26 +94,51 @@ enum cat_disjoint_bits {
> > D2_LEASE,
> > D2_DP,
> > D2_DRMRES };
> > -DECLARE_DYNDBG_CLASSMAP(map_disjoint_bits, DD_CLASS_TYPE_DISJOINT_BITS, 0,
> > - "D2_CORE",
> > - "D2_DRIVER",
> > - "D2_KMS",
> > - "D2_PRIME",
> > - "D2_ATOMIC",
> > - "D2_VBL",
> > - "D2_STATE",
> > - "D2_LEASE",
> > - "D2_DP",
> > - "D2_DRMRES");
> > -DD_SYS_WRAP(disjoint_bits, p);
> > -DD_SYS_WRAP(disjoint_bits, T);
> > -
> > -/* numeric verbosity, V2 > V1 related */
> > -enum cat_level_num { V0 = 14, V1, V2, V3, V4, V5, V6, V7 };
> > -DECLARE_DYNDBG_CLASSMAP(map_level_num, DD_CLASS_TYPE_LEVEL_NUM, 14,
> > - "V0", "V1", "V2", "V3", "V4", "V5", "V6", "V7");
> > -DD_SYS_WRAP(level_num, p);
> > -DD_SYS_WRAP(level_num, T);
> > +
> > +/* numeric verbosity, V2 > V1 related. V0 is > D2_DRM_RES */
> > +enum cat_level_num { V0 = 16, V1, V2, V3, V4, V5, V6, V7 };
> > +
> > +/* recapitulate DRM's multi-classmap setup */
> > +#if !defined(TEST_DYNAMIC_DEBUG_SUBMOD)
> > +/*
> > + * In single user, or parent / coordinator (drm.ko) modules, define
> > + * classmaps on the client enums above, and then declares the PARAMS
> > + * ref'g the classmaps. Each is exported.
> > + */
> > +DYNAMIC_DEBUG_CLASSMAP_DEFINE(map_disjoint_bits, DD_CLASS_TYPE_DISJOINT_BITS,
> > + D2_CORE,
> > + "D2_CORE",
> > + "D2_DRIVER",
> > + "D2_KMS",
> > + "D2_PRIME",
> > + "D2_ATOMIC",
> > + "D2_VBL",
> > + "D2_STATE",
> > + "D2_LEASE",
> > + "D2_DP",
> > + "D2_DRMRES");
> > +
> > +DYNAMIC_DEBUG_CLASSMAP_DEFINE(map_level_num, DD_CLASS_TYPE_LEVEL_NUM,
> > + V0, "V0", "V1", "V2", "V3", "V4", "V5", "V6", "V7");
> > +
> > +/*
> > + * now add the sysfs-params
> > + */
> > +
> > +DYNAMIC_DEBUG_CLASSMAP_PARAM(disjoint_bits, p);
> > +DYNAMIC_DEBUG_CLASSMAP_PARAM(level_num, p);
> > +
> > +#else /* TEST_DYNAMIC_DEBUG_SUBMOD */
> > +
> > +/*
> > + * in submod/drm-drivers, use the classmaps defined in top/parent
> > + * module above.
> > + */
> > +
> > +DYNAMIC_DEBUG_CLASSMAP_USE(map_disjoint_bits);
> > +DYNAMIC_DEBUG_CLASSMAP_USE(map_level_num);
> > +
> > +#endif
> >
> > /* stand-in for all pr_debug etc */
> > #define prdbg(SYM) __pr_debug_cls(SYM, #SYM " msg\n")
> > @@ -115,6 +174,7 @@ static void do_levels(void)
> >
> > static void do_prints(void)
> > {
> > + pr_debug("do_prints:\n");
> > do_cats();
> > do_levels();
> > }
> > diff --git a/lib/test_dynamic_debug_submod.c b/lib/test_dynamic_debug_submod.c
> > new file mode 100644
> > index 000000000000..672aabf40160
> > --- /dev/null
> > +++ b/lib/test_dynamic_debug_submod.c
> > @@ -0,0 +1,14 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Kernel module for testing dynamic_debug
> > + *
> > + * Authors:
> > + * Jim Cromie <jim.cromie@gmail.com>
> > + */
> > +
> > +/*
> > + * clone the parent, inherit all the properties, for consistency and
> > + * simpler accounting in test expectations.
> > + */
> > +#define TEST_DYNAMIC_DEBUG_SUBMOD
> > +#include "test_dynamic_debug.c"
>
> --
> Louis Chauvet, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
>
>
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 18/54] selftests-dyndbg: add tools/testing/selftests/dynamic_debug/*
2025-04-15 10:02 ` Louis Chauvet
@ 2025-04-15 19:46 ` jim.cromie
0 siblings, 0 replies; 81+ messages in thread
From: jim.cromie @ 2025-04-15 19:46 UTC (permalink / raw)
To: Louis Chauvet
Cc: jbaron, gregkh, ukaszb, linux-kernel, dri-devel, amd-gfx,
intel-gvt-dev, intel-gfx, daniel.vetter, tvrtko.ursulin,
jani.nikula, ville.syrjala
On Tue, Apr 15, 2025 at 4:02 AM Louis Chauvet <louis.chauvet@bootlin.com> wrote:
>
>
>
> Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> > Add a selftest script for dynamic-debug. The config requires
> > CONFIG_TEST_DYNAMIC_DEBUG=m and CONFIG_TEST_DYNAMIC_DEBUG_SUBMOD=m,
> > which tacitly requires either CONFIG_DYNAMIC_DEBUG=y or
> > CONFIG_DYNAMIC_DEBUG_CORE=y
> >
> > ATM this has just basic_tests(), which modify pr_debug() flags in the
> > builtin params module. This means they're available to manipulate and
> > observe the effects in "cat control".
> >
> > This is backported from another feature branch; the support-fns (thx
> > Lukas) have unused features at the moment, they'll get used shortly.
> >
> > The script enables simple virtme-ng testing:
> >
> > [jimc@gandalf b0-ftrace]$ vrun_t
> > virtme-ng 1.32+115.g07b109d
> > doing: vng --name v6.14-rc4-60-gd5f48427de0c \
> > --user root -v -p 4 -a dynamic_debug.verbose=3 V=1 \
> > -- ../tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
> > virtme: waiting for virtiofsd to start
> > ..
> >
> > And add dynamic_debug to TARGETS, so `make run_tests` sees it properly
> >
> > For the impatient, set TARGETS explicitly:
> >
> > bash-5.2# make TARGETS=dynamic_debug run_tests
> > make[1]: ...
> > TAP version 13
> > 1..1
> > [ 35.552922] dyndbg: read 3 bytes from userspace
> > [ 35.553099] dyndbg: query 0: "=_" mod:*
> > [ 35.553544] dyndbg: processed 1 queries, with 1778 matches, 0 errs
> >
> > Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> > Co-developed-by: Łukasz Bartosik <ukaszb@chromium.org>
> > Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
> > ---
> > -r3 turn off green at end
> > drop config dep on TEST_DYNAMIC_DEBUG,
> > since basic-test uses builtin params
> >
> > - check KCONFIG_CONFIG to avoid silly fails
> >
> > Several tests are dependent upon config choices. Lets avoid failing
> > where that is noise.
> >
> > The KCONFIG_CONFIG var exists to convey the config-file around. If
> > the var names a file, read it and extract the relevant CONFIG items,
> > and use them to skip the dependent tests, thus avoiding the fails that
> > would follow, and the disruption to whatever CI is running these
> > selftests.
> >
> > If the envar doesn't name a config-file, ".config" is assumed.
> >
> > CONFIG_DYNAMIC_DEBUG=y:
> >
> > basic-tests() and comma-terminator-tests() test for the presence of
> > the builtin pr_debugs in module/main.c, which I deemed stable and
> > therefore safe to count. That said, the test fails if only
> > CONFIG_DYNAMIC_DEBUG_CORE=y is set. It could be rewritten to test
> > against test-dynamic-debug.ko, but that just trades one config
> > dependence for another.
> >
> > CONFIG_TEST_DYNAMIC_DEBUG=m
> >
> > As written, test_percent_splitting() modprobes test_dynamic_debug,
> > enables several classes, and count them. It could be re-written to
> > work for the builtin module also, but builtin test modules are not a
> > common or desirable build/config.
> >
> > CONFIG_TEST_DYNAMIC_DEBUG=m && CONFIG_TEST_DYNAMIC_DEBUG_SUBMOD=m
> >
> > test_mod_submod() recaps the bug found in DRM-CI where drivers werent
> > enabled by drm.debug=<bits>. It modprobes both test_dynamic_debug &
> > test_dynamic_debug_submod, so it depends on a loadable modules config.
> >
> > It could be rewritten to work in a builtin parent config; DRM=y is
> > common enough to be pertinent, but testing that config also wouldn't
> > really test anything more fully than all-loadable modules, since they
> > default together.
> >
> > generalize-test-env
> > ---
> > MAINTAINERS | 1 +
> > tools/testing/selftests/Makefile | 1 +
> > .../testing/selftests/dynamic_debug/Makefile | 9 +
> > tools/testing/selftests/dynamic_debug/config | 7 +
> > .../dynamic_debug/dyndbg_selftest.sh | 257 ++++++++++++++++++
> > 5 files changed, 275 insertions(+)
> > create mode 100644 tools/testing/selftests/dynamic_debug/Makefile
> > create mode 100644 tools/testing/selftests/dynamic_debug/config
> > create mode 100755 tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
> >
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index 1c5fcbd9e408..1192ad6c65c1 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -8140,6 +8140,7 @@ S: Maintained
> > F: include/linux/dynamic_debug.h
> > F: lib/dynamic_debug.c
> > F: lib/test_dynamic_debug*.c
> > +F: tools/testing/selftests/dynamic_debug/*
> >
> > DYNAMIC INTERRUPT MODERATION
> > M: Tal Gilboa <talgi@nvidia.com>
> > diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
> > index 8daac70c2f9d..b6a323c7f986 100644
> > --- a/tools/testing/selftests/Makefile
> > +++ b/tools/testing/selftests/Makefile
> > @@ -26,6 +26,7 @@ TARGETS += drivers/net/team
> > TARGETS += drivers/net/virtio_net
> > TARGETS += drivers/platform/x86/intel/ifs
> > TARGETS += dt
> > +TARGETS += dynamic_debug
> > TARGETS += efivarfs
> > TARGETS += exec
> > TARGETS += fchmodat2
> > diff --git a/tools/testing/selftests/dynamic_debug/Makefile b/tools/testing/selftests/dynamic_debug/Makefile
> > new file mode 100644
> > index 000000000000..6d06fa7f1040
> > --- /dev/null
> > +++ b/tools/testing/selftests/dynamic_debug/Makefile
> > @@ -0,0 +1,9 @@
> > +# SPDX-License-Identifier: GPL-2.0-only
> > +# borrowed from Makefile for user memory selftests
> > +
> > +# No binaries, but make sure arg-less "make" doesn't trigger "run_tests"
> > +all:
> > +
> > +TEST_PROGS := dyndbg_selftest.sh
> > +
> > +include ../lib.mk
> > diff --git a/tools/testing/selftests/dynamic_debug/config b/tools/testing/selftests/dynamic_debug/config
> > new file mode 100644
> > index 000000000000..0f906ff53908
> > --- /dev/null
> > +++ b/tools/testing/selftests/dynamic_debug/config
> > @@ -0,0 +1,7 @@
> > +
> > +# basic tests ref the builtin params module
> > +CONFIG_DYNAMIC_DEBUG=m
> > +
> > +# more testing is possible with these
> > +# CONFIG_TEST_DYNAMIC_DEBUG=m
> > +# CONFIG_TEST_DYNAMIC_DEBUG_SUBMOD=m
> > diff --git a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
> > new file mode 100755
> > index 000000000000..465fad3f392c
> > --- /dev/null
> > +++ b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
> > @@ -0,0 +1,257 @@
> > +#!/bin/bash
> > +# SPDX-License-Identifier: GPL-2.0-only
> > +
> > +V=${V:=0} # invoke as V=1 $0 for global verbose
> > +RED="\033[0;31m"
> > +GREEN="\033[0;32m"
> > +YELLOW="\033[0;33m"
> > +BLUE="\033[0;34m"
> > +MAGENTA="\033[0;35m"
> > +CYAN="\033[0;36m"
> > +NC="\033[0;0m"
> > +error_msg=""
> > +
> > +[ -e /proc/dynamic_debug/control ] || {
> > + echo -e "${RED}: this test requires CONFIG_DYNAMIC_DEBUG=y ${NC}"
> > + exit 0 # nothing to test here, no good reason to fail.
> > +}
> > +
> > +# need info to avoid failures due to untestable configs
> > +
> > +[ -f "$KCONFIG_CONFIG" ] || KCONFIG_CONFIG=".config"
> > +if [ -f "$KCONFIG_CONFIG" ]; then
> > + echo "# consulting KCONFIG_CONFIG: $KCONFIG_CONFIG"
> > + grep -q "CONFIG_DYNAMIC_DEBUG=y" $KCONFIG_CONFIG ; LACK_DD_BUILTIN=$?
> > + grep -q "CONFIG_TEST_DYNAMIC_DEBUG=m" $KCONFIG_CONFIG ; LACK_TMOD=$?
> > + grep -q "CONFIG_TEST_DYNAMIC_DEBUG_SUBMOD=m" $KCONFIG_CONFIG ; LACK_TMOD_SUBMOD=$?
> > + if [ $V -eq 1 ]; then
> > + echo LACK_DD_BUILTIN: $LACK_DD_BUILTIN
> > + echo LACK_TMOD: $LACK_TMOD
> > + echo LACK_TMOD_SUBMOD: $LACK_TMOD_SUBMOD
> > + fi
> > +else
> > + LACK_DD_BUILTIN=0
> > + LACK_TMOD=0
> > + LACK_TMOD_SUBMOD=0
> > +fi
>
> Nitpick for the sh file: is it normal to have inconsistent indenting ?(4
> space, tabs, 8 spaces)
>
hmm.
I just checked scripts/bpf_doc.py
it uses 4 space indents, I didnt check for tabs.
But I will go look for inconsistencies and mixes of spaces & tabs
> > +function vx () {
> > + echo $1 > /sys/module/dynamic_debug/parameters/verbose
> > +}
> > +
> > +function ddgrep () {
> > + grep $1 /proc/dynamic_debug/control
> > +}
> > +
> > +function doprints () {
> > + cat /sys/module/test_dynamic_debug/parameters/do_prints
> > +}
> > +
> > +function ddcmd () {
> > + exp_exit_code=0
> > + num_args=$#
> > + if [ "${@:$#}" = "pass" ]; then
> > + num_args=$#-1
> > + elif [ "${@:$#}" = "fail" ]; then
> > + num_args=$#-1
> > + exp_exit_code=1
> > + fi
> > + args=${@:1:$num_args}
> > + output=$((echo "$args" > /proc/dynamic_debug/control) 2>&1)
> > + exit_code=$?
> > + error_msg=$(echo $output | cut -d ":" -f 5 | sed -e 's/^[[:space:]]*//')
> > + handle_exit_code $BASH_LINENO $FUNCNAME $exit_code $exp_exit_code
> > +}
> > +
> > +function handle_exit_code() {
> > + local exp_exit_code=0
> > + [ $# == 4 ] && exp_exit_code=$4
> > + if [ $3 -ne $exp_exit_code ]; then
> > + echo -e "${RED}: $BASH_SOURCE:$1 $2() expected to exit with code $exp_exit_code"
> > + [ $3 == 1 ] && echo "Error: '$error_msg'"
> > + exit
> > + fi
> > +}
> > +
> > +# $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
> > +# $4 - optional when $3 is set to "-r" then $4 can be used to pass "-v"
> > +function check_match_ct {
> > + pattern="\s$1\s"
> > + exp_cnt=0
> > +
> > + [ "$3" == "-r" ] && pattern="$1"
> > + let cnt=$(ddgrep "$pattern" | wc -l)
> > + if [ $V -eq 1 ] || [ "$3" == "-v" ] || [ "$4" == "-v" ]; then
> > + echo -ne "${BLUE}" && ddgrep $pattern && echo -ne "${NC}"
> > + fi
> > + [ $# -gt 1 ] && exp_cnt=$2
> > + if [ $cnt -ne $exp_cnt ]; then
> > + echo -e "${RED}: $BASH_SOURCE:$BASH_LINENO check failed expected $exp_cnt on $1, got $cnt"
> > + exit
> > + else
> > + echo ": $cnt matches on $1"
> > + fi
> > +}
> > +
> > +# $1 - trace instance name
> > +# #2 - if > 0 then directory is expected to exist, if <= 0 then otherwise
> > +# $3 - "-v" for verbose
> > +function check_trace_instance_dir {
> > + if [ -e /sys/kernel/tracing/instances/$1 ]; then
> > + if [ "$3" == "-v" ] ; then
> > + echo "ls -l /sys/kernel/tracing/instances/$1: "
> > + ls -l /sys/kernel/tracing/instances/$1
> > + fi
> > + if [ $2 -le 0 ]; then
> > + echo -e "${RED}: $BASH_SOURCE:$BASH_LINENO error trace instance \
> > + '/sys/kernel/tracing/instances/$1' does exist"
> > + exit
> > + fi
> > + else
> > + if [ $2 -gt 0 ]; then
> > + echo -e "${RED}: $BASH_SOURCE:$BASH_LINENO error trace instance \
> > + '/sys/kernel/tracing/instances/$1' does not exist"
> > + exit
> > + fi
> > + fi
> > +}
> > +
> > +function tmark {
> > + echo $* > /sys/kernel/tracing/trace_marker
> > +}
> > +
> > +# $1 - trace instance name
> > +# $2 - line number
> > +# $3 - if > 0 then the instance is expected to be opened, otherwise
> > +# the instance is expected to be closed
> > +function check_trace_instance {
> > + output=$(tail -n9 /proc/dynamic_debug/control | grep ": Opened trace instances" \
> > + | xargs -n1 | grep $1)
> > + if [ "$output" != $1 ] && [ $3 -gt 0 ]; then
> > + echo -e "${RED}: $BASH_SOURCE:$2 trace instance $1 is not opened"
> > + exit
> > + fi
> > + if [ "$output" == $1 ] && [ $3 -le 0 ]; then
> > + echo -e "${RED}: $BASH_SOURCE:$2 trace instance $1 is not closed"
> > + exit
> > + fi
> > +}
> > +
> > +function is_trace_instance_opened {
> > + check_trace_instance $1 $BASH_LINENO 1
> > +}
> > +
> > +function is_trace_instance_closed {
> > + check_trace_instance $1 $BASH_LINENO 0
> > +}
> > +
> > +# $1 - trace instance directory to delete
> > +# $2 - if > 0 then directory is expected to be deleted successfully, if <= 0 then otherwise
> > +function del_trace_instance_dir() {
> > + exp_exit_code=1
> > + [ $2 -gt 0 ] && exp_exit_code=0
> > + output=$((rmdir /sys/kernel/debug/tracing/instances/$1) 2>&1)
> > + exit_code=$?
> > + error_msg=$(echo $output | cut -d ":" -f 3 | sed -e 's/^[[:space:]]*//')
> > + handle_exit_code $BASH_LINENO $FUNCNAME $exit_code $exp_exit_code
> > +}
> > +
> > +function error_log_ref {
> > + # to show what I got
> > + : echo "# error-log-ref: $1"
> > + : echo cat \$2
> > +}
> > +
> > +function ifrmmod {
> > + lsmod | grep $1 2>&1>/dev/null && rmmod $1
> > +}
> > +
> > +# $1 - text to search for
> > +function search_trace() {
> > + search_trace_name 0 1 $1
> > +}
> > +
> > +# $1 - trace instance name, 0 for global event trace
> > +# $2 - line number counting from the bottom
> > +# $3 - text to search for
> > +function search_trace_name() {
> > + if [ "$1" = "0" ]; then
> > + buf=$(cat /sys/kernel/debug/tracing/trace)
> > + line=$(tail -$2 /sys/kernel/debug/tracing/trace | head -1 | sed -e 's/^[[:space:]]*//')
> > + else
> > + buf=$(cat /sys/kernel/debug/tracing/instances/$1/trace)
> > + line=$(tail -$2 /sys/kernel/debug/tracing/instances/$1/trace | head -1 | \
> > + sed -e 's/^[[:space:]]*//')
> > + fi
> > + if [ $2 = 0 ]; then
> > + # whole-buf check
> > + output=$(echo $buf | grep "$3")
> > + else
> > + output=$(echo $line | grep "$3")
> > + fi
> > + if [ "$output" = "" ]; then
> > + echo -e "${RED}: $BASH_SOURCE:$BASH_LINENO search for '$3' failed \
> > + in line '$line' or '$buf'"
> > + exit
> > + fi
> > + if [ $V = 1 ]; then
> > + echo -e "${MAGENTA}: search_trace_name in $1 found: \n$output \nin:${BLUE} $buf ${NC}"
> > + fi
> > +}
> > +
> > +# $1 - error message to check
> > +function check_err_msg() {
> > + if [ "$error_msg" != "$1" ]; then
> > + echo -e "${RED}: $BASH_SOURCE:$BASH_LINENO error message '$error_msg' \
> > + does not match with '$1'"
> > + exit
> > + fi
> > +}
> > +
> > +function basic_tests {
> > + echo -e "${GREEN}# BASIC_TESTS ${NC}"
> > + if [ $LACK_DD_BUILTIN -eq 1 ]; then
> > + echo "SKIP"
> > + return
> > + fi
> > + ddcmd =_ # zero everything
> > + check_match_ct =p 0
> > +
> > + # module params are builtin to handle boot args
> > + check_match_ct '\[params\]' 4 -r
> > + ddcmd module params +mpf
> > + check_match_ct =pmf 4
> > +
> > + # multi-cmd input, newline separated, with embedded comments
> > + cat <<"EOF" > /proc/dynamic_debug/control
> > + module params =_ # clear params
> > + module params +mf # set flags
> > + module params func parse_args +sl # other flags
> > +EOF
> > + check_match_ct =mf 3
> > + check_match_ct =mfsl 1
> > + ddcmd =_
> > +}
> > +
> > +tests_list=(
> > + basic_tests
> > +)
> > +
> > +# Run tests
> > +
> > +ifrmmod test_dynamic_debug_submod
> > +ifrmmod test_dynamic_debug
> > +
> > +for test in "${tests_list[@]}"
> > +do
> > + $test
> > + echo ""
> > +done
> > +echo -en "${GREEN}# Done on: "
> > +date
> > +echo -en "${NC}"
>
> --
> Louis Chauvet, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
>
>
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 20/54] dyndbg: check DYNAMIC_DEBUG_CLASSMAP_DEFINE args at compile-time
2025-04-15 10:04 ` Louis Chauvet
@ 2025-04-15 19:54 ` jim.cromie
2025-04-16 6:54 ` Louis Chauvet
0 siblings, 1 reply; 81+ messages in thread
From: jim.cromie @ 2025-04-15 19:54 UTC (permalink / raw)
To: Louis Chauvet
Cc: jbaron, gregkh, ukaszb, linux-kernel, dri-devel, amd-gfx,
intel-gvt-dev, intel-gfx, daniel.vetter, tvrtko.ursulin,
jani.nikula, ville.syrjala
On Tue, Apr 15, 2025 at 4:04 AM Louis Chauvet <louis.chauvet@bootlin.com> wrote:
>
>
>
> Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> > Add __DYNAMIC_DEBUG_CLASSMAP_CHECK to implement the following
> > arg-checks at compile-time:
> >
> > 0 <= _base < 63
> > class_names is not empty
> > class_names[0] is a string
>
> I don't see where this is checked, did I miss something?
kinda/sorta ? theres no explicit check for "string".
BUT
this would fail, cuz 1 doesnt fit into a char* arr[0]
> > +DYNDBG_CLASSMAP_DEFINE(fail_str_type, 0, 0, 1 /* not a string */);
Im perhaps over-simplifying the description
>
> > (class_names.length + _base) < 63
> >
> > These compile-time checks will prevent several misuses; 4 such
> > examples are added to test_dynamic_debug_submod.ko, and will fail
> > compilation if -DDD_MACRO_ARGCHECK is added to cflags. This wouldn't
> > be a useful CONFIG_ item, since it breaks the build.
> >
> > Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> > ---
> > v3- $macro_name =~ s/DYNDBG/DYNAMIC_DEBUG/
> >
> > prev-
> > - split static-asserts to __DYNDBG_CLASSMAP_CHECK
> > - move __DYNDBG_CLASSMAP_CHECK above kdoc for DYNDBG_CLASSMAP_DEFINE
> > silences kernel-doc warnings
> > ---
> > include/linux/dynamic_debug.h | 9 +++++++++
> > lib/test_dynamic_debug.c | 11 +++++++++++
> > 2 files changed, 20 insertions(+)
> >
> > diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
> > index 9af825c84e70..4941ef2adb46 100644
> > --- a/include/linux/dynamic_debug.h
> > +++ b/include/linux/dynamic_debug.h
> > @@ -99,6 +99,14 @@ struct _ddebug_class_map {
> > enum ddebug_class_map_type map_type;
> > };
> >
> > +#define __DYNAMIC_DEBUG_CLASSMAP_CHECK(_clnames, _base) \
> > + static_assert(((_base) >= 0 && (_base) < _DPRINTK_CLASS_DFLT), \
> > + "_base must be in 0..62"); \
> > + static_assert(ARRAY_SIZE(_clnames) > 0, \
> > + "classnames array size must be > 0"); \
> > + static_assert((ARRAY_SIZE(_clnames) + (_base)) < _DPRINTK_CLASS_DFLT, \
> > + "_base + classnames.length exceeds range")
> > +
> > /**
> > * DYNAMIC_DEBUG_CLASSMAP_DEFINE - define debug classes used by a module.
> > * @_var: name of the classmap, exported for other modules coordinated use.
> > @@ -112,6 +120,7 @@ struct _ddebug_class_map {
> > */
> > #define DYNAMIC_DEBUG_CLASSMAP_DEFINE(_var, _mapty, _base, ...) \
> > static const char *_var##_classnames[] = { __VA_ARGS__ }; \
>
> Or maybe it was already enforced by this, but in this case the commit
> message contains too much checks.
>
> > + __DYNAMIC_DEBUG_CLASSMAP_CHECK(_var##_classnames, (_base)); \
> > extern struct _ddebug_class_map _var; \
> > struct _ddebug_class_map __aligned(8) __used \
> > __section("__dyndbg_class_maps") _var = { \
> > diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
> > index e42916b08fd4..9f9e3fddd7e6 100644
> > --- a/lib/test_dynamic_debug.c
> > +++ b/lib/test_dynamic_debug.c
> > @@ -146,8 +146,19 @@ DYNDBG_CLASSMAP_DEFINE(classid_range_conflict, 0, D2_CORE + 1, "D3_CORE");
> > DYNAMIC_DEBUG_CLASSMAP_USE(map_disjoint_bits);
> > DYNAMIC_DEBUG_CLASSMAP_USE(map_level_num);
> >
> > +#if defined(DD_MACRO_ARGCHECK)
> > +/*
> > + * Exersize compile-time arg-checks in DYNDBG_CLASSMAP_DEFINE.
> > + * These will break compilation.
> > + */
> > +DYNDBG_CLASSMAP_DEFINE(fail_base_neg, 0, -1, "NEGATIVE_BASE_ARG");
> > +DYNDBG_CLASSMAP_DEFINE(fail_base_big, 0, 100, "TOOBIG_BASE_ARG");
> > +DYNDBG_CLASSMAP_DEFINE(fail_str_type, 0, 0, 1 /* not a string */);
> > +DYNDBG_CLASSMAP_DEFINE(fail_emptyclass, 0, 0 /* ,empty */);
> > #endif
> >
> > +#endif /* TEST_DYNAMIC_DEBUG_SUBMOD */
> > +
> > /* stand-in for all pr_debug etc */
> > #define prdbg(SYM) __pr_debug_cls(SYM, #SYM " msg\n")
> >
>
> --
> Louis Chauvet, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
>
>
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 21/54] dyndbg-test: change do_prints testpoint to accept a loopct
2025-04-15 10:04 ` Louis Chauvet
@ 2025-04-15 20:15 ` jim.cromie
0 siblings, 0 replies; 81+ messages in thread
From: jim.cromie @ 2025-04-15 20:15 UTC (permalink / raw)
To: Louis Chauvet
Cc: jbaron, gregkh, ukaszb, linux-kernel, dri-devel, amd-gfx,
intel-gvt-dev, intel-gfx, daniel.vetter, tvrtko.ursulin,
jani.nikula, ville.syrjala
On Tue, Apr 15, 2025 at 4:04 AM Louis Chauvet <louis.chauvet@bootlin.com> wrote:
>
>
>
> Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> > echo 1000 > /sys/module/test_dynamic_debug/parameters/do_prints
> >
> > This allows its use as a scriptable load generator, to generate
> > dynamic-prefix-emits for flag combinations vs undecorated messages.
> > This will make it easy to assess the cost of the prefixing.
> >
> > Reading the ./do_prints node also prints messages (once) to the-log.
> >
> > NB: the count is clamped to 10000, chosen to be notice able, but not
> > annoying, and not enough to accidentally flood the logs.
> >
> > Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
>
> Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
>
> I think this could be in a separate series / merged independently to
> reduce the size of this series.
I have no strong opinions here.
I included it to acknowledge that this patchset is mainly for performance,
ie to replace LOTS of bit-tests, (some of which are tested at framerate).
So it follows that I should be able to demonstrate the savings somehow.
I havent done so yet, I was hoping that the benefits are obvious
enough not require proof.
>
> > ---
> > lib/test_dynamic_debug.c | 37 ++++++++++++++++++++++++++-----------
> > 1 file changed, 26 insertions(+), 11 deletions(-)
> >
> > diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
> > index 9f9e3fddd7e6..4a3d2612ef60 100644
> > --- a/lib/test_dynamic_debug.c
> > +++ b/lib/test_dynamic_debug.c
> > @@ -29,18 +29,30 @@
> >
> > #include <linux/module.h>
> >
> > -/* re-gen output by reading or writing sysfs node: do_prints */
> > -
> > -static void do_prints(void); /* device under test */
> > +/* re-trigger debug output by reading or writing sysfs node: do_prints */
> > +#define PRINT_CLAMP 10000
> > +static void do_prints(unsigned int); /* device under test */
> > static int param_set_do_prints(const char *instr, const struct kernel_param *kp)
> > {
> > - do_prints();
> > + int rc;
> > + unsigned int ct;
> > +
> > + rc = kstrtouint(instr, 0, &ct);
> > + if (rc) {
> > + pr_err("expecting numeric input, using 1 instead\n");
> > + ct = 1;
> > + }
> > + if (ct > PRINT_CLAMP) {
> > + ct = PRINT_CLAMP;
> > + pr_info("clamping print-count to %d\n", ct);
> > + }
> > + do_prints(ct);
> > return 0;
> > }
> > static int param_get_do_prints(char *buffer, const struct kernel_param *kp)
> > {
> > - do_prints();
> > - return scnprintf(buffer, PAGE_SIZE, "did do_prints\n");
> > + do_prints(1);
> > + return scnprintf(buffer, PAGE_SIZE, "did 1 do_prints\n");
> > }
> > static const struct kernel_param_ops param_ops_do_prints = {
> > .set = param_set_do_prints,
> > @@ -191,17 +203,20 @@ static void do_levels(void)
> > prdbg(V7);
> > }
> >
> > -static void do_prints(void)
> > +static void do_prints(unsigned int ct)
> > {
> > - pr_debug("do_prints:\n");
> > - do_cats();
> > - do_levels();
> > + /* maybe clamp this */
> > + pr_debug("do-prints %d times:\n", ct);
> > + for (; ct; ct--) {
> > + do_cats();
> > + do_levels();
> > + }
> > }
> >
> > static int __init test_dynamic_debug_init(void)
> > {
> > pr_debug("init start\n");
> > - do_prints();
> > + do_prints(1);
> > pr_debug("init done\n");
> > return 0;
> > }
>
> --
> Louis Chauvet, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
>
>
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 23/54] dyndbg: treat comma as a token separator
2025-04-15 10:04 ` Louis Chauvet
@ 2025-04-15 20:17 ` jim.cromie
0 siblings, 0 replies; 81+ messages in thread
From: jim.cromie @ 2025-04-15 20:17 UTC (permalink / raw)
To: Louis Chauvet
Cc: jbaron, gregkh, ukaszb, linux-kernel, dri-devel, amd-gfx,
intel-gvt-dev, intel-gfx, daniel.vetter, tvrtko.ursulin,
jani.nikula, ville.syrjala
On Tue, Apr 15, 2025 at 4:05 AM Louis Chauvet <louis.chauvet@bootlin.com> wrote:
>
>
>
> Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> > Treat comma as a token terminator, just like a space. This allows a
> > user to avoid quoting hassles when spaces are otherwise needed:
> >
> > :#> modprobe drm dyndbg=class,DRM_UT_CORE,+p\;class,DRM_UT_KMS,+p
> >
> > or as a boot arg:
> >
> > drm.dyndbg=class,DRM_UT_CORE,+p # todo: support multi-query here
> >
> > Given the many ways a boot-line +args can be assembled and then passed
> > in/down/around shell based tools, this may allow side-stepping all
> > sorts of quoting hassles thru those layers.
> >
> > existing query format:
> >
> > modprobe test_dynamic_debug dyndbg="class D2_CORE +p"
> >
> > new format:
> >
> > modprobe test_dynamic_debug dyndbg=class,D2_CORE,+p
> >
> > ALSO
> >
> > selftests-dyndbg: add comma_terminator_tests
> >
> > New fn validates parsing and effect of queries using combinations of
> > commas and spaces to delimit the tokens.
> >
> > It manipulates pr-debugs in builtin module/params, so might have deps
> > I havent foreseen on odd configurations.
> >
> > Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> > Co-developed-by: Łukasz Bartosik <ukaszb@chromium.org>
> > Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
> > ---
> > - skip comma tests if no builtins
> > -v3 squash in tests and doc
> > ---
> > .../admin-guide/dynamic-debug-howto.rst | 9 +++++---
> > lib/dynamic_debug.c | 17 +++++++++++----
> > .../dynamic_debug/dyndbg_selftest.sh | 21 ++++++++++++++++++-
> > 3 files changed, 39 insertions(+), 8 deletions(-)
> >
> > diff --git a/Documentation/admin-guide/dynamic-debug-howto.rst b/Documentation/admin-guide/dynamic-debug-howto.rst
> > index 63a511f2337b..e2dbb5d9b314 100644
> > --- a/Documentation/admin-guide/dynamic-debug-howto.rst
> > +++ b/Documentation/admin-guide/dynamic-debug-howto.rst
> > @@ -78,11 +78,12 @@ Command Language Reference
> > ==========================
> >
> > At the basic lexical level, a command is a sequence of words separated
> > -by spaces or tabs. So these are all equivalent::
> > +by spaces, tabs, or commas. So these are all equivalent::
> >
> > :#> ddcmd file svcsock.c line 1603 +p
> > :#> ddcmd "file svcsock.c line 1603 +p"
> > :#> ddcmd ' file svcsock.c line 1603 +p '
> > + :#> ddcmd file,svcsock.c,line,1603,+p
> >
> > Command submissions are bounded by a write() system call.
> > Multiple commands can be written together, separated by ``;`` or ``\n``::
> > @@ -167,9 +168,11 @@ 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::
> > + suffix and with ``-`` changed to ``_``.
> >
> > - module sunrpc
> > + Examples::
> > +
> > + module,sunrpc # with ',' as token separator
> > module nfsd
> > module drm* # both drm, drm_kms_helper
> >
> > diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
> > index 0d603caadef8..5737f1b4eba8 100644
> > --- a/lib/dynamic_debug.c
> > +++ b/lib/dynamic_debug.c
> > @@ -299,6 +299,14 @@ static int ddebug_change(const struct ddebug_query *query, struct flag_settings
> > return nfound;
> > }
> >
> > +static char *skip_spaces_and_commas(const char *str)
> > +{
> > + str = skip_spaces(str);
> > + while (*str == ',')
> > + str = skip_spaces(++str);
> > + return (char *)str;
> > +}
> > +
> > /*
> > * Split the buffer `buf' into space-separated words.
> > * Handles simple " and ' quoting, i.e. without nested,
> > @@ -312,8 +320,8 @@ static int ddebug_tokenize(char *buf, char *words[], int maxwords)
> > while (*buf) {
> > char *end;
> >
> > - /* Skip leading whitespace */
> > - buf = skip_spaces(buf);
> > + /* Skip leading whitespace and comma */
> > + buf = skip_spaces_and_commas(buf);
> > if (!*buf)
> > break; /* oh, it was trailing whitespace */
> > if (*buf == '#')
> > @@ -329,7 +337,7 @@ static int ddebug_tokenize(char *buf, char *words[], int maxwords)
> > return -EINVAL; /* unclosed quote */
> > }
> > } else {
> > - for (end = buf; *end && !isspace(*end); end++)
> > + for (end = buf; *end && !isspace(*end) && *end != ','; end++)
> > ;
>
> Why don't you use the skip_spaces_and_commas here?
yes, thx. I will.
>
> > if (end == buf) {
> > pr_err("parse err after word:%d=%s\n", nwords,
> > @@ -601,7 +609,8 @@ static int ddebug_exec_queries(char *query, const char *modname)
> > if (split)
> > *split++ = '\0';
> >
> > - query = skip_spaces(query);
> > + query = skip_spaces_and_commas(query);
> > +
> > if (!query || !*query || *query == '#')
> > continue;
> >
> > diff --git a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
> > index 465fad3f392c..c7bf521f36ee 100755
> > --- a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
> > +++ b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
> > @@ -216,7 +216,7 @@ function check_err_msg() {
> > function basic_tests {
> > echo -e "${GREEN}# BASIC_TESTS ${NC}"
> > if [ $LACK_DD_BUILTIN -eq 1 ]; then
> > - echo "SKIP"
> > + echo "SKIP - test requires params, which is a builtin module"
> > return
> > fi
> > ddcmd =_ # zero everything
> > @@ -238,8 +238,27 @@ EOF
> > ddcmd =_
> > }
> >
> > +function comma_terminator_tests {
> > + echo -e "${GREEN}# COMMA_TERMINATOR_TESTS ${NC}"
> > + if [ $LACK_DD_BUILTIN -eq 1 ]; then
> > + echo "SKIP - test requires params, which is a builtin module"
> > + return
> > + fi
> > + # try combos of spaces & commas
> > + check_match_ct '\[params\]' 4 -r
> > + ddcmd module,params,=_ # commas as spaces
> > + ddcmd module,params,+mpf # turn on module's pr-debugs
> > + check_match_ct =pmf 4
> > + ddcmd ,module ,, , params, -p
> > + check_match_ct =mf 4
> > + ddcmd " , module ,,, , params, -m" #
> > + check_match_ct =f 4
> > + ddcmd =_
> > +}
> > +
> > tests_list=(
> > basic_tests
> > + comma_terminator_tests
> > )
> >
> > # Run tests
>
> --
> Louis Chauvet, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
>
>
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 26/54] dyndbg: change __dynamic_func_call_cls* macros into expressions
2025-04-15 10:06 ` Louis Chauvet
@ 2025-04-15 22:49 ` jim.cromie
0 siblings, 0 replies; 81+ messages in thread
From: jim.cromie @ 2025-04-15 22:49 UTC (permalink / raw)
To: Louis Chauvet
Cc: jbaron, gregkh, ukaszb, linux-kernel, dri-devel, amd-gfx,
intel-gvt-dev, intel-gfx, daniel.vetter, tvrtko.ursulin,
jani.nikula, ville.syrjala
On Tue, Apr 15, 2025 at 4:06 AM Louis Chauvet <louis.chauvet@bootlin.com> wrote:
>
>
>
> Le 02/04/2025 à 19:41, Jim Cromie a écrit :
> > The Xe driver's XE_IOCTL_DBG macro calls drm_dbg() from inside an if
> > (expression). This breaks when CONFIG_DRM_USE_DYNAMIC_DEBUG=y because
> > the invoked macro has a do-while-0 wrapper.
> >
> > if (cond && (drm_dbg("expr-form"),1)) {
> > ... do some more stuff
> > }
> >
> > Fix for this usage by changing __dynamic_func_call_cls{,_no_desc}
> > macros into expressions, by replacing the do-while-0s with a ({ })
> > wrapper. In the common usage, the trailing ';' converts the
> > expression into a statement.
> >
> > drm_dbg("statement form");
> >
> > Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> > ---
> > ---
> > include/linux/dynamic_debug.h | 12 ++++++------
> > 1 file changed, 6 insertions(+), 6 deletions(-)
> >
> > diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
> > index ce221a702f84..2d87cca27544 100644
> > --- a/include/linux/dynamic_debug.h
> > +++ b/include/linux/dynamic_debug.h
> > @@ -337,20 +337,20 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
> > * (|_cls): adds in _DPRINT_CLASS_DFLT as needed
> > * (|_no_desc): former gets callsite descriptor as 1st arg (for prdbgs)
> > */
> > -#define __dynamic_func_call_cls(id, cls, fmt, func, ...) do { \
> > - DEFINE_DYNAMIC_DEBUG_METADATA_CLS((id), cls, fmt); \
> > +#define __dynamic_func_call_cls(id, cls, fmt, func, ...) ({ \
> > + DEFINE_DYNAMIC_DEBUG_METADATA_CLS(id, cls, fmt); \
>
> You remove the protection around id here.
>
> > if (DYNAMIC_DEBUG_BRANCH(id)) \
> > - func(&id, ##__VA_ARGS__); \
> > -} while (0)
> > + func(&(id), ##__VA_ARGS__); \
>
> But you add the protection here.
>
> I think in macro it is better to be defensive, so I expect to have ()
> everywhere (except places where it breaks the compilation).
>
yeah, Im a bit inconsistent.
defensive parens are almost never a compilation err.
I'll go thru the macros again
> > +})
> > #define __dynamic_func_call(id, fmt, func, ...) \
> > __dynamic_func_call_cls(id, _DPRINTK_CLASS_DFLT, fmt, \
> > func, ##__VA_ARGS__)
> >
> > -#define __dynamic_func_call_cls_no_desc(id, cls, fmt, func, ...) do { \
> > +#define __dynamic_func_call_cls_no_desc(id, cls, fmt, func, ...) ({ \
> > DEFINE_DYNAMIC_DEBUG_METADATA_CLS(id, cls, fmt); \
> > if (DYNAMIC_DEBUG_BRANCH(id)) \
> > func(__VA_ARGS__); \
> > -} while (0)
> > +})
> > #define __dynamic_func_call_no_desc(id, fmt, func, ...) \
> > __dynamic_func_call_cls_no_desc(id, _DPRINTK_CLASS_DFLT, \
> > fmt, func, ##__VA_ARGS__)
>
> --
> Louis Chauvet, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
>
>
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 20/54] dyndbg: check DYNAMIC_DEBUG_CLASSMAP_DEFINE args at compile-time
2025-04-15 19:54 ` jim.cromie
@ 2025-04-16 6:54 ` Louis Chauvet
0 siblings, 0 replies; 81+ messages in thread
From: Louis Chauvet @ 2025-04-16 6:54 UTC (permalink / raw)
To: jim.cromie
Cc: jbaron, gregkh, ukaszb, linux-kernel, dri-devel, amd-gfx,
intel-gvt-dev, intel-gfx, daniel.vetter, tvrtko.ursulin,
jani.nikula, ville.syrjala
Le 15/04/2025 à 21:54, jim.cromie@gmail.com a écrit :
> On Tue, Apr 15, 2025 at 4:04 AM Louis Chauvet <louis.chauvet@bootlin.com> wrote:
>>
>>
>>
>> Le 02/04/2025 à 19:41, Jim Cromie a écrit :
>>> Add __DYNAMIC_DEBUG_CLASSMAP_CHECK to implement the following
>>> arg-checks at compile-time:
>>>
>>> 0 <= _base < 63
>>> class_names is not empty
>>> class_names[0] is a string
>>
>> I don't see where this is checked, did I miss something?
>
> kinda/sorta ? theres no explicit check for "string".
> BUT
> this would fail, cuz 1 doesnt fit into a char* arr[0]
You are totally right, I was looking for a static_assert, but the
compiler do some checks too, sorry!
>>> +DYNDBG_CLASSMAP_DEFINE(fail_str_type, 0, 0, 1 /* not a string */);
>
> Im perhaps over-simplifying the description
>
>>
>>> (class_names.length + _base) < 63
>>>
>>> These compile-time checks will prevent several misuses; 4 such
>>> examples are added to test_dynamic_debug_submod.ko, and will fail
>>> compilation if -DDD_MACRO_ARGCHECK is added to cflags. This wouldn't
>>> be a useful CONFIG_ item, since it breaks the build.
>>>
>>> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
>>> ---
>>> v3- $macro_name =~ s/DYNDBG/DYNAMIC_DEBUG/
>>>
>>> prev-
>>> - split static-asserts to __DYNDBG_CLASSMAP_CHECK
>>> - move __DYNDBG_CLASSMAP_CHECK above kdoc for DYNDBG_CLASSMAP_DEFINE
>>> silences kernel-doc warnings
>>> ---
>>> include/linux/dynamic_debug.h | 9 +++++++++
>>> lib/test_dynamic_debug.c | 11 +++++++++++
>>> 2 files changed, 20 insertions(+)
>>>
>>> diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
>>> index 9af825c84e70..4941ef2adb46 100644
>>> --- a/include/linux/dynamic_debug.h
>>> +++ b/include/linux/dynamic_debug.h
>>> @@ -99,6 +99,14 @@ struct _ddebug_class_map {
>>> enum ddebug_class_map_type map_type;
>>> };
>>>
>>> +#define __DYNAMIC_DEBUG_CLASSMAP_CHECK(_clnames, _base) \
>>> + static_assert(((_base) >= 0 && (_base) < _DPRINTK_CLASS_DFLT), \
>>> + "_base must be in 0..62"); \
>>> + static_assert(ARRAY_SIZE(_clnames) > 0, \
>>> + "classnames array size must be > 0"); \
>>> + static_assert((ARRAY_SIZE(_clnames) + (_base)) < _DPRINTK_CLASS_DFLT, \
>>> + "_base + classnames.length exceeds range")
>>> +
>>> /**
>>> * DYNAMIC_DEBUG_CLASSMAP_DEFINE - define debug classes used by a module.
>>> * @_var: name of the classmap, exported for other modules coordinated use.
>>> @@ -112,6 +120,7 @@ struct _ddebug_class_map {
>>> */
>>> #define DYNAMIC_DEBUG_CLASSMAP_DEFINE(_var, _mapty, _base, ...) \
>>> static const char *_var##_classnames[] = { __VA_ARGS__ }; \
>>
>> Or maybe it was already enforced by this, but in this case the commit
>> message contains too much checks.
>>
>>> + __DYNAMIC_DEBUG_CLASSMAP_CHECK(_var##_classnames, (_base)); \
>>> extern struct _ddebug_class_map _var; \
>>> struct _ddebug_class_map __aligned(8) __used \
>>> __section("__dyndbg_class_maps") _var = { \
>>> diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
>>> index e42916b08fd4..9f9e3fddd7e6 100644
>>> --- a/lib/test_dynamic_debug.c
>>> +++ b/lib/test_dynamic_debug.c
>>> @@ -146,8 +146,19 @@ DYNDBG_CLASSMAP_DEFINE(classid_range_conflict, 0, D2_CORE + 1, "D3_CORE");
>>> DYNAMIC_DEBUG_CLASSMAP_USE(map_disjoint_bits);
>>> DYNAMIC_DEBUG_CLASSMAP_USE(map_level_num);
>>>
>>> +#if defined(DD_MACRO_ARGCHECK)
>>> +/*
>>> + * Exersize compile-time arg-checks in DYNDBG_CLASSMAP_DEFINE.
>>> + * These will break compilation.
>>> + */
>>> +DYNDBG_CLASSMAP_DEFINE(fail_base_neg, 0, -1, "NEGATIVE_BASE_ARG");
>>> +DYNDBG_CLASSMAP_DEFINE(fail_base_big, 0, 100, "TOOBIG_BASE_ARG");
>>> +DYNDBG_CLASSMAP_DEFINE(fail_str_type, 0, 0, 1 /* not a string */);
>>> +DYNDBG_CLASSMAP_DEFINE(fail_emptyclass, 0, 0 /* ,empty */);
>>> #endif
>>>
>>> +#endif /* TEST_DYNAMIC_DEBUG_SUBMOD */
>>> +
>>> /* stand-in for all pr_debug etc */
>>> #define prdbg(SYM) __pr_debug_cls(SYM, #SYM " msg\n")
>>>
>>
>> --
>> Louis Chauvet, Bootlin
>> Embedded Linux and Kernel engineering
>> https://bootlin.com
>>
>>
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 28/54] dyndbg: restore classmap protection when theres a controlling_param
2025-04-02 17:41 ` [PATCH v3 28/54] dyndbg: restore classmap protection when theres a controlling_param Jim Cromie
@ 2025-06-20 14:41 ` Sean Paul
2025-07-29 22:00 ` jim.cromie
0 siblings, 1 reply; 81+ messages in thread
From: Sean Paul @ 2025-06-20 14:41 UTC (permalink / raw)
To: Jim Cromie
Cc: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel, dri-devel,
amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter, tvrtko.ursulin,
jani.nikula, ville.syrjala
On Thu, Apr 3, 2025 at 9:48 AM Jim Cromie <jim.cromie@gmail.com> wrote:
>
\snip
>
> -static void ddebug_match_apply_kparam(const struct kernel_param *kp,
> - const struct _ddebug_class_map *map,
> - const char *mod_name)
> +static struct _ddebug_class_param *
> +ddebug_get_classmap_kparam(const struct kernel_param *kp,
> + const struct _ddebug_class_map *map)
> {
> struct _ddebug_class_param *dcp;
>
> if (kp->ops != ¶m_ops_dyndbg_classes)
> - return;
> + return false;
Return type is struct _ddebug_class_param *, should this be NULL?
>
> dcp = (struct _ddebug_class_param *)kp->arg;
>
> - if (map == dcp->map) {
> + return (map == dcp->map)
> + ? dcp : (struct _ddebug_class_param *)NULL;
> +}
> +
> +static void ddebug_match_apply_kparam(const struct kernel_param *kp,
> + struct _ddebug_class_map *map,
> + const char *mod_name)
> +{
> + struct _ddebug_class_param *dcp = ddebug_get_classmap_kparam(kp, map);
> +
> + if (dcp) {
> + map->controlling_param = dcp;
> v2pr_info(" kp:%s.%s =0x%lx", mod_name, kp->name, *dcp->bits);
> vpr_cm_info(map, " %s mapped to: ", mod_name);
> ddebug_sync_classbits(kp, mod_name);
> }
> }
>
> -static void ddebug_apply_params(const struct _ddebug_class_map *cm, const char *mod_name)
> +static void ddebug_apply_params(struct _ddebug_class_map *cm, const char *mod_name)
> {
> const struct kernel_param *kp;
> #if IS_ENABLED(CONFIG_MODULES)
> @@ -1266,6 +1288,13 @@ static void ddebug_apply_params(const struct _ddebug_class_map *cm, const char *
> }
> }
>
> +/*
> + * called from add_module, ie early. it can find controlling kparams,
> + * which can/does? enable protection of this classmap from class-less
> + * queries, on the grounds that the user created the kparam, means to
> + * use it, and expects it to reflect reality. We should oblige him,
> + * and protect those classmaps from classless "-p" changes.
> + */
> static void ddebug_apply_class_maps(const struct _ddebug_info *di)
> {
> struct _ddebug_class_map *cm;
> --
> 2.49.0
>
^ permalink raw reply [flat|nested] 81+ messages in thread
* Re: [PATCH v3 28/54] dyndbg: restore classmap protection when theres a controlling_param
2025-06-20 14:41 ` Sean Paul
@ 2025-07-29 22:00 ` jim.cromie
0 siblings, 0 replies; 81+ messages in thread
From: jim.cromie @ 2025-07-29 22:00 UTC (permalink / raw)
To: Sean Paul
Cc: jbaron, gregkh, ukaszb, louis.chauvet, linux-kernel, dri-devel,
amd-gfx, intel-gvt-dev, intel-gfx, daniel.vetter, tvrtko.ursulin,
jani.nikula, ville.syrjala
[-- Attachment #1: Type: text/plain, Size: 876 bytes --]
On Fri, Jun 20, 2025 at 8:47 AM Sean Paul <seanpaul@chromium.org> wrote:
> On Thu, Apr 3, 2025 at 9:48 AM Jim Cromie <jim.cromie@gmail.com> wrote:
> >
>
> \snip
>
> >
> > -static void ddebug_match_apply_kparam(const struct kernel_param *kp,
> > - const struct _ddebug_class_map
> *map,
> > - const char *mod_name)
> > +static struct _ddebug_class_param *
> > +ddebug_get_classmap_kparam(const struct kernel_param *kp,
> > + const struct _ddebug_class_map *map)
> > {
> > struct _ddebug_class_param *dcp;
> >
> > if (kp->ops != ¶m_ops_dyndbg_classes)
> > - return;
> > + return false;
>
> Return type is struct _ddebug_class_param *, should this be NULL?
>
>
yes it should. thx. will revise
>
>
[-- Attachment #2: Type: text/html, Size: 1590 bytes --]
^ permalink raw reply [flat|nested] 81+ messages in thread
end of thread, other threads:[~2025-07-30 6:55 UTC | newest]
Thread overview: 81+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-02 17:41 [PATCH v3 00/54] Fix CONFIG_DRM_USE_DYNAMIC_DEBUG=y Jim Cromie
2025-04-02 17:41 ` [PATCH v3 01/54] vmlinux.lds.h: fixup HEADERED_SECTION{,_BY} macros Jim Cromie
2025-04-15 9:59 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 02/54] docs/dyndbg: update examples \012 to \n Jim Cromie
2025-04-15 9:59 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 03/54] docs/dyndbg: explain flags parse 1st Jim Cromie
2025-04-02 17:41 ` [PATCH v3 04/54] test-dyndbg: fixup CLASSMAP usage error Jim Cromie
2025-04-02 17:41 ` [PATCH v3 05/54] dyndbg: reword "class unknown, " to "class:_UNKNOWN_" Jim Cromie
2025-04-02 17:41 ` [PATCH v3 06/54] dyndbg: make ddebug_class_param union members same size Jim Cromie
2025-04-02 17:41 ` [PATCH v3 07/54] dyndbg: drop NUM_TYPE_ARRAY Jim Cromie
2025-04-02 17:41 ` [PATCH v3 08/54] dyndbg: reduce verbose/debug clutter Jim Cromie
2025-04-02 17:41 ` [PATCH v3 09/54] dyndbg: refactor param_set_dyndbg_classes and below Jim Cromie
2025-04-02 17:41 ` [PATCH v3 10/54] dyndbg: tighten fn-sig of ddebug_apply_class_bitmap Jim Cromie
2025-04-02 17:41 ` [PATCH v3 11/54] dyndbg: replace classmap list with a vector Jim Cromie
2025-04-15 9:59 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 12/54] dyndbg: macrofy a 2-index for-loop pattern Jim Cromie
2025-04-02 17:41 ` [PATCH v3 13/54] dyndbg, module: make proper substructs in _ddebug_info Jim Cromie
2025-04-15 9:59 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 14/54] dyndbg: hoist classmap-filter-by-modname up to ddebug_add_module Jim Cromie
2025-04-15 10:00 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 15/54] dyndbg: ddebug_table.mod_name down to _ddebug_info Jim Cromie
2025-04-02 17:41 ` [PATCH v3 16/54] dyndbg-API: remove DD_CLASS_TYPE_(DISJOINT|LEVEL)_NAMES and code Jim Cromie
2025-04-15 10:00 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 17/54] dyndbg-API: replace DECLARE_DYNDBG_CLASSMAP Jim Cromie
2025-04-15 10:01 ` Louis Chauvet
2025-04-15 19:38 ` jim.cromie
2025-04-02 17:41 ` [PATCH v3 18/54] selftests-dyndbg: add tools/testing/selftests/dynamic_debug/* Jim Cromie
2025-04-15 10:02 ` Louis Chauvet
2025-04-15 19:46 ` jim.cromie
2025-04-02 17:41 ` [PATCH v3 19/54] dyndbg: detect class_id reservation conflicts Jim Cromie
2025-04-15 10:03 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 20/54] dyndbg: check DYNAMIC_DEBUG_CLASSMAP_DEFINE args at compile-time Jim Cromie
2025-04-15 10:04 ` Louis Chauvet
2025-04-15 19:54 ` jim.cromie
2025-04-16 6:54 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 21/54] dyndbg-test: change do_prints testpoint to accept a loopct Jim Cromie
2025-04-15 10:04 ` Louis Chauvet
2025-04-15 20:15 ` jim.cromie
2025-04-02 17:41 ` [PATCH v3 22/54] dyndbg-API: promote DYNAMIC_DEBUG_CLASSMAP_PARAM to API Jim Cromie
2025-04-15 10:06 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 23/54] dyndbg: treat comma as a token separator Jim Cromie
2025-04-15 10:04 ` Louis Chauvet
2025-04-15 20:17 ` jim.cromie
2025-04-02 17:41 ` [PATCH v3 24/54] dyndbg: split multi-query strings with % Jim Cromie
2025-04-02 17:41 ` [PATCH v3 25/54] selftests-dyndbg: add test_mod_submod Jim Cromie
2025-04-02 17:41 ` [PATCH v3 26/54] dyndbg: change __dynamic_func_call_cls* macros into expressions Jim Cromie
2025-04-15 10:06 ` Louis Chauvet
2025-04-15 22:49 ` jim.cromie
2025-04-02 17:41 ` [PATCH v3 27/54] dyndbg: drop "protection" of class'd pr_debugs from legacy queries Jim Cromie
2025-04-15 10:06 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 28/54] dyndbg: restore classmap protection when theres a controlling_param Jim Cromie
2025-06-20 14:41 ` Sean Paul
2025-07-29 22:00 ` jim.cromie
2025-04-02 17:41 ` [PATCH v3 29/54] docs/dyndbg: add classmap info to howto Jim Cromie
2025-04-15 10:06 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 30/54] drm: use correct ccflags-y spelling Jim Cromie
2025-04-02 17:41 ` [PATCH v3 31/54] drm-dyndbg: adapt drm core to use dyndbg classmaps-v2 Jim Cromie
2025-04-02 17:41 ` [PATCH v3 32/54] drm-dyndbg: adapt DRM to invoke DYNAMIC_DEBUG_CLASSMAP_PARAM Jim Cromie
2025-04-02 17:41 ` [PATCH v3 33/54] drm-print: fix config-dependent unused variable Jim Cromie
2025-04-02 17:41 ` [PATCH v3 34/54] drm-dyndbg: DRM_CLASSMAP_USE in amdgpu driver Jim Cromie
2025-04-02 17:41 ` [PATCH v3 35/54] drm-dyndbg: DRM_CLASSMAP_USE in i915 driver Jim Cromie
2025-04-02 17:41 ` [PATCH v3 36/54] drm-dyndbg: DRM_CLASSMAP_USE in drm_crtc_helper Jim Cromie
2025-04-02 17:41 ` [PATCH v3 37/54] drm-dyndbg: DRM_CLASSMAP_USE in drm_dp_helper Jim Cromie
2025-04-02 17:41 ` [PATCH v3 38/54] drm-dyndbg: DRM_CLASSMAP_USE in nouveau Jim Cromie
2025-04-02 17:41 ` [PATCH v3 39/54] drm-dyndbg: add DRM_CLASSMAP_USE to Xe driver Jim Cromie
2025-04-02 17:41 ` [PATCH v3 40/54] drm-dyndbg: add DRM_CLASSMAP_USE to virtio_gpu Jim Cromie
2025-04-02 17:41 ` [PATCH v3 41/54] drm-dyndbg: add DRM_CLASSMAP_USE to simpledrm Jim Cromie
2025-04-02 17:41 ` [PATCH v3 42/54] drm-dyndbg: add DRM_CLASSMAP_USE to bochs Jim Cromie
2025-04-02 17:41 ` [PATCH v3 43/54] drm-dyndbg: add DRM_CLASSMAP_USE to etnaviv Jim Cromie
2025-04-02 17:41 ` [PATCH v3 44/54] drm-dyndbg: add DRM_CLASSMAP_USE to gma500 driver Jim Cromie
2025-04-02 17:41 ` [PATCH v3 45/54] drm-dyndbg: add DRM_CLASSMAP_USE to radeon Jim Cromie
2025-04-02 17:41 ` [PATCH v3 46/54] drm-dyndbg: add DRM_CLASSMAP_USE to vmwgfx driver Jim Cromie
2025-04-02 17:41 ` [PATCH v3 47/54] drm-dyndbg: add DRM_CLASSMAP_USE to vkms driver Jim Cromie
2025-04-02 17:41 ` [PATCH v3 48/54] drm-dyndbg: add DRM_CLASSMAP_USE to udl driver Jim Cromie
2025-04-02 17:41 ` [PATCH v3 49/54] drm-dyndbg: add DRM_CLASSMAP_USE to mgag200 driver Jim Cromie
2025-04-02 17:41 ` [PATCH v3 50/54] drm-dyndbg: add DRM_CLASSMAP_USE to the gud driver Jim Cromie
2025-04-02 17:41 ` [PATCH v3 51/54] drm-dyndbg: add DRM_CLASSMAP_USE to the qxl driver Jim Cromie
2025-04-02 17:41 ` [PATCH v3 52/54] drm-dyndbg: add DRM_CLASSMAP_USE to the drm_gem_shmem_helper driver Jim Cromie
2025-04-02 17:41 ` [PATCH v3 53/54] drm: restore CONFIG_DRM_USE_DYNAMIC_DEBUG un-BROKEN Jim Cromie
2025-04-15 10:00 ` Louis Chauvet
2025-04-02 17:41 ` [PATCH v3 54/54] drm: RFC - make drm_dyndbg_user.o for drm-*_helpers, drivers Jim Cromie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).