hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
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 }
....@@ -44,6 +44,12 @@
4444 }
4545
4646 #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
4753
4854 /* printk's without a loglevel use this.. */
4955 #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
....@@ -83,6 +89,8 @@
8389 #define DEVKMSG_STR_MAX_SIZE 10
8490 extern char devkmsg_log_str[];
8591 struct ctl_table;
92
+
93
+extern int suppress_printk;
8694
8795 struct va_format {
8896 const char *fmt;
....@@ -146,31 +154,16 @@
146154 void early_printk(const char *s, ...) { }
147155 #endif
148156
149
-#ifdef CONFIG_PRINTK_NMI
150
-extern void printk_nmi_enter(void);
151
-extern void printk_nmi_exit(void);
152
-extern void printk_nmi_direct_enter(void);
153
-extern void printk_nmi_direct_exit(void);
154
-#else
155
-static inline void printk_nmi_enter(void) { }
156
-static inline void printk_nmi_exit(void) { }
157
-static inline void printk_nmi_direct_enter(void) { }
158
-static inline void printk_nmi_direct_exit(void) { }
159
-#endif /* PRINTK_NMI */
157
+struct dev_printk_info;
160158
161159 #ifdef CONFIG_PRINTK
162
-asmlinkage __printf(5, 0)
160
+asmlinkage __printf(4, 0)
163161 int vprintk_emit(int facility, int level,
164
- const char *dict, size_t dictlen,
162
+ const struct dev_printk_info *dev_info,
165163 const char *fmt, va_list args);
166164
167165 asmlinkage __printf(1, 0)
168166 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, ...);
174167
175168 asmlinkage __printf(1, 2) __cold
176169 int printk(const char *fmt, ...);
....@@ -194,7 +187,7 @@
194187 extern int dmesg_restrict;
195188
196189 extern int
197
-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,
198191 size_t *lenp, loff_t *ppos);
199192
200193 extern void wake_up_klogd(void);
....@@ -206,9 +199,8 @@
206199 __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
207200 void dump_stack_print_info(const char *log_lvl);
208201 void show_regs_print_info(const char *log_lvl);
202
+extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold;
209203 extern asmlinkage void dump_stack(void) __cold;
210
-extern void printk_safe_flush(void);
211
-extern void printk_safe_flush_on_panic(void);
212204 #else
213205 static inline __printf(1, 0)
214206 int vprintk(const char *s, va_list args)
....@@ -269,55 +261,127 @@
269261 {
270262 }
271263
272
-static inline asmlinkage void dump_stack(void)
264
+static inline void dump_stack_lvl(const char *log_lvl)
273265 {
274266 }
275267
276
-static inline void printk_safe_flush(void)
277
-{
278
-}
279
-
280
-static inline void printk_safe_flush_on_panic(void)
268
+static inline void dump_stack(void)
281269 {
282270 }
283271 #endif
284272
285273 extern int kptr_restrict;
286274
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
+ */
287288 #ifndef pr_fmt
288289 #define pr_fmt(fmt) fmt
289290 #endif
290291
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.
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.
296299 */
297300 #define pr_emerg(fmt, ...) \
298301 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
+ */
299310 #define pr_alert(fmt, ...) \
300311 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
+ */
301320 #define pr_crit(fmt, ...) \
302321 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
+ */
303330 #define pr_err(fmt, ...) \
304331 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
305
-#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, ...) \
306341 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
307
-#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
+ */
308350 #define pr_notice(fmt, ...) \
309351 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
+ */
310360 #define pr_info(fmt, ...) \
311361 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.
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.
316371 */
317372 #define pr_cont(fmt, ...) \
318373 printk(KERN_CONT fmt, ##__VA_ARGS__)
319374
320
-/* 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
+ */
321385 #ifdef DEBUG
322386 #define pr_devel(fmt, ...) \
323387 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
....@@ -328,11 +392,23 @@
328392
329393
330394 /* If you are writing a driver, please use dev_dbg instead */
331
-#if defined(CONFIG_DYNAMIC_DEBUG)
395
+#if defined(CONFIG_DYNAMIC_DEBUG) || \
396
+ (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
332397 #include <linux/dynamic_debug.h>
333398
334
-/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
335
-#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, ...) \
336412 dynamic_pr_debug(fmt, ##__VA_ARGS__)
337413 #elif defined(DEBUG)
338414 #define pr_debug(fmt, ...) \
....@@ -349,7 +425,7 @@
349425 #ifdef CONFIG_PRINTK
350426 #define printk_once(fmt, ...) \
351427 ({ \
352
- static bool __print_once __read_mostly; \
428
+ static bool __section(".data.once") __print_once; \
353429 bool __ret_print_once = !__print_once; \
354430 \
355431 if (!__print_once) { \
....@@ -360,7 +436,7 @@
360436 })
361437 #define printk_deferred_once(fmt, ...) \
362438 ({ \
363
- static bool __print_once __read_mostly; \
439
+ static bool __section(".data.once") __print_once; \
364440 bool __ret_print_once = !__print_once; \
365441 \
366442 if (!__print_once) { \
....@@ -390,8 +466,7 @@
390466 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
391467 #define pr_info_once(fmt, ...) \
392468 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__)
469
+/* no pr_cont_once, don't do that... */
395470
396471 #if defined(DEBUG)
397472 #define pr_devel_once(fmt, ...) \
....@@ -409,6 +484,8 @@
409484 #define pr_debug_once(fmt, ...) \
410485 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
411486 #endif
487
+
488
+bool pr_flush(int timeout_ms, bool reset_on_progress);
412489
413490 /*
414491 * ratelimited messages with local ratelimit_state,
....@@ -454,7 +531,8 @@
454531 #endif
455532
456533 /* If you are writing a driver, please use dev_dbg instead */
457
-#if defined(CONFIG_DYNAMIC_DEBUG)
534
+#if defined(CONFIG_DYNAMIC_DEBUG) || \
535
+ (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
458536 /* descriptor check is first to prevent flooding with "callbacks suppressed" */
459537 #define pr_debug_ratelimited(fmt, ...) \
460538 do { \
....@@ -462,7 +540,7 @@
462540 DEFAULT_RATELIMIT_INTERVAL, \
463541 DEFAULT_RATELIMIT_BURST); \
464542 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
465
- if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
543
+ if (DYNAMIC_DEBUG_BRANCH(descriptor) && \
466544 __ratelimit(&_rs)) \
467545 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
468546 } while (0)
....@@ -488,13 +566,6 @@
488566 extern void print_hex_dump(const char *level, const char *prefix_str,
489567 int prefix_type, int rowsize, int groupsize,
490568 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) */
498569 #else
499570 static inline void print_hex_dump(const char *level, const char *prefix_str,
500571 int prefix_type, int rowsize, int groupsize,
....@@ -508,7 +579,8 @@
508579
509580 #endif
510581
511
-#if defined(CONFIG_DYNAMIC_DEBUG)
582
+#if defined(CONFIG_DYNAMIC_DEBUG) || \
583
+ (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
512584 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
513585 groupsize, buf, len, ascii) \
514586 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
....@@ -526,4 +598,19 @@
526598 }
527599 #endif
528600
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
+
529616 #endif