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;
....@@ -141,38 +149,21 @@
141149 #ifdef CONFIG_EARLY_PRINTK
142150 extern asmlinkage __printf(1, 2)
143151 void early_printk(const char *fmt, ...);
144
-extern void printk_kill(void);
145152 #else
146153 static inline __printf(1, 2) __cold
147154 void early_printk(const char *s, ...) { }
148
-static inline void printk_kill(void) { }
149155 #endif
150156
151
-#ifdef CONFIG_PRINTK_NMI
152
-extern void printk_nmi_enter(void);
153
-extern void printk_nmi_exit(void);
154
-extern void printk_nmi_direct_enter(void);
155
-extern void printk_nmi_direct_exit(void);
156
-#else
157
-static inline void printk_nmi_enter(void) { }
158
-static inline void printk_nmi_exit(void) { }
159
-static inline void printk_nmi_direct_enter(void) { }
160
-static inline void printk_nmi_direct_exit(void) { }
161
-#endif /* PRINTK_NMI */
157
+struct dev_printk_info;
162158
163159 #ifdef CONFIG_PRINTK
164
-asmlinkage __printf(5, 0)
160
+asmlinkage __printf(4, 0)
165161 int vprintk_emit(int facility, int level,
166
- const char *dict, size_t dictlen,
162
+ const struct dev_printk_info *dev_info,
167163 const char *fmt, va_list args);
168164
169165 asmlinkage __printf(1, 0)
170166 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, ...);
176167
177168 asmlinkage __printf(1, 2) __cold
178169 int printk(const char *fmt, ...);
....@@ -196,7 +187,7 @@
196187 extern int dmesg_restrict;
197188
198189 extern int
199
-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,
200191 size_t *lenp, loff_t *ppos);
201192
202193 extern void wake_up_klogd(void);
....@@ -208,9 +199,8 @@
208199 __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
209200 void dump_stack_print_info(const char *log_lvl);
210201 void show_regs_print_info(const char *log_lvl);
202
+extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold;
211203 extern asmlinkage void dump_stack(void) __cold;
212
-extern void printk_safe_flush(void);
213
-extern void printk_safe_flush_on_panic(void);
214204 #else
215205 static inline __printf(1, 0)
216206 int vprintk(const char *s, va_list args)
....@@ -271,55 +261,127 @@
271261 {
272262 }
273263
274
-static inline asmlinkage void dump_stack(void)
264
+static inline void dump_stack_lvl(const char *log_lvl)
275265 {
276266 }
277267
278
-static inline void printk_safe_flush(void)
279
-{
280
-}
281
-
282
-static inline void printk_safe_flush_on_panic(void)
268
+static inline void dump_stack(void)
283269 {
284270 }
285271 #endif
286272
287273 extern int kptr_restrict;
288274
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
+ */
289288 #ifndef pr_fmt
290289 #define pr_fmt(fmt) fmt
291290 #endif
292291
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.
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.
298299 */
299300 #define pr_emerg(fmt, ...) \
300301 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
+ */
301310 #define pr_alert(fmt, ...) \
302311 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
+ */
303320 #define pr_crit(fmt, ...) \
304321 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
+ */
305330 #define pr_err(fmt, ...) \
306331 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
307
-#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, ...) \
308341 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
309
-#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
+ */
310350 #define pr_notice(fmt, ...) \
311351 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
+ */
312360 #define pr_info(fmt, ...) \
313361 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.
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.
318371 */
319372 #define pr_cont(fmt, ...) \
320373 printk(KERN_CONT fmt, ##__VA_ARGS__)
321374
322
-/* 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
+ */
323385 #ifdef DEBUG
324386 #define pr_devel(fmt, ...) \
325387 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
....@@ -330,11 +392,23 @@
330392
331393
332394 /* If you are writing a driver, please use dev_dbg instead */
333
-#if defined(CONFIG_DYNAMIC_DEBUG)
395
+#if defined(CONFIG_DYNAMIC_DEBUG) || \
396
+ (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
334397 #include <linux/dynamic_debug.h>
335398
336
-/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
337
-#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, ...) \
338412 dynamic_pr_debug(fmt, ##__VA_ARGS__)
339413 #elif defined(DEBUG)
340414 #define pr_debug(fmt, ...) \
....@@ -351,7 +425,7 @@
351425 #ifdef CONFIG_PRINTK
352426 #define printk_once(fmt, ...) \
353427 ({ \
354
- static bool __print_once __read_mostly; \
428
+ static bool __section(".data.once") __print_once; \
355429 bool __ret_print_once = !__print_once; \
356430 \
357431 if (!__print_once) { \
....@@ -362,7 +436,7 @@
362436 })
363437 #define printk_deferred_once(fmt, ...) \
364438 ({ \
365
- static bool __print_once __read_mostly; \
439
+ static bool __section(".data.once") __print_once; \
366440 bool __ret_print_once = !__print_once; \
367441 \
368442 if (!__print_once) { \
....@@ -392,8 +466,7 @@
392466 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
393467 #define pr_info_once(fmt, ...) \
394468 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__)
469
+/* no pr_cont_once, don't do that... */
397470
398471 #if defined(DEBUG)
399472 #define pr_devel_once(fmt, ...) \
....@@ -411,6 +484,8 @@
411484 #define pr_debug_once(fmt, ...) \
412485 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
413486 #endif
487
+
488
+bool pr_flush(int timeout_ms, bool reset_on_progress);
414489
415490 /*
416491 * ratelimited messages with local ratelimit_state,
....@@ -456,7 +531,8 @@
456531 #endif
457532
458533 /* If you are writing a driver, please use dev_dbg instead */
459
-#if defined(CONFIG_DYNAMIC_DEBUG)
534
+#if defined(CONFIG_DYNAMIC_DEBUG) || \
535
+ (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
460536 /* descriptor check is first to prevent flooding with "callbacks suppressed" */
461537 #define pr_debug_ratelimited(fmt, ...) \
462538 do { \
....@@ -464,7 +540,7 @@
464540 DEFAULT_RATELIMIT_INTERVAL, \
465541 DEFAULT_RATELIMIT_BURST); \
466542 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
467
- if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
543
+ if (DYNAMIC_DEBUG_BRANCH(descriptor) && \
468544 __ratelimit(&_rs)) \
469545 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
470546 } while (0)
....@@ -490,13 +566,6 @@
490566 extern void print_hex_dump(const char *level, const char *prefix_str,
491567 int prefix_type, int rowsize, int groupsize,
492568 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) */
500569 #else
501570 static inline void print_hex_dump(const char *level, const char *prefix_str,
502571 int prefix_type, int rowsize, int groupsize,
....@@ -510,7 +579,8 @@
510579
511580 #endif
512581
513
-#if defined(CONFIG_DYNAMIC_DEBUG)
582
+#if defined(CONFIG_DYNAMIC_DEBUG) || \
583
+ (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
514584 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
515585 groupsize, buf, len, ascii) \
516586 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
....@@ -528,4 +598,19 @@
528598 }
529599 #endif
530600
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
+
531616 #endif