]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/linux/dynamic_debug.h
mm: memcontrol: convert NR_ANON_THPS account to pages
[mirror_ubuntu-jammy-kernel.git] / include / linux / dynamic_debug.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
e9d376f0
JB
2#ifndef _DYNAMIC_DEBUG_H
3#define _DYNAMIC_DEBUG_H
4
e9666d10 5#if defined(CONFIG_JUMP_LABEL)
9049fc74
JB
6#include <linux/jump_label.h>
7#endif
8
e9d376f0
JB
9/*
10 * An instance of this structure is created in a special
11 * ELF section at every dynamic debug callsite. At runtime,
12 * the special section is treated as an array of these.
13 */
14struct _ddebug {
15 /*
16 * These fields are used to drive the user interface
17 * for selecting and displaying debug callsites.
18 */
19 const char *modname;
20 const char *function;
21 const char *filename;
22 const char *format;
e703ddae 23 unsigned int lineno:18;
e9d376f0 24 /*
3faa2860
JC
25 * The flags field controls the behaviour at the callsite.
26 * The bits here are changed dynamically when the user
2b2f68b5 27 * writes commands to <debugfs>/dynamic_debug/control
e9d376f0 28 */
5ca7d2a6
JC
29#define _DPRINTK_FLAGS_NONE 0
30#define _DPRINTK_FLAGS_PRINT (1<<0) /* printk() a message using the format */
8ba6ebf5
BVA
31#define _DPRINTK_FLAGS_INCL_MODNAME (1<<1)
32#define _DPRINTK_FLAGS_INCL_FUNCNAME (1<<2)
33#define _DPRINTK_FLAGS_INCL_LINENO (1<<3)
34#define _DPRINTK_FLAGS_INCL_TID (1<<4)
b558c96f
JC
35#if defined DEBUG
36#define _DPRINTK_FLAGS_DEFAULT _DPRINTK_FLAGS_PRINT
37#else
e9d376f0 38#define _DPRINTK_FLAGS_DEFAULT 0
b558c96f 39#endif
e9d376f0 40 unsigned int flags:8;
e9666d10 41#ifdef CONFIG_JUMP_LABEL
9049fc74
JB
42 union {
43 struct static_key_true dd_key_true;
44 struct static_key_false dd_key_false;
45 } key;
46#endif
e9d376f0
JB
47} __attribute__((aligned(8)));
48
49
e9d376f0 50
ceabef7d 51#if defined(CONFIG_DYNAMIC_DEBUG_CORE)
a2d375ed
JC
52
53/* exported for module authors to exercise >control */
54int dynamic_debug_exec_queries(const char *query, const char *modname);
55
a4507fed
RV
56int ddebug_add_module(struct _ddebug *tab, unsigned int n,
57 const char *modname);
ff49d74a 58extern int ddebug_remove_module(const char *mod_name);
b9075fa9 59extern __printf(2, 3)
906d2015 60void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...);
e9d376f0 61
b48420c1
JC
62extern int ddebug_dyndbg_module_param_cb(char *param, char *val,
63 const char *modname);
64
cbc46635
JP
65struct device;
66
b9075fa9 67extern __printf(3, 4)
906d2015
JP
68void __dynamic_dev_dbg(struct _ddebug *descriptor, const struct device *dev,
69 const char *fmt, ...);
cbc46635 70
ffa10cb4
JB
71struct net_device;
72
b9075fa9 73extern __printf(3, 4)
906d2015
JP
74void __dynamic_netdev_dbg(struct _ddebug *descriptor,
75 const struct net_device *dev,
76 const char *fmt, ...);
ffa10cb4 77
923abb9d
GP
78struct ib_device;
79
80extern __printf(3, 4)
81void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
82 const struct ib_device *ibdev,
83 const char *fmt, ...);
84
2bdde670 85#define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt) \
c0d2af63 86 static struct _ddebug __aligned(8) \
33def849 87 __section("__dyndbg") name = { \
07613b0b
JB
88 .modname = KBUILD_MODNAME, \
89 .function = __func__, \
90 .filename = __FILE__, \
91 .format = (fmt), \
92 .lineno = __LINE__, \
9049fc74 93 .flags = _DPRINTK_FLAGS_DEFAULT, \
2bdde670 94 _DPRINTK_KEY_INIT \
07613b0b
JB
95 }
96
e9666d10 97#ifdef CONFIG_JUMP_LABEL
9049fc74 98
9049fc74 99#ifdef DEBUG
2bdde670
RV
100
101#define _DPRINTK_KEY_INIT .key.dd_key_true = (STATIC_KEY_TRUE_INIT)
9049fc74
JB
102
103#define DYNAMIC_DEBUG_BRANCH(descriptor) \
104 static_branch_likely(&descriptor.key.dd_key_true)
105#else
2bdde670 106#define _DPRINTK_KEY_INIT .key.dd_key_false = (STATIC_KEY_FALSE_INIT)
9049fc74
JB
107
108#define DYNAMIC_DEBUG_BRANCH(descriptor) \
109 static_branch_unlikely(&descriptor.key.dd_key_false)
110#endif
111
a2d375ed 112#else /* !CONFIG_JUMP_LABEL */
9049fc74 113
2bdde670 114#define _DPRINTK_KEY_INIT
9049fc74
JB
115
116#ifdef DEBUG
117#define DYNAMIC_DEBUG_BRANCH(descriptor) \
118 likely(descriptor.flags & _DPRINTK_FLAGS_PRINT)
119#else
120#define DYNAMIC_DEBUG_BRANCH(descriptor) \
121 unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)
122#endif
123
a2d375ed 124#endif /* CONFIG_JUMP_LABEL */
9049fc74 125
47cdd64b
RV
126#define __dynamic_func_call(id, fmt, func, ...) do { \
127 DEFINE_DYNAMIC_DEBUG_METADATA(id, fmt); \
128 if (DYNAMIC_DEBUG_BRANCH(id)) \
129 func(&id, ##__VA_ARGS__); \
07613b0b
JB
130} while (0)
131
47cdd64b
RV
132#define __dynamic_func_call_no_desc(id, fmt, func, ...) do { \
133 DEFINE_DYNAMIC_DEBUG_METADATA(id, fmt); \
134 if (DYNAMIC_DEBUG_BRANCH(id)) \
135 func(__VA_ARGS__); \
07613b0b
JB
136} while (0)
137
47cdd64b
RV
138/*
139 * "Factory macro" for generating a call to func, guarded by a
e5ebffe1 140 * DYNAMIC_DEBUG_BRANCH. The dynamic debug descriptor will be
47cdd64b
RV
141 * initialized using the fmt argument. The function will be called with
142 * the address of the descriptor as first argument, followed by all
143 * the varargs. Note that fmt is repeated in invocations of this
144 * macro.
145 */
146#define _dynamic_func_call(fmt, func, ...) \
147 __dynamic_func_call(__UNIQUE_ID(ddebug), fmt, func, ##__VA_ARGS__)
148/*
149 * A variant that does the same, except that the descriptor is not
150 * passed as the first argument to the function; it is only called
151 * with precisely the macro's varargs.
152 */
153#define _dynamic_func_call_no_desc(fmt, func, ...) \
154 __dynamic_func_call_no_desc(__UNIQUE_ID(ddebug), fmt, func, ##__VA_ARGS__)
ffa10cb4 155
47cdd64b
RV
156#define dynamic_pr_debug(fmt, ...) \
157 _dynamic_func_call(fmt, __dynamic_pr_debug, \
158 pr_fmt(fmt), ##__VA_ARGS__)
159
160#define dynamic_dev_dbg(dev, fmt, ...) \
161 _dynamic_func_call(fmt,__dynamic_dev_dbg, \
162 dev, fmt, ##__VA_ARGS__)
163
164#define dynamic_netdev_dbg(dev, fmt, ...) \
165 _dynamic_func_call(fmt, __dynamic_netdev_dbg, \
166 dev, fmt, ##__VA_ARGS__)
167
923abb9d
GP
168#define dynamic_ibdev_dbg(dev, fmt, ...) \
169 _dynamic_func_call(fmt, __dynamic_ibdev_dbg, \
170 dev, fmt, ##__VA_ARGS__)
171
47cdd64b
RV
172#define dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
173 groupsize, buf, len, ascii) \
174 _dynamic_func_call_no_desc(__builtin_constant_p(prefix_str) ? prefix_str : "hexdump", \
175 print_hex_dump, \
176 KERN_DEBUG, prefix_str, prefix_type, \
177 rowsize, groupsize, buf, len, ascii)
7a555613 178
a2d375ed 179#else /* !CONFIG_DYNAMIC_DEBUG_CORE */
e9d376f0 180
b48420c1
JC
181#include <linux/string.h>
182#include <linux/errno.h>
a2d375ed 183#include <linux/printk.h>
b48420c1 184
a4507fed
RV
185static inline int ddebug_add_module(struct _ddebug *tab, unsigned int n,
186 const char *modname)
187{
188 return 0;
189}
190
ff49d74a 191static inline int ddebug_remove_module(const char *mod)
e9d376f0
JB
192{
193 return 0;
194}
195
b48420c1
JC
196static inline int ddebug_dyndbg_module_param_cb(char *param, char *val,
197 const char *modname)
198{
199 if (strstr(param, "dyndbg")) {
516cf1be
JC
200 /* avoid pr_warn(), which wants pr_fmt() fully defined */
201 printk(KERN_WARNING "dyndbg param is supported only in "
b48420c1
JC
202 "CONFIG_DYNAMIC_DEBUG builds\n");
203 return 0; /* allow and ignore */
204 }
205 return -EINVAL;
206}
207
00b55864
JP
208#define dynamic_pr_debug(fmt, ...) \
209 do { if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); } while (0)
be70e267 210#define dynamic_dev_dbg(dev, fmt, ...) \
00b55864 211 do { if (0) dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); } while (0)
011c7289
AB
212#define dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
213 groupsize, buf, len, ascii) \
214 do { if (0) \
215 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, \
216 rowsize, groupsize, buf, len, ascii); \
217 } while (0)
a2d375ed
JC
218
219static inline int dynamic_debug_exec_queries(const char *query, const char *modname)
220{
221 pr_warn("kernel not built with CONFIG_DYNAMIC_DEBUG_CORE\n");
222 return 0;
223}
224
225#endif /* !CONFIG_DYNAMIC_DEBUG_CORE */
e9d376f0
JB
226
227#endif