.. | .. |
---|
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 | } |
---|
.. | .. |
---|
83 | 83 | #define DEVKMSG_STR_MAX_SIZE 10 |
---|
84 | 84 | extern char devkmsg_log_str[]; |
---|
85 | 85 | struct ctl_table; |
---|
| 86 | + |
---|
| 87 | +extern int suppress_printk; |
---|
86 | 88 | |
---|
87 | 89 | struct va_format { |
---|
88 | 90 | const char *fmt; |
---|
.. | .. |
---|
158 | 160 | static inline void printk_nmi_direct_exit(void) { } |
---|
159 | 161 | #endif /* PRINTK_NMI */ |
---|
160 | 162 | |
---|
| 163 | +struct dev_printk_info; |
---|
| 164 | + |
---|
161 | 165 | #ifdef CONFIG_PRINTK |
---|
162 | | -asmlinkage __printf(5, 0) |
---|
| 166 | +asmlinkage __printf(4, 0) |
---|
163 | 167 | int vprintk_emit(int facility, int level, |
---|
164 | | - const char *dict, size_t dictlen, |
---|
| 168 | + const struct dev_printk_info *dev_info, |
---|
165 | 169 | const char *fmt, va_list args); |
---|
166 | 170 | |
---|
167 | 171 | asmlinkage __printf(1, 0) |
---|
168 | 172 | int vprintk(const char *fmt, va_list args); |
---|
169 | | - |
---|
170 | | -asmlinkage __printf(5, 6) __cold |
---|
171 | | -int printk_emit(int facility, int level, |
---|
172 | | - const char *dict, size_t dictlen, |
---|
173 | | - const char *fmt, ...); |
---|
174 | 173 | |
---|
175 | 174 | asmlinkage __printf(1, 2) __cold |
---|
176 | 175 | int printk(const char *fmt, ...); |
---|
.. | .. |
---|
194 | 193 | extern int dmesg_restrict; |
---|
195 | 194 | |
---|
196 | 195 | extern int |
---|
197 | | -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, |
---|
198 | 197 | size_t *lenp, loff_t *ppos); |
---|
199 | 198 | |
---|
200 | 199 | extern void wake_up_klogd(void); |
---|
.. | .. |
---|
206 | 205 | __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...); |
---|
207 | 206 | void dump_stack_print_info(const char *log_lvl); |
---|
208 | 207 | void show_regs_print_info(const char *log_lvl); |
---|
| 208 | +extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold; |
---|
209 | 209 | extern asmlinkage void dump_stack(void) __cold; |
---|
210 | 210 | extern void printk_safe_flush(void); |
---|
211 | 211 | extern void printk_safe_flush_on_panic(void); |
---|
.. | .. |
---|
269 | 269 | { |
---|
270 | 270 | } |
---|
271 | 271 | |
---|
272 | | -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) |
---|
273 | 277 | { |
---|
274 | 278 | } |
---|
275 | 279 | |
---|
.. | .. |
---|
284 | 288 | |
---|
285 | 289 | extern int kptr_restrict; |
---|
286 | 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 | + */ |
---|
287 | 304 | #ifndef pr_fmt |
---|
288 | 305 | #define pr_fmt(fmt) fmt |
---|
289 | 306 | #endif |
---|
290 | 307 | |
---|
291 | | -/* |
---|
292 | | - * These can be used to print at the various log levels. |
---|
293 | | - * All of these will print unconditionally, although note that pr_debug() |
---|
294 | | - * and other debug macros are compiled out unless either DEBUG is defined |
---|
295 | | - * 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. |
---|
296 | 315 | */ |
---|
297 | 316 | #define pr_emerg(fmt, ...) \ |
---|
298 | 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 | + */ |
---|
299 | 326 | #define pr_alert(fmt, ...) \ |
---|
300 | 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 | + */ |
---|
301 | 336 | #define pr_crit(fmt, ...) \ |
---|
302 | 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 | + */ |
---|
303 | 346 | #define pr_err(fmt, ...) \ |
---|
304 | 347 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) |
---|
305 | | -#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, ...) \ |
---|
306 | 357 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) |
---|
307 | | -#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 | + */ |
---|
308 | 366 | #define pr_notice(fmt, ...) \ |
---|
309 | 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 | + */ |
---|
310 | 376 | #define pr_info(fmt, ...) \ |
---|
311 | 377 | printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) |
---|
312 | | -/* |
---|
313 | | - * Like KERN_CONT, pr_cont() should only be used when continuing |
---|
314 | | - * a line with no newline ('\n') enclosed. Otherwise it defaults |
---|
315 | | - * 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. |
---|
316 | 387 | */ |
---|
317 | 388 | #define pr_cont(fmt, ...) \ |
---|
318 | 389 | printk(KERN_CONT fmt, ##__VA_ARGS__) |
---|
319 | 390 | |
---|
320 | | -/* 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 | + */ |
---|
321 | 401 | #ifdef DEBUG |
---|
322 | 402 | #define pr_devel(fmt, ...) \ |
---|
323 | 403 | printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
---|
.. | .. |
---|
328 | 408 | |
---|
329 | 409 | |
---|
330 | 410 | /* If you are writing a driver, please use dev_dbg instead */ |
---|
331 | | -#if defined(CONFIG_DYNAMIC_DEBUG) |
---|
| 411 | +#if defined(CONFIG_DYNAMIC_DEBUG) || \ |
---|
| 412 | + (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) |
---|
332 | 413 | #include <linux/dynamic_debug.h> |
---|
333 | 414 | |
---|
334 | | -/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ |
---|
335 | | -#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, ...) \ |
---|
336 | 428 | dynamic_pr_debug(fmt, ##__VA_ARGS__) |
---|
337 | 429 | #elif defined(DEBUG) |
---|
338 | 430 | #define pr_debug(fmt, ...) \ |
---|
.. | .. |
---|
349 | 441 | #ifdef CONFIG_PRINTK |
---|
350 | 442 | #define printk_once(fmt, ...) \ |
---|
351 | 443 | ({ \ |
---|
352 | | - static bool __print_once __read_mostly; \ |
---|
| 444 | + static bool __section(".data.once") __print_once; \ |
---|
353 | 445 | bool __ret_print_once = !__print_once; \ |
---|
354 | 446 | \ |
---|
355 | 447 | if (!__print_once) { \ |
---|
.. | .. |
---|
360 | 452 | }) |
---|
361 | 453 | #define printk_deferred_once(fmt, ...) \ |
---|
362 | 454 | ({ \ |
---|
363 | | - static bool __print_once __read_mostly; \ |
---|
| 455 | + static bool __section(".data.once") __print_once; \ |
---|
364 | 456 | bool __ret_print_once = !__print_once; \ |
---|
365 | 457 | \ |
---|
366 | 458 | if (!__print_once) { \ |
---|
.. | .. |
---|
390 | 482 | printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) |
---|
391 | 483 | #define pr_info_once(fmt, ...) \ |
---|
392 | 484 | printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) |
---|
393 | | -#define pr_cont_once(fmt, ...) \ |
---|
394 | | - printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) |
---|
| 485 | +/* no pr_cont_once, don't do that... */ |
---|
395 | 486 | |
---|
396 | 487 | #if defined(DEBUG) |
---|
397 | 488 | #define pr_devel_once(fmt, ...) \ |
---|
.. | .. |
---|
454 | 545 | #endif |
---|
455 | 546 | |
---|
456 | 547 | /* If you are writing a driver, please use dev_dbg instead */ |
---|
457 | | -#if defined(CONFIG_DYNAMIC_DEBUG) |
---|
| 548 | +#if defined(CONFIG_DYNAMIC_DEBUG) || \ |
---|
| 549 | + (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) |
---|
458 | 550 | /* descriptor check is first to prevent flooding with "callbacks suppressed" */ |
---|
459 | 551 | #define pr_debug_ratelimited(fmt, ...) \ |
---|
460 | 552 | do { \ |
---|
.. | .. |
---|
462 | 554 | DEFAULT_RATELIMIT_INTERVAL, \ |
---|
463 | 555 | DEFAULT_RATELIMIT_BURST); \ |
---|
464 | 556 | DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \ |
---|
465 | | - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ |
---|
| 557 | + if (DYNAMIC_DEBUG_BRANCH(descriptor) && \ |
---|
466 | 558 | __ratelimit(&_rs)) \ |
---|
467 | 559 | __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \ |
---|
468 | 560 | } while (0) |
---|
.. | .. |
---|
488 | 580 | extern void print_hex_dump(const char *level, const char *prefix_str, |
---|
489 | 581 | int prefix_type, int rowsize, int groupsize, |
---|
490 | 582 | const void *buf, size_t len, bool ascii); |
---|
491 | | -#if defined(CONFIG_DYNAMIC_DEBUG) |
---|
492 | | -#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \ |
---|
493 | | - dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true) |
---|
494 | | -#else |
---|
495 | | -extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, |
---|
496 | | - const void *buf, size_t len); |
---|
497 | | -#endif /* defined(CONFIG_DYNAMIC_DEBUG) */ |
---|
498 | 583 | #else |
---|
499 | 584 | static inline void print_hex_dump(const char *level, const char *prefix_str, |
---|
500 | 585 | int prefix_type, int rowsize, int groupsize, |
---|
.. | .. |
---|
508 | 593 | |
---|
509 | 594 | #endif |
---|
510 | 595 | |
---|
511 | | -#if defined(CONFIG_DYNAMIC_DEBUG) |
---|
| 596 | +#if defined(CONFIG_DYNAMIC_DEBUG) || \ |
---|
| 597 | + (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) |
---|
512 | 598 | #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ |
---|
513 | 599 | groupsize, buf, len, ascii) \ |
---|
514 | 600 | dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ |
---|
.. | .. |
---|
526 | 612 | } |
---|
527 | 613 | #endif |
---|
528 | 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 | + |
---|
529 | 649 | #endif |
---|