]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/linux/printk.h
mm, oom_reaper: do not attempt to reap a task more than twice
[mirror_ubuntu-artful-kernel.git] / include / linux / printk.h
CommitLineData
968ab183
LT
1#ifndef __KERNEL_PRINTK__
2#define __KERNEL_PRINTK__
3
1b2c289b 4#include <stdarg.h>
162a7e75 5#include <linux/init.h>
314ba352 6#include <linux/kern_levels.h>
154c2670 7#include <linux/linkage.h>
c28aa1f0 8#include <linux/cache.h>
162a7e75 9
968ab183
LT
10extern const char linux_banner[];
11extern const char linux_proc_banner[];
12
acc8fa41
JP
13static inline int printk_get_level(const char *buffer)
14{
04d2c8c8 15 if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
acc8fa41
JP
16 switch (buffer[1]) {
17 case '0' ... '7':
18 case 'd': /* KERN_DEFAULT */
acc8fa41
JP
19 return buffer[1];
20 }
21 }
22 return 0;
23}
24
25static inline const char *printk_skip_level(const char *buffer)
26{
0185698c
PM
27 if (printk_get_level(buffer))
28 return buffer + 2;
29
acc8fa41
JP
30 return buffer;
31}
32
d43ff430
TH
33#define CONSOLE_EXT_LOG_MAX 8192
34
a8fe19eb 35/* printk's without a loglevel use this.. */
42a9dc0b 36#define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
a8fe19eb
BP
37
38/* We show everything that is MORE important than this.. */
39#define CONSOLE_LOGLEVEL_SILENT 0 /* Mum's the word */
40#define CONSOLE_LOGLEVEL_MIN 1 /* Minimum loglevel we let people use */
41#define CONSOLE_LOGLEVEL_QUIET 4 /* Shhh ..., when booted with "quiet" */
42#define CONSOLE_LOGLEVEL_DEFAULT 7 /* anything MORE serious than KERN_DEBUG */
43#define CONSOLE_LOGLEVEL_DEBUG 10 /* issue debug messages */
44#define CONSOLE_LOGLEVEL_MOTORMOUTH 15 /* You can't shut this one up */
45
968ab183
LT
46extern int console_printk[];
47
48#define console_loglevel (console_printk[0])
49#define default_message_loglevel (console_printk[1])
50#define minimum_console_loglevel (console_printk[2])
51#define default_console_loglevel (console_printk[3])
52
a9747cc3
JP
53static inline void console_silent(void)
54{
a8fe19eb 55 console_loglevel = CONSOLE_LOGLEVEL_SILENT;
a9747cc3
JP
56}
57
58static inline void console_verbose(void)
59{
60 if (console_loglevel)
a8fe19eb 61 console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
a9747cc3
JP
62}
63
968ab183
LT
64struct va_format {
65 const char *fmt;
66 va_list *va;
67};
68
69/*
70 * FW_BUG
71 * Add this to a message where you are sure the firmware is buggy or behaves
72 * really stupid or out of spec. Be aware that the responsible BIOS developer
73 * should be able to fix this issue or at least get a concrete idea of the
74 * problem by reading your message without the need of looking at the kernel
75 * code.
76 *
77 * Use it for definite and high priority BIOS bugs.
78 *
79 * FW_WARN
80 * Use it for not that clear (e.g. could the kernel messed up things already?)
81 * and medium priority BIOS bugs.
82 *
83 * FW_INFO
84 * Use this one if you want to tell the user or vendor about something
85 * suspicious, but generally harmless related to the firmware.
86 *
87 * Use it for information or very low priority BIOS bugs.
88 */
89#define FW_BUG "[Firmware Bug]: "
90#define FW_WARN "[Firmware Warn]: "
91#define FW_INFO "[Firmware Info]: "
92
93/*
94 * HW_ERR
95 * Add this to a message for hardware errors, so that user can report
96 * it to hardware vendor instead of LKML or software vendor.
97 */
98#define HW_ERR "[Hardware Error]: "
99
0a9a8bfd
NH
100/*
101 * DEPRECATED
102 * Add this to a message whenever you want to warn user space about the use
103 * of a deprecated aspect of an API so they can stop using it
104 */
105#define DEPRECATED "[Deprecated]: "
106
5264f2f7
JP
107/*
108 * Dummy printk for disabled debugging statements to use whilst maintaining
fe22cd9b 109 * gcc's format checking.
5264f2f7 110 */
069f0cd0
BP
111#define no_printk(fmt, ...) \
112({ \
113 do { \
114 if (0) \
115 printk(fmt, ##__VA_ARGS__); \
116 } while (0); \
117 0; \
118})
5264f2f7 119
d0380e6c 120#ifdef CONFIG_EARLY_PRINTK
b9075fa9 121extern asmlinkage __printf(1, 2)
5264f2f7 122void early_printk(const char *fmt, ...);
d0380e6c
TG
123#else
124static inline __printf(1, 2) __cold
125void early_printk(const char *s, ...) { }
126#endif
5264f2f7 127
42a0bb3f
PM
128#ifdef CONFIG_PRINTK_NMI
129extern void printk_nmi_init(void);
130extern void printk_nmi_enter(void);
131extern void printk_nmi_exit(void);
132extern void printk_nmi_flush(void);
cf9b1106 133extern void printk_nmi_flush_on_panic(void);
42a0bb3f
PM
134#else
135static inline void printk_nmi_init(void) { }
136static inline void printk_nmi_enter(void) { }
137static inline void printk_nmi_exit(void) { }
138static inline void printk_nmi_flush(void) { }
cf9b1106 139static inline void printk_nmi_flush_on_panic(void) { }
42a0bb3f 140#endif /* PRINTK_NMI */
04b74b27 141
968ab183 142#ifdef CONFIG_PRINTK
7ff9554b
KS
143asmlinkage __printf(5, 0)
144int vprintk_emit(int facility, int level,
145 const char *dict, size_t dictlen,
146 const char *fmt, va_list args);
147
b9075fa9 148asmlinkage __printf(1, 0)
5264f2f7 149int vprintk(const char *fmt, va_list args);
7ff9554b
KS
150
151asmlinkage __printf(5, 6) __cold
d487d575
SK
152int printk_emit(int facility, int level,
153 const char *dict, size_t dictlen,
154 const char *fmt, ...);
7ff9554b 155
b9075fa9 156asmlinkage __printf(1, 2) __cold
5264f2f7 157int printk(const char *fmt, ...);
968ab183 158
3ccf3e83 159/*
aac74dc4 160 * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
3ccf3e83 161 */
aac74dc4 162__printf(1, 2) __cold int printk_deferred(const char *fmt, ...);
3ccf3e83 163
968ab183
LT
164/*
165 * Please don't use printk_ratelimit(), because it shares ratelimiting state
166 * with all other unrelated printk_ratelimit() callsites. Instead use
167 * printk_ratelimited() or plain old __ratelimit().
168 */
169extern int __printk_ratelimit(const char *func);
170#define printk_ratelimit() __printk_ratelimit(__func__)
171extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
172 unsigned int interval_msec);
173
174extern int printk_delay_msec;
175extern int dmesg_restrict;
455cd5ab 176extern int kptr_restrict;
968ab183 177
dc72c32e
FW
178extern void wake_up_klogd(void);
179
07261edb
PK
180char *log_buf_addr_get(void);
181u32 log_buf_len_get(void);
968ab183 182void log_buf_kexec_setup(void);
162a7e75 183void __init setup_log_buf(int early);
8db14860 184__printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
196779b9 185void dump_stack_print_info(const char *log_lvl);
a43cb95d 186void show_regs_print_info(const char *log_lvl);
968ab183 187#else
b9075fa9 188static inline __printf(1, 0)
5264f2f7
JP
189int vprintk(const char *s, va_list args)
190{
191 return 0;
192}
b9075fa9 193static inline __printf(1, 2) __cold
5264f2f7
JP
194int printk(const char *s, ...)
195{
196 return 0;
197}
3ccf3e83 198static inline __printf(1, 2) __cold
aac74dc4 199int printk_deferred(const char *s, ...)
3ccf3e83
PZ
200{
201 return 0;
202}
5264f2f7
JP
203static inline int printk_ratelimit(void)
204{
205 return 0;
206}
207static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
208 unsigned int interval_msec)
209{
210 return false;
211}
968ab183 212
dc72c32e
FW
213static inline void wake_up_klogd(void)
214{
215}
216
07261edb
PK
217static inline char *log_buf_addr_get(void)
218{
219 return NULL;
220}
221
222static inline u32 log_buf_len_get(void)
223{
224 return 0;
225}
226
968ab183
LT
227static inline void log_buf_kexec_setup(void)
228{
229}
162a7e75
MT
230
231static inline void setup_log_buf(int early)
232{
233}
196779b9 234
8db14860 235static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...)
98e5e1bf
TH
236{
237}
238
196779b9
TH
239static inline void dump_stack_print_info(const char *log_lvl)
240{
241}
a43cb95d
TH
242
243static inline void show_regs_print_info(const char *log_lvl)
244{
245}
968ab183
LT
246#endif
247
b6c035d0 248extern asmlinkage void dump_stack(void) __cold;
968ab183 249
968ab183
LT
250#ifndef pr_fmt
251#define pr_fmt(fmt) fmt
252#endif
253
6e099f55
DS
254/*
255 * These can be used to print at the various log levels.
256 * All of these will print unconditionally, although note that pr_debug()
257 * and other debug macros are compiled out unless either DEBUG is defined
258 * or CONFIG_DYNAMIC_DEBUG is set.
259 */
968ab183 260#define pr_emerg(fmt, ...) \
a3f938bf 261 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
968ab183 262#define pr_alert(fmt, ...) \
a3f938bf 263 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
968ab183 264#define pr_crit(fmt, ...) \
a3f938bf 265 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
968ab183 266#define pr_err(fmt, ...) \
a3f938bf 267 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
968ab183 268#define pr_warning(fmt, ...) \
a3f938bf 269 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
270#define pr_warn pr_warning
271#define pr_notice(fmt, ...) \
a3f938bf 272 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
968ab183 273#define pr_info(fmt, ...) \
a3f938bf 274 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
7b1460ec
SR
275/*
276 * Like KERN_CONT, pr_cont() should only be used when continuing
277 * a line with no newline ('\n') enclosed. Otherwise it defaults
278 * back to KERN_DEFAULT.
279 */
968ab183
LT
280#define pr_cont(fmt, ...) \
281 printk(KERN_CONT fmt, ##__VA_ARGS__)
282
283/* pr_devel() should produce zero code unless DEBUG is defined */
284#ifdef DEBUG
285#define pr_devel(fmt, ...) \
286 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
287#else
288#define pr_devel(fmt, ...) \
5264f2f7 289 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
290#endif
291
29fc2bc7
JP
292#include <linux/dynamic_debug.h>
293
968ab183 294/* If you are writing a driver, please use dev_dbg instead */
b558c96f 295#if defined(CONFIG_DYNAMIC_DEBUG)
968ab183
LT
296/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
297#define pr_debug(fmt, ...) \
298 dynamic_pr_debug(fmt, ##__VA_ARGS__)
b558c96f
JC
299#elif defined(DEBUG)
300#define pr_debug(fmt, ...) \
301 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
302#else
303#define pr_debug(fmt, ...) \
5264f2f7 304 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
305#endif
306
16cb839f
JP
307/*
308 * Print a one-time message (analogous to WARN_ONCE() et al):
309 */
310
311#ifdef CONFIG_PRINTK
c28aa1f0
JP
312#define printk_once(fmt, ...) \
313({ \
314 static bool __print_once __read_mostly; \
069f0cd0 315 bool __ret_print_once = !__print_once; \
c28aa1f0
JP
316 \
317 if (!__print_once) { \
318 __print_once = true; \
319 printk(fmt, ##__VA_ARGS__); \
320 } \
069f0cd0 321 unlikely(__ret_print_once); \
16cb839f 322})
c224815d
JS
323#define printk_deferred_once(fmt, ...) \
324({ \
325 static bool __print_once __read_mostly; \
069f0cd0 326 bool __ret_print_once = !__print_once; \
c224815d
JS
327 \
328 if (!__print_once) { \
329 __print_once = true; \
330 printk_deferred(fmt, ##__VA_ARGS__); \
331 } \
069f0cd0 332 unlikely(__ret_print_once); \
c224815d 333})
16cb839f 334#else
c28aa1f0 335#define printk_once(fmt, ...) \
16cb839f 336 no_printk(fmt, ##__VA_ARGS__)
c224815d
JS
337#define printk_deferred_once(fmt, ...) \
338 no_printk(fmt, ##__VA_ARGS__)
16cb839f
JP
339#endif
340
341#define pr_emerg_once(fmt, ...) \
342 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
343#define pr_alert_once(fmt, ...) \
344 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
345#define pr_crit_once(fmt, ...) \
346 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
347#define pr_err_once(fmt, ...) \
348 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
349#define pr_warn_once(fmt, ...) \
350 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
351#define pr_notice_once(fmt, ...) \
352 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
353#define pr_info_once(fmt, ...) \
354 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
355#define pr_cont_once(fmt, ...) \
356 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
36d308d8
MG
357
358#if defined(DEBUG)
359#define pr_devel_once(fmt, ...) \
360 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
361#else
362#define pr_devel_once(fmt, ...) \
363 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
364#endif
365
16cb839f
JP
366/* If you are writing a driver, please use dev_dbg instead */
367#if defined(DEBUG)
368#define pr_debug_once(fmt, ...) \
369 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
370#else
371#define pr_debug_once(fmt, ...) \
372 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
373#endif
374
968ab183
LT
375/*
376 * ratelimited messages with local ratelimit_state,
377 * no local ratelimit_state used in the !PRINTK case
378 */
379#ifdef CONFIG_PRINTK
6ec42a56
JP
380#define printk_ratelimited(fmt, ...) \
381({ \
968ab183
LT
382 static DEFINE_RATELIMIT_STATE(_rs, \
383 DEFAULT_RATELIMIT_INTERVAL, \
384 DEFAULT_RATELIMIT_BURST); \
385 \
386 if (__ratelimit(&_rs)) \
387 printk(fmt, ##__VA_ARGS__); \
388})
389#else
6ec42a56
JP
390#define printk_ratelimited(fmt, ...) \
391 no_printk(fmt, ##__VA_ARGS__)
968ab183
LT
392#endif
393
6ec42a56 394#define pr_emerg_ratelimited(fmt, ...) \
968ab183 395 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 396#define pr_alert_ratelimited(fmt, ...) \
968ab183 397 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 398#define pr_crit_ratelimited(fmt, ...) \
968ab183 399 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 400#define pr_err_ratelimited(fmt, ...) \
968ab183 401 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 402#define pr_warn_ratelimited(fmt, ...) \
968ab183 403 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 404#define pr_notice_ratelimited(fmt, ...) \
968ab183 405 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 406#define pr_info_ratelimited(fmt, ...) \
968ab183
LT
407 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
408/* no pr_cont_ratelimited, don't do that... */
36d308d8
MG
409
410#if defined(DEBUG)
411#define pr_devel_ratelimited(fmt, ...) \
412 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
413#else
414#define pr_devel_ratelimited(fmt, ...) \
415 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
416#endif
417
968ab183 418/* If you are writing a driver, please use dev_dbg instead */
29fc2bc7
JP
419#if defined(CONFIG_DYNAMIC_DEBUG)
420/* descriptor check is first to prevent flooding with "callbacks suppressed" */
421#define pr_debug_ratelimited(fmt, ...) \
422do { \
423 static DEFINE_RATELIMIT_STATE(_rs, \
424 DEFAULT_RATELIMIT_INTERVAL, \
425 DEFAULT_RATELIMIT_BURST); \
515a9adc 426 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
29fc2bc7
JP
427 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
428 __ratelimit(&_rs)) \
515a9adc 429 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
29fc2bc7
JP
430} while (0)
431#elif defined(DEBUG)
6ec42a56 432#define pr_debug_ratelimited(fmt, ...) \
968ab183
LT
433 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
434#else
435#define pr_debug_ratelimited(fmt, ...) \
5264f2f7 436 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
437#endif
438
e11fea92
KS
439extern const struct file_operations kmsg_fops;
440
ac83ed68
JP
441enum {
442 DUMP_PREFIX_NONE,
443 DUMP_PREFIX_ADDRESS,
444 DUMP_PREFIX_OFFSET
445};
114fc1af
AS
446extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
447 int groupsize, char *linebuf, size_t linebuflen,
448 bool ascii);
ac83ed68
JP
449#ifdef CONFIG_PRINTK
450extern void print_hex_dump(const char *level, const char *prefix_str,
451 int prefix_type, int rowsize, int groupsize,
452 const void *buf, size_t len, bool ascii);
7a555613
VK
453#if defined(CONFIG_DYNAMIC_DEBUG)
454#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
455 dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
456#else
ac83ed68
JP
457extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
458 const void *buf, size_t len);
7a555613 459#endif /* defined(CONFIG_DYNAMIC_DEBUG) */
ac83ed68
JP
460#else
461static inline void print_hex_dump(const char *level, const char *prefix_str,
462 int prefix_type, int rowsize, int groupsize,
463 const void *buf, size_t len, bool ascii)
464{
465}
466static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
467 const void *buf, size_t len)
468{
469}
470
471#endif
472
7a555613
VK
473#if defined(CONFIG_DYNAMIC_DEBUG)
474#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
475 groupsize, buf, len, ascii) \
476 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
477 groupsize, buf, len, ascii)
cdf17449 478#elif defined(DEBUG)
7a555613
VK
479#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
480 groupsize, buf, len, ascii) \
481 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
482 groupsize, buf, len, ascii)
cdf17449
LW
483#else
484static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
485 int rowsize, int groupsize,
486 const void *buf, size_t len, bool ascii)
487{
488}
489#endif
7a555613 490
968ab183 491#endif