]> Git Repo - J-linux.git/blob - include/linux/printk.h
Merge tag 'apparmor-pr-2024-07-25' of git://git.kernel.org/pub/scm/linux/kernel/git...
[J-linux.git] / include / linux / printk.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __KERNEL_PRINTK__
3 #define __KERNEL_PRINTK__
4
5 #include <linux/stdarg.h>
6 #include <linux/init.h>
7 #include <linux/kern_levels.h>
8 #include <linux/linkage.h>
9 #include <linux/ratelimit_types.h>
10 #include <linux/once_lite.h>
11
12 extern const char linux_banner[];
13 extern const char linux_proc_banner[];
14
15 extern int oops_in_progress;    /* If set, an oops, panic(), BUG() or die() is in progress */
16
17 #define PRINTK_MAX_SINGLE_HEADER_LEN 2
18
19 static inline int printk_get_level(const char *buffer)
20 {
21         if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
22                 switch (buffer[1]) {
23                 case '0' ... '7':
24                 case 'c':       /* KERN_CONT */
25                         return buffer[1];
26                 }
27         }
28         return 0;
29 }
30
31 static inline const char *printk_skip_level(const char *buffer)
32 {
33         if (printk_get_level(buffer))
34                 return buffer + 2;
35
36         return buffer;
37 }
38
39 static inline const char *printk_skip_headers(const char *buffer)
40 {
41         while (printk_get_level(buffer))
42                 buffer = printk_skip_level(buffer);
43
44         return buffer;
45 }
46
47 /* printk's without a loglevel use this.. */
48 #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
49
50 /* We show everything that is MORE important than this.. */
51 #define CONSOLE_LOGLEVEL_SILENT  0 /* Mum's the word */
52 #define CONSOLE_LOGLEVEL_MIN     1 /* Minimum loglevel we let people use */
53 #define CONSOLE_LOGLEVEL_DEBUG  10 /* issue debug messages */
54 #define CONSOLE_LOGLEVEL_MOTORMOUTH 15  /* You can't shut this one up */
55
56 /*
57  * Default used to be hard-coded at 7, quiet used to be hardcoded at 4,
58  * we're now allowing both to be set from kernel config.
59  */
60 #define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT
61 #define CONSOLE_LOGLEVEL_QUIET   CONFIG_CONSOLE_LOGLEVEL_QUIET
62
63 int match_devname_and_update_preferred_console(const char *match,
64                                                const char *name,
65                                                const short idx);
66
67 extern int console_printk[];
68
69 #define console_loglevel (console_printk[0])
70 #define default_message_loglevel (console_printk[1])
71 #define minimum_console_loglevel (console_printk[2])
72 #define default_console_loglevel (console_printk[3])
73
74 extern void console_verbose(void);
75
76 /* strlen("ratelimit") + 1 */
77 #define DEVKMSG_STR_MAX_SIZE 10
78 extern char devkmsg_log_str[DEVKMSG_STR_MAX_SIZE];
79 struct ctl_table;
80
81 extern int suppress_printk;
82
83 struct va_format {
84         const char *fmt;
85         va_list *va;
86 };
87
88 /*
89  * FW_BUG
90  * Add this to a message where you are sure the firmware is buggy or behaves
91  * really stupid or out of spec. Be aware that the responsible BIOS developer
92  * should be able to fix this issue or at least get a concrete idea of the
93  * problem by reading your message without the need of looking at the kernel
94  * code.
95  *
96  * Use it for definite and high priority BIOS bugs.
97  *
98  * FW_WARN
99  * Use it for not that clear (e.g. could the kernel messed up things already?)
100  * and medium priority BIOS bugs.
101  *
102  * FW_INFO
103  * Use this one if you want to tell the user or vendor about something
104  * suspicious, but generally harmless related to the firmware.
105  *
106  * Use it for information or very low priority BIOS bugs.
107  */
108 #define FW_BUG          "[Firmware Bug]: "
109 #define FW_WARN         "[Firmware Warn]: "
110 #define FW_INFO         "[Firmware Info]: "
111
112 /*
113  * HW_ERR
114  * Add this to a message for hardware errors, so that user can report
115  * it to hardware vendor instead of LKML or software vendor.
116  */
117 #define HW_ERR          "[Hardware Error]: "
118
119 /*
120  * DEPRECATED
121  * Add this to a message whenever you want to warn user space about the use
122  * of a deprecated aspect of an API so they can stop using it
123  */
124 #define DEPRECATED      "[Deprecated]: "
125
126 /*
127  * Dummy printk for disabled debugging statements to use whilst maintaining
128  * gcc's format checking.
129  */
130 #define no_printk(fmt, ...)                             \
131 ({                                                      \
132         if (0)                                          \
133                 _printk(fmt, ##__VA_ARGS__);            \
134         0;                                              \
135 })
136
137 #ifdef CONFIG_EARLY_PRINTK
138 extern asmlinkage __printf(1, 2)
139 void early_printk(const char *fmt, ...);
140 #else
141 static inline __printf(1, 2) __cold
142 void early_printk(const char *s, ...) { }
143 #endif
144
145 struct dev_printk_info;
146
147 #ifdef CONFIG_PRINTK
148 asmlinkage __printf(4, 0)
149 int vprintk_emit(int facility, int level,
150                  const struct dev_printk_info *dev_info,
151                  const char *fmt, va_list args);
152
153 asmlinkage __printf(1, 0)
154 int vprintk(const char *fmt, va_list args);
155
156 asmlinkage __printf(1, 2) __cold
157 int _printk(const char *fmt, ...);
158
159 /*
160  * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
161  */
162 __printf(1, 2) __cold int _printk_deferred(const char *fmt, ...);
163
164 extern void __printk_safe_enter(void);
165 extern void __printk_safe_exit(void);
166 /*
167  * The printk_deferred_enter/exit macros are available only as a hack for
168  * some code paths that need to defer all printk console printing. Interrupts
169  * must be disabled for the deferred duration.
170  */
171 #define printk_deferred_enter __printk_safe_enter
172 #define printk_deferred_exit __printk_safe_exit
173
174 /*
175  * Please don't use printk_ratelimit(), because it shares ratelimiting state
176  * with all other unrelated printk_ratelimit() callsites.  Instead use
177  * printk_ratelimited() or plain old __ratelimit().
178  */
179 extern int __printk_ratelimit(const char *func);
180 #define printk_ratelimit() __printk_ratelimit(__func__)
181 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
182                                    unsigned int interval_msec);
183
184 extern int printk_delay_msec;
185 extern int dmesg_restrict;
186
187 extern void wake_up_klogd(void);
188
189 char *log_buf_addr_get(void);
190 u32 log_buf_len_get(void);
191 void log_buf_vmcoreinfo_setup(void);
192 void __init setup_log_buf(int early);
193 __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
194 void dump_stack_print_info(const char *log_lvl);
195 void show_regs_print_info(const char *log_lvl);
196 extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold;
197 extern asmlinkage void dump_stack(void) __cold;
198 void printk_trigger_flush(void);
199 void console_try_replay_all(void);
200 #else
201 static inline __printf(1, 0)
202 int vprintk(const char *s, va_list args)
203 {
204         return 0;
205 }
206 static inline __printf(1, 2) __cold
207 int _printk(const char *s, ...)
208 {
209         return 0;
210 }
211 static inline __printf(1, 2) __cold
212 int _printk_deferred(const char *s, ...)
213 {
214         return 0;
215 }
216
217 static inline void printk_deferred_enter(void)
218 {
219 }
220
221 static inline void printk_deferred_exit(void)
222 {
223 }
224
225 static inline int printk_ratelimit(void)
226 {
227         return 0;
228 }
229 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
230                                           unsigned int interval_msec)
231 {
232         return false;
233 }
234
235 static inline void wake_up_klogd(void)
236 {
237 }
238
239 static inline char *log_buf_addr_get(void)
240 {
241         return NULL;
242 }
243
244 static inline u32 log_buf_len_get(void)
245 {
246         return 0;
247 }
248
249 static inline void log_buf_vmcoreinfo_setup(void)
250 {
251 }
252
253 static inline void setup_log_buf(int early)
254 {
255 }
256
257 static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...)
258 {
259 }
260
261 static inline void dump_stack_print_info(const char *log_lvl)
262 {
263 }
264
265 static inline void show_regs_print_info(const char *log_lvl)
266 {
267 }
268
269 static inline void dump_stack_lvl(const char *log_lvl)
270 {
271 }
272
273 static inline void dump_stack(void)
274 {
275 }
276 static inline void printk_trigger_flush(void)
277 {
278 }
279 static inline void console_try_replay_all(void)
280 {
281 }
282 #endif
283
284 bool this_cpu_in_panic(void);
285
286 #ifdef CONFIG_SMP
287 extern int __printk_cpu_sync_try_get(void);
288 extern void __printk_cpu_sync_wait(void);
289 extern void __printk_cpu_sync_put(void);
290
291 #else
292
293 #define __printk_cpu_sync_try_get() true
294 #define __printk_cpu_sync_wait()
295 #define __printk_cpu_sync_put()
296 #endif /* CONFIG_SMP */
297
298 /**
299  * printk_cpu_sync_get_irqsave() - Disable interrupts and acquire the printk
300  *                                 cpu-reentrant spinning lock.
301  * @flags: Stack-allocated storage for saving local interrupt state,
302  *         to be passed to printk_cpu_sync_put_irqrestore().
303  *
304  * If the lock is owned by another CPU, spin until it becomes available.
305  * Interrupts are restored while spinning.
306  *
307  * CAUTION: This function must be used carefully. It does not behave like a
308  * typical lock. Here are important things to watch out for...
309  *
310  *     * This function is reentrant on the same CPU. Therefore the calling
311  *       code must not assume exclusive access to data if code accessing the
312  *       data can run reentrant or within NMI context on the same CPU.
313  *
314  *     * If there exists usage of this function from NMI context, it becomes
315  *       unsafe to perform any type of locking or spinning to wait for other
316  *       CPUs after calling this function from any context. This includes
317  *       using spinlocks or any other busy-waiting synchronization methods.
318  */
319 #define printk_cpu_sync_get_irqsave(flags)              \
320         for (;;) {                                      \
321                 local_irq_save(flags);                  \
322                 if (__printk_cpu_sync_try_get())        \
323                         break;                          \
324                 local_irq_restore(flags);               \
325                 __printk_cpu_sync_wait();               \
326         }
327
328 /**
329  * printk_cpu_sync_put_irqrestore() - Release the printk cpu-reentrant spinning
330  *                                    lock and restore interrupts.
331  * @flags: Caller's saved interrupt state, from printk_cpu_sync_get_irqsave().
332  */
333 #define printk_cpu_sync_put_irqrestore(flags)   \
334         do {                                    \
335                 __printk_cpu_sync_put();        \
336                 local_irq_restore(flags);       \
337         } while (0)
338
339 extern int kptr_restrict;
340
341 /**
342  * pr_fmt - used by the pr_*() macros to generate the printk format string
343  * @fmt: format string passed from a pr_*() macro
344  *
345  * This macro can be used to generate a unified format string for pr_*()
346  * macros. A common use is to prefix all pr_*() messages in a file with a common
347  * string. For example, defining this at the top of a source file:
348  *
349  *        #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
350  *
351  * would prefix all pr_info, pr_emerg... messages in the file with the module
352  * name.
353  */
354 #ifndef pr_fmt
355 #define pr_fmt(fmt) fmt
356 #endif
357
358 struct module;
359
360 #ifdef CONFIG_PRINTK_INDEX
361 struct pi_entry {
362         const char *fmt;
363         const char *func;
364         const char *file;
365         unsigned int line;
366
367         /*
368          * While printk and pr_* have the level stored in the string at compile
369          * time, some subsystems dynamically add it at runtime through the
370          * format string. For these dynamic cases, we allow the subsystem to
371          * tell us the level at compile time.
372          *
373          * NULL indicates that the level, if any, is stored in fmt.
374          */
375         const char *level;
376
377         /*
378          * The format string used by various subsystem specific printk()
379          * wrappers to prefix the message.
380          *
381          * Note that the static prefix defined by the pr_fmt() macro is stored
382          * directly in the message format (@fmt), not here.
383          */
384         const char *subsys_fmt_prefix;
385 } __packed;
386
387 #define __printk_index_emit(_fmt, _level, _subsys_fmt_prefix)           \
388         do {                                                            \
389                 if (__builtin_constant_p(_fmt) && __builtin_constant_p(_level)) { \
390                         /*
391                          * We check __builtin_constant_p multiple times here
392                          * for the same input because GCC will produce an error
393                          * if we try to assign a static variable to fmt if it
394                          * is not a constant, even with the outer if statement.
395                          */                                             \
396                         static const struct pi_entry _entry             \
397                         __used = {                                      \
398                                 .fmt = __builtin_constant_p(_fmt) ? (_fmt) : NULL, \
399                                 .func = __func__,                       \
400                                 .file = __FILE__,                       \
401                                 .line = __LINE__,                       \
402                                 .level = __builtin_constant_p(_level) ? (_level) : NULL, \
403                                 .subsys_fmt_prefix = _subsys_fmt_prefix,\
404                         };                                              \
405                         static const struct pi_entry *_entry_ptr        \
406                         __used __section(".printk_index") = &_entry;    \
407                 }                                                       \
408         } while (0)
409
410 #else /* !CONFIG_PRINTK_INDEX */
411 #define __printk_index_emit(...) do {} while (0)
412 #endif /* CONFIG_PRINTK_INDEX */
413
414 /*
415  * Some subsystems have their own custom printk that applies a va_format to a
416  * generic format, for example, to include a device number or other metadata
417  * alongside the format supplied by the caller.
418  *
419  * In order to store these in the way they would be emitted by the printk
420  * infrastructure, the subsystem provides us with the start, fixed string, and
421  * any subsequent text in the format string.
422  *
423  * We take a variable argument list as pr_fmt/dev_fmt/etc are sometimes passed
424  * as multiple arguments (eg: `"%s: ", "blah"`), and we must only take the
425  * first one.
426  *
427  * subsys_fmt_prefix must be known at compile time, or compilation will fail
428  * (since this is a mistake). If fmt or level is not known at compile time, no
429  * index entry will be made (since this can legitimately happen).
430  */
431 #define printk_index_subsys_emit(subsys_fmt_prefix, level, fmt, ...) \
432         __printk_index_emit(fmt, level, subsys_fmt_prefix)
433
434 #define printk_index_wrap(_p_func, _fmt, ...)                           \
435         ({                                                              \
436                 __printk_index_emit(_fmt, NULL, NULL);                  \
437                 _p_func(_fmt, ##__VA_ARGS__);                           \
438         })
439
440
441 /**
442  * printk - print a kernel message
443  * @fmt: format string
444  *
445  * This is printk(). It can be called from any context. We want it to work.
446  *
447  * If printk indexing is enabled, _printk() is called from printk_index_wrap.
448  * Otherwise, printk is simply #defined to _printk.
449  *
450  * We try to grab the console_lock. If we succeed, it's easy - we log the
451  * output and call the console drivers.  If we fail to get the semaphore, we
452  * place the output into the log buffer and return. The current holder of
453  * the console_sem will notice the new output in console_unlock(); and will
454  * send it to the consoles before releasing the lock.
455  *
456  * One effect of this deferred printing is that code which calls printk() and
457  * then changes console_loglevel may break. This is because console_loglevel
458  * is inspected when the actual printing occurs.
459  *
460  * See also:
461  * printf(3)
462  *
463  * See the vsnprintf() documentation for format string extensions over C99.
464  */
465 #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
466 #define printk_deferred(fmt, ...)                                       \
467         printk_index_wrap(_printk_deferred, fmt, ##__VA_ARGS__)
468
469 /**
470  * pr_emerg - Print an emergency-level message
471  * @fmt: format string
472  * @...: arguments for the format string
473  *
474  * This macro expands to a printk with KERN_EMERG loglevel. It uses pr_fmt() to
475  * generate the format string.
476  */
477 #define pr_emerg(fmt, ...) \
478         printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
479 /**
480  * pr_alert - Print an alert-level message
481  * @fmt: format string
482  * @...: arguments for the format string
483  *
484  * This macro expands to a printk with KERN_ALERT loglevel. It uses pr_fmt() to
485  * generate the format string.
486  */
487 #define pr_alert(fmt, ...) \
488         printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
489 /**
490  * pr_crit - Print a critical-level message
491  * @fmt: format string
492  * @...: arguments for the format string
493  *
494  * This macro expands to a printk with KERN_CRIT loglevel. It uses pr_fmt() to
495  * generate the format string.
496  */
497 #define pr_crit(fmt, ...) \
498         printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
499 /**
500  * pr_err - Print an error-level message
501  * @fmt: format string
502  * @...: arguments for the format string
503  *
504  * This macro expands to a printk with KERN_ERR loglevel. It uses pr_fmt() to
505  * generate the format string.
506  */
507 #define pr_err(fmt, ...) \
508         printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
509 /**
510  * pr_warn - Print a warning-level message
511  * @fmt: format string
512  * @...: arguments for the format string
513  *
514  * This macro expands to a printk with KERN_WARNING loglevel. It uses pr_fmt()
515  * to generate the format string.
516  */
517 #define pr_warn(fmt, ...) \
518         printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
519 /**
520  * pr_notice - Print a notice-level message
521  * @fmt: format string
522  * @...: arguments for the format string
523  *
524  * This macro expands to a printk with KERN_NOTICE loglevel. It uses pr_fmt() to
525  * generate the format string.
526  */
527 #define pr_notice(fmt, ...) \
528         printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
529 /**
530  * pr_info - Print an info-level message
531  * @fmt: format string
532  * @...: arguments for the format string
533  *
534  * This macro expands to a printk with KERN_INFO loglevel. It uses pr_fmt() to
535  * generate the format string.
536  */
537 #define pr_info(fmt, ...) \
538         printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
539
540 /**
541  * pr_cont - Continues a previous log message in the same line.
542  * @fmt: format string
543  * @...: arguments for the format string
544  *
545  * This macro expands to a printk with KERN_CONT loglevel. It should only be
546  * used when continuing a log message with no newline ('\n') enclosed. Otherwise
547  * it defaults back to KERN_DEFAULT loglevel.
548  */
549 #define pr_cont(fmt, ...) \
550         printk(KERN_CONT fmt, ##__VA_ARGS__)
551
552 /**
553  * pr_devel - Print a debug-level message conditionally
554  * @fmt: format string
555  * @...: arguments for the format string
556  *
557  * This macro expands to a printk with KERN_DEBUG loglevel if DEBUG is
558  * defined. Otherwise it does nothing.
559  *
560  * It uses pr_fmt() to generate the format string.
561  */
562 #ifdef DEBUG
563 #define pr_devel(fmt, ...) \
564         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
565 #else
566 #define pr_devel(fmt, ...) \
567         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
568 #endif
569
570
571 /* If you are writing a driver, please use dev_dbg instead */
572 #if defined(CONFIG_DYNAMIC_DEBUG) || \
573         (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
574 #include <linux/dynamic_debug.h>
575
576 /**
577  * pr_debug - Print a debug-level message conditionally
578  * @fmt: format string
579  * @...: arguments for the format string
580  *
581  * This macro expands to dynamic_pr_debug() if CONFIG_DYNAMIC_DEBUG is
582  * set. Otherwise, if DEBUG is defined, it's equivalent to a printk with
583  * KERN_DEBUG loglevel. If DEBUG is not defined it does nothing.
584  *
585  * It uses pr_fmt() to generate the format string (dynamic_pr_debug() uses
586  * pr_fmt() internally).
587  */
588 #define pr_debug(fmt, ...)                      \
589         dynamic_pr_debug(fmt, ##__VA_ARGS__)
590 #elif defined(DEBUG)
591 #define pr_debug(fmt, ...) \
592         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
593 #else
594 #define pr_debug(fmt, ...) \
595         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
596 #endif
597
598 /*
599  * Print a one-time message (analogous to WARN_ONCE() et al):
600  */
601
602 #ifdef CONFIG_PRINTK
603 #define printk_once(fmt, ...)                                   \
604         DO_ONCE_LITE(printk, fmt, ##__VA_ARGS__)
605 #define printk_deferred_once(fmt, ...)                          \
606         DO_ONCE_LITE(printk_deferred, fmt, ##__VA_ARGS__)
607 #else
608 #define printk_once(fmt, ...)                                   \
609         no_printk(fmt, ##__VA_ARGS__)
610 #define printk_deferred_once(fmt, ...)                          \
611         no_printk(fmt, ##__VA_ARGS__)
612 #endif
613
614 #define pr_emerg_once(fmt, ...)                                 \
615         printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
616 #define pr_alert_once(fmt, ...)                                 \
617         printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
618 #define pr_crit_once(fmt, ...)                                  \
619         printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
620 #define pr_err_once(fmt, ...)                                   \
621         printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
622 #define pr_warn_once(fmt, ...)                                  \
623         printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
624 #define pr_notice_once(fmt, ...)                                \
625         printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
626 #define pr_info_once(fmt, ...)                                  \
627         printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
628 /* no pr_cont_once, don't do that... */
629
630 #if defined(DEBUG)
631 #define pr_devel_once(fmt, ...)                                 \
632         printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
633 #else
634 #define pr_devel_once(fmt, ...)                                 \
635         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
636 #endif
637
638 /* If you are writing a driver, please use dev_dbg instead */
639 #if defined(DEBUG)
640 #define pr_debug_once(fmt, ...)                                 \
641         printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
642 #else
643 #define pr_debug_once(fmt, ...)                                 \
644         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
645 #endif
646
647 /*
648  * ratelimited messages with local ratelimit_state,
649  * no local ratelimit_state used in the !PRINTK case
650  */
651 #ifdef CONFIG_PRINTK
652 #define printk_ratelimited(fmt, ...)                                    \
653 ({                                                                      \
654         static DEFINE_RATELIMIT_STATE(_rs,                              \
655                                       DEFAULT_RATELIMIT_INTERVAL,       \
656                                       DEFAULT_RATELIMIT_BURST);         \
657                                                                         \
658         if (__ratelimit(&_rs))                                          \
659                 printk(fmt, ##__VA_ARGS__);                             \
660 })
661 #else
662 #define printk_ratelimited(fmt, ...)                                    \
663         no_printk(fmt, ##__VA_ARGS__)
664 #endif
665
666 #define pr_emerg_ratelimited(fmt, ...)                                  \
667         printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
668 #define pr_alert_ratelimited(fmt, ...)                                  \
669         printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
670 #define pr_crit_ratelimited(fmt, ...)                                   \
671         printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
672 #define pr_err_ratelimited(fmt, ...)                                    \
673         printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
674 #define pr_warn_ratelimited(fmt, ...)                                   \
675         printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
676 #define pr_notice_ratelimited(fmt, ...)                                 \
677         printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
678 #define pr_info_ratelimited(fmt, ...)                                   \
679         printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
680 /* no pr_cont_ratelimited, don't do that... */
681
682 #if defined(DEBUG)
683 #define pr_devel_ratelimited(fmt, ...)                                  \
684         printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
685 #else
686 #define pr_devel_ratelimited(fmt, ...)                                  \
687         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
688 #endif
689
690 /* If you are writing a driver, please use dev_dbg instead */
691 #if defined(CONFIG_DYNAMIC_DEBUG) || \
692         (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
693 /* descriptor check is first to prevent flooding with "callbacks suppressed" */
694 #define pr_debug_ratelimited(fmt, ...)                                  \
695 do {                                                                    \
696         static DEFINE_RATELIMIT_STATE(_rs,                              \
697                                       DEFAULT_RATELIMIT_INTERVAL,       \
698                                       DEFAULT_RATELIMIT_BURST);         \
699         DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt));         \
700         if (DYNAMIC_DEBUG_BRANCH(descriptor) &&                         \
701             __ratelimit(&_rs))                                          \
702                 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__);    \
703 } while (0)
704 #elif defined(DEBUG)
705 #define pr_debug_ratelimited(fmt, ...)                                  \
706         printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
707 #else
708 #define pr_debug_ratelimited(fmt, ...) \
709         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
710 #endif
711
712 extern const struct file_operations kmsg_fops;
713
714 enum {
715         DUMP_PREFIX_NONE,
716         DUMP_PREFIX_ADDRESS,
717         DUMP_PREFIX_OFFSET
718 };
719 extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
720                               int groupsize, char *linebuf, size_t linebuflen,
721                               bool ascii);
722 #ifdef CONFIG_PRINTK
723 extern void print_hex_dump(const char *level, const char *prefix_str,
724                            int prefix_type, int rowsize, int groupsize,
725                            const void *buf, size_t len, bool ascii);
726 #else
727 static inline void print_hex_dump(const char *level, const char *prefix_str,
728                                   int prefix_type, int rowsize, int groupsize,
729                                   const void *buf, size_t len, bool ascii)
730 {
731 }
732 static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
733                                         const void *buf, size_t len)
734 {
735 }
736
737 #endif
738
739 #if defined(CONFIG_DYNAMIC_DEBUG) || \
740         (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
741 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize,  \
742                              groupsize, buf, len, ascii)        \
743         dynamic_hex_dump(prefix_str, prefix_type, rowsize,      \
744                          groupsize, buf, len, ascii)
745 #elif defined(DEBUG)
746 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize,          \
747                              groupsize, buf, len, ascii)                \
748         print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize,    \
749                        groupsize, buf, len, ascii)
750 #else
751 static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
752                                         int rowsize, int groupsize,
753                                         const void *buf, size_t len, bool ascii)
754 {
755 }
756 #endif
757
758 /**
759  * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params
760  * @prefix_str: string to prefix each line with;
761  *  caller supplies trailing spaces for alignment if desired
762  * @prefix_type: controls whether prefix of an offset, address, or none
763  *  is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE)
764  * @buf: data blob to dump
765  * @len: number of bytes in the @buf
766  *
767  * Calls print_hex_dump(), with log level of KERN_DEBUG,
768  * rowsize of 16, groupsize of 1, and ASCII output included.
769  */
770 #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
771         print_hex_dump_debug(prefix_str, prefix_type, 16, 1, buf, len, true)
772
773 #endif
This page took 0.073226 seconds and 4 git commands to generate.