Skip to content

Commit ceabef7

Browse files
Orson Zhaitorvalds
authored andcommitted
dynamic_debug: add an option to enable dynamic debug for modules only
Instead of enabling dynamic debug globally with CONFIG_DYNAMIC_DEBUG, CONFIG_DYNAMIC_DEBUG_CORE will only enable core function of dynamic debug. With the DYNAMIC_DEBUG_MODULE defined for any modules, dynamic debug will be tied to them. This is useful for people who only want to enable dynamic debug for kernel modules without worrying about kernel image size and memory consumption is increasing too much. [[email protected]: v2] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Orson Zhai <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Acked-by: Greg Kroah-Hartman <[email protected]> Acked-by: Petr Mladek <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Sergey Senozhatsky <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Jason Baron <[email protected]> Cc: Randy Dunlap <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent e1eb26f commit ceabef7

File tree

10 files changed

+46
-14
lines changed

10 files changed

+46
-14
lines changed

Documentation/admin-guide/dynamic-debug-howto.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ kernel code to obtain additional kernel information. Currently, if
1313
``print_hex_dump_debug()``/``print_hex_dump_bytes()`` calls can be dynamically
1414
enabled per-callsite.
1515

16+
If you do not want to enable dynamic debug globally (i.e. in some embedded
17+
system), you may set ``CONFIG_DYNAMIC_DEBUG_CORE`` as basic support of dynamic
18+
debug and add ``ccflags := -DDYNAMIC_DEBUG_MODULE`` into the Makefile of any
19+
modules which you'd like to dynamically debug later.
20+
1621
If ``CONFIG_DYNAMIC_DEBUG`` is not set, ``print_hex_dump_debug()`` is just
1722
shortcut for ``print_hex_dump(KERN_DEBUG)``.
1823

include/linux/dev_printk.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ void _dev_info(const struct device *dev, const char *fmt, ...)
109109
#define dev_info(dev, fmt, ...) \
110110
_dev_info(dev, dev_fmt(fmt), ##__VA_ARGS__)
111111

112-
#if defined(CONFIG_DYNAMIC_DEBUG)
112+
#if defined(CONFIG_DYNAMIC_DEBUG) || \
113+
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
113114
#define dev_dbg(dev, fmt, ...) \
114115
dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
115116
#elif defined(DEBUG)
@@ -181,7 +182,8 @@ do { \
181182
dev_level_ratelimited(dev_notice, dev, fmt, ##__VA_ARGS__)
182183
#define dev_info_ratelimited(dev, fmt, ...) \
183184
dev_level_ratelimited(dev_info, dev, fmt, ##__VA_ARGS__)
184-
#if defined(CONFIG_DYNAMIC_DEBUG)
185+
#if defined(CONFIG_DYNAMIC_DEBUG) || \
186+
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
185187
/* descriptor check is first to prevent flooding with "callbacks suppressed" */
186188
#define dev_dbg_ratelimited(dev, fmt, ...) \
187189
do { \

include/linux/dynamic_debug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct _ddebug {
4848

4949

5050

51-
#if defined(CONFIG_DYNAMIC_DEBUG)
51+
#if defined(CONFIG_DYNAMIC_DEBUG_CORE)
5252
int ddebug_add_module(struct _ddebug *tab, unsigned int n,
5353
const char *modname);
5454
extern int ddebug_remove_module(const char *mod_name);

include/linux/net.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ do { \
264264
net_ratelimited_function(pr_warn, fmt, ##__VA_ARGS__)
265265
#define net_info_ratelimited(fmt, ...) \
266266
net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__)
267-
#if defined(CONFIG_DYNAMIC_DEBUG)
267+
#if defined(CONFIG_DYNAMIC_DEBUG) || \
268+
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
268269
#define net_dbg_ratelimited(fmt, ...) \
269270
do { \
270271
DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \

include/linux/netdevice.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4942,7 +4942,8 @@ do { \
49424942
#define MODULE_ALIAS_NETDEV(device) \
49434943
MODULE_ALIAS("netdev-" device)
49444944

4945-
#if defined(CONFIG_DYNAMIC_DEBUG)
4945+
#if defined(CONFIG_DYNAMIC_DEBUG) || \
4946+
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
49464947
#define netdev_dbg(__dev, format, args...) \
49474948
do { \
49484949
dynamic_netdev_dbg(__dev, format, ##args); \
@@ -5012,7 +5013,8 @@ do { \
50125013
#define netif_info(priv, type, dev, fmt, args...) \
50135014
netif_level(info, priv, type, dev, fmt, ##args)
50145015

5015-
#if defined(CONFIG_DYNAMIC_DEBUG)
5016+
#if defined(CONFIG_DYNAMIC_DEBUG) || \
5017+
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
50165018
#define netif_dbg(priv, type, netdev, format, args...) \
50175019
do { \
50185020
if (netif_msg_##type(priv)) \

include/linux/printk.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,8 @@ extern int kptr_restrict;
399399

400400

401401
/* If you are writing a driver, please use dev_dbg instead */
402-
#if defined(CONFIG_DYNAMIC_DEBUG)
402+
#if defined(CONFIG_DYNAMIC_DEBUG) || \
403+
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
403404
#include <linux/dynamic_debug.h>
404405

405406
/**
@@ -535,7 +536,8 @@ extern int kptr_restrict;
535536
#endif
536537

537538
/* If you are writing a driver, please use dev_dbg instead */
538-
#if defined(CONFIG_DYNAMIC_DEBUG)
539+
#if defined(CONFIG_DYNAMIC_DEBUG) || \
540+
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
539541
/* descriptor check is first to prevent flooding with "callbacks suppressed" */
540542
#define pr_debug_ratelimited(fmt, ...) \
541543
do { \
@@ -582,7 +584,8 @@ static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
582584

583585
#endif
584586

585-
#if defined(CONFIG_DYNAMIC_DEBUG)
587+
#if defined(CONFIG_DYNAMIC_DEBUG) || \
588+
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
586589
#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
587590
groupsize, buf, len, ascii) \
588591
dynamic_hex_dump(prefix_str, prefix_type, rowsize, \

include/rdma/ib_verbs.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ void ibdev_notice(const struct ib_device *ibdev, const char *format, ...);
100100
__printf(2, 3) __cold
101101
void ibdev_info(const struct ib_device *ibdev, const char *format, ...);
102102

103-
#if defined(CONFIG_DYNAMIC_DEBUG)
103+
#if defined(CONFIG_DYNAMIC_DEBUG) || \
104+
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
104105
#define ibdev_dbg(__dev, format, args...) \
105106
dynamic_ibdev_dbg(__dev, format, ##args)
106107
#else
@@ -133,7 +134,8 @@ do { \
133134
#define ibdev_info_ratelimited(ibdev, fmt, ...) \
134135
ibdev_level_ratelimited(ibdev_info, ibdev, fmt, ##__VA_ARGS__)
135136

136-
#if defined(CONFIG_DYNAMIC_DEBUG)
137+
#if defined(CONFIG_DYNAMIC_DEBUG) || \
138+
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
137139
/* descriptor check is first to prevent flooding with "callbacks suppressed" */
138140
#define ibdev_dbg_ratelimited(ibdev, fmt, ...) \
139141
do { \

lib/Kconfig.debug

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ config DYNAMIC_DEBUG
9999
default n
100100
depends on PRINTK
101101
depends on (DEBUG_FS || PROC_FS)
102+
select DYNAMIC_DEBUG_CORE
102103
help
103104

104105
Compiles debug level messages into the kernel, which would not
@@ -165,6 +166,17 @@ config DYNAMIC_DEBUG
165166
See Documentation/admin-guide/dynamic-debug-howto.rst for additional
166167
information.
167168

169+
config DYNAMIC_DEBUG_CORE
170+
bool "Enable core function of dynamic debug support"
171+
depends on PRINTK
172+
depends on (DEBUG_FS || PROC_FS)
173+
help
174+
Enable core functional support of dynamic debug. It is useful
175+
when you want to tie dynamic debug to your kernel modules with
176+
DYNAMIC_DEBUG_MODULE defined for each of them, especially for
177+
the case of embedded system where the kernel image size is
178+
sensitive for people.
179+
168180
config SYMBOLIC_ERRNAME
169181
bool "Support symbolic error names in printf"
170182
default y if PRINTK

lib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ lib-$(CONFIG_GENERIC_BUG) += bug.o
190190

191191
obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o
192192

193-
obj-$(CONFIG_DYNAMIC_DEBUG) += dynamic_debug.o
193+
obj-$(CONFIG_DYNAMIC_DEBUG_CORE) += dynamic_debug.o
194194
obj-$(CONFIG_SYMBOLIC_ERRNAME) += errname.o
195195

196196
obj-$(CONFIG_NLATTR) += nlattr.o

lib/dynamic_debug.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,8 +1032,13 @@ static int __init dynamic_debug_init(void)
10321032
int verbose_bytes = 0;
10331033

10341034
if (&__start___verbose == &__stop___verbose) {
1035-
pr_warn("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n");
1036-
return 1;
1035+
if (IS_ENABLED(CONFIG_DYNAMIC_DEBUG)) {
1036+
pr_warn("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n");
1037+
return 1;
1038+
}
1039+
pr_info("Ignore empty _ddebug table in a CONFIG_DYNAMIC_DEBUG_CORE build\n");
1040+
ddebug_init_success = 1;
1041+
return 0;
10371042
}
10381043
iter = __start___verbose;
10391044
modname = iter->modname;

0 commit comments

Comments
 (0)