Commit ceabef7d authored by Orson Zhai's avatar Orson Zhai Committed by Linus Torvalds

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.

[orson.zhai@unisoc.com: v2]
  Link: http://lkml.kernel.org/r/1587408228-10861-1-git-send-email-orson.unisoc@gmail.comSigned-off-by: default avatarOrson Zhai <orson.zhai@unisoc.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: default avatarPetr Mladek <pmladek@suse.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jason Baron <jbaron@akamai.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Link: http://lkml.kernel.org/r/1586521984-5890-1-git-send-email-orson.unisoc@gmail.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e1eb26fa
...@@ -13,6 +13,11 @@ kernel code to obtain additional kernel information. Currently, if ...@@ -13,6 +13,11 @@ kernel code to obtain additional kernel information. Currently, if
``print_hex_dump_debug()``/``print_hex_dump_bytes()`` calls can be dynamically ``print_hex_dump_debug()``/``print_hex_dump_bytes()`` calls can be dynamically
enabled per-callsite. enabled per-callsite.
If you do not want to enable dynamic debug globally (i.e. in some embedded
system), you may set ``CONFIG_DYNAMIC_DEBUG_CORE`` as basic support of dynamic
debug and add ``ccflags := -DDYNAMIC_DEBUG_MODULE`` into the Makefile of any
modules which you'd like to dynamically debug later.
If ``CONFIG_DYNAMIC_DEBUG`` is not set, ``print_hex_dump_debug()`` is just If ``CONFIG_DYNAMIC_DEBUG`` is not set, ``print_hex_dump_debug()`` is just
shortcut for ``print_hex_dump(KERN_DEBUG)``. shortcut for ``print_hex_dump(KERN_DEBUG)``.
......
...@@ -109,7 +109,8 @@ void _dev_info(const struct device *dev, const char *fmt, ...) ...@@ -109,7 +109,8 @@ void _dev_info(const struct device *dev, const char *fmt, ...)
#define dev_info(dev, fmt, ...) \ #define dev_info(dev, fmt, ...) \
_dev_info(dev, dev_fmt(fmt), ##__VA_ARGS__) _dev_info(dev, dev_fmt(fmt), ##__VA_ARGS__)
#if defined(CONFIG_DYNAMIC_DEBUG) #if defined(CONFIG_DYNAMIC_DEBUG) || \
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
#define dev_dbg(dev, fmt, ...) \ #define dev_dbg(dev, fmt, ...) \
dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__) dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
#elif defined(DEBUG) #elif defined(DEBUG)
...@@ -181,7 +182,8 @@ do { \ ...@@ -181,7 +182,8 @@ do { \
dev_level_ratelimited(dev_notice, dev, fmt, ##__VA_ARGS__) dev_level_ratelimited(dev_notice, dev, fmt, ##__VA_ARGS__)
#define dev_info_ratelimited(dev, fmt, ...) \ #define dev_info_ratelimited(dev, fmt, ...) \
dev_level_ratelimited(dev_info, dev, fmt, ##__VA_ARGS__) dev_level_ratelimited(dev_info, dev, fmt, ##__VA_ARGS__)
#if defined(CONFIG_DYNAMIC_DEBUG) #if defined(CONFIG_DYNAMIC_DEBUG) || \
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
/* descriptor check is first to prevent flooding with "callbacks suppressed" */ /* descriptor check is first to prevent flooding with "callbacks suppressed" */
#define dev_dbg_ratelimited(dev, fmt, ...) \ #define dev_dbg_ratelimited(dev, fmt, ...) \
do { \ do { \
......
...@@ -48,7 +48,7 @@ struct _ddebug { ...@@ -48,7 +48,7 @@ struct _ddebug {
#if defined(CONFIG_DYNAMIC_DEBUG) #if defined(CONFIG_DYNAMIC_DEBUG_CORE)
int ddebug_add_module(struct _ddebug *tab, unsigned int n, int ddebug_add_module(struct _ddebug *tab, unsigned int n,
const char *modname); const char *modname);
extern int ddebug_remove_module(const char *mod_name); extern int ddebug_remove_module(const char *mod_name);
......
...@@ -264,7 +264,8 @@ do { \ ...@@ -264,7 +264,8 @@ do { \
net_ratelimited_function(pr_warn, fmt, ##__VA_ARGS__) net_ratelimited_function(pr_warn, fmt, ##__VA_ARGS__)
#define net_info_ratelimited(fmt, ...) \ #define net_info_ratelimited(fmt, ...) \
net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__) net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__)
#if defined(CONFIG_DYNAMIC_DEBUG) #if defined(CONFIG_DYNAMIC_DEBUG) || \
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
#define net_dbg_ratelimited(fmt, ...) \ #define net_dbg_ratelimited(fmt, ...) \
do { \ do { \
DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
......
...@@ -4942,7 +4942,8 @@ do { \ ...@@ -4942,7 +4942,8 @@ do { \
#define MODULE_ALIAS_NETDEV(device) \ #define MODULE_ALIAS_NETDEV(device) \
MODULE_ALIAS("netdev-" device) MODULE_ALIAS("netdev-" device)
#if defined(CONFIG_DYNAMIC_DEBUG) #if defined(CONFIG_DYNAMIC_DEBUG) || \
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
#define netdev_dbg(__dev, format, args...) \ #define netdev_dbg(__dev, format, args...) \
do { \ do { \
dynamic_netdev_dbg(__dev, format, ##args); \ dynamic_netdev_dbg(__dev, format, ##args); \
...@@ -5012,7 +5013,8 @@ do { \ ...@@ -5012,7 +5013,8 @@ do { \
#define netif_info(priv, type, dev, fmt, args...) \ #define netif_info(priv, type, dev, fmt, args...) \
netif_level(info, priv, type, dev, fmt, ##args) netif_level(info, priv, type, dev, fmt, ##args)
#if defined(CONFIG_DYNAMIC_DEBUG) #if defined(CONFIG_DYNAMIC_DEBUG) || \
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
#define netif_dbg(priv, type, netdev, format, args...) \ #define netif_dbg(priv, type, netdev, format, args...) \
do { \ do { \
if (netif_msg_##type(priv)) \ if (netif_msg_##type(priv)) \
......
...@@ -399,7 +399,8 @@ extern int kptr_restrict; ...@@ -399,7 +399,8 @@ extern int kptr_restrict;
/* If you are writing a driver, please use dev_dbg instead */ /* If you are writing a driver, please use dev_dbg instead */
#if defined(CONFIG_DYNAMIC_DEBUG) #if defined(CONFIG_DYNAMIC_DEBUG) || \
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
#include <linux/dynamic_debug.h> #include <linux/dynamic_debug.h>
/** /**
...@@ -535,7 +536,8 @@ extern int kptr_restrict; ...@@ -535,7 +536,8 @@ extern int kptr_restrict;
#endif #endif
/* If you are writing a driver, please use dev_dbg instead */ /* If you are writing a driver, please use dev_dbg instead */
#if defined(CONFIG_DYNAMIC_DEBUG) #if defined(CONFIG_DYNAMIC_DEBUG) || \
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
/* descriptor check is first to prevent flooding with "callbacks suppressed" */ /* descriptor check is first to prevent flooding with "callbacks suppressed" */
#define pr_debug_ratelimited(fmt, ...) \ #define pr_debug_ratelimited(fmt, ...) \
do { \ do { \
...@@ -582,7 +584,8 @@ static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type, ...@@ -582,7 +584,8 @@ static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
#endif #endif
#if defined(CONFIG_DYNAMIC_DEBUG) #if defined(CONFIG_DYNAMIC_DEBUG) || \
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
groupsize, buf, len, ascii) \ groupsize, buf, len, ascii) \
dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
......
...@@ -100,7 +100,8 @@ void ibdev_notice(const struct ib_device *ibdev, const char *format, ...); ...@@ -100,7 +100,8 @@ void ibdev_notice(const struct ib_device *ibdev, const char *format, ...);
__printf(2, 3) __cold __printf(2, 3) __cold
void ibdev_info(const struct ib_device *ibdev, const char *format, ...); void ibdev_info(const struct ib_device *ibdev, const char *format, ...);
#if defined(CONFIG_DYNAMIC_DEBUG) #if defined(CONFIG_DYNAMIC_DEBUG) || \
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
#define ibdev_dbg(__dev, format, args...) \ #define ibdev_dbg(__dev, format, args...) \
dynamic_ibdev_dbg(__dev, format, ##args) dynamic_ibdev_dbg(__dev, format, ##args)
#else #else
...@@ -133,7 +134,8 @@ do { \ ...@@ -133,7 +134,8 @@ do { \
#define ibdev_info_ratelimited(ibdev, fmt, ...) \ #define ibdev_info_ratelimited(ibdev, fmt, ...) \
ibdev_level_ratelimited(ibdev_info, ibdev, fmt, ##__VA_ARGS__) ibdev_level_ratelimited(ibdev_info, ibdev, fmt, ##__VA_ARGS__)
#if defined(CONFIG_DYNAMIC_DEBUG) #if defined(CONFIG_DYNAMIC_DEBUG) || \
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
/* descriptor check is first to prevent flooding with "callbacks suppressed" */ /* descriptor check is first to prevent flooding with "callbacks suppressed" */
#define ibdev_dbg_ratelimited(ibdev, fmt, ...) \ #define ibdev_dbg_ratelimited(ibdev, fmt, ...) \
do { \ do { \
......
...@@ -99,6 +99,7 @@ config DYNAMIC_DEBUG ...@@ -99,6 +99,7 @@ config DYNAMIC_DEBUG
default n default n
depends on PRINTK depends on PRINTK
depends on (DEBUG_FS || PROC_FS) depends on (DEBUG_FS || PROC_FS)
select DYNAMIC_DEBUG_CORE
help help
Compiles debug level messages into the kernel, which would not Compiles debug level messages into the kernel, which would not
...@@ -165,6 +166,17 @@ config DYNAMIC_DEBUG ...@@ -165,6 +166,17 @@ config DYNAMIC_DEBUG
See Documentation/admin-guide/dynamic-debug-howto.rst for additional See Documentation/admin-guide/dynamic-debug-howto.rst for additional
information. information.
config DYNAMIC_DEBUG_CORE
bool "Enable core function of dynamic debug support"
depends on PRINTK
depends on (DEBUG_FS || PROC_FS)
help
Enable core functional support of dynamic debug. It is useful
when you want to tie dynamic debug to your kernel modules with
DYNAMIC_DEBUG_MODULE defined for each of them, especially for
the case of embedded system where the kernel image size is
sensitive for people.
config SYMBOLIC_ERRNAME config SYMBOLIC_ERRNAME
bool "Support symbolic error names in printf" bool "Support symbolic error names in printf"
default y if PRINTK default y if PRINTK
......
...@@ -190,7 +190,7 @@ lib-$(CONFIG_GENERIC_BUG) += bug.o ...@@ -190,7 +190,7 @@ lib-$(CONFIG_GENERIC_BUG) += bug.o
obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o
obj-$(CONFIG_DYNAMIC_DEBUG) += dynamic_debug.o obj-$(CONFIG_DYNAMIC_DEBUG_CORE) += dynamic_debug.o
obj-$(CONFIG_SYMBOLIC_ERRNAME) += errname.o obj-$(CONFIG_SYMBOLIC_ERRNAME) += errname.o
obj-$(CONFIG_NLATTR) += nlattr.o obj-$(CONFIG_NLATTR) += nlattr.o
......
...@@ -1032,9 +1032,14 @@ static int __init dynamic_debug_init(void) ...@@ -1032,9 +1032,14 @@ static int __init dynamic_debug_init(void)
int verbose_bytes = 0; int verbose_bytes = 0;
if (&__start___verbose == &__stop___verbose) { if (&__start___verbose == &__stop___verbose) {
if (IS_ENABLED(CONFIG_DYNAMIC_DEBUG)) {
pr_warn("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n"); pr_warn("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n");
return 1; return 1;
} }
pr_info("Ignore empty _ddebug table in a CONFIG_DYNAMIC_DEBUG_CORE build\n");
ddebug_init_success = 1;
return 0;
}
iter = __start___verbose; iter = __start___verbose;
modname = iter->modname; modname = iter->modname;
iter_start = iter; iter_start = iter;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment