| .. | .. |
|---|
| 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 | } |
|---|
| .. | .. |
|---|
| 84 | 84 | extern char devkmsg_log_str[]; |
|---|
| 85 | 85 | struct ctl_table; |
|---|
| 86 | 86 | |
|---|
| 87 | +extern int suppress_printk; |
|---|
| 88 | + |
|---|
| 87 | 89 | struct va_format { |
|---|
| 88 | 90 | const char *fmt; |
|---|
| 89 | 91 | va_list *va; |
|---|
| .. | .. |
|---|
| 141 | 143 | #ifdef CONFIG_EARLY_PRINTK |
|---|
| 142 | 144 | extern asmlinkage __printf(1, 2) |
|---|
| 143 | 145 | void early_printk(const char *fmt, ...); |
|---|
| 144 | | -extern void printk_kill(void); |
|---|
| 145 | 146 | #else |
|---|
| 146 | 147 | static inline __printf(1, 2) __cold |
|---|
| 147 | 148 | void early_printk(const char *s, ...) { } |
|---|
| 148 | | -static inline void printk_kill(void) { } |
|---|
| 149 | 149 | #endif |
|---|
| 150 | 150 | |
|---|
| 151 | 151 | #ifdef CONFIG_PRINTK_NMI |
|---|
| .. | .. |
|---|
| 160 | 160 | static inline void printk_nmi_direct_exit(void) { } |
|---|
| 161 | 161 | #endif /* PRINTK_NMI */ |
|---|
| 162 | 162 | |
|---|
| 163 | +struct dev_printk_info; |
|---|
| 164 | + |
|---|
| 163 | 165 | #ifdef CONFIG_PRINTK |
|---|
| 164 | | -asmlinkage __printf(5, 0) |
|---|
| 166 | +asmlinkage __printf(4, 0) |
|---|
| 165 | 167 | int vprintk_emit(int facility, int level, |
|---|
| 166 | | - const char *dict, size_t dictlen, |
|---|
| 168 | + const struct dev_printk_info *dev_info, |
|---|
| 167 | 169 | const char *fmt, va_list args); |
|---|
| 168 | 170 | |
|---|
| 169 | 171 | asmlinkage __printf(1, 0) |
|---|
| 170 | 172 | 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 | 173 | |
|---|
| 177 | 174 | asmlinkage __printf(1, 2) __cold |
|---|
| 178 | 175 | int printk(const char *fmt, ...); |
|---|
| .. | .. |
|---|
| 196 | 193 | extern int dmesg_restrict; |
|---|
| 197 | 194 | |
|---|
| 198 | 195 | extern int |
|---|
| 199 | | -devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, void __user *buf, |
|---|
| 196 | +devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, void *buf, |
|---|
| 200 | 197 | size_t *lenp, loff_t *ppos); |
|---|
| 201 | 198 | |
|---|
| 202 | 199 | extern void wake_up_klogd(void); |
|---|
| .. | .. |
|---|
| 208 | 205 | __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...); |
|---|
| 209 | 206 | void dump_stack_print_info(const char *log_lvl); |
|---|
| 210 | 207 | void show_regs_print_info(const char *log_lvl); |
|---|
| 208 | +extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold; |
|---|
| 211 | 209 | extern asmlinkage void dump_stack(void) __cold; |
|---|
| 212 | 210 | extern void printk_safe_flush(void); |
|---|
| 213 | 211 | extern void printk_safe_flush_on_panic(void); |
|---|
| .. | .. |
|---|
| 271 | 269 | { |
|---|
| 272 | 270 | } |
|---|
| 273 | 271 | |
|---|
| 274 | | -static inline asmlinkage void dump_stack(void) |
|---|
| 272 | +static inline void dump_stack_lvl(const char *log_lvl) |
|---|
| 273 | +{ |
|---|
| 274 | +} |
|---|
| 275 | + |
|---|
| 276 | +static inline void dump_stack(void) |
|---|
| 275 | 277 | { |
|---|
| 276 | 278 | } |
|---|
| 277 | 279 | |
|---|
| .. | .. |
|---|
| 286 | 288 | |
|---|
| 287 | 289 | extern int kptr_restrict; |
|---|
| 288 | 290 | |
|---|
| 291 | +/** |
|---|
| 292 | + * pr_fmt - used by the pr_*() macros to generate the printk format string |
|---|
| 293 | + * @fmt: format string passed from a pr_*() macro |
|---|
| 294 | + * |
|---|
| 295 | + * This macro can be used to generate a unified format string for pr_*() |
|---|
| 296 | + * macros. A common use is to prefix all pr_*() messages in a file with a common |
|---|
| 297 | + * string. For example, defining this at the top of a source file: |
|---|
| 298 | + * |
|---|
| 299 | + * #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
|---|
| 300 | + * |
|---|
| 301 | + * would prefix all pr_info, pr_emerg... messages in the file with the module |
|---|
| 302 | + * name. |
|---|
| 303 | + */ |
|---|
| 289 | 304 | #ifndef pr_fmt |
|---|
| 290 | 305 | #define pr_fmt(fmt) fmt |
|---|
| 291 | 306 | #endif |
|---|
| 292 | 307 | |
|---|
| 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. |
|---|
| 308 | +/** |
|---|
| 309 | + * pr_emerg - Print an emergency-level message |
|---|
| 310 | + * @fmt: format string |
|---|
| 311 | + * @...: arguments for the format string |
|---|
| 312 | + * |
|---|
| 313 | + * This macro expands to a printk with KERN_EMERG loglevel. It uses pr_fmt() to |
|---|
| 314 | + * generate the format string. |
|---|
| 298 | 315 | */ |
|---|
| 299 | 316 | #define pr_emerg(fmt, ...) \ |
|---|
| 300 | 317 | printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) |
|---|
| 318 | +/** |
|---|
| 319 | + * pr_alert - Print an alert-level message |
|---|
| 320 | + * @fmt: format string |
|---|
| 321 | + * @...: arguments for the format string |
|---|
| 322 | + * |
|---|
| 323 | + * This macro expands to a printk with KERN_ALERT loglevel. It uses pr_fmt() to |
|---|
| 324 | + * generate the format string. |
|---|
| 325 | + */ |
|---|
| 301 | 326 | #define pr_alert(fmt, ...) \ |
|---|
| 302 | 327 | printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) |
|---|
| 328 | +/** |
|---|
| 329 | + * pr_crit - Print a critical-level message |
|---|
| 330 | + * @fmt: format string |
|---|
| 331 | + * @...: arguments for the format string |
|---|
| 332 | + * |
|---|
| 333 | + * This macro expands to a printk with KERN_CRIT loglevel. It uses pr_fmt() to |
|---|
| 334 | + * generate the format string. |
|---|
| 335 | + */ |
|---|
| 303 | 336 | #define pr_crit(fmt, ...) \ |
|---|
| 304 | 337 | printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) |
|---|
| 338 | +/** |
|---|
| 339 | + * pr_err - Print an error-level message |
|---|
| 340 | + * @fmt: format string |
|---|
| 341 | + * @...: arguments for the format string |
|---|
| 342 | + * |
|---|
| 343 | + * This macro expands to a printk with KERN_ERR loglevel. It uses pr_fmt() to |
|---|
| 344 | + * generate the format string. |
|---|
| 345 | + */ |
|---|
| 305 | 346 | #define pr_err(fmt, ...) \ |
|---|
| 306 | 347 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) |
|---|
| 307 | | -#define pr_warning(fmt, ...) \ |
|---|
| 348 | +/** |
|---|
| 349 | + * pr_warn - Print a warning-level message |
|---|
| 350 | + * @fmt: format string |
|---|
| 351 | + * @...: arguments for the format string |
|---|
| 352 | + * |
|---|
| 353 | + * This macro expands to a printk with KERN_WARNING loglevel. It uses pr_fmt() |
|---|
| 354 | + * to generate the format string. |
|---|
| 355 | + */ |
|---|
| 356 | +#define pr_warn(fmt, ...) \ |
|---|
| 308 | 357 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) |
|---|
| 309 | | -#define pr_warn pr_warning |
|---|
| 358 | +/** |
|---|
| 359 | + * pr_notice - Print a notice-level message |
|---|
| 360 | + * @fmt: format string |
|---|
| 361 | + * @...: arguments for the format string |
|---|
| 362 | + * |
|---|
| 363 | + * This macro expands to a printk with KERN_NOTICE loglevel. It uses pr_fmt() to |
|---|
| 364 | + * generate the format string. |
|---|
| 365 | + */ |
|---|
| 310 | 366 | #define pr_notice(fmt, ...) \ |
|---|
| 311 | 367 | printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) |
|---|
| 368 | +/** |
|---|
| 369 | + * pr_info - Print an info-level message |
|---|
| 370 | + * @fmt: format string |
|---|
| 371 | + * @...: arguments for the format string |
|---|
| 372 | + * |
|---|
| 373 | + * This macro expands to a printk with KERN_INFO loglevel. It uses pr_fmt() to |
|---|
| 374 | + * generate the format string. |
|---|
| 375 | + */ |
|---|
| 312 | 376 | #define pr_info(fmt, ...) \ |
|---|
| 313 | 377 | 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. |
|---|
| 378 | + |
|---|
| 379 | +/** |
|---|
| 380 | + * pr_cont - Continues a previous log message in the same line. |
|---|
| 381 | + * @fmt: format string |
|---|
| 382 | + * @...: arguments for the format string |
|---|
| 383 | + * |
|---|
| 384 | + * This macro expands to a printk with KERN_CONT loglevel. It should only be |
|---|
| 385 | + * used when continuing a log message with no newline ('\n') enclosed. Otherwise |
|---|
| 386 | + * it defaults back to KERN_DEFAULT loglevel. |
|---|
| 318 | 387 | */ |
|---|
| 319 | 388 | #define pr_cont(fmt, ...) \ |
|---|
| 320 | 389 | printk(KERN_CONT fmt, ##__VA_ARGS__) |
|---|
| 321 | 390 | |
|---|
| 322 | | -/* pr_devel() should produce zero code unless DEBUG is defined */ |
|---|
| 391 | +/** |
|---|
| 392 | + * pr_devel - Print a debug-level message conditionally |
|---|
| 393 | + * @fmt: format string |
|---|
| 394 | + * @...: arguments for the format string |
|---|
| 395 | + * |
|---|
| 396 | + * This macro expands to a printk with KERN_DEBUG loglevel if DEBUG is |
|---|
| 397 | + * defined. Otherwise it does nothing. |
|---|
| 398 | + * |
|---|
| 399 | + * It uses pr_fmt() to generate the format string. |
|---|
| 400 | + */ |
|---|
| 323 | 401 | #ifdef DEBUG |
|---|
| 324 | 402 | #define pr_devel(fmt, ...) \ |
|---|
| 325 | 403 | printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
|---|
| .. | .. |
|---|
| 330 | 408 | |
|---|
| 331 | 409 | |
|---|
| 332 | 410 | /* If you are writing a driver, please use dev_dbg instead */ |
|---|
| 333 | | -#if defined(CONFIG_DYNAMIC_DEBUG) |
|---|
| 411 | +#if defined(CONFIG_DYNAMIC_DEBUG) || \ |
|---|
| 412 | + (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) |
|---|
| 334 | 413 | #include <linux/dynamic_debug.h> |
|---|
| 335 | 414 | |
|---|
| 336 | | -/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ |
|---|
| 337 | | -#define pr_debug(fmt, ...) \ |
|---|
| 415 | +/** |
|---|
| 416 | + * pr_debug - Print a debug-level message conditionally |
|---|
| 417 | + * @fmt: format string |
|---|
| 418 | + * @...: arguments for the format string |
|---|
| 419 | + * |
|---|
| 420 | + * This macro expands to dynamic_pr_debug() if CONFIG_DYNAMIC_DEBUG is |
|---|
| 421 | + * set. Otherwise, if DEBUG is defined, it's equivalent to a printk with |
|---|
| 422 | + * KERN_DEBUG loglevel. If DEBUG is not defined it does nothing. |
|---|
| 423 | + * |
|---|
| 424 | + * It uses pr_fmt() to generate the format string (dynamic_pr_debug() uses |
|---|
| 425 | + * pr_fmt() internally). |
|---|
| 426 | + */ |
|---|
| 427 | +#define pr_debug(fmt, ...) \ |
|---|
| 338 | 428 | dynamic_pr_debug(fmt, ##__VA_ARGS__) |
|---|
| 339 | 429 | #elif defined(DEBUG) |
|---|
| 340 | 430 | #define pr_debug(fmt, ...) \ |
|---|
| .. | .. |
|---|
| 351 | 441 | #ifdef CONFIG_PRINTK |
|---|
| 352 | 442 | #define printk_once(fmt, ...) \ |
|---|
| 353 | 443 | ({ \ |
|---|
| 354 | | - static bool __print_once __read_mostly; \ |
|---|
| 444 | + static bool __section(".data.once") __print_once; \ |
|---|
| 355 | 445 | bool __ret_print_once = !__print_once; \ |
|---|
| 356 | 446 | \ |
|---|
| 357 | 447 | if (!__print_once) { \ |
|---|
| .. | .. |
|---|
| 362 | 452 | }) |
|---|
| 363 | 453 | #define printk_deferred_once(fmt, ...) \ |
|---|
| 364 | 454 | ({ \ |
|---|
| 365 | | - static bool __print_once __read_mostly; \ |
|---|
| 455 | + static bool __section(".data.once") __print_once; \ |
|---|
| 366 | 456 | bool __ret_print_once = !__print_once; \ |
|---|
| 367 | 457 | \ |
|---|
| 368 | 458 | if (!__print_once) { \ |
|---|
| .. | .. |
|---|
| 392 | 482 | printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) |
|---|
| 393 | 483 | #define pr_info_once(fmt, ...) \ |
|---|
| 394 | 484 | 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__) |
|---|
| 485 | +/* no pr_cont_once, don't do that... */ |
|---|
| 397 | 486 | |
|---|
| 398 | 487 | #if defined(DEBUG) |
|---|
| 399 | 488 | #define pr_devel_once(fmt, ...) \ |
|---|
| .. | .. |
|---|
| 456 | 545 | #endif |
|---|
| 457 | 546 | |
|---|
| 458 | 547 | /* If you are writing a driver, please use dev_dbg instead */ |
|---|
| 459 | | -#if defined(CONFIG_DYNAMIC_DEBUG) |
|---|
| 548 | +#if defined(CONFIG_DYNAMIC_DEBUG) || \ |
|---|
| 549 | + (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) |
|---|
| 460 | 550 | /* descriptor check is first to prevent flooding with "callbacks suppressed" */ |
|---|
| 461 | 551 | #define pr_debug_ratelimited(fmt, ...) \ |
|---|
| 462 | 552 | do { \ |
|---|
| .. | .. |
|---|
| 464 | 554 | DEFAULT_RATELIMIT_INTERVAL, \ |
|---|
| 465 | 555 | DEFAULT_RATELIMIT_BURST); \ |
|---|
| 466 | 556 | DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \ |
|---|
| 467 | | - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ |
|---|
| 557 | + if (DYNAMIC_DEBUG_BRANCH(descriptor) && \ |
|---|
| 468 | 558 | __ratelimit(&_rs)) \ |
|---|
| 469 | 559 | __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \ |
|---|
| 470 | 560 | } while (0) |
|---|
| .. | .. |
|---|
| 490 | 580 | extern void print_hex_dump(const char *level, const char *prefix_str, |
|---|
| 491 | 581 | int prefix_type, int rowsize, int groupsize, |
|---|
| 492 | 582 | 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 | 583 | #else |
|---|
| 501 | 584 | static inline void print_hex_dump(const char *level, const char *prefix_str, |
|---|
| 502 | 585 | int prefix_type, int rowsize, int groupsize, |
|---|
| .. | .. |
|---|
| 510 | 593 | |
|---|
| 511 | 594 | #endif |
|---|
| 512 | 595 | |
|---|
| 513 | | -#if defined(CONFIG_DYNAMIC_DEBUG) |
|---|
| 596 | +#if defined(CONFIG_DYNAMIC_DEBUG) || \ |
|---|
| 597 | + (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) |
|---|
| 514 | 598 | #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ |
|---|
| 515 | 599 | groupsize, buf, len, ascii) \ |
|---|
| 516 | 600 | dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ |
|---|
| .. | .. |
|---|
| 528 | 612 | } |
|---|
| 529 | 613 | #endif |
|---|
| 530 | 614 | |
|---|
| 615 | +/** |
|---|
| 616 | + * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params |
|---|
| 617 | + * @prefix_str: string to prefix each line with; |
|---|
| 618 | + * caller supplies trailing spaces for alignment if desired |
|---|
| 619 | + * @prefix_type: controls whether prefix of an offset, address, or none |
|---|
| 620 | + * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE) |
|---|
| 621 | + * @buf: data blob to dump |
|---|
| 622 | + * @len: number of bytes in the @buf |
|---|
| 623 | + * |
|---|
| 624 | + * Calls print_hex_dump(), with log level of KERN_DEBUG, |
|---|
| 625 | + * rowsize of 16, groupsize of 1, and ASCII output included. |
|---|
| 626 | + */ |
|---|
| 627 | +#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \ |
|---|
| 628 | + print_hex_dump_debug(prefix_str, prefix_type, 16, 1, buf, len, true) |
|---|
| 629 | + |
|---|
| 630 | +#ifdef CONFIG_PRINTK |
|---|
| 631 | +extern void __printk_safe_enter(void); |
|---|
| 632 | +extern void __printk_safe_exit(void); |
|---|
| 633 | +/* |
|---|
| 634 | + * The printk_deferred_enter/exit macros are available only as a hack for |
|---|
| 635 | + * some code paths that need to defer all printk console printing. Interrupts |
|---|
| 636 | + * must be disabled for the deferred duration. |
|---|
| 637 | + */ |
|---|
| 638 | +#define printk_deferred_enter __printk_safe_enter |
|---|
| 639 | +#define printk_deferred_exit __printk_safe_exit |
|---|
| 640 | +#else |
|---|
| 641 | +static inline void printk_deferred_enter(void) |
|---|
| 642 | +{ |
|---|
| 643 | +} |
|---|
| 644 | +static inline void printk_deferred_exit(void) |
|---|
| 645 | +{ |
|---|
| 646 | +} |
|---|
| 647 | +#endif |
|---|
| 648 | + |
|---|
| 531 | 649 | #endif |
|---|