Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 2 | #ifndef __KERNEL_PRINTK__ |
| 3 | #define __KERNEL_PRINTK__ |
| 4 | |
Alexey Dobriyan | c0891ac | 2021-08-02 23:40:32 +0300 | [diff] [blame] | 5 | #include <linux/stdarg.h> |
Mike Travis | 162a7e7 | 2011-05-24 17:13:20 -0700 | [diff] [blame] | 6 | #include <linux/init.h> |
Joe Perches | 314ba35 | 2012-07-30 14:40:11 -0700 | [diff] [blame] | 7 | #include <linux/kern_levels.h> |
Ralf Baechle | 154c267 | 2013-05-21 10:51:10 +0200 | [diff] [blame] | 8 | #include <linux/linkage.h> |
Herbert Xu | b4a461e | 2020-07-21 16:22:48 +1000 | [diff] [blame] | 9 | #include <linux/ratelimit_types.h> |
Tanner Love | a358f40 | 2021-06-28 09:50:06 -0400 | [diff] [blame] | 10 | #include <linux/once_lite.h> |
Mike Travis | 162a7e7 | 2011-05-24 17:13:20 -0700 | [diff] [blame] | 11 | |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 12 | extern const char linux_banner[]; |
| 13 | extern const char linux_proc_banner[]; |
| 14 | |
Andy Shevchenko | 36d818f | 2020-09-11 20:02:02 +0300 | [diff] [blame] | 15 | extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */ |
| 16 | |
Petr Mladek | 262c5e8 | 2016-12-12 16:45:50 -0800 | [diff] [blame] | 17 | #define PRINTK_MAX_SINGLE_HEADER_LEN 2 |
| 18 | |
Joe Perches | acc8fa41 | 2012-07-30 14:40:09 -0700 | [diff] [blame] | 19 | static inline int printk_get_level(const char *buffer) |
| 20 | { |
Joe Perches | 04d2c8c | 2012-07-30 14:40:17 -0700 | [diff] [blame] | 21 | if (buffer[0] == KERN_SOH_ASCII && buffer[1]) { |
Joe Perches | acc8fa41 | 2012-07-30 14:40:09 -0700 | [diff] [blame] | 22 | switch (buffer[1]) { |
| 23 | case '0' ... '7': |
Linus Torvalds | 4bcc595 | 2016-10-08 20:32:40 -0700 | [diff] [blame] | 24 | case 'c': /* KERN_CONT */ |
Joe Perches | acc8fa41 | 2012-07-30 14:40:09 -0700 | [diff] [blame] | 25 | return buffer[1]; |
| 26 | } |
| 27 | } |
| 28 | return 0; |
| 29 | } |
| 30 | |
| 31 | static inline const char *printk_skip_level(const char *buffer) |
| 32 | { |
Petr Mladek | 0185698 | 2014-04-03 14:48:38 -0700 | [diff] [blame] | 33 | if (printk_get_level(buffer)) |
| 34 | return buffer + 2; |
| 35 | |
Joe Perches | acc8fa41 | 2012-07-30 14:40:09 -0700 | [diff] [blame] | 36 | return buffer; |
| 37 | } |
| 38 | |
Petr Mladek | 4979575 | 2016-12-12 16:45:47 -0800 | [diff] [blame] | 39 | static inline const char *printk_skip_headers(const char *buffer) |
| 40 | { |
| 41 | while (printk_get_level(buffer)) |
| 42 | buffer = printk_skip_level(buffer); |
| 43 | |
| 44 | return buffer; |
| 45 | } |
| 46 | |
Tejun Heo | d43ff43 | 2015-06-25 15:01:24 -0700 | [diff] [blame] | 47 | #define CONSOLE_EXT_LOG_MAX 8192 |
| 48 | |
Borislav Petkov | a8fe19e | 2014-06-04 16:11:46 -0700 | [diff] [blame] | 49 | /* printk's without a loglevel use this.. */ |
Alex Elder | 42a9dc0 | 2014-08-06 16:09:01 -0700 | [diff] [blame] | 50 | #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT |
Borislav Petkov | a8fe19e | 2014-06-04 16:11:46 -0700 | [diff] [blame] | 51 | |
| 52 | /* We show everything that is MORE important than this.. */ |
| 53 | #define CONSOLE_LOGLEVEL_SILENT 0 /* Mum's the word */ |
| 54 | #define CONSOLE_LOGLEVEL_MIN 1 /* Minimum loglevel we let people use */ |
Borislav Petkov | a8fe19e | 2014-06-04 16:11:46 -0700 | [diff] [blame] | 55 | #define CONSOLE_LOGLEVEL_DEBUG 10 /* issue debug messages */ |
| 56 | #define CONSOLE_LOGLEVEL_MOTORMOUTH 15 /* You can't shut this one up */ |
| 57 | |
Olof Johansson | a8cfdc6 | 2016-12-12 16:45:56 -0800 | [diff] [blame] | 58 | /* |
Hans de Goede | 22eceb8 | 2018-06-19 13:57:26 +0200 | [diff] [blame] | 59 | * Default used to be hard-coded at 7, quiet used to be hardcoded at 4, |
| 60 | * we're now allowing both to be set from kernel config. |
Olof Johansson | a8cfdc6 | 2016-12-12 16:45:56 -0800 | [diff] [blame] | 61 | */ |
| 62 | #define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT |
Hans de Goede | 22eceb8 | 2018-06-19 13:57:26 +0200 | [diff] [blame] | 63 | #define CONSOLE_LOGLEVEL_QUIET CONFIG_CONSOLE_LOGLEVEL_QUIET |
Olof Johansson | a8cfdc6 | 2016-12-12 16:45:56 -0800 | [diff] [blame] | 64 | |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 65 | extern int console_printk[]; |
| 66 | |
| 67 | #define console_loglevel (console_printk[0]) |
| 68 | #define default_message_loglevel (console_printk[1]) |
| 69 | #define minimum_console_loglevel (console_printk[2]) |
| 70 | #define default_console_loglevel (console_printk[3]) |
| 71 | |
Dmitry Safonov | 10102a8 | 2021-07-27 14:06:35 +0100 | [diff] [blame] | 72 | extern void console_verbose(void); |
Joe Perches | a9747cc3 | 2011-01-12 16:59:43 -0800 | [diff] [blame] | 73 | |
Borislav Petkov | 750afe7 | 2016-08-02 14:04:07 -0700 | [diff] [blame] | 74 | /* strlen("ratelimit") + 1 */ |
| 75 | #define DEVKMSG_STR_MAX_SIZE 10 |
| 76 | extern char devkmsg_log_str[]; |
| 77 | struct ctl_table; |
| 78 | |
Feng Tang | c39ea0b | 2019-05-14 15:45:34 -0700 | [diff] [blame] | 79 | extern int suppress_printk; |
| 80 | |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 81 | struct va_format { |
| 82 | const char *fmt; |
| 83 | va_list *va; |
| 84 | }; |
| 85 | |
| 86 | /* |
| 87 | * FW_BUG |
| 88 | * Add this to a message where you are sure the firmware is buggy or behaves |
| 89 | * really stupid or out of spec. Be aware that the responsible BIOS developer |
| 90 | * should be able to fix this issue or at least get a concrete idea of the |
| 91 | * problem by reading your message without the need of looking at the kernel |
| 92 | * code. |
| 93 | * |
| 94 | * Use it for definite and high priority BIOS bugs. |
| 95 | * |
| 96 | * FW_WARN |
| 97 | * Use it for not that clear (e.g. could the kernel messed up things already?) |
| 98 | * and medium priority BIOS bugs. |
| 99 | * |
| 100 | * FW_INFO |
| 101 | * Use this one if you want to tell the user or vendor about something |
| 102 | * suspicious, but generally harmless related to the firmware. |
| 103 | * |
| 104 | * Use it for information or very low priority BIOS bugs. |
| 105 | */ |
| 106 | #define FW_BUG "[Firmware Bug]: " |
| 107 | #define FW_WARN "[Firmware Warn]: " |
| 108 | #define FW_INFO "[Firmware Info]: " |
| 109 | |
| 110 | /* |
| 111 | * HW_ERR |
| 112 | * Add this to a message for hardware errors, so that user can report |
| 113 | * it to hardware vendor instead of LKML or software vendor. |
| 114 | */ |
| 115 | #define HW_ERR "[Hardware Error]: " |
| 116 | |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 117 | /* |
Neil Horman | 0a9a8bf | 2013-12-23 08:29:42 -0500 | [diff] [blame] | 118 | * DEPRECATED |
| 119 | * Add this to a message whenever you want to warn user space about the use |
| 120 | * of a deprecated aspect of an API so they can stop using it |
| 121 | */ |
| 122 | #define DEPRECATED "[Deprecated]: " |
| 123 | |
| 124 | /* |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 125 | * Dummy printk for disabled debugging statements to use whilst maintaining |
Aaron Conole | fe22cd9b | 2016-01-15 16:59:12 -0800 | [diff] [blame] | 126 | * gcc's format checking. |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 127 | */ |
Borislav Petkov | 069f0cd | 2016-07-05 00:31:26 +0200 | [diff] [blame] | 128 | #define no_printk(fmt, ...) \ |
| 129 | ({ \ |
Masahiro Yamada | 93b138d | 2017-09-18 00:01:44 +0900 | [diff] [blame] | 130 | if (0) \ |
Geert Uytterhoeven | 87436e6 | 2024-02-28 15:00:02 +0100 | [diff] [blame] | 131 | _printk(fmt, ##__VA_ARGS__); \ |
Borislav Petkov | 069f0cd | 2016-07-05 00:31:26 +0200 | [diff] [blame] | 132 | 0; \ |
| 133 | }) |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 134 | |
Thomas Gleixner | d0380e6 | 2013-04-29 16:17:18 -0700 | [diff] [blame] | 135 | #ifdef CONFIG_EARLY_PRINTK |
Joe Perches | b9075fa | 2011-10-31 17:11:33 -0700 | [diff] [blame] | 136 | extern asmlinkage __printf(1, 2) |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 137 | void early_printk(const char *fmt, ...); |
Thomas Gleixner | d0380e6 | 2013-04-29 16:17:18 -0700 | [diff] [blame] | 138 | #else |
| 139 | static inline __printf(1, 2) __cold |
| 140 | void early_printk(const char *s, ...) { } |
| 141 | #endif |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 142 | |
John Ogness | 74caba7 | 2020-09-21 13:24:45 +0206 | [diff] [blame] | 143 | struct dev_printk_info; |
| 144 | |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 145 | #ifdef CONFIG_PRINTK |
John Ogness | 74caba7 | 2020-09-21 13:24:45 +0206 | [diff] [blame] | 146 | asmlinkage __printf(4, 0) |
Kay Sievers | 7ff9554 | 2012-05-03 02:29:13 +0200 | [diff] [blame] | 147 | int vprintk_emit(int facility, int level, |
John Ogness | 74caba7 | 2020-09-21 13:24:45 +0206 | [diff] [blame] | 148 | const struct dev_printk_info *dev_info, |
Kay Sievers | 7ff9554 | 2012-05-03 02:29:13 +0200 | [diff] [blame] | 149 | const char *fmt, va_list args); |
| 150 | |
Joe Perches | b9075fa | 2011-10-31 17:11:33 -0700 | [diff] [blame] | 151 | asmlinkage __printf(1, 0) |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 152 | int vprintk(const char *fmt, va_list args); |
Kay Sievers | 7ff9554 | 2012-05-03 02:29:13 +0200 | [diff] [blame] | 153 | |
Joe Perches | b9075fa | 2011-10-31 17:11:33 -0700 | [diff] [blame] | 154 | asmlinkage __printf(1, 2) __cold |
Chris Down | 3370155 | 2021-06-15 17:52:53 +0100 | [diff] [blame] | 155 | int _printk(const char *fmt, ...); |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 156 | |
| 157 | /* |
John Stultz | aac74dc | 2014-06-04 16:11:40 -0700 | [diff] [blame] | 158 | * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ ! |
Peter Zijlstra | 3ccf3e8 | 2012-02-27 10:47:00 +0100 | [diff] [blame] | 159 | */ |
Chris Down | 3370155 | 2021-06-15 17:52:53 +0100 | [diff] [blame] | 160 | __printf(1, 2) __cold int _printk_deferred(const char *fmt, ...); |
Peter Zijlstra | 3ccf3e8 | 2012-02-27 10:47:00 +0100 | [diff] [blame] | 161 | |
John Ogness | 85e3e7f | 2021-07-15 21:39:57 +0206 | [diff] [blame] | 162 | extern void __printk_safe_enter(void); |
| 163 | extern void __printk_safe_exit(void); |
| 164 | /* |
| 165 | * The printk_deferred_enter/exit macros are available only as a hack for |
| 166 | * some code paths that need to defer all printk console printing. Interrupts |
| 167 | * must be disabled for the deferred duration. |
| 168 | */ |
| 169 | #define printk_deferred_enter __printk_safe_enter |
| 170 | #define printk_deferred_exit __printk_safe_exit |
| 171 | |
Peter Zijlstra | 3ccf3e8 | 2012-02-27 10:47:00 +0100 | [diff] [blame] | 172 | /* |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 173 | * Please don't use printk_ratelimit(), because it shares ratelimiting state |
| 174 | * with all other unrelated printk_ratelimit() callsites. Instead use |
| 175 | * printk_ratelimited() or plain old __ratelimit(). |
| 176 | */ |
| 177 | extern int __printk_ratelimit(const char *func); |
| 178 | #define printk_ratelimit() __printk_ratelimit(__func__) |
| 179 | extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, |
| 180 | unsigned int interval_msec); |
| 181 | |
| 182 | extern int printk_delay_msec; |
| 183 | extern int dmesg_restrict; |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 184 | |
Frederic Weisbecker | dc72c32 | 2013-03-22 15:04:39 -0700 | [diff] [blame] | 185 | extern void wake_up_klogd(void); |
| 186 | |
Pranith Kumar | 07261ed | 2015-01-26 12:58:43 -0800 | [diff] [blame] | 187 | char *log_buf_addr_get(void); |
| 188 | u32 log_buf_len_get(void); |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 189 | void log_buf_vmcoreinfo_setup(void); |
Mike Travis | 162a7e7 | 2011-05-24 17:13:20 -0700 | [diff] [blame] | 190 | void __init setup_log_buf(int early); |
Nicolas Iooss | 8db1486 | 2015-07-17 16:23:42 -0700 | [diff] [blame] | 191 | __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...); |
Tejun Heo | 196779b | 2013-04-30 15:27:12 -0700 | [diff] [blame] | 192 | void dump_stack_print_info(const char *log_lvl); |
Tejun Heo | a43cb95 | 2013-04-30 15:27:17 -0700 | [diff] [blame] | 193 | void show_regs_print_info(const char *log_lvl); |
Alexander Potapenko | 4469c0f | 2021-06-28 19:40:30 -0700 | [diff] [blame] | 194 | extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold; |
Dave Young | e36df28 | 2018-02-13 15:28:34 +0800 | [diff] [blame] | 195 | extern asmlinkage void dump_stack(void) __cold; |
Nicholas Piggin | 5d5e452 | 2021-11-07 14:51:16 +1000 | [diff] [blame] | 196 | void printk_trigger_flush(void); |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 197 | #else |
Joe Perches | b9075fa | 2011-10-31 17:11:33 -0700 | [diff] [blame] | 198 | static inline __printf(1, 0) |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 199 | int vprintk(const char *s, va_list args) |
| 200 | { |
| 201 | return 0; |
| 202 | } |
Joe Perches | b9075fa | 2011-10-31 17:11:33 -0700 | [diff] [blame] | 203 | static inline __printf(1, 2) __cold |
Chris Down | 3370155 | 2021-06-15 17:52:53 +0100 | [diff] [blame] | 204 | int _printk(const char *s, ...) |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 205 | { |
| 206 | return 0; |
| 207 | } |
Peter Zijlstra | 3ccf3e8 | 2012-02-27 10:47:00 +0100 | [diff] [blame] | 208 | static inline __printf(1, 2) __cold |
Chris Down | 3370155 | 2021-06-15 17:52:53 +0100 | [diff] [blame] | 209 | int _printk_deferred(const char *s, ...) |
Peter Zijlstra | 3ccf3e8 | 2012-02-27 10:47:00 +0100 | [diff] [blame] | 210 | { |
| 211 | return 0; |
| 212 | } |
John Ogness | 85e3e7f | 2021-07-15 21:39:57 +0206 | [diff] [blame] | 213 | |
| 214 | static inline void printk_deferred_enter(void) |
| 215 | { |
| 216 | } |
| 217 | |
| 218 | static inline void printk_deferred_exit(void) |
| 219 | { |
| 220 | } |
| 221 | |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 222 | static inline int printk_ratelimit(void) |
| 223 | { |
| 224 | return 0; |
| 225 | } |
| 226 | static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, |
| 227 | unsigned int interval_msec) |
| 228 | { |
| 229 | return false; |
| 230 | } |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 231 | |
Frederic Weisbecker | dc72c32 | 2013-03-22 15:04:39 -0700 | [diff] [blame] | 232 | static inline void wake_up_klogd(void) |
| 233 | { |
| 234 | } |
| 235 | |
Pranith Kumar | 07261ed | 2015-01-26 12:58:43 -0800 | [diff] [blame] | 236 | static inline char *log_buf_addr_get(void) |
| 237 | { |
| 238 | return NULL; |
| 239 | } |
| 240 | |
| 241 | static inline u32 log_buf_len_get(void) |
| 242 | { |
| 243 | return 0; |
| 244 | } |
| 245 | |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 246 | static inline void log_buf_vmcoreinfo_setup(void) |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 247 | { |
| 248 | } |
Mike Travis | 162a7e7 | 2011-05-24 17:13:20 -0700 | [diff] [blame] | 249 | |
| 250 | static inline void setup_log_buf(int early) |
| 251 | { |
| 252 | } |
Tejun Heo | 196779b | 2013-04-30 15:27:12 -0700 | [diff] [blame] | 253 | |
Nicolas Iooss | 8db1486 | 2015-07-17 16:23:42 -0700 | [diff] [blame] | 254 | static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...) |
Tejun Heo | 98e5e1b | 2013-04-30 15:27:15 -0700 | [diff] [blame] | 255 | { |
| 256 | } |
| 257 | |
Tejun Heo | 196779b | 2013-04-30 15:27:12 -0700 | [diff] [blame] | 258 | static inline void dump_stack_print_info(const char *log_lvl) |
| 259 | { |
| 260 | } |
Tejun Heo | a43cb95 | 2013-04-30 15:27:17 -0700 | [diff] [blame] | 261 | |
| 262 | static inline void show_regs_print_info(const char *log_lvl) |
| 263 | { |
| 264 | } |
Sergey Senozhatsky | 099f1c8 | 2016-12-27 23:16:06 +0900 | [diff] [blame] | 265 | |
Alexander Potapenko | 4469c0f | 2021-06-28 19:40:30 -0700 | [diff] [blame] | 266 | static inline void dump_stack_lvl(const char *log_lvl) |
| 267 | { |
| 268 | } |
| 269 | |
Alexey Dobriyan | e6310f0 | 2019-01-03 15:26:37 -0800 | [diff] [blame] | 270 | static inline void dump_stack(void) |
Dave Young | e36df28 | 2018-02-13 15:28:34 +0800 | [diff] [blame] | 271 | { |
| 272 | } |
Nicholas Piggin | 5d5e452 | 2021-11-07 14:51:16 +1000 | [diff] [blame] | 273 | static inline void printk_trigger_flush(void) |
| 274 | { |
| 275 | } |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 276 | #endif |
| 277 | |
John Ogness | 766c268 | 2021-06-17 11:56:50 +0206 | [diff] [blame] | 278 | #ifdef CONFIG_SMP |
John Ogness | faebd69 | 2022-04-21 23:28:36 +0206 | [diff] [blame] | 279 | extern int __printk_cpu_sync_try_get(void); |
| 280 | extern void __printk_cpu_sync_wait(void); |
| 281 | extern void __printk_cpu_sync_put(void); |
John Ogness | 766c268 | 2021-06-17 11:56:50 +0206 | [diff] [blame] | 282 | |
John Ogness | f534332 | 2022-04-21 23:28:37 +0206 | [diff] [blame] | 283 | #else |
| 284 | |
| 285 | #define __printk_cpu_sync_try_get() true |
| 286 | #define __printk_cpu_sync_wait() |
| 287 | #define __printk_cpu_sync_put() |
| 288 | #endif /* CONFIG_SMP */ |
| 289 | |
John Ogness | 766c268 | 2021-06-17 11:56:50 +0206 | [diff] [blame] | 290 | /** |
John Ogness | f534332 | 2022-04-21 23:28:37 +0206 | [diff] [blame] | 291 | * printk_cpu_sync_get_irqsave() - Disable interrupts and acquire the printk |
| 292 | * cpu-reentrant spinning lock. |
John Ogness | 766c268 | 2021-06-17 11:56:50 +0206 | [diff] [blame] | 293 | * @flags: Stack-allocated storage for saving local interrupt state, |
John Ogness | faebd69 | 2022-04-21 23:28:36 +0206 | [diff] [blame] | 294 | * to be passed to printk_cpu_sync_put_irqrestore(). |
John Ogness | 766c268 | 2021-06-17 11:56:50 +0206 | [diff] [blame] | 295 | * |
| 296 | * If the lock is owned by another CPU, spin until it becomes available. |
| 297 | * Interrupts are restored while spinning. |
John Ogness | faebd69 | 2022-04-21 23:28:36 +0206 | [diff] [blame] | 298 | * |
| 299 | * CAUTION: This function must be used carefully. It does not behave like a |
| 300 | * typical lock. Here are important things to watch out for... |
| 301 | * |
| 302 | * * This function is reentrant on the same CPU. Therefore the calling |
| 303 | * code must not assume exclusive access to data if code accessing the |
| 304 | * data can run reentrant or within NMI context on the same CPU. |
| 305 | * |
| 306 | * * If there exists usage of this function from NMI context, it becomes |
| 307 | * unsafe to perform any type of locking or spinning to wait for other |
| 308 | * CPUs after calling this function from any context. This includes |
| 309 | * using spinlocks or any other busy-waiting synchronization methods. |
John Ogness | 766c268 | 2021-06-17 11:56:50 +0206 | [diff] [blame] | 310 | */ |
John Ogness | faebd69 | 2022-04-21 23:28:36 +0206 | [diff] [blame] | 311 | #define printk_cpu_sync_get_irqsave(flags) \ |
| 312 | for (;;) { \ |
| 313 | local_irq_save(flags); \ |
| 314 | if (__printk_cpu_sync_try_get()) \ |
| 315 | break; \ |
| 316 | local_irq_restore(flags); \ |
| 317 | __printk_cpu_sync_wait(); \ |
John Ogness | 766c268 | 2021-06-17 11:56:50 +0206 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | /** |
John Ogness | faebd69 | 2022-04-21 23:28:36 +0206 | [diff] [blame] | 321 | * printk_cpu_sync_put_irqrestore() - Release the printk cpu-reentrant spinning |
| 322 | * lock and restore interrupts. |
| 323 | * @flags: Caller's saved interrupt state, from printk_cpu_sync_get_irqsave(). |
John Ogness | 766c268 | 2021-06-17 11:56:50 +0206 | [diff] [blame] | 324 | */ |
John Ogness | faebd69 | 2022-04-21 23:28:36 +0206 | [diff] [blame] | 325 | #define printk_cpu_sync_put_irqrestore(flags) \ |
John Ogness | 766c268 | 2021-06-17 11:56:50 +0206 | [diff] [blame] | 326 | do { \ |
John Ogness | faebd69 | 2022-04-21 23:28:36 +0206 | [diff] [blame] | 327 | __printk_cpu_sync_put(); \ |
John Ogness | 766c268 | 2021-06-17 11:56:50 +0206 | [diff] [blame] | 328 | local_irq_restore(flags); \ |
John Ogness | faebd69 | 2022-04-21 23:28:36 +0206 | [diff] [blame] | 329 | } while (0) |
John Ogness | 766c268 | 2021-06-17 11:56:50 +0206 | [diff] [blame] | 330 | |
Arnd Bergmann | 01c313d | 2017-11-13 17:50:59 +0100 | [diff] [blame] | 331 | extern int kptr_restrict; |
| 332 | |
Ricardo Cañuelo | 90c165f0 | 2020-04-03 11:36:17 +0200 | [diff] [blame] | 333 | /** |
| 334 | * pr_fmt - used by the pr_*() macros to generate the printk format string |
| 335 | * @fmt: format string passed from a pr_*() macro |
| 336 | * |
| 337 | * This macro can be used to generate a unified format string for pr_*() |
| 338 | * macros. A common use is to prefix all pr_*() messages in a file with a common |
| 339 | * string. For example, defining this at the top of a source file: |
| 340 | * |
| 341 | * #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 342 | * |
| 343 | * would prefix all pr_info, pr_emerg... messages in the file with the module |
| 344 | * name. |
| 345 | */ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 346 | #ifndef pr_fmt |
| 347 | #define pr_fmt(fmt) fmt |
| 348 | #endif |
| 349 | |
Chris Down | 3370155 | 2021-06-15 17:52:53 +0100 | [diff] [blame] | 350 | struct module; |
| 351 | |
| 352 | #ifdef CONFIG_PRINTK_INDEX |
| 353 | struct pi_entry { |
| 354 | const char *fmt; |
| 355 | const char *func; |
| 356 | const char *file; |
| 357 | unsigned int line; |
| 358 | |
| 359 | /* |
| 360 | * While printk and pr_* have the level stored in the string at compile |
| 361 | * time, some subsystems dynamically add it at runtime through the |
| 362 | * format string. For these dynamic cases, we allow the subsystem to |
| 363 | * tell us the level at compile time. |
| 364 | * |
| 365 | * NULL indicates that the level, if any, is stored in fmt. |
| 366 | */ |
| 367 | const char *level; |
| 368 | |
| 369 | /* |
| 370 | * The format string used by various subsystem specific printk() |
| 371 | * wrappers to prefix the message. |
| 372 | * |
| 373 | * Note that the static prefix defined by the pr_fmt() macro is stored |
| 374 | * directly in the message format (@fmt), not here. |
| 375 | */ |
| 376 | const char *subsys_fmt_prefix; |
| 377 | } __packed; |
| 378 | |
| 379 | #define __printk_index_emit(_fmt, _level, _subsys_fmt_prefix) \ |
| 380 | do { \ |
| 381 | if (__builtin_constant_p(_fmt) && __builtin_constant_p(_level)) { \ |
| 382 | /* |
| 383 | * We check __builtin_constant_p multiple times here |
| 384 | * for the same input because GCC will produce an error |
| 385 | * if we try to assign a static variable to fmt if it |
| 386 | * is not a constant, even with the outer if statement. |
| 387 | */ \ |
| 388 | static const struct pi_entry _entry \ |
| 389 | __used = { \ |
| 390 | .fmt = __builtin_constant_p(_fmt) ? (_fmt) : NULL, \ |
| 391 | .func = __func__, \ |
| 392 | .file = __FILE__, \ |
| 393 | .line = __LINE__, \ |
| 394 | .level = __builtin_constant_p(_level) ? (_level) : NULL, \ |
| 395 | .subsys_fmt_prefix = _subsys_fmt_prefix,\ |
| 396 | }; \ |
| 397 | static const struct pi_entry *_entry_ptr \ |
| 398 | __used __section(".printk_index") = &_entry; \ |
| 399 | } \ |
| 400 | } while (0) |
| 401 | |
| 402 | #else /* !CONFIG_PRINTK_INDEX */ |
| 403 | #define __printk_index_emit(...) do {} while (0) |
| 404 | #endif /* CONFIG_PRINTK_INDEX */ |
| 405 | |
| 406 | /* |
| 407 | * Some subsystems have their own custom printk that applies a va_format to a |
| 408 | * generic format, for example, to include a device number or other metadata |
| 409 | * alongside the format supplied by the caller. |
| 410 | * |
| 411 | * In order to store these in the way they would be emitted by the printk |
| 412 | * infrastructure, the subsystem provides us with the start, fixed string, and |
| 413 | * any subsequent text in the format string. |
| 414 | * |
| 415 | * We take a variable argument list as pr_fmt/dev_fmt/etc are sometimes passed |
| 416 | * as multiple arguments (eg: `"%s: ", "blah"`), and we must only take the |
| 417 | * first one. |
| 418 | * |
| 419 | * subsys_fmt_prefix must be known at compile time, or compilation will fail |
| 420 | * (since this is a mistake). If fmt or level is not known at compile time, no |
| 421 | * index entry will be made (since this can legitimately happen). |
| 422 | */ |
| 423 | #define printk_index_subsys_emit(subsys_fmt_prefix, level, fmt, ...) \ |
| 424 | __printk_index_emit(fmt, level, subsys_fmt_prefix) |
| 425 | |
| 426 | #define printk_index_wrap(_p_func, _fmt, ...) \ |
| 427 | ({ \ |
| 428 | __printk_index_emit(_fmt, NULL, NULL); \ |
| 429 | _p_func(_fmt, ##__VA_ARGS__); \ |
| 430 | }) |
| 431 | |
| 432 | |
Jonathan Corbet | 7d9e266 | 2021-07-25 15:16:00 -0600 | [diff] [blame] | 433 | /** |
| 434 | * printk - print a kernel message |
| 435 | * @fmt: format string |
| 436 | * |
| 437 | * This is printk(). It can be called from any context. We want it to work. |
| 438 | * |
| 439 | * If printk indexing is enabled, _printk() is called from printk_index_wrap. |
| 440 | * Otherwise, printk is simply #defined to _printk. |
| 441 | * |
| 442 | * We try to grab the console_lock. If we succeed, it's easy - we log the |
| 443 | * output and call the console drivers. If we fail to get the semaphore, we |
| 444 | * place the output into the log buffer and return. The current holder of |
| 445 | * the console_sem will notice the new output in console_unlock(); and will |
| 446 | * send it to the consoles before releasing the lock. |
| 447 | * |
| 448 | * One effect of this deferred printing is that code which calls printk() and |
| 449 | * then changes console_loglevel may break. This is because console_loglevel |
| 450 | * is inspected when the actual printing occurs. |
| 451 | * |
| 452 | * See also: |
| 453 | * printf(3) |
| 454 | * |
| 455 | * See the vsnprintf() documentation for format string extensions over C99. |
| 456 | */ |
Chris Down | 3370155 | 2021-06-15 17:52:53 +0100 | [diff] [blame] | 457 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__) |
| 458 | #define printk_deferred(fmt, ...) \ |
| 459 | printk_index_wrap(_printk_deferred, fmt, ##__VA_ARGS__) |
| 460 | |
Ricardo Cañuelo | 90c165f0 | 2020-04-03 11:36:17 +0200 | [diff] [blame] | 461 | /** |
| 462 | * pr_emerg - Print an emergency-level message |
| 463 | * @fmt: format string |
| 464 | * @...: arguments for the format string |
| 465 | * |
| 466 | * This macro expands to a printk with KERN_EMERG loglevel. It uses pr_fmt() to |
| 467 | * generate the format string. |
Dan Streetman | 6e099f5 | 2014-06-04 16:11:44 -0700 | [diff] [blame] | 468 | */ |
Linus Torvalds | a0cba21 | 2016-08-09 10:48:18 -0700 | [diff] [blame] | 469 | #define pr_emerg(fmt, ...) \ |
| 470 | printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) |
Ricardo Cañuelo | 90c165f0 | 2020-04-03 11:36:17 +0200 | [diff] [blame] | 471 | /** |
| 472 | * pr_alert - Print an alert-level message |
| 473 | * @fmt: format string |
| 474 | * @...: arguments for the format string |
| 475 | * |
| 476 | * This macro expands to a printk with KERN_ALERT loglevel. It uses pr_fmt() to |
| 477 | * generate the format string. |
| 478 | */ |
Linus Torvalds | a0cba21 | 2016-08-09 10:48:18 -0700 | [diff] [blame] | 479 | #define pr_alert(fmt, ...) \ |
| 480 | printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) |
Ricardo Cañuelo | 90c165f0 | 2020-04-03 11:36:17 +0200 | [diff] [blame] | 481 | /** |
| 482 | * pr_crit - Print a critical-level message |
| 483 | * @fmt: format string |
| 484 | * @...: arguments for the format string |
| 485 | * |
| 486 | * This macro expands to a printk with KERN_CRIT loglevel. It uses pr_fmt() to |
| 487 | * generate the format string. |
| 488 | */ |
Linus Torvalds | a0cba21 | 2016-08-09 10:48:18 -0700 | [diff] [blame] | 489 | #define pr_crit(fmt, ...) \ |
| 490 | printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) |
Ricardo Cañuelo | 90c165f0 | 2020-04-03 11:36:17 +0200 | [diff] [blame] | 491 | /** |
| 492 | * pr_err - Print an error-level message |
| 493 | * @fmt: format string |
| 494 | * @...: arguments for the format string |
| 495 | * |
| 496 | * This macro expands to a printk with KERN_ERR loglevel. It uses pr_fmt() to |
| 497 | * generate the format string. |
| 498 | */ |
Linus Torvalds | a0cba21 | 2016-08-09 10:48:18 -0700 | [diff] [blame] | 499 | #define pr_err(fmt, ...) \ |
| 500 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) |
Ricardo Cañuelo | 90c165f0 | 2020-04-03 11:36:17 +0200 | [diff] [blame] | 501 | /** |
| 502 | * pr_warn - Print a warning-level message |
| 503 | * @fmt: format string |
| 504 | * @...: arguments for the format string |
| 505 | * |
| 506 | * This macro expands to a printk with KERN_WARNING loglevel. It uses pr_fmt() |
| 507 | * to generate the format string. |
| 508 | */ |
Kefeng Wang | 61ff72f | 2019-11-28 08:47:51 +0800 | [diff] [blame] | 509 | #define pr_warn(fmt, ...) \ |
Linus Torvalds | a0cba21 | 2016-08-09 10:48:18 -0700 | [diff] [blame] | 510 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) |
Ricardo Cañuelo | 90c165f0 | 2020-04-03 11:36:17 +0200 | [diff] [blame] | 511 | /** |
| 512 | * pr_notice - Print a notice-level message |
| 513 | * @fmt: format string |
| 514 | * @...: arguments for the format string |
| 515 | * |
| 516 | * This macro expands to a printk with KERN_NOTICE loglevel. It uses pr_fmt() to |
| 517 | * generate the format string. |
| 518 | */ |
Linus Torvalds | a0cba21 | 2016-08-09 10:48:18 -0700 | [diff] [blame] | 519 | #define pr_notice(fmt, ...) \ |
| 520 | printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) |
Ricardo Cañuelo | 90c165f0 | 2020-04-03 11:36:17 +0200 | [diff] [blame] | 521 | /** |
| 522 | * pr_info - Print an info-level message |
| 523 | * @fmt: format string |
| 524 | * @...: arguments for the format string |
| 525 | * |
| 526 | * This macro expands to a printk with KERN_INFO loglevel. It uses pr_fmt() to |
| 527 | * generate the format string. |
| 528 | */ |
Linus Torvalds | a0cba21 | 2016-08-09 10:48:18 -0700 | [diff] [blame] | 529 | #define pr_info(fmt, ...) \ |
| 530 | printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) |
Ricardo Cañuelo | 90c165f0 | 2020-04-03 11:36:17 +0200 | [diff] [blame] | 531 | |
| 532 | /** |
| 533 | * pr_cont - Continues a previous log message in the same line. |
| 534 | * @fmt: format string |
| 535 | * @...: arguments for the format string |
| 536 | * |
| 537 | * This macro expands to a printk with KERN_CONT loglevel. It should only be |
| 538 | * used when continuing a log message with no newline ('\n') enclosed. Otherwise |
| 539 | * it defaults back to KERN_DEFAULT loglevel. |
Steven Rostedt | 7b1460e | 2015-04-15 16:16:59 -0700 | [diff] [blame] | 540 | */ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 541 | #define pr_cont(fmt, ...) \ |
| 542 | printk(KERN_CONT fmt, ##__VA_ARGS__) |
| 543 | |
Ricardo Cañuelo | 90c165f0 | 2020-04-03 11:36:17 +0200 | [diff] [blame] | 544 | /** |
| 545 | * pr_devel - Print a debug-level message conditionally |
| 546 | * @fmt: format string |
| 547 | * @...: arguments for the format string |
| 548 | * |
| 549 | * This macro expands to a printk with KERN_DEBUG loglevel if DEBUG is |
| 550 | * defined. Otherwise it does nothing. |
| 551 | * |
| 552 | * It uses pr_fmt() to generate the format string. |
| 553 | */ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 554 | #ifdef DEBUG |
| 555 | #define pr_devel(fmt, ...) \ |
| 556 | printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
| 557 | #else |
| 558 | #define pr_devel(fmt, ...) \ |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 559 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 560 | #endif |
| 561 | |
Joe Perches | 29fc2bc | 2013-10-26 20:41:53 -0700 | [diff] [blame] | 562 | |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 563 | /* If you are writing a driver, please use dev_dbg instead */ |
Orson Zhai | ceabef7 | 2020-06-07 21:40:14 -0700 | [diff] [blame] | 564 | #if defined(CONFIG_DYNAMIC_DEBUG) || \ |
| 565 | (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) |
Luis de Bethencourt | 9d5059c | 2016-08-02 14:03:47 -0700 | [diff] [blame] | 566 | #include <linux/dynamic_debug.h> |
| 567 | |
Ricardo Cañuelo | 90c165f0 | 2020-04-03 11:36:17 +0200 | [diff] [blame] | 568 | /** |
| 569 | * pr_debug - Print a debug-level message conditionally |
| 570 | * @fmt: format string |
| 571 | * @...: arguments for the format string |
| 572 | * |
| 573 | * This macro expands to dynamic_pr_debug() if CONFIG_DYNAMIC_DEBUG is |
| 574 | * set. Otherwise, if DEBUG is defined, it's equivalent to a printk with |
| 575 | * KERN_DEBUG loglevel. If DEBUG is not defined it does nothing. |
| 576 | * |
| 577 | * It uses pr_fmt() to generate the format string (dynamic_pr_debug() uses |
| 578 | * pr_fmt() internally). |
| 579 | */ |
| 580 | #define pr_debug(fmt, ...) \ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 581 | dynamic_pr_debug(fmt, ##__VA_ARGS__) |
Jim Cromie | b558c96 | 2011-12-19 17:11:18 -0500 | [diff] [blame] | 582 | #elif defined(DEBUG) |
| 583 | #define pr_debug(fmt, ...) \ |
| 584 | printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 585 | #else |
| 586 | #define pr_debug(fmt, ...) \ |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 587 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 588 | #endif |
| 589 | |
| 590 | /* |
Joe Perches | 16cb839 | 2011-01-12 16:59:46 -0800 | [diff] [blame] | 591 | * Print a one-time message (analogous to WARN_ONCE() et al): |
| 592 | */ |
| 593 | |
| 594 | #ifdef CONFIG_PRINTK |
Joe Perches | c28aa1f0 | 2014-01-23 15:54:16 -0800 | [diff] [blame] | 595 | #define printk_once(fmt, ...) \ |
Tanner Love | a358f40 | 2021-06-28 09:50:06 -0400 | [diff] [blame] | 596 | DO_ONCE_LITE(printk, fmt, ##__VA_ARGS__) |
John Stultz | c224815 | 2014-06-04 16:11:41 -0700 | [diff] [blame] | 597 | #define printk_deferred_once(fmt, ...) \ |
Tanner Love | a358f40 | 2021-06-28 09:50:06 -0400 | [diff] [blame] | 598 | DO_ONCE_LITE(printk_deferred, fmt, ##__VA_ARGS__) |
Joe Perches | 16cb839 | 2011-01-12 16:59:46 -0800 | [diff] [blame] | 599 | #else |
Joe Perches | c28aa1f0 | 2014-01-23 15:54:16 -0800 | [diff] [blame] | 600 | #define printk_once(fmt, ...) \ |
Joe Perches | 16cb839 | 2011-01-12 16:59:46 -0800 | [diff] [blame] | 601 | no_printk(fmt, ##__VA_ARGS__) |
John Stultz | c224815 | 2014-06-04 16:11:41 -0700 | [diff] [blame] | 602 | #define printk_deferred_once(fmt, ...) \ |
| 603 | no_printk(fmt, ##__VA_ARGS__) |
Joe Perches | 16cb839 | 2011-01-12 16:59:46 -0800 | [diff] [blame] | 604 | #endif |
| 605 | |
| 606 | #define pr_emerg_once(fmt, ...) \ |
| 607 | printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) |
| 608 | #define pr_alert_once(fmt, ...) \ |
| 609 | printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) |
| 610 | #define pr_crit_once(fmt, ...) \ |
| 611 | printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) |
| 612 | #define pr_err_once(fmt, ...) \ |
| 613 | printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) |
| 614 | #define pr_warn_once(fmt, ...) \ |
| 615 | printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) |
| 616 | #define pr_notice_once(fmt, ...) \ |
| 617 | printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) |
| 618 | #define pr_info_once(fmt, ...) \ |
| 619 | printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) |
Tetsuo Handa | eb012d1 | 2020-05-25 00:32:43 +0900 | [diff] [blame] | 620 | /* no pr_cont_once, don't do that... */ |
Mikhail Gruzdev | 36d308d | 2013-02-21 16:43:10 -0800 | [diff] [blame] | 621 | |
| 622 | #if defined(DEBUG) |
| 623 | #define pr_devel_once(fmt, ...) \ |
| 624 | printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
| 625 | #else |
| 626 | #define pr_devel_once(fmt, ...) \ |
| 627 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
| 628 | #endif |
| 629 | |
Joe Perches | 16cb839 | 2011-01-12 16:59:46 -0800 | [diff] [blame] | 630 | /* If you are writing a driver, please use dev_dbg instead */ |
| 631 | #if defined(DEBUG) |
| 632 | #define pr_debug_once(fmt, ...) \ |
| 633 | printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
| 634 | #else |
| 635 | #define pr_debug_once(fmt, ...) \ |
| 636 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
| 637 | #endif |
| 638 | |
| 639 | /* |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 640 | * ratelimited messages with local ratelimit_state, |
| 641 | * no local ratelimit_state used in the !PRINTK case |
| 642 | */ |
| 643 | #ifdef CONFIG_PRINTK |
Joe Perches | 6ec42a56 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 644 | #define printk_ratelimited(fmt, ...) \ |
| 645 | ({ \ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 646 | static DEFINE_RATELIMIT_STATE(_rs, \ |
| 647 | DEFAULT_RATELIMIT_INTERVAL, \ |
| 648 | DEFAULT_RATELIMIT_BURST); \ |
| 649 | \ |
| 650 | if (__ratelimit(&_rs)) \ |
| 651 | printk(fmt, ##__VA_ARGS__); \ |
| 652 | }) |
| 653 | #else |
Joe Perches | 6ec42a56 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 654 | #define printk_ratelimited(fmt, ...) \ |
| 655 | no_printk(fmt, ##__VA_ARGS__) |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 656 | #endif |
| 657 | |
Joe Perches | 6ec42a56 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 658 | #define pr_emerg_ratelimited(fmt, ...) \ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 659 | printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) |
Joe Perches | 6ec42a56 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 660 | #define pr_alert_ratelimited(fmt, ...) \ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 661 | printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) |
Joe Perches | 6ec42a56 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 662 | #define pr_crit_ratelimited(fmt, ...) \ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 663 | printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) |
Joe Perches | 6ec42a56 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 664 | #define pr_err_ratelimited(fmt, ...) \ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 665 | printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) |
Joe Perches | 6ec42a56 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 666 | #define pr_warn_ratelimited(fmt, ...) \ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 667 | printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) |
Joe Perches | 6ec42a56 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 668 | #define pr_notice_ratelimited(fmt, ...) \ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 669 | printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) |
Joe Perches | 6ec42a56 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 670 | #define pr_info_ratelimited(fmt, ...) \ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 671 | printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) |
| 672 | /* no pr_cont_ratelimited, don't do that... */ |
Mikhail Gruzdev | 36d308d | 2013-02-21 16:43:10 -0800 | [diff] [blame] | 673 | |
| 674 | #if defined(DEBUG) |
| 675 | #define pr_devel_ratelimited(fmt, ...) \ |
| 676 | printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
| 677 | #else |
| 678 | #define pr_devel_ratelimited(fmt, ...) \ |
| 679 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
| 680 | #endif |
| 681 | |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 682 | /* If you are writing a driver, please use dev_dbg instead */ |
Orson Zhai | ceabef7 | 2020-06-07 21:40:14 -0700 | [diff] [blame] | 683 | #if defined(CONFIG_DYNAMIC_DEBUG) || \ |
| 684 | (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) |
Joe Perches | 29fc2bc | 2013-10-26 20:41:53 -0700 | [diff] [blame] | 685 | /* descriptor check is first to prevent flooding with "callbacks suppressed" */ |
| 686 | #define pr_debug_ratelimited(fmt, ...) \ |
| 687 | do { \ |
| 688 | static DEFINE_RATELIMIT_STATE(_rs, \ |
| 689 | DEFAULT_RATELIMIT_INTERVAL, \ |
| 690 | DEFAULT_RATELIMIT_BURST); \ |
Jason A. Donenfeld | 515a9ad | 2015-09-09 15:36:12 -0700 | [diff] [blame] | 691 | DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \ |
Rasmus Villemoes | a9d4ab7 | 2019-03-07 16:27:29 -0800 | [diff] [blame] | 692 | if (DYNAMIC_DEBUG_BRANCH(descriptor) && \ |
Joe Perches | 29fc2bc | 2013-10-26 20:41:53 -0700 | [diff] [blame] | 693 | __ratelimit(&_rs)) \ |
Jason A. Donenfeld | 515a9ad | 2015-09-09 15:36:12 -0700 | [diff] [blame] | 694 | __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \ |
Joe Perches | 29fc2bc | 2013-10-26 20:41:53 -0700 | [diff] [blame] | 695 | } while (0) |
| 696 | #elif defined(DEBUG) |
Joe Perches | 6ec42a56 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 697 | #define pr_debug_ratelimited(fmt, ...) \ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 698 | printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
| 699 | #else |
| 700 | #define pr_debug_ratelimited(fmt, ...) \ |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 701 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 702 | #endif |
| 703 | |
Kay Sievers | e11fea92 | 2012-05-03 02:29:41 +0200 | [diff] [blame] | 704 | extern const struct file_operations kmsg_fops; |
| 705 | |
Joe Perches | ac83ed6 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 706 | enum { |
| 707 | DUMP_PREFIX_NONE, |
| 708 | DUMP_PREFIX_ADDRESS, |
| 709 | DUMP_PREFIX_OFFSET |
| 710 | }; |
Andy Shevchenko | 114fc1a | 2015-02-12 15:02:29 -0800 | [diff] [blame] | 711 | extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, |
| 712 | int groupsize, char *linebuf, size_t linebuflen, |
| 713 | bool ascii); |
Joe Perches | ac83ed6 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 714 | #ifdef CONFIG_PRINTK |
| 715 | extern void print_hex_dump(const char *level, const char *prefix_str, |
| 716 | int prefix_type, int rowsize, int groupsize, |
| 717 | const void *buf, size_t len, bool ascii); |
Joe Perches | ac83ed6 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 718 | #else |
| 719 | static inline void print_hex_dump(const char *level, const char *prefix_str, |
| 720 | int prefix_type, int rowsize, int groupsize, |
| 721 | const void *buf, size_t len, bool ascii) |
| 722 | { |
| 723 | } |
| 724 | static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type, |
| 725 | const void *buf, size_t len) |
| 726 | { |
| 727 | } |
| 728 | |
| 729 | #endif |
| 730 | |
Orson Zhai | ceabef7 | 2020-06-07 21:40:14 -0700 | [diff] [blame] | 731 | #if defined(CONFIG_DYNAMIC_DEBUG) || \ |
| 732 | (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) |
Vladimir Kondratiev | 7a55561 | 2012-12-05 16:48:27 -0500 | [diff] [blame] | 733 | #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ |
| 734 | groupsize, buf, len, ascii) \ |
| 735 | dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ |
| 736 | groupsize, buf, len, ascii) |
Linus Walleij | cdf1744 | 2015-09-09 15:37:11 -0700 | [diff] [blame] | 737 | #elif defined(DEBUG) |
Vladimir Kondratiev | 7a55561 | 2012-12-05 16:48:27 -0500 | [diff] [blame] | 738 | #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ |
| 739 | groupsize, buf, len, ascii) \ |
| 740 | print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \ |
| 741 | groupsize, buf, len, ascii) |
Linus Walleij | cdf1744 | 2015-09-09 15:37:11 -0700 | [diff] [blame] | 742 | #else |
| 743 | static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type, |
| 744 | int rowsize, int groupsize, |
| 745 | const void *buf, size_t len, bool ascii) |
| 746 | { |
| 747 | } |
| 748 | #endif |
Vladimir Kondratiev | 7a55561 | 2012-12-05 16:48:27 -0500 | [diff] [blame] | 749 | |
Stephen Boyd | 091cb099 | 2019-09-25 16:46:29 -0700 | [diff] [blame] | 750 | /** |
| 751 | * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params |
| 752 | * @prefix_str: string to prefix each line with; |
| 753 | * caller supplies trailing spaces for alignment if desired |
| 754 | * @prefix_type: controls whether prefix of an offset, address, or none |
| 755 | * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE) |
| 756 | * @buf: data blob to dump |
| 757 | * @len: number of bytes in the @buf |
| 758 | * |
| 759 | * Calls print_hex_dump(), with log level of KERN_DEBUG, |
| 760 | * rowsize of 16, groupsize of 1, and ASCII output included. |
| 761 | */ |
| 762 | #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \ |
| 763 | print_hex_dump_debug(prefix_str, prefix_type, 16, 1, buf, len, true) |
| 764 | |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 765 | #endif |