* [PATCH] printk.h: fix overzealous pr_fmt in pr_debug_ratelimited
@ 2026-11-25 18:12 Jim Cromie via B4 Relay
0 siblings, 0 replies; only message in thread
From: Jim Cromie via B4 Relay @ 2026-11-25 18:12 UTC (permalink / raw)
To: Petr Mladek, John Ogness, Steven Rostedt, Sergey Senozhatsky,
Jason Baron, Andrew Morton, Jason A. Donenfeld
Cc: printk, linux-kernel, Philipp Hahn, Jim Cromie
From: Jim Cromie <jim.cromie@gmail.com>
Historically, the CONFIG_DYNAMIC_DEBUG implementation of
pr_debug_ratelimited() passed raw fmt to both metadata and runtime:
DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt);
if (unlikely(...) && __ratelimit(&_rs))
__dynamic_pr_debug(&descriptor, fmt, ##__VA_ARGS__);
While descriptor metadata was clean, emitted dmesg records lacked the
pr_fmt prefix present in the !CONFIG_DYNAMIC_DEBUG fallbacks.
In 2015, commit 515a9adce0f0 ("include/linux/printk.h: include pr_fmt
in pr_debug_ratelimited") fixed the missing prefix by wrapping fmt in
__dynamic_pr_debug() with pr_fmt(). However, it also wrapped fmt in
the metadata macro:
DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt));
This causes two problems:
1. Build failure when pr_fmt() expands to multiple arguments, e.g.:
#define pr_fmt(fmt) KBUILD_MODNAME ".%s " fmt, __func__
Passing pr_fmt(fmt) into DEFINE_DYNAMIC_DEBUG_METADATA() expands
across the comma in DEFINE_DYNAMIC_DEBUG_METADATA_CLS(), supplying
4 arguments where it takes 3.
2. Metadata pollution even for single-argument pr_fmt(): baking the
prefix into .format breaks anchored queries such as:
echo format "^foo" > /proc/dynamic_debug/control
Drop the pr_fmt() wrapper from DEFINE_DYNAMIC_DEBUG_METADATA() in
pr_debug_ratelimited(), restoring consistency with dynamic_pr_debug,
dev_dbg_ratelimited, and net_dbg_ratelimited. Update
lib/test_dynamic_debug.c to exercise pr_fmt() with __func__ in
pr_debug_ratelimited().
Reported-by: Philipp Hahn <phahn-oss@avm.de>
Link: https://lore.kernel.org/lkml/a5e3c89fe5f4126873d58dd3472e66c56550ff91.1773779753.git.phahn-oss@avm.de/
Fixes: 515a9adce0f0 ("include/linux/printk.h: include pr_fmt in pr_debug_ratelimited")
Cc: Jason A. Donenfeld <Jason@zx2c4.com>
Cc: Petr Mladek <pmladek@suse.com>
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
include/linux/printk.h | 2 +-
lib/test_dynamic_debug.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/linux/printk.h b/include/linux/printk.h
index f594c1266bfd..cd29fb467b05 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -742,7 +742,7 @@ do { \
static DEFINE_RATELIMIT_STATE(_rs, \
DEFAULT_RATELIMIT_INTERVAL, \
DEFAULT_RATELIMIT_BURST); \
- DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
+ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
if (DYNAMIC_DEBUG_BRANCH(descriptor) && \
__ratelimit(&_rs)) \
__dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
index 77c2a669b6af..cf1e3b5f6f0f 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);
---
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
change-id: 20261125-pr-fmt-1ab0985ffaae
Best regards,
--
Jim Cromie <jim.cromie@gmail.com>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-25 18:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 18:12 [PATCH] printk.h: fix overzealous pr_fmt in pr_debug_ratelimited Jim Cromie via B4 Relay
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®