hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
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 }
....@@ -83,6 +83,8 @@
8383 #define DEVKMSG_STR_MAX_SIZE 10
8484 extern char devkmsg_log_str[];
8585 struct ctl_table;
86
+
87
+extern int suppress_printk;
8688
8789 struct va_format {
8890 const char *fmt;
....@@ -158,19 +160,16 @@
158160 static inline void printk_nmi_direct_exit(void) { }
159161 #endif /* PRINTK_NMI */
160162
163
+struct dev_printk_info;
164
+
161165 #ifdef CONFIG_PRINTK
162
-asmlinkage __printf(5, 0)
166
+asmlinkage __printf(4, 0)
163167 int vprintk_emit(int facility, int level,
164
- const char *dict, size_t dictlen,
168
+ const struct dev_printk_info *dev_info,
165169 const char *fmt, va_list args);
166170
167171 asmlinkage __printf(1, 0)
168172 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, ...);
174173
175174 asmlinkage __printf(1, 2) __cold
176175 int printk(const char *fmt, ...);
....@@ -194,7 +193,7 @@
194193 extern int dmesg_restrict;
195194
196195 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,
198197 size_t *lenp, loff_t *ppos);
199198
200199 extern void wake_up_klogd(void);
....@@ -206,6 +205,7 @@
206205 __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
207206 void dump_stack_print_info(const char *log_lvl);
208207 void show_regs_print_info(const char *log_lvl);
208
+extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold;
209209 extern asmlinkage void dump_stack(void) __cold;
210210 extern void printk_safe_flush(void);
211211 extern void printk_safe_flush_on_panic(void);
....@@ -269,7 +269,11 @@
269269 {
270270 }
271271
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)
273277 {
274278 }
275279
....@@ -284,40 +288,116 @@
284288
285289 extern int kptr_restrict;
286290
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
+ */
287304 #ifndef pr_fmt
288305 #define pr_fmt(fmt) fmt
289306 #endif
290307
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.
296315 */
297316 #define pr_emerg(fmt, ...) \
298317 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
+ */
299326 #define pr_alert(fmt, ...) \
300327 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
+ */
301336 #define pr_crit(fmt, ...) \
302337 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
+ */
303346 #define pr_err(fmt, ...) \
304347 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, ...) \
306357 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
+ */
308366 #define pr_notice(fmt, ...) \
309367 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
+ */
310376 #define pr_info(fmt, ...) \
311377 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.
316387 */
317388 #define pr_cont(fmt, ...) \
318389 printk(KERN_CONT fmt, ##__VA_ARGS__)
319390
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
+ */
321401 #ifdef DEBUG
322402 #define pr_devel(fmt, ...) \
323403 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
....@@ -328,11 +408,23 @@
328408
329409
330410 /* 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))
332413 #include <linux/dynamic_debug.h>
333414
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, ...) \
336428 dynamic_pr_debug(fmt, ##__VA_ARGS__)
337429 #elif defined(DEBUG)
338430 #define pr_debug(fmt, ...) \
....@@ -349,7 +441,7 @@
349441 #ifdef CONFIG_PRINTK
350442 #define printk_once(fmt, ...) \
351443 ({ \
352
- static bool __print_once __read_mostly; \
444
+ static bool __section(".data.once") __print_once; \
353445 bool __ret_print_once = !__print_once; \
354446 \
355447 if (!__print_once) { \
....@@ -360,7 +452,7 @@
360452 })
361453 #define printk_deferred_once(fmt, ...) \
362454 ({ \
363
- static bool __print_once __read_mostly; \
455
+ static bool __section(".data.once") __print_once; \
364456 bool __ret_print_once = !__print_once; \
365457 \
366458 if (!__print_once) { \
....@@ -390,8 +482,7 @@
390482 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
391483 #define pr_info_once(fmt, ...) \
392484 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... */
395486
396487 #if defined(DEBUG)
397488 #define pr_devel_once(fmt, ...) \
....@@ -454,7 +545,8 @@
454545 #endif
455546
456547 /* 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))
458550 /* descriptor check is first to prevent flooding with "callbacks suppressed" */
459551 #define pr_debug_ratelimited(fmt, ...) \
460552 do { \
....@@ -462,7 +554,7 @@
462554 DEFAULT_RATELIMIT_INTERVAL, \
463555 DEFAULT_RATELIMIT_BURST); \
464556 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
465
- if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
557
+ if (DYNAMIC_DEBUG_BRANCH(descriptor) && \
466558 __ratelimit(&_rs)) \
467559 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
468560 } while (0)
....@@ -488,13 +580,6 @@
488580 extern void print_hex_dump(const char *level, const char *prefix_str,
489581 int prefix_type, int rowsize, int groupsize,
490582 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) */
498583 #else
499584 static inline void print_hex_dump(const char *level, const char *prefix_str,
500585 int prefix_type, int rowsize, int groupsize,
....@@ -508,7 +593,8 @@
508593
509594 #endif
510595
511
-#if defined(CONFIG_DYNAMIC_DEBUG)
596
+#if defined(CONFIG_DYNAMIC_DEBUG) || \
597
+ (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
512598 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
513599 groupsize, buf, len, ascii) \
514600 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
....@@ -526,4 +612,38 @@
526612 }
527613 #endif
528614
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
+
529649 #endif