* dyndbg: pr_fmt(fmt) with additional arguments?
@ 2026-02-27 11:12 Philipp Hahn
2026-03-13 12:55 ` Philipp Hahn
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Philipp Hahn @ 2026-02-27 11:12 UTC (permalink / raw)
To: Jason Baron, Jim Cromie, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 957 bytes --]
Hello Jason, hello Jim,
I've been using the following in my modules to prefix all messages with
the module and function name:
#define pr_fmt(fmt) KBUILD_MODNAME ".%s ", __func__
This worked nicely until `pr_debug_ratelimit()` is used: The additional
arguments breaks `DEFINE_DYNAMIC_DEBUG_METADATA_CLS`:
#define pr_debug_ratelimited(fmt, ...) \
DEFINE_DYNAMIC_DEBUG_METADATA(…, pr_fmt(fmt)); \
#define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt) \
DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, …, fmt)
#define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt) \
static struct _ddebug __aligned(8) \
__section("__dyndbg") name = { \
… \
.format = (fmt), \
This could be fixed easily by adding an additional '...' to it to slurp
any additional argument which `pr_fmt` might add.
Would this be okay or do I miss something?
For testing I have recompiled current 7.0.0-rc1 for x86_64 with no
compile failures.
Philipp Hahn
[-- Attachment #2: 0001-dyndbg-Ignore-additional-arguments-from-pr_fmt.quilt --]
[-- Type: text/plain, Size: 2306 bytes --]
From 545173a75e3928ec000b1127bfc99439b7fa2f8b Mon Sep 17 00:00:00 2001
Message-ID: <545173a75e3928ec000b1127bfc99439b7fa2f8b.1772186702.git.p.hahn@avm.de>
From: Philipp Hahn <phahn-oss@avm.de>
Date: Fri, 27 Feb 2026 10:53:04 +0100
Subject: [PATCH] dyndbg: Ignore additional arguments from pr_fmt
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Organization: FRITZ! Technology GmbH, Berlin, Germany
pr_fmt can be used to add a common prefix to any output from a module:
#define pr_fmt(fmt) KBUILD_MODNAME ".%s ", __func__
But adding additional arguments breaks dynamic debug:
> error: macro "DEFINE_DYNAMIC_DEBUG_METADATA_CLS" passed 4 arguments, but takes just 3
> | pr_debug_ratelimited("%s", "Hello world!");
> | ^
> note: macro "DEFINE_DYNAMIC_DEBUG_METADATA_CLS" defined here
> | #define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt) \
> |
> error: ‘DEFINE_DYNAMIC_DEBUG_METADATA_CLS’ undeclared (first use in this function)
> | DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, _DPRINTK_CLASS_DFLT, fmt)
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> note: in expansion of macro ‘DEFINE_DYNAMIC_DEBUG_METADATA’
> | DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> note: in expansion of macro ‘pr_debug_ratelimited’
> | pr_debug_ratelimited("%s", "Hello world!");
> | ^~~~~~~~~~~~~~~~~~~~
Add an additional ', ...' to DEFINE_DYNAMIC_DEBUG_METADATA_CLS to slurp
any additional argument, which `pr_fmt` might add.
Signed-off-by: Philipp Hahn <phahn-oss@avm.de>
---
include/linux/dynamic_debug.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 05743900a1169..0ac0df04bac00 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -167,7 +167,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
dump_stack(); \
}
-#define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt) \
+#define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt, ...) \
static struct _ddebug __aligned(8) \
__section("__dyndbg") name = { \
.modname = KBUILD_MODNAME, \
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: dyndbg: pr_fmt(fmt) with additional arguments?
2026-02-27 11:12 dyndbg: pr_fmt(fmt) with additional arguments? Philipp Hahn
@ 2026-03-13 12:55 ` Philipp Hahn
2026-03-15 23:30 ` jim.cromie
2026-03-17 20:39 ` [PATCH v2] dyndbg: Ignore additional arguments from pr_fmt Philipp Hahn
2 siblings, 0 replies; 5+ messages in thread
From: Philipp Hahn @ 2026-03-13 12:55 UTC (permalink / raw)
To: Jason Baron, Jim Cromie, linux-kernel
Hello,
Am Fri, Feb 27, 2026 at 12:33:18PM +0100 schrieb Philipp Hahn:
> I've been using the following in my modules to prefix all messages with
> the module and function name:
> #define pr_fmt(fmt) KBUILD_MODNAME ".%s ", __func__
<https://docs.kernel.org/core-api/printk-basics.html> itself has the
following example:
> #define pr_fmt(fmt) "%s:%s: " fmt, KBUILD_MODNAME, __func__
This breaks pr_debug_ratelimited().
> This could be fixed easily by adding an additional '...' to
> `DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt)` to slurp any
> additional argument which `pr_fmt` might add.
>
> Would this be okay or do I miss something?
>
> For testing I have recompiled current 7.0.0-rc1 for x86_64 with no
> compile failures.
Ping?
Philipp Hahn
> From 545173a75e3928ec000b1127bfc99439b7fa2f8b Mon Sep 17 00:00:00 2001
> Message-ID: <545173a75e3928ec000b1127bfc99439b7fa2f8b.1772186702.git.p.hahn@avm.de>
> From: Philipp Hahn <phahn-oss@avm.de>
> Date: Fri, 27 Feb 2026 10:53:04 +0100
> Subject: [PATCH] dyndbg: Ignore additional arguments from pr_fmt
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
> Organization: FRITZ! Technology GmbH, Berlin, Germany
>
> pr_fmt can be used to add a common prefix to any output from a module:
> #define pr_fmt(fmt) KBUILD_MODNAME ".%s ", __func__
>
> But adding additional arguments breaks dynamic debug:
> > error: macro "DEFINE_DYNAMIC_DEBUG_METADATA_CLS" passed 4 arguments, but takes just 3
> > | pr_debug_ratelimited("%s", "Hello world!");
> > | ^
> > note: macro "DEFINE_DYNAMIC_DEBUG_METADATA_CLS" defined here
> > | #define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt) \
> > |
> > error: ‘DEFINE_DYNAMIC_DEBUG_METADATA_CLS’ undeclared (first use in this function)
> > | DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, _DPRINTK_CLASS_DFLT, fmt)
> > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > note: in expansion of macro ‘DEFINE_DYNAMIC_DEBUG_METADATA’
> > | DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
> > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > note: in expansion of macro ‘pr_debug_ratelimited’
> > | pr_debug_ratelimited("%s", "Hello world!");
> > | ^~~~~~~~~~~~~~~~~~~~
>
> Add an additional ', ...' to DEFINE_DYNAMIC_DEBUG_METADATA_CLS to slurp
> any additional argument, which `pr_fmt` might add.
>
> Signed-off-by: Philipp Hahn <phahn-oss@avm.de>
> ---
> include/linux/dynamic_debug.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
> index 05743900a1169..0ac0df04bac00 100644
> --- a/include/linux/dynamic_debug.h
> +++ b/include/linux/dynamic_debug.h
> @@ -167,7 +167,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
> dump_stack(); \
> }
>
> -#define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt) \
> +#define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt, ...) \
> static struct _ddebug __aligned(8) \
> __section("__dyndbg") name = { \
> .modname = KBUILD_MODNAME, \
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: dyndbg: pr_fmt(fmt) with additional arguments?
2026-02-27 11:12 dyndbg: pr_fmt(fmt) with additional arguments? Philipp Hahn
2026-03-13 12:55 ` Philipp Hahn
@ 2026-03-15 23:30 ` jim.cromie
2026-03-17 20:41 ` Philipp Hahn
2026-03-17 20:39 ` [PATCH v2] dyndbg: Ignore additional arguments from pr_fmt Philipp Hahn
2 siblings, 1 reply; 5+ messages in thread
From: jim.cromie @ 2026-03-15 23:30 UTC (permalink / raw)
To: Jason Baron, Jim Cromie, linux-kernel, phahn-oss; +Cc: Greg KH
On Fri, Feb 27, 2026 at 4:12 AM Philipp Hahn <phahn-oss@avm.de> wrote:
>
> Hello Jason, hello Jim,
>
> I've been using the following in my modules to prefix all messages with
> the module and function name:
> #define pr_fmt(fmt) KBUILD_MODNAME ".%s ", __func__
Your example loses the fmt, so is not actually useful.
but that said, the compile err is real, I hit it once I changed
1 - the pr_debug("exited") call in test_dynamic_debug.c
to pr_debug_ratelimited.
2- the pr_fmt in same:
#if defined(TEST_DYNAMIC_DEBUG_SUBMOD)
- #define pr_fmt(fmt) "test_dd_submod: " fmt
+ #define pr_fmt(fmt) KBUILD_MODNAME " test_dd_submod: %s" fmt, __func__
2 was my test-case, on my latest branch, yours (on master) will be different.
please add that test to your patch, and my
Acked-by: Jim Cromie <jim.cromie@gmail.com>
>
> This worked nicely until `pr_debug_ratelimit()` is used: The additional
> arguments breaks `DEFINE_DYNAMIC_DEBUG_METADATA_CLS`:
>
> #define pr_debug_ratelimited(fmt, ...) \
> DEFINE_DYNAMIC_DEBUG_METADATA(…, pr_fmt(fmt)); \
>
> #define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt) \
> DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, …, fmt)
>
> #define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt) \
> static struct _ddebug __aligned(8) \
> __section("__dyndbg") name = { \
> … \
> .format = (fmt), \
>
> This could be fixed easily by adding an additional '...' to it to slurp
> any additional argument which `pr_fmt` might add.
>
> Would this be okay or do I miss something?
>
> For testing I have recompiled current 7.0.0-rc1 for x86_64 with no
> compile failures.
>
> Philipp Hahn
I tried this locally, it built and ran w/o errors.
Ackd-by: Jim Cromie <jim.cromie@gmail.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] dyndbg: Ignore additional arguments from pr_fmt
2026-02-27 11:12 dyndbg: pr_fmt(fmt) with additional arguments? Philipp Hahn
2026-03-13 12:55 ` Philipp Hahn
2026-03-15 23:30 ` jim.cromie
@ 2026-03-17 20:39 ` Philipp Hahn
2 siblings, 0 replies; 5+ messages in thread
From: Philipp Hahn @ 2026-03-17 20:39 UTC (permalink / raw)
To: Jason Baron, Jim Cromie; +Cc: linux-kernel, Philipp Hahn
pr_fmt can be used to add a common prefix to any output from a module:
#define pr_fmt(fmt) KBUILD_MODNAME ".%s " fmt, __func__
But adding additional arguments breaks dynamic debug:
> error: macro "DEFINE_DYNAMIC_DEBUG_METADATA_CLS" passed 4 arguments, but takes just 3
> | pr_debug_ratelimited("%s", "Hello world!");
> | ^
> note: macro "DEFINE_DYNAMIC_DEBUG_METADATA_CLS" defined here
> | #define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt) \
> |
> error: ‘DEFINE_DYNAMIC_DEBUG_METADATA_CLS’ undeclared (first use in this function)
> | DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, _DPRINTK_CLASS_DFLT, fmt)
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> note: in expansion of macro ‘DEFINE_DYNAMIC_DEBUG_METADATA’
> | DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> note: in expansion of macro ‘pr_debug_ratelimited’
> | pr_debug_ratelimited("%s", "Hello world!");
> | ^~~~~~~~~~~~~~~~~~~~
Add an additional ', ...' to DEFINE_DYNAMIC_DEBUG_METADATA_CLS to slurp
any additional argument, which `pr_fmt` might add.
Signed-off-by: Philipp Hahn <phahn-oss@avm.de>
Acked-by: Jim Cromie <jim.cromie@gmail.com>
---
include/linux/dynamic_debug.h | 2 +-
lib/test_dynamic_debug.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 05743900a1169..0ac0df04bac00 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -167,7 +167,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
dump_stack(); \
}
-#define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt) \
+#define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt, ...) \
static struct _ddebug __aligned(8) \
__section("__dyndbg") name = { \
.modname = KBUILD_MODNAME, \
diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
index 77c2a669b6afd..cf1e3b5f6f0f8 100644
--- a/lib/test_dynamic_debug.c
+++ b/lib/test_dynamic_debug.c
@@ -6,7 +6,7 @@
* Jim Cromie <jim.cromie@gmail.com>
*/
-#define pr_fmt(fmt) "test_dd: " fmt
+#define pr_fmt(fmt) "test_dd: %s " fmt, __func__
#include <linux/module.h>
@@ -155,7 +155,7 @@ static int __init test_dynamic_debug_init(void)
static void __exit test_dynamic_debug_exit(void)
{
- pr_debug("exited\n");
+ pr_debug_ratelimited("exited\n");
}
module_init(test_dynamic_debug_init);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: dyndbg: pr_fmt(fmt) with additional arguments?
2026-03-15 23:30 ` jim.cromie
@ 2026-03-17 20:41 ` Philipp Hahn
0 siblings, 0 replies; 5+ messages in thread
From: Philipp Hahn @ 2026-03-17 20:41 UTC (permalink / raw)
To: jim.cromie; +Cc: Jason Baron, linux-kernel, Greg KH
Hello Jim,
Am Sun, Mar 15, 2026 at 05:30:43PM -0600 schrieb jim.cromie@gmail.com:
> On Fri, Feb 27, 2026 at 4:12 AM Philipp Hahn <phahn-oss@avm.de> wrote:
> >
> > Hello Jason, hello Jim,
> >
> > I've been using the following in my modules to prefix all messages with
> > the module and function name:
> > #define pr_fmt(fmt) KBUILD_MODNAME ".%s ", __func__
>
> Your example loses the fmt, so is not actually useful.
Yes, somehow that 'fmt' got lost; I've re-added it.
> but that said, the compile err is real, I hit it once I changed
>
> 1 - the pr_debug("exited") call in test_dynamic_debug.c
> to pr_debug_ratelimited.
>
> 2- the pr_fmt in same:
> #if defined(TEST_DYNAMIC_DEBUG_SUBMOD)
> - #define pr_fmt(fmt) "test_dd_submod: " fmt
> + #define pr_fmt(fmt) KBUILD_MODNAME " test_dd_submod: %s" fmt, __func__
>
> 2 was my test-case, on my latest branch, yours (on master) will be different.
>
> please add that test to your patch, and my
> Acked-by: Jim Cromie <jim.cromie@gmail.com>
I did both; v2 is on it's way. Thank you for your review.
Philipp Hahn
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-03-17 20:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-27 11:12 dyndbg: pr_fmt(fmt) with additional arguments? Philipp Hahn
2026-03-13 12:55 ` Philipp Hahn
2026-03-15 23:30 ` jim.cromie
2026-03-17 20:41 ` Philipp Hahn
2026-03-17 20:39 ` [PATCH v2] dyndbg: Ignore additional arguments from pr_fmt Philipp Hahn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox