hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/include/linux/printk.h
....@@ -6,11 +6,12 @@
66 #include <linux/init.h>
77 #include <linux/kern_levels.h>
88 #include <linux/linkage.h>
9
-#include <linux/cache.h>
9
+#include <linux/ratelimit_types.h>
1010
1111 extern const char linux_banner[];
12
-extern const char *linux_banner_ptr;
1312 extern const char linux_proc_banner[];
13
+
14
+extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */
1415
1516 #define PRINTK_MAX_SINGLE_HEADER_LEN 2
1617
....@@ -19,7 +20,6 @@
1920 if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
2021 switch (buffer[1]) {
2122 case '0' ... '7':
22
- case 'd': /* KERN_DEFAULT */
2323 case 'c': /* KERN_CONT */
2424 return buffer[1];
2525 }
....@@ -84,6 +84,8 @@
8484 extern char devkmsg_log_str[];
8585 struct ctl_table;
8686
87
+extern int suppress_printk;
88
+
8789 struct va_format {
8890 const char *fmt;
8991 va_list *va;
....@@ -141,11 +143,9 @@
141143 #ifdef CONFIG_EARLY_PRINTK
142144 extern asmlinkage __printf(1, 2)
143145 void early_printk(const char *fmt, ...);
144
-extern void printk_kill(void);
145146 #else
146147 static inline __printf(1, 2) __cold
147148 void early_printk(const char *s, ...) { }
148
-static inline void printk_kill(void) { }
149149 #endif
150150
151151 #ifdef CONFIG_PRINTK_NMI
....@@ -160,19 +160,16 @@
160160 static inline void printk_nmi_direct_exit(void) { }
161161 #endif /* PRINTK_NMI */
162162
163
+struct dev_printk_info;
164
+
163165 #ifdef CONFIG_PRINTK
164
-asmlinkage __printf(5, 0)
166
+asmlinkage __printf(4, 0)
165167 int vprintk_emit(int facility, int level,
166
- const char *dict, size_t dictlen,
168
+ const struct dev_printk_info *dev_info,
167169 const char *fmt, va_list args);
168170
169171 asmlinkage __printf(1, 0)
170172 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, ...);
176173
177174 asmlinkage __printf(1, 2) __cold
178175 int printk(const char *fmt, ...);
....@@ -196,7 +193,7 @@
196193 extern int dmesg_restrict;
197194
198195 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,
200197 size_t *lenp, loff_t *ppos);
201198
202199 extern void wake_up_klogd(void);
....@@ -208,6 +205,7 @@
208205 __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
209206 void dump_stack_print_info(const char *log_lvl);
210207 void show_regs_print_info(const char *log_lvl);
208
+extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold;
211209 extern asmlinkage void dump_stack(void) __cold;
212210 extern void printk_safe_flush(void);
213211 extern void printk_safe_flush_on_panic(void);
....@@ -271,7 +269,11 @@
271269 {
272270 }
273271
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)
275277 {
276278 }
277279
....@@ -286,40 +288,116 @@
286288
287289 extern int kptr_restrict;
288290
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
+ */
289304 #ifndef pr_fmt
290305 #define pr_fmt(fmt) fmt
291306 #endif
292307
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.
298315 */
299316 #define pr_emerg(fmt, ...) \
300317 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
+ */
301326 #define pr_alert(fmt, ...) \
302327 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
+ */
303336 #define pr_crit(fmt, ...) \
304337 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
+ */
305346 #define pr_err(fmt, ...) \
306347 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, ...) \
308357 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
+ */
310366 #define pr_notice(fmt, ...) \
311367 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
+ */
312376 #define pr_info(fmt, ...) \
313377 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.
318387 */
319388 #define pr_cont(fmt, ...) \
320389 printk(KERN_CONT fmt, ##__VA_ARGS__)
321390
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
+ */
323401 #ifdef DEBUG
324402 #define pr_devel(fmt, ...) \
325403 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
....@@ -330,11 +408,23 @@
330408
331409
332410 /* 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))
334413 #include <linux/dynamic_debug.h>
335414
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, ...) \
338428 dynamic_pr_debug(fmt, ##__VA_ARGS__)
339429 #elif defined(DEBUG)
340430 #define pr_debug(fmt, ...) \
....@@ -351,7 +441,7 @@
351441 #ifdef CONFIG_PRINTK
352442 #define printk_once(fmt, ...) \
353443 ({ \
354
- static bool __print_once __read_mostly; \
444
+ static bool __section(".data.once") __print_once; \
355445 bool __ret_print_once = !__print_once; \
356446 \
357447 if (!__print_once) { \
....@@ -362,7 +452,7 @@
362452 })
363453 #define printk_deferred_once(fmt, ...) \
364454 ({ \
365
- static bool __print_once __read_mostly; \
455
+ static bool __section(".data.once") __print_once; \
366456 bool __ret_print_once = !__print_once; \
367457 \
368458 if (!__print_once) { \
....@@ -392,8 +482,7 @@
392482 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
393483 #define pr_info_once(fmt, ...) \
394484 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... */
397486
398487 #if defined(DEBUG)
399488 #define pr_devel_once(fmt, ...) \
....@@ -456,7 +545,8 @@
456545 #endif
457546
458547 /* 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))
460550 /* descriptor check is first to prevent flooding with "callbacks suppressed" */
461551 #define pr_debug_ratelimited(fmt, ...) \
462552 do { \
....@@ -464,7 +554,7 @@
464554 DEFAULT_RATELIMIT_INTERVAL, \
465555 DEFAULT_RATELIMIT_BURST); \
466556 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
467
- if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
557
+ if (DYNAMIC_DEBUG_BRANCH(descriptor) && \
468558 __ratelimit(&_rs)) \
469559 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
470560 } while (0)
....@@ -490,13 +580,6 @@
490580 extern void print_hex_dump(const char *level, const char *prefix_str,
491581 int prefix_type, int rowsize, int groupsize,
492582 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) */
500583 #else
501584 static inline void print_hex_dump(const char *level, const char *prefix_str,
502585 int prefix_type, int rowsize, int groupsize,
....@@ -510,7 +593,8 @@
510593
511594 #endif
512595
513
-#if defined(CONFIG_DYNAMIC_DEBUG)
596
+#if defined(CONFIG_DYNAMIC_DEBUG) || \
597
+ (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
514598 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
515599 groupsize, buf, len, ascii) \
516600 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
....@@ -528,4 +612,38 @@
528612 }
529613 #endif
530614
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
+
531649 #endif