.. | .. |
---|
6 | 6 | #include <linux/init.h> |
---|
7 | 7 | #include <linux/kern_levels.h> |
---|
8 | 8 | #include <linux/linkage.h> |
---|
9 | | -#include <linux/cache.h> |
---|
| 9 | +#include <linux/ratelimit_types.h> |
---|
10 | 10 | |
---|
11 | 11 | extern const char linux_banner[]; |
---|
12 | | -extern const char *linux_banner_ptr; |
---|
13 | 12 | extern const char linux_proc_banner[]; |
---|
| 13 | + |
---|
| 14 | +extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */ |
---|
14 | 15 | |
---|
15 | 16 | #define PRINTK_MAX_SINGLE_HEADER_LEN 2 |
---|
16 | 17 | |
---|
.. | .. |
---|
19 | 20 | if (buffer[0] == KERN_SOH_ASCII && buffer[1]) { |
---|
20 | 21 | switch (buffer[1]) { |
---|
21 | 22 | case '0' ... '7': |
---|
22 | | - case 'd': /* KERN_DEFAULT */ |
---|
23 | 23 | case 'c': /* KERN_CONT */ |
---|
24 | 24 | return buffer[1]; |
---|
25 | 25 | } |
---|
.. | .. |
---|
44 | 44 | } |
---|
45 | 45 | |
---|
46 | 46 | #define CONSOLE_EXT_LOG_MAX 8192 |
---|
| 47 | + |
---|
| 48 | +/* |
---|
| 49 | + * The maximum size of a record formatted for console printing |
---|
| 50 | + * (i.e. with the prefix prepended to every line). |
---|
| 51 | + */ |
---|
| 52 | +#define CONSOLE_LOG_MAX 4096 |
---|
47 | 53 | |
---|
48 | 54 | /* printk's without a loglevel use this.. */ |
---|
49 | 55 | #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT |
---|
.. | .. |
---|
83 | 89 | #define DEVKMSG_STR_MAX_SIZE 10 |
---|
84 | 90 | extern char devkmsg_log_str[]; |
---|
85 | 91 | struct ctl_table; |
---|
| 92 | + |
---|
| 93 | +extern int suppress_printk; |
---|
86 | 94 | |
---|
87 | 95 | struct va_format { |
---|
88 | 96 | const char *fmt; |
---|
.. | .. |
---|
141 | 149 | #ifdef CONFIG_EARLY_PRINTK |
---|
142 | 150 | extern asmlinkage __printf(1, 2) |
---|
143 | 151 | void early_printk(const char *fmt, ...); |
---|
144 | | -extern void printk_kill(void); |
---|
145 | 152 | #else |
---|
146 | 153 | static inline __printf(1, 2) __cold |
---|
147 | 154 | void early_printk(const char *s, ...) { } |
---|
148 | | -static inline void printk_kill(void) { } |
---|
149 | 155 | #endif |
---|
150 | 156 | |
---|
151 | | -#ifdef CONFIG_PRINTK_NMI |
---|
152 | | -extern void printk_nmi_enter(void); |
---|
153 | | -extern void printk_nmi_exit(void); |
---|
154 | | -extern void printk_nmi_direct_enter(void); |
---|
155 | | -extern void printk_nmi_direct_exit(void); |
---|
156 | | -#else |
---|
157 | | -static inline void printk_nmi_enter(void) { } |
---|
158 | | -static inline void printk_nmi_exit(void) { } |
---|
159 | | -static inline void printk_nmi_direct_enter(void) { } |
---|
160 | | -static inline void printk_nmi_direct_exit(void) { } |
---|
161 | | -#endif /* PRINTK_NMI */ |
---|
| 157 | +struct dev_printk_info; |
---|
162 | 158 | |
---|
163 | 159 | #ifdef CONFIG_PRINTK |
---|
164 | | -asmlinkage __printf(5, 0) |
---|
| 160 | +asmlinkage __printf(4, 0) |
---|
165 | 161 | int vprintk_emit(int facility, int level, |
---|
166 | | - const char *dict, size_t dictlen, |
---|
| 162 | + const struct dev_printk_info *dev_info, |
---|
167 | 163 | const char *fmt, va_list args); |
---|
168 | 164 | |
---|
169 | 165 | asmlinkage __printf(1, 0) |
---|
170 | 166 | int vprintk(const char *fmt, va_list args); |
---|
171 | | - |
---|
172 | | -asmlinkage __printf(5, 6) __cold |
---|
173 | | -int printk_emit(int facility, int level, |
---|
174 | | - const char *dict, size_t dictlen, |
---|
175 | | - const char *fmt, ...); |
---|
176 | 167 | |
---|
177 | 168 | asmlinkage __printf(1, 2) __cold |
---|
178 | 169 | int printk(const char *fmt, ...); |
---|
.. | .. |
---|
196 | 187 | extern int dmesg_restrict; |
---|
197 | 188 | |
---|
198 | 189 | extern int |
---|
199 | | -devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, void __user *buf, |
---|
| 190 | +devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, void *buf, |
---|
200 | 191 | size_t *lenp, loff_t *ppos); |
---|
201 | 192 | |
---|
202 | 193 | extern void wake_up_klogd(void); |
---|
.. | .. |
---|
208 | 199 | __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...); |
---|
209 | 200 | void dump_stack_print_info(const char *log_lvl); |
---|
210 | 201 | void show_regs_print_info(const char *log_lvl); |
---|
| 202 | +extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold; |
---|
211 | 203 | extern asmlinkage void dump_stack(void) __cold; |
---|
212 | | -extern void printk_safe_flush(void); |
---|
213 | | -extern void printk_safe_flush_on_panic(void); |
---|
214 | 204 | #else |
---|
215 | 205 | static inline __printf(1, 0) |
---|
216 | 206 | int vprintk(const char *s, va_list args) |
---|
.. | .. |
---|
271 | 261 | { |
---|
272 | 262 | } |
---|
273 | 263 | |
---|
274 | | -static inline asmlinkage void dump_stack(void) |
---|
| 264 | +static inline void dump_stack_lvl(const char *log_lvl) |
---|
275 | 265 | { |
---|
276 | 266 | } |
---|
277 | 267 | |
---|
278 | | -static inline void printk_safe_flush(void) |
---|
279 | | -{ |
---|
280 | | -} |
---|
281 | | - |
---|
282 | | -static inline void printk_safe_flush_on_panic(void) |
---|
| 268 | +static inline void dump_stack(void) |
---|
283 | 269 | { |
---|
284 | 270 | } |
---|
285 | 271 | #endif |
---|
286 | 272 | |
---|
287 | 273 | extern int kptr_restrict; |
---|
288 | 274 | |
---|
| 275 | +/** |
---|
| 276 | + * pr_fmt - used by the pr_*() macros to generate the printk format string |
---|
| 277 | + * @fmt: format string passed from a pr_*() macro |
---|
| 278 | + * |
---|
| 279 | + * This macro can be used to generate a unified format string for pr_*() |
---|
| 280 | + * macros. A common use is to prefix all pr_*() messages in a file with a common |
---|
| 281 | + * string. For example, defining this at the top of a source file: |
---|
| 282 | + * |
---|
| 283 | + * #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
---|
| 284 | + * |
---|
| 285 | + * would prefix all pr_info, pr_emerg... messages in the file with the module |
---|
| 286 | + * name. |
---|
| 287 | + */ |
---|
289 | 288 | #ifndef pr_fmt |
---|
290 | 289 | #define pr_fmt(fmt) fmt |
---|
291 | 290 | #endif |
---|
292 | 291 | |
---|
293 | | -/* |
---|
294 | | - * These can be used to print at the various log levels. |
---|
295 | | - * All of these will print unconditionally, although note that pr_debug() |
---|
296 | | - * and other debug macros are compiled out unless either DEBUG is defined |
---|
297 | | - * or CONFIG_DYNAMIC_DEBUG is set. |
---|
| 292 | +/** |
---|
| 293 | + * pr_emerg - Print an emergency-level message |
---|
| 294 | + * @fmt: format string |
---|
| 295 | + * @...: arguments for the format string |
---|
| 296 | + * |
---|
| 297 | + * This macro expands to a printk with KERN_EMERG loglevel. It uses pr_fmt() to |
---|
| 298 | + * generate the format string. |
---|
298 | 299 | */ |
---|
299 | 300 | #define pr_emerg(fmt, ...) \ |
---|
300 | 301 | printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) |
---|
| 302 | +/** |
---|
| 303 | + * pr_alert - Print an alert-level message |
---|
| 304 | + * @fmt: format string |
---|
| 305 | + * @...: arguments for the format string |
---|
| 306 | + * |
---|
| 307 | + * This macro expands to a printk with KERN_ALERT loglevel. It uses pr_fmt() to |
---|
| 308 | + * generate the format string. |
---|
| 309 | + */ |
---|
301 | 310 | #define pr_alert(fmt, ...) \ |
---|
302 | 311 | printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) |
---|
| 312 | +/** |
---|
| 313 | + * pr_crit - Print a critical-level message |
---|
| 314 | + * @fmt: format string |
---|
| 315 | + * @...: arguments for the format string |
---|
| 316 | + * |
---|
| 317 | + * This macro expands to a printk with KERN_CRIT loglevel. It uses pr_fmt() to |
---|
| 318 | + * generate the format string. |
---|
| 319 | + */ |
---|
303 | 320 | #define pr_crit(fmt, ...) \ |
---|
304 | 321 | printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) |
---|
| 322 | +/** |
---|
| 323 | + * pr_err - Print an error-level message |
---|
| 324 | + * @fmt: format string |
---|
| 325 | + * @...: arguments for the format string |
---|
| 326 | + * |
---|
| 327 | + * This macro expands to a printk with KERN_ERR loglevel. It uses pr_fmt() to |
---|
| 328 | + * generate the format string. |
---|
| 329 | + */ |
---|
305 | 330 | #define pr_err(fmt, ...) \ |
---|
306 | 331 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) |
---|
307 | | -#define pr_warning(fmt, ...) \ |
---|
| 332 | +/** |
---|
| 333 | + * pr_warn - Print a warning-level message |
---|
| 334 | + * @fmt: format string |
---|
| 335 | + * @...: arguments for the format string |
---|
| 336 | + * |
---|
| 337 | + * This macro expands to a printk with KERN_WARNING loglevel. It uses pr_fmt() |
---|
| 338 | + * to generate the format string. |
---|
| 339 | + */ |
---|
| 340 | +#define pr_warn(fmt, ...) \ |
---|
308 | 341 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) |
---|
309 | | -#define pr_warn pr_warning |
---|
| 342 | +/** |
---|
| 343 | + * pr_notice - Print a notice-level message |
---|
| 344 | + * @fmt: format string |
---|
| 345 | + * @...: arguments for the format string |
---|
| 346 | + * |
---|
| 347 | + * This macro expands to a printk with KERN_NOTICE loglevel. It uses pr_fmt() to |
---|
| 348 | + * generate the format string. |
---|
| 349 | + */ |
---|
310 | 350 | #define pr_notice(fmt, ...) \ |
---|
311 | 351 | printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) |
---|
| 352 | +/** |
---|
| 353 | + * pr_info - Print an info-level message |
---|
| 354 | + * @fmt: format string |
---|
| 355 | + * @...: arguments for the format string |
---|
| 356 | + * |
---|
| 357 | + * This macro expands to a printk with KERN_INFO loglevel. It uses pr_fmt() to |
---|
| 358 | + * generate the format string. |
---|
| 359 | + */ |
---|
312 | 360 | #define pr_info(fmt, ...) \ |
---|
313 | 361 | printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) |
---|
314 | | -/* |
---|
315 | | - * Like KERN_CONT, pr_cont() should only be used when continuing |
---|
316 | | - * a line with no newline ('\n') enclosed. Otherwise it defaults |
---|
317 | | - * back to KERN_DEFAULT. |
---|
| 362 | + |
---|
| 363 | +/** |
---|
| 364 | + * pr_cont - Continues a previous log message in the same line. |
---|
| 365 | + * @fmt: format string |
---|
| 366 | + * @...: arguments for the format string |
---|
| 367 | + * |
---|
| 368 | + * This macro expands to a printk with KERN_CONT loglevel. It should only be |
---|
| 369 | + * used when continuing a log message with no newline ('\n') enclosed. Otherwise |
---|
| 370 | + * it defaults back to KERN_DEFAULT loglevel. |
---|
318 | 371 | */ |
---|
319 | 372 | #define pr_cont(fmt, ...) \ |
---|
320 | 373 | printk(KERN_CONT fmt, ##__VA_ARGS__) |
---|
321 | 374 | |
---|
322 | | -/* pr_devel() should produce zero code unless DEBUG is defined */ |
---|
| 375 | +/** |
---|
| 376 | + * pr_devel - Print a debug-level message conditionally |
---|
| 377 | + * @fmt: format string |
---|
| 378 | + * @...: arguments for the format string |
---|
| 379 | + * |
---|
| 380 | + * This macro expands to a printk with KERN_DEBUG loglevel if DEBUG is |
---|
| 381 | + * defined. Otherwise it does nothing. |
---|
| 382 | + * |
---|
| 383 | + * It uses pr_fmt() to generate the format string. |
---|
| 384 | + */ |
---|
323 | 385 | #ifdef DEBUG |
---|
324 | 386 | #define pr_devel(fmt, ...) \ |
---|
325 | 387 | printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
---|
.. | .. |
---|
330 | 392 | |
---|
331 | 393 | |
---|
332 | 394 | /* If you are writing a driver, please use dev_dbg instead */ |
---|
333 | | -#if defined(CONFIG_DYNAMIC_DEBUG) |
---|
| 395 | +#if defined(CONFIG_DYNAMIC_DEBUG) || \ |
---|
| 396 | + (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) |
---|
334 | 397 | #include <linux/dynamic_debug.h> |
---|
335 | 398 | |
---|
336 | | -/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ |
---|
337 | | -#define pr_debug(fmt, ...) \ |
---|
| 399 | +/** |
---|
| 400 | + * pr_debug - Print a debug-level message conditionally |
---|
| 401 | + * @fmt: format string |
---|
| 402 | + * @...: arguments for the format string |
---|
| 403 | + * |
---|
| 404 | + * This macro expands to dynamic_pr_debug() if CONFIG_DYNAMIC_DEBUG is |
---|
| 405 | + * set. Otherwise, if DEBUG is defined, it's equivalent to a printk with |
---|
| 406 | + * KERN_DEBUG loglevel. If DEBUG is not defined it does nothing. |
---|
| 407 | + * |
---|
| 408 | + * It uses pr_fmt() to generate the format string (dynamic_pr_debug() uses |
---|
| 409 | + * pr_fmt() internally). |
---|
| 410 | + */ |
---|
| 411 | +#define pr_debug(fmt, ...) \ |
---|
338 | 412 | dynamic_pr_debug(fmt, ##__VA_ARGS__) |
---|
339 | 413 | #elif defined(DEBUG) |
---|
340 | 414 | #define pr_debug(fmt, ...) \ |
---|
.. | .. |
---|
351 | 425 | #ifdef CONFIG_PRINTK |
---|
352 | 426 | #define printk_once(fmt, ...) \ |
---|
353 | 427 | ({ \ |
---|
354 | | - static bool __print_once __read_mostly; \ |
---|
| 428 | + static bool __section(".data.once") __print_once; \ |
---|
355 | 429 | bool __ret_print_once = !__print_once; \ |
---|
356 | 430 | \ |
---|
357 | 431 | if (!__print_once) { \ |
---|
.. | .. |
---|
362 | 436 | }) |
---|
363 | 437 | #define printk_deferred_once(fmt, ...) \ |
---|
364 | 438 | ({ \ |
---|
365 | | - static bool __print_once __read_mostly; \ |
---|
| 439 | + static bool __section(".data.once") __print_once; \ |
---|
366 | 440 | bool __ret_print_once = !__print_once; \ |
---|
367 | 441 | \ |
---|
368 | 442 | if (!__print_once) { \ |
---|
.. | .. |
---|
392 | 466 | printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) |
---|
393 | 467 | #define pr_info_once(fmt, ...) \ |
---|
394 | 468 | printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) |
---|
395 | | -#define pr_cont_once(fmt, ...) \ |
---|
396 | | - printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) |
---|
| 469 | +/* no pr_cont_once, don't do that... */ |
---|
397 | 470 | |
---|
398 | 471 | #if defined(DEBUG) |
---|
399 | 472 | #define pr_devel_once(fmt, ...) \ |
---|
.. | .. |
---|
411 | 484 | #define pr_debug_once(fmt, ...) \ |
---|
412 | 485 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
---|
413 | 486 | #endif |
---|
| 487 | + |
---|
| 488 | +bool pr_flush(int timeout_ms, bool reset_on_progress); |
---|
414 | 489 | |
---|
415 | 490 | /* |
---|
416 | 491 | * ratelimited messages with local ratelimit_state, |
---|
.. | .. |
---|
456 | 531 | #endif |
---|
457 | 532 | |
---|
458 | 533 | /* If you are writing a driver, please use dev_dbg instead */ |
---|
459 | | -#if defined(CONFIG_DYNAMIC_DEBUG) |
---|
| 534 | +#if defined(CONFIG_DYNAMIC_DEBUG) || \ |
---|
| 535 | + (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) |
---|
460 | 536 | /* descriptor check is first to prevent flooding with "callbacks suppressed" */ |
---|
461 | 537 | #define pr_debug_ratelimited(fmt, ...) \ |
---|
462 | 538 | do { \ |
---|
.. | .. |
---|
464 | 540 | DEFAULT_RATELIMIT_INTERVAL, \ |
---|
465 | 541 | DEFAULT_RATELIMIT_BURST); \ |
---|
466 | 542 | DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \ |
---|
467 | | - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ |
---|
| 543 | + if (DYNAMIC_DEBUG_BRANCH(descriptor) && \ |
---|
468 | 544 | __ratelimit(&_rs)) \ |
---|
469 | 545 | __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \ |
---|
470 | 546 | } while (0) |
---|
.. | .. |
---|
490 | 566 | extern void print_hex_dump(const char *level, const char *prefix_str, |
---|
491 | 567 | int prefix_type, int rowsize, int groupsize, |
---|
492 | 568 | const void *buf, size_t len, bool ascii); |
---|
493 | | -#if defined(CONFIG_DYNAMIC_DEBUG) |
---|
494 | | -#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \ |
---|
495 | | - dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true) |
---|
496 | | -#else |
---|
497 | | -extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, |
---|
498 | | - const void *buf, size_t len); |
---|
499 | | -#endif /* defined(CONFIG_DYNAMIC_DEBUG) */ |
---|
500 | 569 | #else |
---|
501 | 570 | static inline void print_hex_dump(const char *level, const char *prefix_str, |
---|
502 | 571 | int prefix_type, int rowsize, int groupsize, |
---|
.. | .. |
---|
510 | 579 | |
---|
511 | 580 | #endif |
---|
512 | 581 | |
---|
513 | | -#if defined(CONFIG_DYNAMIC_DEBUG) |
---|
| 582 | +#if defined(CONFIG_DYNAMIC_DEBUG) || \ |
---|
| 583 | + (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) |
---|
514 | 584 | #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ |
---|
515 | 585 | groupsize, buf, len, ascii) \ |
---|
516 | 586 | dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ |
---|
.. | .. |
---|
528 | 598 | } |
---|
529 | 599 | #endif |
---|
530 | 600 | |
---|
| 601 | +/** |
---|
| 602 | + * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params |
---|
| 603 | + * @prefix_str: string to prefix each line with; |
---|
| 604 | + * caller supplies trailing spaces for alignment if desired |
---|
| 605 | + * @prefix_type: controls whether prefix of an offset, address, or none |
---|
| 606 | + * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE) |
---|
| 607 | + * @buf: data blob to dump |
---|
| 608 | + * @len: number of bytes in the @buf |
---|
| 609 | + * |
---|
| 610 | + * Calls print_hex_dump(), with log level of KERN_DEBUG, |
---|
| 611 | + * rowsize of 16, groupsize of 1, and ASCII output included. |
---|
| 612 | + */ |
---|
| 613 | +#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \ |
---|
| 614 | + print_hex_dump_debug(prefix_str, prefix_type, 16, 1, buf, len, true) |
---|
| 615 | + |
---|
531 | 616 | #endif |
---|