2 * linux/kernel/printk.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
6 * Modified to make sys_syslog() more flexible: added commands to
7 * return the last 4k of kernel messages, regardless of whether
8 * they've been read or not. Added option to suppress kernel printk's
9 * to the console. Added hook for sending the console messages
10 * elsewhere, in preparation for a serial line console (someday).
12 * Modified for sysctl support, 1/8/97, Chris Horn.
13 * Fixed SMP synchronization, 08/08/99, Manfred Spraul
14 * manfred@colorfullife.com
15 * Rewrote bits to get rid of console_lock
16 * 01Mar01 Andrew Morton
19 #include <linux/kernel.h>
21 #include <linux/tty.h>
22 #include <linux/tty_driver.h>
23 #include <linux/console.h>
24 #include <linux/init.h>
25 #include <linux/jiffies.h>
26 #include <linux/nmi.h>
27 #include <linux/module.h>
28 #include <linux/moduleparam.h>
29 #include <linux/interrupt.h> /* For in_interrupt() */
30 #include <linux/delay.h>
31 #include <linux/smp.h>
32 #include <linux/security.h>
33 #include <linux/bootmem.h>
34 #include <linux/memblock.h>
35 #include <linux/aio.h>
36 #include <linux/syscalls.h>
37 #include <linux/kexec.h>
38 #include <linux/kdb.h>
39 #include <linux/ratelimit.h>
40 #include <linux/kmsg_dump.h>
41 #include <linux/syslog.h>
42 #include <linux/cpu.h>
43 #include <linux/notifier.h>
44 #include <linux/rculist.h>
45 #include <linux/poll.h>
46 #include <linux/irq_work.h>
47 #include <linux/utsname.h>
49 #include <asm/uaccess.h>
51 #define CREATE_TRACE_POINTS
52 #include <trace/events/printk.h>
54 #ifdef CONFIG_EARLY_PRINTK_DIRECT
55 extern void printascii(char *);
58 /* printk's without a loglevel use this.. */
59 #define DEFAULT_MESSAGE_LOGLEVEL CONFIG_DEFAULT_MESSAGE_LOGLEVEL
61 /* We show everything that is MORE important than this.. */
62 #define MINIMUM_CONSOLE_LOGLEVEL 1 /* Minimum loglevel we let people use */
63 #define DEFAULT_CONSOLE_LOGLEVEL 7 /* anything MORE serious than KERN_DEBUG */
65 int console_printk[4] = {
66 DEFAULT_CONSOLE_LOGLEVEL, /* console_loglevel */
67 DEFAULT_MESSAGE_LOGLEVEL, /* default_message_loglevel */
68 MINIMUM_CONSOLE_LOGLEVEL, /* minimum_console_loglevel */
69 DEFAULT_CONSOLE_LOGLEVEL, /* default_console_loglevel */
73 * Low level drivers may need that to know if they can schedule in
74 * their unblank() callback or not. So let's export it.
77 EXPORT_SYMBOL(oops_in_progress);
80 * console_sem protects the console_drivers list, and also
81 * provides serialisation for access to the entire console
84 static DEFINE_SEMAPHORE(console_sem);
85 struct console *console_drivers;
86 EXPORT_SYMBOL_GPL(console_drivers);
89 static struct lockdep_map console_lock_dep_map = {
90 .name = "console_lock"
95 * This is used for debugging the mess that is the VT code by
96 * keeping track if we have the console semaphore held. It's
97 * definitely not the perfect debug tool (we don't know if _WE_
98 * hold it are racing, but it helps tracking those weird code
99 * path in the console code where we end up in places I want
100 * locked without the console sempahore held
102 static int console_locked, console_suspended;
105 * If exclusive_console is non-NULL then only this console is to be printed to.
107 static struct console *exclusive_console;
110 * Array of consoles built from command line options (console=)
112 struct console_cmdline
114 char name[8]; /* Name of the driver */
115 int index; /* Minor dev. to use */
116 char *options; /* Options for the driver */
117 #ifdef CONFIG_A11Y_BRAILLE_CONSOLE
118 char *brl_options; /* Options for braille driver */
122 #define MAX_CMDLINECONSOLES 8
124 static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];
125 static int selected_console = -1;
126 static int preferred_console = -1;
127 int console_set_on_cmdline;
128 EXPORT_SYMBOL(console_set_on_cmdline);
130 /* Flag: console code may call schedule() */
131 static int console_may_schedule;
134 * The printk log buffer consists of a chain of concatenated variable
135 * length records. Every record starts with a record header, containing
136 * the overall length of the record.
138 * The heads to the first and last entry in the buffer, as well as the
139 * sequence numbers of these both entries are maintained when messages
142 * If the heads indicate available messages, the length in the header
143 * tells the start next message. A length == 0 for the next message
144 * indicates a wrap-around to the beginning of the buffer.
146 * Every record carries the monotonic timestamp in microseconds, as well as
147 * the standard userspace syslog level and syslog facility. The usual
148 * kernel messages use LOG_KERN; userspace-injected messages always carry
149 * a matching syslog facility, by default LOG_USER. The origin of every
150 * message can be reliably determined that way.
152 * The human readable log message directly follows the message header. The
153 * length of the message text is stored in the header, the stored message
156 * Optionally, a message can carry a dictionary of properties (key/value pairs),
157 * to provide userspace with a machine-readable message context.
159 * Examples for well-defined, commonly used property names are:
160 * DEVICE=b12:8 device identifier
164 * +sound:card0 subsystem:devname
165 * SUBSYSTEM=pci driver-core subsystem name
167 * Valid characters in property names are [a-zA-Z0-9.-_]. The plain text value
168 * follows directly after a '=' character. Every property is terminated by
169 * a '\0' character. The last property is not terminated.
171 * Example of a message structure:
172 * 0000 ff 8f 00 00 00 00 00 00 monotonic time in nsec
173 * 0008 34 00 record is 52 bytes long
174 * 000a 0b 00 text is 11 bytes long
175 * 000c 1f 00 dictionary is 23 bytes long
176 * 000e 03 00 LOG_KERN (facility) LOG_ERR (level)
177 * 0010 69 74 27 73 20 61 20 6c "it's a l"
179 * 001b 44 45 56 49 43 "DEVIC"
180 * 45 3d 62 38 3a 32 00 44 "E=b8:2\0D"
181 * 52 49 56 45 52 3d 62 75 "RIVER=bu"
183 * 0032 00 00 00 padding to next message header
185 * The 'struct log' buffer header must never be directly exported to
186 * userspace, it is a kernel-private implementation detail that might
187 * need to be changed in the future, when the requirements change.
189 * /dev/kmsg exports the structured data in the following line format:
190 * "level,sequnum,timestamp;<message text>\n"
192 * The optional key/value pairs are attached as continuation lines starting
193 * with a space character and terminated by a newline. All possible
194 * non-prinatable characters are escaped in the "\xff" notation.
196 * Users of the export format should ignore possible additional values
197 * separated by ',', and find the message after the ';' character.
201 LOG_NOCONS = 1, /* already flushed, do not print to console */
202 LOG_NEWLINE = 2, /* text ended with a newline */
203 LOG_PREFIX = 4, /* text started with a prefix */
204 LOG_CONT = 8, /* text is a fragment of a continuation line */
208 u64 ts_nsec; /* timestamp in nanoseconds */
209 u16 len; /* length of entire record */
210 u16 text_len; /* length of text buffer */
211 u16 dict_len; /* length of dictionary buffer */
212 u8 facility; /* syslog facility */
213 u8 flags:5; /* internal record flags */
214 u8 level:3; /* syslog level */
218 * The logbuf_lock protects kmsg buffer, indices, counters. It is also
219 * used in interesting ways to provide interlocking in console_unlock();
221 static DEFINE_RAW_SPINLOCK(logbuf_lock);
224 DECLARE_WAIT_QUEUE_HEAD(log_wait);
225 /* the next printk record to read by syslog(READ) or /proc/kmsg */
226 static u64 syslog_seq;
227 static u32 syslog_idx;
228 static enum log_flags syslog_prev;
229 static size_t syslog_partial;
231 /* index and sequence number of the first record stored in the buffer */
232 static u64 log_first_seq;
233 static u32 log_first_idx;
235 /* index and sequence number of the next record to store in the buffer */
236 static u64 log_next_seq;
237 static u32 log_next_idx;
239 /* the next printk record to write to the console */
240 static u64 console_seq;
241 static u32 console_idx;
242 static enum log_flags console_prev;
244 /* the next printk record to read after the last 'clear' command */
245 static u64 clear_seq;
246 static u32 clear_idx;
248 #define PREFIX_MAX 32
249 #define LOG_LINE_MAX 1024 - PREFIX_MAX
252 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
255 #define LOG_ALIGN __alignof__(struct log)
257 #define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT)
258 static char __log_buf[__LOG_BUF_LEN] __aligned(LOG_ALIGN);
259 static char *log_buf = __log_buf;
260 static u32 log_buf_len = __LOG_BUF_LEN;
262 /* cpu currently holding logbuf_lock */
263 static volatile unsigned int logbuf_cpu = UINT_MAX;
265 /* human readable text of the record */
266 static char *log_text(const struct log *msg)
268 return (char *)msg + sizeof(struct log);
271 /* optional key/value pair dictionary attached to the record */
272 static char *log_dict(const struct log *msg)
274 return (char *)msg + sizeof(struct log) + msg->text_len;
277 /* get record by index; idx must point to valid msg */
278 static struct log *log_from_idx(u32 idx)
280 struct log *msg = (struct log *)(log_buf + idx);
283 * A length == 0 record is the end of buffer marker. Wrap around and
284 * read the message at the start of the buffer.
287 return (struct log *)log_buf;
291 /* get next record; idx must point to valid msg */
292 static u32 log_next(u32 idx)
294 struct log *msg = (struct log *)(log_buf + idx);
296 /* length == 0 indicates the end of the buffer; wrap */
298 * A length == 0 record is the end of buffer marker. Wrap around and
299 * read the message at the start of the buffer as *this* one, and
300 * return the one after that.
303 msg = (struct log *)log_buf;
306 return idx + msg->len;
309 #ifdef CONFIG_RK_LAST_LOG
310 extern void rk_last_log_text(char *text, size_t size);
311 static char rk_text[1024];
312 static size_t msg_print_text(const struct log *msg, enum log_flags prev,
313 bool syslog, char *buf, size_t size);
315 /* insert record into the buffer, discard old ones, update heads */
316 static void log_store(int facility, int level,
317 enum log_flags flags, u64 ts_nsec,
318 const char *dict, u16 dict_len,
319 const char *text, u16 text_len)
324 /* number of '\0' padding bytes to next message */
325 size = sizeof(struct log) + text_len + dict_len;
326 pad_len = (-size) & (LOG_ALIGN - 1);
329 while (log_first_seq < log_next_seq) {
332 if (log_next_idx > log_first_idx)
333 free = max(log_buf_len - log_next_idx, log_first_idx);
335 free = log_first_idx - log_next_idx;
337 if (free > size + sizeof(struct log))
340 /* drop old messages until we have enough contiuous space */
341 log_first_idx = log_next(log_first_idx);
345 if (log_next_idx + size + sizeof(struct log) >= log_buf_len) {
347 * This message + an additional empty header does not fit
348 * at the end of the buffer. Add an empty header with len == 0
349 * to signify a wrap around.
351 memset(log_buf + log_next_idx, 0, sizeof(struct log));
356 msg = (struct log *)(log_buf + log_next_idx);
357 memcpy(log_text(msg), text, text_len);
358 msg->text_len = text_len;
359 memcpy(log_dict(msg), dict, dict_len);
360 msg->dict_len = dict_len;
361 msg->facility = facility;
362 msg->level = level & 7;
363 msg->flags = flags & 0x1f;
365 msg->ts_nsec = ts_nsec;
367 msg->ts_nsec = local_clock();
368 memset(log_dict(msg) + dict_len, 0, pad_len);
369 msg->len = sizeof(struct log) + text_len + dict_len + pad_len;
371 #ifdef CONFIG_RK_LAST_LOG
372 size = msg_print_text(msg, msg->flags, true, rk_text, sizeof(rk_text));
373 rk_last_log_text(rk_text, size);
376 log_next_idx += msg->len;
380 #ifdef CONFIG_SECURITY_DMESG_RESTRICT
381 int dmesg_restrict = 1;
386 static int syslog_action_restricted(int type)
391 * Unless restricted, we allow "read all" and "get buffer size"
394 return type != SYSLOG_ACTION_READ_ALL &&
395 type != SYSLOG_ACTION_SIZE_BUFFER;
398 static int check_syslog_permissions(int type, bool from_file)
401 * If this is from /proc/kmsg and we've already opened it, then we've
402 * already done the capabilities checks at open time.
404 if (from_file && type != SYSLOG_ACTION_OPEN)
407 if (syslog_action_restricted(type)) {
408 if (capable(CAP_SYSLOG))
411 * For historical reasons, accept CAP_SYS_ADMIN too, with
414 if (capable(CAP_SYS_ADMIN)) {
415 pr_warn_once("%s (%d): Attempt to access syslog with "
416 "CAP_SYS_ADMIN but no CAP_SYSLOG "
418 current->comm, task_pid_nr(current));
423 return security_syslog(type);
427 /* /dev/kmsg - userspace message inject/listen interface */
428 struct devkmsg_user {
436 static ssize_t devkmsg_writev(struct kiocb *iocb, const struct iovec *iv,
437 unsigned long count, loff_t pos)
441 int level = default_message_loglevel;
442 int facility = 1; /* LOG_USER */
443 size_t len = iov_length(iv, count);
446 if (len > LOG_LINE_MAX)
448 buf = kmalloc(len+1, GFP_KERNEL);
453 for (i = 0; i < count; i++) {
454 if (copy_from_user(line, iv[i].iov_base, iv[i].iov_len)) {
458 line += iv[i].iov_len;
462 * Extract and skip the syslog prefix <[0-9]*>. Coming from userspace
463 * the decimal value represents 32bit, the lower 3 bit are the log
464 * level, the rest are the log facility.
466 * If no prefix or no userspace facility is specified, we
467 * enforce LOG_USER, to be able to reliably distinguish
468 * kernel-generated messages from userspace-injected ones.
471 if (line[0] == '<') {
474 i = simple_strtoul(line+1, &endp, 10);
475 if (endp && endp[0] == '>') {
486 printk_emit(facility, level, NULL, 0, "%s", line);
492 static ssize_t devkmsg_read(struct file *file, char __user *buf,
493 size_t count, loff_t *ppos)
495 struct devkmsg_user *user = file->private_data;
506 ret = mutex_lock_interruptible(&user->lock);
509 raw_spin_lock_irq(&logbuf_lock);
510 while (user->seq == log_next_seq) {
511 if (file->f_flags & O_NONBLOCK) {
513 raw_spin_unlock_irq(&logbuf_lock);
517 raw_spin_unlock_irq(&logbuf_lock);
518 ret = wait_event_interruptible(log_wait,
519 user->seq != log_next_seq);
522 raw_spin_lock_irq(&logbuf_lock);
525 if (user->seq < log_first_seq) {
526 /* our last seen message is gone, return error and reset */
527 user->idx = log_first_idx;
528 user->seq = log_first_seq;
530 raw_spin_unlock_irq(&logbuf_lock);
534 msg = log_from_idx(user->idx);
535 ts_usec = msg->ts_nsec;
536 do_div(ts_usec, 1000);
539 * If we couldn't merge continuation line fragments during the print,
540 * export the stored flags to allow an optional external merge of the
541 * records. Merging the records isn't always neccessarily correct, like
542 * when we hit a race during printing. In most cases though, it produces
543 * better readable output. 'c' in the record flags mark the first
544 * fragment of a line, '+' the following.
546 if (msg->flags & LOG_CONT && !(user->prev & LOG_CONT))
548 else if ((msg->flags & LOG_CONT) ||
549 ((user->prev & LOG_CONT) && !(msg->flags & LOG_PREFIX)))
552 len = sprintf(user->buf, "%u,%llu,%llu,%c;",
553 (msg->facility << 3) | msg->level,
554 user->seq, ts_usec, cont);
555 user->prev = msg->flags;
557 /* escape non-printable characters */
558 for (i = 0; i < msg->text_len; i++) {
559 unsigned char c = log_text(msg)[i];
561 if (c < ' ' || c >= 127 || c == '\\')
562 len += sprintf(user->buf + len, "\\x%02x", c);
564 user->buf[len++] = c;
566 user->buf[len++] = '\n';
571 for (i = 0; i < msg->dict_len; i++) {
572 unsigned char c = log_dict(msg)[i];
575 user->buf[len++] = ' ';
580 user->buf[len++] = '\n';
585 if (c < ' ' || c >= 127 || c == '\\') {
586 len += sprintf(user->buf + len, "\\x%02x", c);
590 user->buf[len++] = c;
592 user->buf[len++] = '\n';
595 user->idx = log_next(user->idx);
597 raw_spin_unlock_irq(&logbuf_lock);
604 if (copy_to_user(buf, user->buf, len)) {
610 mutex_unlock(&user->lock);
614 static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence)
616 struct devkmsg_user *user = file->private_data;
624 raw_spin_lock_irq(&logbuf_lock);
627 /* the first record */
628 user->idx = log_first_idx;
629 user->seq = log_first_seq;
633 * The first record after the last SYSLOG_ACTION_CLEAR,
634 * like issued by 'dmesg -c'. Reading /dev/kmsg itself
635 * changes no global state, and does not clear anything.
637 user->idx = clear_idx;
638 user->seq = clear_seq;
641 /* after the last record */
642 user->idx = log_next_idx;
643 user->seq = log_next_seq;
648 raw_spin_unlock_irq(&logbuf_lock);
652 static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
654 struct devkmsg_user *user = file->private_data;
658 return POLLERR|POLLNVAL;
660 poll_wait(file, &log_wait, wait);
662 raw_spin_lock_irq(&logbuf_lock);
663 if (user->seq < log_next_seq) {
664 /* return error when data has vanished underneath us */
665 if (user->seq < log_first_seq)
666 ret = POLLIN|POLLRDNORM|POLLERR|POLLPRI;
668 ret = POLLIN|POLLRDNORM;
670 raw_spin_unlock_irq(&logbuf_lock);
675 static int devkmsg_open(struct inode *inode, struct file *file)
677 struct devkmsg_user *user;
680 /* write-only does not need any file context */
681 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
684 err = check_syslog_permissions(SYSLOG_ACTION_READ_ALL,
689 user = kmalloc(sizeof(struct devkmsg_user), GFP_KERNEL);
693 mutex_init(&user->lock);
695 raw_spin_lock_irq(&logbuf_lock);
696 user->idx = log_first_idx;
697 user->seq = log_first_seq;
698 raw_spin_unlock_irq(&logbuf_lock);
700 file->private_data = user;
704 static int devkmsg_release(struct inode *inode, struct file *file)
706 struct devkmsg_user *user = file->private_data;
711 mutex_destroy(&user->lock);
716 const struct file_operations kmsg_fops = {
717 .open = devkmsg_open,
718 .read = devkmsg_read,
719 .aio_write = devkmsg_writev,
720 .llseek = devkmsg_llseek,
721 .poll = devkmsg_poll,
722 .release = devkmsg_release,
727 * This appends the listed symbols to /proc/vmcoreinfo
729 * /proc/vmcoreinfo is used by various utiilties, like crash and makedumpfile to
730 * obtain access to symbols that are otherwise very difficult to locate. These
731 * symbols are specifically used so that utilities can access and extract the
732 * dmesg log from a vmcore file after a crash.
734 void log_buf_kexec_setup(void)
736 VMCOREINFO_SYMBOL(log_buf);
737 VMCOREINFO_SYMBOL(log_buf_len);
738 VMCOREINFO_SYMBOL(log_first_idx);
739 VMCOREINFO_SYMBOL(log_next_idx);
741 * Export struct log size and field offsets. User space tools can
742 * parse it and detect any changes to structure down the line.
744 VMCOREINFO_STRUCT_SIZE(log);
745 VMCOREINFO_OFFSET(log, ts_nsec);
746 VMCOREINFO_OFFSET(log, len);
747 VMCOREINFO_OFFSET(log, text_len);
748 VMCOREINFO_OFFSET(log, dict_len);
752 /* requested log_buf_len from kernel cmdline */
753 static unsigned long __initdata new_log_buf_len;
755 /* save requested log_buf_len since it's too early to process it */
756 static int __init log_buf_len_setup(char *str)
758 unsigned size = memparse(str, &str);
761 size = roundup_pow_of_two(size);
762 if (size > log_buf_len)
763 new_log_buf_len = size;
767 early_param("log_buf_len", log_buf_len_setup);
769 void __init setup_log_buf(int early)
775 if (!new_log_buf_len)
781 mem = memblock_alloc(new_log_buf_len, PAGE_SIZE);
784 new_log_buf = __va(mem);
786 new_log_buf = alloc_bootmem_nopanic(new_log_buf_len);
789 if (unlikely(!new_log_buf)) {
790 pr_err("log_buf_len: %ld bytes not available\n",
795 raw_spin_lock_irqsave(&logbuf_lock, flags);
796 log_buf_len = new_log_buf_len;
797 log_buf = new_log_buf;
799 free = __LOG_BUF_LEN - log_next_idx;
800 memcpy(log_buf, __log_buf, __LOG_BUF_LEN);
801 raw_spin_unlock_irqrestore(&logbuf_lock, flags);
803 pr_info("log_buf_len: %d\n", log_buf_len);
804 pr_info("early log buf free: %d(%d%%)\n",
805 free, (free * 100) / __LOG_BUF_LEN);
808 static bool __read_mostly ignore_loglevel;
810 static int __init ignore_loglevel_setup(char *str)
813 printk(KERN_INFO "debug: ignoring loglevel setting.\n");
818 early_param("ignore_loglevel", ignore_loglevel_setup);
819 module_param(ignore_loglevel, bool, S_IRUGO | S_IWUSR);
820 MODULE_PARM_DESC(ignore_loglevel, "ignore loglevel setting, to"
821 "print all kernel messages to the console.");
823 #ifdef CONFIG_BOOT_PRINTK_DELAY
825 static int boot_delay; /* msecs delay after each printk during bootup */
826 static unsigned long long loops_per_msec; /* based on boot_delay */
828 static int __init boot_delay_setup(char *str)
832 lpj = preset_lpj ? preset_lpj : 1000000; /* some guess */
833 loops_per_msec = (unsigned long long)lpj / 1000 * HZ;
835 get_option(&str, &boot_delay);
836 if (boot_delay > 10 * 1000)
839 pr_debug("boot_delay: %u, preset_lpj: %ld, lpj: %lu, "
840 "HZ: %d, loops_per_msec: %llu\n",
841 boot_delay, preset_lpj, lpj, HZ, loops_per_msec);
844 __setup("boot_delay=", boot_delay_setup);
846 static void boot_delay_msec(int level)
848 unsigned long long k;
849 unsigned long timeout;
851 if ((boot_delay == 0 || system_state != SYSTEM_BOOTING)
852 || (level >= console_loglevel && !ignore_loglevel)) {
856 k = (unsigned long long)loops_per_msec * boot_delay;
858 timeout = jiffies + msecs_to_jiffies(boot_delay);
863 * use (volatile) jiffies to prevent
864 * compiler reduction; loop termination via jiffies
865 * is secondary and may or may not happen.
867 if (time_after(jiffies, timeout))
869 touch_nmi_watchdog();
873 static inline void boot_delay_msec(int level)
878 #if defined(CONFIG_PRINTK_TIME)
879 static bool printk_time = 1;
881 static bool printk_time;
883 module_param_named(time, printk_time, bool, S_IRUGO | S_IWUSR);
885 static size_t print_time(u64 ts, char *buf)
887 unsigned long rem_nsec;
892 rem_nsec = do_div(ts, 1000000000);
895 return snprintf(NULL, 0, "[%5lu.000000] ", (unsigned long)ts);
897 return sprintf(buf, "[%5lu.%06lu] ",
898 (unsigned long)ts, rem_nsec / 1000);
901 static size_t print_prefix(const struct log *msg, bool syslog, char *buf)
904 unsigned int prefix = (msg->facility << 3) | msg->level;
908 len += sprintf(buf, "<%u>", prefix);
913 else if (prefix > 99)
920 len += print_time(msg->ts_nsec, buf ? buf + len : NULL);
924 static size_t msg_print_text(const struct log *msg, enum log_flags prev,
925 bool syslog, char *buf, size_t size)
927 const char *text = log_text(msg);
928 size_t text_size = msg->text_len;
933 if ((prev & LOG_CONT) && !(msg->flags & LOG_PREFIX))
936 if (msg->flags & LOG_CONT) {
937 if ((prev & LOG_CONT) && !(prev & LOG_NEWLINE))
940 if (!(msg->flags & LOG_NEWLINE))
945 const char *next = memchr(text, '\n', text_size);
949 text_len = next - text;
951 text_size -= next - text;
953 text_len = text_size;
957 if (print_prefix(msg, syslog, NULL) +
958 text_len + 1 >= size - len)
962 len += print_prefix(msg, syslog, buf + len);
963 memcpy(buf + len, text, text_len);
968 /* SYSLOG_ACTION_* buffer size only calculation */
970 len += print_prefix(msg, syslog, NULL);
983 static int syslog_print(char __user *buf, int size)
989 text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL);
997 raw_spin_lock_irq(&logbuf_lock);
998 if (syslog_seq < log_first_seq) {
999 /* messages are gone, move to first one */
1000 syslog_seq = log_first_seq;
1001 syslog_idx = log_first_idx;
1005 if (syslog_seq == log_next_seq) {
1006 raw_spin_unlock_irq(&logbuf_lock);
1010 skip = syslog_partial;
1011 msg = log_from_idx(syslog_idx);
1012 n = msg_print_text(msg, syslog_prev, true, text,
1013 LOG_LINE_MAX + PREFIX_MAX);
1014 if (n - syslog_partial <= size) {
1015 /* message fits into buffer, move forward */
1016 syslog_idx = log_next(syslog_idx);
1018 syslog_prev = msg->flags;
1019 n -= syslog_partial;
1022 /* partial read(), remember position */
1024 syslog_partial += n;
1027 raw_spin_unlock_irq(&logbuf_lock);
1032 if (copy_to_user(buf, text + skip, n)) {
1047 static int syslog_print_all(char __user *buf, int size, bool clear)
1052 text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL);
1056 raw_spin_lock_irq(&logbuf_lock);
1061 enum log_flags prev;
1063 if (clear_seq < log_first_seq) {
1064 /* messages are gone, move to first available one */
1065 clear_seq = log_first_seq;
1066 clear_idx = log_first_idx;
1070 * Find first record that fits, including all following records,
1071 * into the user-provided buffer for this dump.
1076 while (seq < log_next_seq) {
1077 struct log *msg = log_from_idx(idx);
1079 len += msg_print_text(msg, prev, true, NULL, 0);
1081 idx = log_next(idx);
1085 /* move first record forward until length fits into the buffer */
1089 while (len > size && seq < log_next_seq) {
1090 struct log *msg = log_from_idx(idx);
1092 len -= msg_print_text(msg, prev, true, NULL, 0);
1094 idx = log_next(idx);
1098 /* last message fitting into this dump */
1099 next_seq = log_next_seq;
1103 while (len >= 0 && seq < next_seq) {
1104 struct log *msg = log_from_idx(idx);
1107 textlen = msg_print_text(msg, prev, true, text,
1108 LOG_LINE_MAX + PREFIX_MAX);
1113 idx = log_next(idx);
1117 raw_spin_unlock_irq(&logbuf_lock);
1118 if (copy_to_user(buf + len, text, textlen))
1122 raw_spin_lock_irq(&logbuf_lock);
1124 if (seq < log_first_seq) {
1125 /* messages are gone, move to next one */
1126 seq = log_first_seq;
1127 idx = log_first_idx;
1134 clear_seq = log_next_seq;
1135 clear_idx = log_next_idx;
1137 raw_spin_unlock_irq(&logbuf_lock);
1143 int do_syslog(int type, char __user *buf, int len, bool from_file)
1146 static int saved_console_loglevel = -1;
1149 error = check_syslog_permissions(type, from_file);
1153 error = security_syslog(type);
1158 case SYSLOG_ACTION_CLOSE: /* Close log */
1160 case SYSLOG_ACTION_OPEN: /* Open log */
1162 case SYSLOG_ACTION_READ: /* Read from log */
1164 if (!buf || len < 0)
1169 if (!access_ok(VERIFY_WRITE, buf, len)) {
1173 error = wait_event_interruptible(log_wait,
1174 syslog_seq != log_next_seq);
1177 error = syslog_print(buf, len);
1179 /* Read/clear last kernel messages */
1180 case SYSLOG_ACTION_READ_CLEAR:
1183 /* Read last kernel messages */
1184 case SYSLOG_ACTION_READ_ALL:
1186 if (!buf || len < 0)
1191 if (!access_ok(VERIFY_WRITE, buf, len)) {
1195 error = syslog_print_all(buf, len, clear);
1197 /* Clear ring buffer */
1198 case SYSLOG_ACTION_CLEAR:
1199 syslog_print_all(NULL, 0, true);
1201 /* Disable logging to console */
1202 case SYSLOG_ACTION_CONSOLE_OFF:
1203 if (saved_console_loglevel == -1)
1204 saved_console_loglevel = console_loglevel;
1205 console_loglevel = minimum_console_loglevel;
1207 /* Enable logging to console */
1208 case SYSLOG_ACTION_CONSOLE_ON:
1209 if (saved_console_loglevel != -1) {
1210 console_loglevel = saved_console_loglevel;
1211 saved_console_loglevel = -1;
1214 /* Set level of messages printed to console */
1215 case SYSLOG_ACTION_CONSOLE_LEVEL:
1217 if (len < 1 || len > 8)
1219 if (len < minimum_console_loglevel)
1220 len = minimum_console_loglevel;
1221 console_loglevel = len;
1222 /* Implicitly re-enable logging to console */
1223 saved_console_loglevel = -1;
1226 /* Number of chars in the log buffer */
1227 case SYSLOG_ACTION_SIZE_UNREAD:
1228 raw_spin_lock_irq(&logbuf_lock);
1229 if (syslog_seq < log_first_seq) {
1230 /* messages are gone, move to first one */
1231 syslog_seq = log_first_seq;
1232 syslog_idx = log_first_idx;
1238 * Short-cut for poll(/"proc/kmsg") which simply checks
1239 * for pending data, not the size; return the count of
1240 * records, not the length.
1242 error = log_next_idx - syslog_idx;
1244 u64 seq = syslog_seq;
1245 u32 idx = syslog_idx;
1246 enum log_flags prev = syslog_prev;
1249 while (seq < log_next_seq) {
1250 struct log *msg = log_from_idx(idx);
1252 error += msg_print_text(msg, prev, true, NULL, 0);
1253 idx = log_next(idx);
1257 error -= syslog_partial;
1259 raw_spin_unlock_irq(&logbuf_lock);
1261 /* Size of the log buffer */
1262 case SYSLOG_ACTION_SIZE_BUFFER:
1263 error = log_buf_len;
1273 SYSCALL_DEFINE3(syslog, int, type, char __user *, buf, int, len)
1275 return do_syslog(type, buf, len, SYSLOG_FROM_READER);
1279 * Call the console drivers, asking them to write out
1280 * log_buf[start] to log_buf[end - 1].
1281 * The console_lock must be held.
1283 static void call_console_drivers(int level, const char *text, size_t len)
1285 struct console *con;
1287 trace_console(text, len);
1289 if (level >= console_loglevel && !ignore_loglevel)
1291 if (!console_drivers)
1294 for_each_console(con) {
1295 if (exclusive_console && con != exclusive_console)
1297 if (!(con->flags & CON_ENABLED))
1301 if (!cpu_online(smp_processor_id()) &&
1302 !(con->flags & CON_ANYTIME))
1304 con->write(con, text, len);
1309 * Zap console related locks when oopsing. Only zap at most once
1310 * every 10 seconds, to leave time for slow consoles to print a
1313 static void zap_locks(void)
1315 static unsigned long oops_timestamp;
1317 if (time_after_eq(jiffies, oops_timestamp) &&
1318 !time_after(jiffies, oops_timestamp + 30 * HZ))
1321 oops_timestamp = jiffies;
1324 /* If a crash is occurring, make sure we can't deadlock */
1325 raw_spin_lock_init(&logbuf_lock);
1326 /* And make sure that we print immediately */
1327 sema_init(&console_sem, 1);
1330 /* Check if we have any console registered that can be called early in boot. */
1331 static int have_callable_console(void)
1333 struct console *con;
1335 for_each_console(con)
1336 if (con->flags & CON_ANYTIME)
1343 * Can we actually use the console at this time on this cpu?
1345 * Console drivers may assume that per-cpu resources have
1346 * been allocated. So unless they're explicitly marked as
1347 * being able to cope (CON_ANYTIME) don't call them until
1348 * this CPU is officially up.
1350 static inline int can_use_console(unsigned int cpu)
1352 return cpu_online(cpu) || have_callable_console();
1356 * Try to get console ownership to actually show the kernel
1357 * messages from a 'printk'. Return true (and with the
1358 * console_lock held, and 'console_locked' set) if it
1359 * is successful, false otherwise.
1361 * This gets called with the 'logbuf_lock' spinlock held and
1362 * interrupts disabled. It should return with 'lockbuf_lock'
1363 * released but interrupts still disabled.
1365 static int console_trylock_for_printk(unsigned int cpu)
1366 __releases(&logbuf_lock)
1368 int retval = 0, wake = 0;
1370 if (console_trylock()) {
1374 * If we can't use the console, we need to release
1375 * the console semaphore by hand to avoid flushing
1376 * the buffer. We need to hold the console semaphore
1377 * in order to do this test safely.
1379 if (!can_use_console(cpu)) {
1385 logbuf_cpu = UINT_MAX;
1386 raw_spin_unlock(&logbuf_lock);
1392 int printk_delay_msec __read_mostly;
1394 static inline void printk_delay(void)
1396 if (unlikely(printk_delay_msec)) {
1397 int m = printk_delay_msec;
1401 touch_nmi_watchdog();
1407 * Continuation lines are buffered, and not committed to the record buffer
1408 * until the line is complete, or a race forces it. The line fragments
1409 * though, are printed immediately to the consoles to ensure everything has
1410 * reached the console in case of a kernel crash.
1412 static struct cont {
1413 char buf[LOG_LINE_MAX];
1414 size_t len; /* length == 0 means unused buffer */
1415 size_t cons; /* bytes written to console */
1416 struct task_struct *owner; /* task of first print*/
1417 u64 ts_nsec; /* time of first print */
1418 u8 level; /* log level of first message */
1419 u8 facility; /* log level of first message */
1420 enum log_flags flags; /* prefix, newline flags */
1421 bool flushed:1; /* buffer sealed and committed */
1424 static void cont_flush(enum log_flags flags)
1433 * If a fragment of this line was directly flushed to the
1434 * console; wait for the console to pick up the rest of the
1435 * line. LOG_NOCONS suppresses a duplicated output.
1437 log_store(cont.facility, cont.level, flags | LOG_NOCONS,
1438 cont.ts_nsec, NULL, 0, cont.buf, cont.len);
1440 cont.flushed = true;
1443 * If no fragment of this line ever reached the console,
1444 * just submit it to the store and free the buffer.
1446 log_store(cont.facility, cont.level, flags, 0,
1447 NULL, 0, cont.buf, cont.len);
1452 static bool cont_add(int facility, int level, const char *text, size_t len)
1454 if (cont.len && cont.flushed)
1457 if (cont.len + len > sizeof(cont.buf)) {
1458 /* the line gets too long, split it up in separate records */
1459 cont_flush(LOG_CONT);
1464 cont.facility = facility;
1466 cont.owner = current;
1467 cont.ts_nsec = local_clock();
1470 cont.flushed = false;
1473 memcpy(cont.buf + cont.len, text, len);
1476 if (cont.len > (sizeof(cont.buf) * 80) / 100)
1477 cont_flush(LOG_CONT);
1482 static size_t cont_print_text(char *text, size_t size)
1487 if (cont.cons == 0 && (console_prev & LOG_NEWLINE)) {
1488 textlen += print_time(cont.ts_nsec, text);
1492 len = cont.len - cont.cons;
1496 memcpy(text + textlen, cont.buf + cont.cons, len);
1498 cont.cons = cont.len;
1502 if (cont.flags & LOG_NEWLINE)
1503 text[textlen++] = '\n';
1504 /* got everything, release buffer */
1510 asmlinkage int vprintk_emit(int facility, int level,
1511 const char *dict, size_t dictlen,
1512 const char *fmt, va_list args)
1514 static int recursion_bug;
1515 static char textbuf[LOG_LINE_MAX];
1516 char *text = textbuf;
1518 enum log_flags lflags = 0;
1519 unsigned long flags;
1521 int printed_len = 0;
1523 boot_delay_msec(level);
1526 /* This stops the holder of console_sem just where we want him */
1527 local_irq_save(flags);
1528 this_cpu = smp_processor_id();
1531 * Ouch, printk recursed into itself!
1533 if (unlikely(logbuf_cpu == this_cpu)) {
1535 * If a crash is occurring during printk() on this CPU,
1536 * then try to get the crash message out but make sure
1537 * we can't deadlock. Otherwise just return to avoid the
1538 * recursion and return - but flag the recursion so that
1539 * it can be printed at the next appropriate moment:
1541 if (!oops_in_progress && !lockdep_recursing(current)) {
1543 goto out_restore_irqs;
1549 raw_spin_lock(&logbuf_lock);
1550 logbuf_cpu = this_cpu;
1552 if (recursion_bug) {
1553 static const char recursion_msg[] =
1554 "BUG: recent printk recursion!";
1557 printed_len += strlen(recursion_msg);
1558 /* emit KERN_CRIT message */
1559 log_store(0, 2, LOG_PREFIX|LOG_NEWLINE, 0,
1560 NULL, 0, recursion_msg, printed_len);
1564 * The printf needs to come first; we need the syslog
1565 * prefix which might be passed-in as a parameter.
1567 text_len = vscnprintf(text, sizeof(textbuf), fmt, args);
1569 /* mark and strip a trailing newline */
1570 if (text_len && text[text_len-1] == '\n') {
1572 lflags |= LOG_NEWLINE;
1575 /* strip kernel syslog prefix and extract log level or control flags */
1576 if (facility == 0) {
1577 int kern_level = printk_get_level(text);
1580 const char *end_of_header = printk_skip_level(text);
1581 switch (kern_level) {
1584 level = kern_level - '0';
1585 case 'd': /* KERN_DEFAULT */
1586 lflags |= LOG_PREFIX;
1587 case 'c': /* KERN_CONT */
1590 text_len -= end_of_header - text;
1591 text = (char *)end_of_header;
1595 #ifdef CONFIG_EARLY_PRINTK_DIRECT
1600 level = default_message_loglevel;
1603 lflags |= LOG_PREFIX|LOG_NEWLINE;
1605 if (!(lflags & LOG_NEWLINE)) {
1607 * Flush the conflicting buffer. An earlier newline was missing,
1608 * or another task also prints continuation lines.
1610 if (cont.len && (lflags & LOG_PREFIX || cont.owner != current))
1611 cont_flush(LOG_NEWLINE);
1613 /* buffer line if possible, otherwise store it right away */
1614 if (!cont_add(facility, level, text, text_len))
1615 log_store(facility, level, lflags | LOG_CONT, 0,
1616 dict, dictlen, text, text_len);
1618 bool stored = false;
1621 * If an earlier newline was missing and it was the same task,
1622 * either merge it with the current buffer and flush, or if
1623 * there was a race with interrupts (prefix == true) then just
1624 * flush it out and store this line separately.
1626 if (cont.len && cont.owner == current) {
1627 if (!(lflags & LOG_PREFIX))
1628 stored = cont_add(facility, level, text, text_len);
1629 cont_flush(LOG_NEWLINE);
1633 log_store(facility, level, lflags, 0,
1634 dict, dictlen, text, text_len);
1636 printed_len += text_len;
1639 * Try to acquire and then immediately release the console semaphore.
1640 * The release will print out buffers and wake up /dev/kmsg and syslog()
1643 * The console_trylock_for_printk() function will release 'logbuf_lock'
1644 * regardless of whether it actually gets the console semaphore or not.
1646 if (console_trylock_for_printk(this_cpu))
1651 local_irq_restore(flags);
1655 EXPORT_SYMBOL(vprintk_emit);
1657 asmlinkage int vprintk(const char *fmt, va_list args)
1659 return vprintk_emit(0, -1, NULL, 0, fmt, args);
1661 EXPORT_SYMBOL(vprintk);
1663 asmlinkage int printk_emit(int facility, int level,
1664 const char *dict, size_t dictlen,
1665 const char *fmt, ...)
1670 va_start(args, fmt);
1671 r = vprintk_emit(facility, level, dict, dictlen, fmt, args);
1676 EXPORT_SYMBOL(printk_emit);
1679 * printk - print a kernel message
1680 * @fmt: format string
1682 * This is printk(). It can be called from any context. We want it to work.
1684 * We try to grab the console_lock. If we succeed, it's easy - we log the
1685 * output and call the console drivers. If we fail to get the semaphore, we
1686 * place the output into the log buffer and return. The current holder of
1687 * the console_sem will notice the new output in console_unlock(); and will
1688 * send it to the consoles before releasing the lock.
1690 * One effect of this deferred printing is that code which calls printk() and
1691 * then changes console_loglevel may break. This is because console_loglevel
1692 * is inspected when the actual printing occurs.
1697 * See the vsnprintf() documentation for format string extensions over C99.
1699 asmlinkage int printk(const char *fmt, ...)
1704 #ifdef CONFIG_KGDB_KDB
1705 if (unlikely(kdb_trap_printk)) {
1706 va_start(args, fmt);
1707 r = vkdb_printf(fmt, args);
1712 va_start(args, fmt);
1713 r = vprintk_emit(0, -1, NULL, 0, fmt, args);
1718 EXPORT_SYMBOL(printk);
1720 #if defined(CONFIG_RK_DEBUG_UART) && (CONFIG_RK_DEBUG_UART >= 0)
1721 void console_disable_suspend(void)
1723 console_suspended = 0;
1726 #else /* CONFIG_PRINTK */
1728 #define LOG_LINE_MAX 0
1729 #define PREFIX_MAX 0
1730 #define LOG_LINE_MAX 0
1731 static u64 syslog_seq;
1732 static u32 syslog_idx;
1733 static u64 console_seq;
1734 static u32 console_idx;
1735 static enum log_flags syslog_prev;
1736 static u64 log_first_seq;
1737 static u32 log_first_idx;
1738 static u64 log_next_seq;
1739 static enum log_flags console_prev;
1740 static struct cont {
1746 static struct log *log_from_idx(u32 idx) { return NULL; }
1747 static u32 log_next(u32 idx) { return 0; }
1748 static void call_console_drivers(int level, const char *text, size_t len) {}
1749 static size_t msg_print_text(const struct log *msg, enum log_flags prev,
1750 bool syslog, char *buf, size_t size) { return 0; }
1751 static size_t cont_print_text(char *text, size_t size) { return 0; }
1753 #endif /* CONFIG_PRINTK */
1755 #ifdef CONFIG_EARLY_PRINTK
1756 struct console *early_console;
1758 void early_vprintk(const char *fmt, va_list ap)
1760 if (early_console) {
1762 int n = vscnprintf(buf, sizeof(buf), fmt, ap);
1764 early_console->write(early_console, buf, n);
1768 asmlinkage void early_printk(const char *fmt, ...)
1773 early_vprintk(fmt, ap);
1778 static int __add_preferred_console(char *name, int idx, char *options,
1781 struct console_cmdline *c;
1785 * See if this tty is not yet registered, and
1786 * if we have a slot free.
1788 for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; i++)
1789 if (strcmp(console_cmdline[i].name, name) == 0 &&
1790 console_cmdline[i].index == idx) {
1792 selected_console = i;
1795 if (i == MAX_CMDLINECONSOLES)
1798 selected_console = i;
1799 c = &console_cmdline[i];
1800 strlcpy(c->name, name, sizeof(c->name));
1801 c->options = options;
1802 #ifdef CONFIG_A11Y_BRAILLE_CONSOLE
1803 c->brl_options = brl_options;
1809 * Set up a list of consoles. Called from init/main.c
1811 static int __init console_setup(char *str)
1813 char buf[sizeof(console_cmdline[0].name) + 4]; /* 4 for index */
1814 char *s, *options, *brl_options = NULL;
1817 #ifdef CONFIG_A11Y_BRAILLE_CONSOLE
1818 if (!memcmp(str, "brl,", 4)) {
1821 } else if (!memcmp(str, "brl=", 4)) {
1822 brl_options = str + 4;
1823 str = strchr(brl_options, ',');
1825 printk(KERN_ERR "need port name after brl=\n");
1833 * Decode str into name, index, options.
1835 if (str[0] >= '0' && str[0] <= '9') {
1836 strcpy(buf, "ttyS");
1837 strncpy(buf + 4, str, sizeof(buf) - 5);
1839 strncpy(buf, str, sizeof(buf) - 1);
1841 buf[sizeof(buf) - 1] = 0;
1842 if ((options = strchr(str, ',')) != NULL)
1845 if (!strcmp(str, "ttya"))
1846 strcpy(buf, "ttyS0");
1847 if (!strcmp(str, "ttyb"))
1848 strcpy(buf, "ttyS1");
1850 for (s = buf; *s; s++)
1851 if ((*s >= '0' && *s <= '9') || *s == ',')
1853 idx = simple_strtoul(s, NULL, 10);
1856 __add_preferred_console(buf, idx, options, brl_options);
1857 console_set_on_cmdline = 1;
1860 __setup("console=", console_setup);
1863 * add_preferred_console - add a device to the list of preferred consoles.
1864 * @name: device name
1865 * @idx: device index
1866 * @options: options for this console
1868 * The last preferred console added will be used for kernel messages
1869 * and stdin/out/err for init. Normally this is used by console_setup
1870 * above to handle user-supplied console arguments; however it can also
1871 * be used by arch-specific code either to override the user or more
1872 * commonly to provide a default console (ie from PROM variables) when
1873 * the user has not supplied one.
1875 int add_preferred_console(char *name, int idx, char *options)
1877 return __add_preferred_console(name, idx, options, NULL);
1880 int update_console_cmdline(char *name, int idx, char *name_new, int idx_new, char *options)
1882 struct console_cmdline *c;
1885 for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; i++)
1886 if (strcmp(console_cmdline[i].name, name) == 0 &&
1887 console_cmdline[i].index == idx) {
1888 c = &console_cmdline[i];
1889 strlcpy(c->name, name_new, sizeof(c->name));
1890 c->name[sizeof(c->name) - 1] = 0;
1891 c->options = options;
1899 bool console_suspend_enabled = 1;
1900 EXPORT_SYMBOL(console_suspend_enabled);
1902 static int __init console_suspend_disable(char *str)
1904 console_suspend_enabled = 0;
1907 __setup("no_console_suspend", console_suspend_disable);
1908 module_param_named(console_suspend, console_suspend_enabled,
1909 bool, S_IRUGO | S_IWUSR);
1910 MODULE_PARM_DESC(console_suspend, "suspend console during suspend"
1911 " and hibernate operations");
1914 * suspend_console - suspend the console subsystem
1916 * This disables printk() while we go into suspend states
1918 void suspend_console(void)
1920 if (!console_suspend_enabled)
1922 printk("Suspending console(s) (use no_console_suspend to debug)\n");
1924 console_suspended = 1;
1928 void resume_console(void)
1930 if (!console_suspend_enabled)
1933 console_suspended = 0;
1938 * console_cpu_notify - print deferred console messages after CPU hotplug
1939 * @self: notifier struct
1940 * @action: CPU hotplug event
1943 * If printk() is called from a CPU that is not online yet, the messages
1944 * will be spooled but will not show up on the console. This function is
1945 * called when a new CPU comes online (or fails to come up), and ensures
1946 * that any such output gets printed.
1948 static int __cpuinit console_cpu_notify(struct notifier_block *self,
1949 unsigned long action, void *hcpu)
1954 case CPU_DOWN_FAILED:
1955 case CPU_UP_CANCELED:
1963 * console_lock - lock the console system for exclusive use.
1965 * Acquires a lock which guarantees that the caller has
1966 * exclusive access to the console system and the console_drivers list.
1968 * Can sleep, returns nothing.
1970 void console_lock(void)
1975 if (console_suspended)
1978 console_may_schedule = 1;
1979 mutex_acquire(&console_lock_dep_map, 0, 0, _RET_IP_);
1981 EXPORT_SYMBOL(console_lock);
1984 * console_trylock - try to lock the console system for exclusive use.
1986 * Tried to acquire a lock which guarantees that the caller has
1987 * exclusive access to the console system and the console_drivers list.
1989 * returns 1 on success, and 0 on failure to acquire the lock.
1991 int console_trylock(void)
1993 if (down_trylock(&console_sem))
1995 if (console_suspended) {
2000 console_may_schedule = 0;
2001 mutex_acquire(&console_lock_dep_map, 0, 1, _RET_IP_);
2004 EXPORT_SYMBOL(console_trylock);
2006 int is_console_locked(void)
2008 return console_locked;
2011 static void console_cont_flush(char *text, size_t size)
2013 unsigned long flags;
2016 raw_spin_lock_irqsave(&logbuf_lock, flags);
2022 * We still queue earlier records, likely because the console was
2023 * busy. The earlier ones need to be printed before this one, we
2024 * did not flush any fragment so far, so just let it queue up.
2026 if (console_seq < log_next_seq && !cont.cons)
2029 len = cont_print_text(text, size);
2030 raw_spin_unlock(&logbuf_lock);
2031 stop_critical_timings();
2032 call_console_drivers(cont.level, text, len);
2033 start_critical_timings();
2034 local_irq_restore(flags);
2037 raw_spin_unlock_irqrestore(&logbuf_lock, flags);
2041 * console_unlock - unlock the console system
2043 * Releases the console_lock which the caller holds on the console system
2044 * and the console driver list.
2046 * While the console_lock was held, console output may have been buffered
2047 * by printk(). If this is the case, console_unlock(); emits
2048 * the output prior to releasing the lock.
2050 * If there is output waiting, we wake /dev/kmsg and syslog() users.
2052 * console_unlock(); may be called from any context.
2054 void console_unlock(void)
2056 static char text[LOG_LINE_MAX + PREFIX_MAX];
2057 static u64 seen_seq;
2058 unsigned long flags;
2059 bool wake_klogd = false;
2062 if (console_suspended) {
2067 console_may_schedule = 0;
2069 /* flush buffered message fragment immediately to console */
2070 console_cont_flush(text, sizeof(text));
2077 raw_spin_lock_irqsave(&logbuf_lock, flags);
2078 if (seen_seq != log_next_seq) {
2080 seen_seq = log_next_seq;
2083 if (console_seq < log_first_seq) {
2084 /* messages are gone, move to first one */
2085 console_seq = log_first_seq;
2086 console_idx = log_first_idx;
2090 if (console_seq == log_next_seq)
2093 msg = log_from_idx(console_idx);
2094 if (msg->flags & LOG_NOCONS) {
2096 * Skip record we have buffered and already printed
2097 * directly to the console when we received it.
2099 console_idx = log_next(console_idx);
2102 * We will get here again when we register a new
2103 * CON_PRINTBUFFER console. Clear the flag so we
2104 * will properly dump everything later.
2106 msg->flags &= ~LOG_NOCONS;
2107 console_prev = msg->flags;
2112 len = msg_print_text(msg, console_prev, false,
2113 text, sizeof(text));
2114 console_idx = log_next(console_idx);
2116 console_prev = msg->flags;
2117 raw_spin_unlock(&logbuf_lock);
2119 stop_critical_timings(); /* don't trace print latency */
2120 call_console_drivers(level, text, len);
2121 start_critical_timings();
2122 local_irq_restore(flags);
2125 mutex_release(&console_lock_dep_map, 1, _RET_IP_);
2127 /* Release the exclusive_console once it is used */
2128 if (unlikely(exclusive_console))
2129 exclusive_console = NULL;
2131 raw_spin_unlock(&logbuf_lock);
2136 * Someone could have filled up the buffer again, so re-check if there's
2137 * something to flush. In case we cannot trylock the console_sem again,
2138 * there's a new owner and the console_unlock() from them will do the
2139 * flush, no worries.
2141 raw_spin_lock(&logbuf_lock);
2142 retry = console_seq != log_next_seq;
2143 raw_spin_unlock_irqrestore(&logbuf_lock, flags);
2145 if (retry && console_trylock())
2151 EXPORT_SYMBOL(console_unlock);
2154 * console_conditional_schedule - yield the CPU if required
2156 * If the console code is currently allowed to sleep, and
2157 * if this CPU should yield the CPU to another task, do
2160 * Must be called within console_lock();.
2162 void __sched console_conditional_schedule(void)
2164 if (console_may_schedule)
2167 EXPORT_SYMBOL(console_conditional_schedule);
2169 void console_unblank(void)
2174 * console_unblank can no longer be called in interrupt context unless
2175 * oops_in_progress is set to 1..
2177 if (oops_in_progress) {
2178 if (down_trylock(&console_sem) != 0)
2184 console_may_schedule = 0;
2186 if ((c->flags & CON_ENABLED) && c->unblank)
2192 * Return the console tty driver structure and its associated index
2194 struct tty_driver *console_device(int *index)
2197 struct tty_driver *driver = NULL;
2200 for_each_console(c) {
2203 driver = c->device(c, index);
2212 * Prevent further output on the passed console device so that (for example)
2213 * serial drivers can disable console output before suspending a port, and can
2214 * re-enable output afterwards.
2216 void console_stop(struct console *console)
2219 console->flags &= ~CON_ENABLED;
2222 EXPORT_SYMBOL(console_stop);
2224 void console_start(struct console *console)
2227 console->flags |= CON_ENABLED;
2230 EXPORT_SYMBOL(console_start);
2232 static int __read_mostly keep_bootcon;
2234 static int __init keep_bootcon_setup(char *str)
2237 printk(KERN_INFO "debug: skip boot console de-registration.\n");
2242 early_param("keep_bootcon", keep_bootcon_setup);
2245 * The console driver calls this routine during kernel initialization
2246 * to register the console printing procedure with printk() and to
2247 * print any messages that were printed by the kernel before the
2248 * console driver was initialized.
2250 * This can happen pretty early during the boot process (because of
2251 * early_printk) - sometimes before setup_arch() completes - be careful
2252 * of what kernel features are used - they may not be initialised yet.
2254 * There are two types of consoles - bootconsoles (early_printk) and
2255 * "real" consoles (everything which is not a bootconsole) which are
2256 * handled differently.
2257 * - Any number of bootconsoles can be registered at any time.
2258 * - As soon as a "real" console is registered, all bootconsoles
2259 * will be unregistered automatically.
2260 * - Once a "real" console is registered, any attempt to register a
2261 * bootconsoles will be rejected
2263 void register_console(struct console *newcon)
2266 unsigned long flags;
2267 struct console *bcon = NULL;
2270 * before we register a new CON_BOOT console, make sure we don't
2271 * already have a valid console
2273 if (console_drivers && newcon->flags & CON_BOOT) {
2274 /* find the last or real console */
2275 for_each_console(bcon) {
2276 if (!(bcon->flags & CON_BOOT)) {
2277 printk(KERN_INFO "Too late to register bootconsole %s%d\n",
2278 newcon->name, newcon->index);
2284 if (console_drivers && console_drivers->flags & CON_BOOT)
2285 bcon = console_drivers;
2287 if (preferred_console < 0 || bcon || !console_drivers)
2288 preferred_console = selected_console;
2290 if (newcon->early_setup)
2291 newcon->early_setup();
2294 * See if we want to use this console driver. If we
2295 * didn't select a console we take the first one
2296 * that registers here.
2298 if (preferred_console < 0) {
2299 if (newcon->index < 0)
2301 if (newcon->setup == NULL ||
2302 newcon->setup(newcon, NULL) == 0) {
2303 newcon->flags |= CON_ENABLED;
2304 if (newcon->device) {
2305 newcon->flags |= CON_CONSDEV;
2306 preferred_console = 0;
2312 * See if this console matches one we selected on
2315 for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0];
2317 if (strcmp(console_cmdline[i].name, newcon->name) != 0)
2319 if (newcon->index >= 0 &&
2320 newcon->index != console_cmdline[i].index)
2322 if (newcon->index < 0)
2323 newcon->index = console_cmdline[i].index;
2324 #ifdef CONFIG_A11Y_BRAILLE_CONSOLE
2325 if (console_cmdline[i].brl_options) {
2326 newcon->flags |= CON_BRL;
2327 braille_register_console(newcon,
2328 console_cmdline[i].index,
2329 console_cmdline[i].options,
2330 console_cmdline[i].brl_options);
2334 if (newcon->setup &&
2335 newcon->setup(newcon, console_cmdline[i].options) != 0)
2337 newcon->flags |= CON_ENABLED;
2338 newcon->index = console_cmdline[i].index;
2339 if (i == selected_console) {
2340 newcon->flags |= CON_CONSDEV;
2341 preferred_console = selected_console;
2346 if (!(newcon->flags & CON_ENABLED))
2350 * If we have a bootconsole, and are switching to a real console,
2351 * don't print everything out again, since when the boot console, and
2352 * the real console are the same physical device, it's annoying to
2353 * see the beginning boot messages twice
2355 if (bcon && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV))
2356 newcon->flags &= ~CON_PRINTBUFFER;
2359 * Put this console in the list - keep the
2360 * preferred driver at the head of the list.
2363 if ((newcon->flags & CON_CONSDEV) || console_drivers == NULL) {
2364 newcon->next = console_drivers;
2365 console_drivers = newcon;
2367 newcon->next->flags &= ~CON_CONSDEV;
2369 newcon->next = console_drivers->next;
2370 console_drivers->next = newcon;
2372 if (newcon->flags & CON_PRINTBUFFER) {
2374 * console_unlock(); will print out the buffered messages
2377 raw_spin_lock_irqsave(&logbuf_lock, flags);
2378 console_seq = syslog_seq;
2379 console_idx = syslog_idx;
2380 console_prev = syslog_prev;
2381 raw_spin_unlock_irqrestore(&logbuf_lock, flags);
2383 * We're about to replay the log buffer. Only do this to the
2384 * just-registered console to avoid excessive message spam to
2385 * the already-registered consoles.
2387 exclusive_console = newcon;
2390 console_sysfs_notify();
2393 * By unregistering the bootconsoles after we enable the real console
2394 * we get the "console xxx enabled" message on all the consoles -
2395 * boot consoles, real consoles, etc - this is to ensure that end
2396 * users know there might be something in the kernel's log buffer that
2397 * went to the bootconsole (that they do not see on the real console)
2400 ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV) &&
2402 /* we need to iterate through twice, to make sure we print
2403 * everything out, before we unregister the console(s)
2405 printk(KERN_INFO "console [%s%d] enabled, bootconsole disabled\n",
2406 newcon->name, newcon->index);
2407 for_each_console(bcon)
2408 if (bcon->flags & CON_BOOT)
2409 unregister_console(bcon);
2411 printk(KERN_INFO "%sconsole [%s%d] enabled\n",
2412 (newcon->flags & CON_BOOT) ? "boot" : "" ,
2413 newcon->name, newcon->index);
2416 EXPORT_SYMBOL(register_console);
2418 int unregister_console(struct console *console)
2420 struct console *a, *b;
2423 #ifdef CONFIG_A11Y_BRAILLE_CONSOLE
2424 if (console->flags & CON_BRL)
2425 return braille_unregister_console(console);
2429 if (console_drivers == console) {
2430 console_drivers=console->next;
2432 } else if (console_drivers) {
2433 for (a=console_drivers->next, b=console_drivers ;
2434 a; b=a, a=b->next) {
2444 * If this isn't the last console and it has CON_CONSDEV set, we
2445 * need to set it on the next preferred console.
2447 if (console_drivers != NULL && console->flags & CON_CONSDEV)
2448 console_drivers->flags |= CON_CONSDEV;
2451 console_sysfs_notify();
2454 EXPORT_SYMBOL(unregister_console);
2456 static int __init printk_late_init(void)
2458 struct console *con;
2460 for_each_console(con) {
2461 if (!keep_bootcon && con->flags & CON_BOOT) {
2462 printk(KERN_INFO "turn off boot console %s%d\n",
2463 con->name, con->index);
2464 unregister_console(con);
2467 hotcpu_notifier(console_cpu_notify, 0);
2470 late_initcall(printk_late_init);
2472 #if defined CONFIG_PRINTK
2474 * Delayed printk version, for scheduler-internal messages:
2476 #define PRINTK_BUF_SIZE 512
2478 #define PRINTK_PENDING_WAKEUP 0x01
2479 #define PRINTK_PENDING_SCHED 0x02
2481 static DEFINE_PER_CPU(int, printk_pending);
2482 static DEFINE_PER_CPU(char [PRINTK_BUF_SIZE], printk_sched_buf);
2484 static void wake_up_klogd_work_func(struct irq_work *irq_work)
2486 int pending = __this_cpu_xchg(printk_pending, 0);
2488 if (pending & PRINTK_PENDING_SCHED) {
2489 char *buf = __get_cpu_var(printk_sched_buf);
2490 printk(KERN_WARNING "[sched_delayed] %s", buf);
2493 if (pending & PRINTK_PENDING_WAKEUP)
2494 wake_up_interruptible(&log_wait);
2497 static DEFINE_PER_CPU(struct irq_work, wake_up_klogd_work) = {
2498 .func = wake_up_klogd_work_func,
2499 .flags = IRQ_WORK_LAZY,
2502 void wake_up_klogd(void)
2505 if (waitqueue_active(&log_wait)) {
2506 this_cpu_or(printk_pending, PRINTK_PENDING_WAKEUP);
2507 irq_work_queue(&__get_cpu_var(wake_up_klogd_work));
2512 int printk_sched(const char *fmt, ...)
2514 unsigned long flags;
2519 local_irq_save(flags);
2520 buf = __get_cpu_var(printk_sched_buf);
2522 va_start(args, fmt);
2523 r = vsnprintf(buf, PRINTK_BUF_SIZE, fmt, args);
2526 __this_cpu_or(printk_pending, PRINTK_PENDING_SCHED);
2527 irq_work_queue(&__get_cpu_var(wake_up_klogd_work));
2528 local_irq_restore(flags);
2534 * printk rate limiting, lifted from the networking subsystem.
2536 * This enforces a rate limit: not more than 10 kernel messages
2537 * every 5s to make a denial-of-service attack impossible.
2539 DEFINE_RATELIMIT_STATE(printk_ratelimit_state, 5 * HZ, 10);
2541 int __printk_ratelimit(const char *func)
2543 return ___ratelimit(&printk_ratelimit_state, func);
2545 EXPORT_SYMBOL(__printk_ratelimit);
2548 * printk_timed_ratelimit - caller-controlled printk ratelimiting
2549 * @caller_jiffies: pointer to caller's state
2550 * @interval_msecs: minimum interval between prints
2552 * printk_timed_ratelimit() returns true if more than @interval_msecs
2553 * milliseconds have elapsed since the last time printk_timed_ratelimit()
2556 bool printk_timed_ratelimit(unsigned long *caller_jiffies,
2557 unsigned int interval_msecs)
2559 if (*caller_jiffies == 0
2560 || !time_in_range(jiffies, *caller_jiffies,
2562 + msecs_to_jiffies(interval_msecs))) {
2563 *caller_jiffies = jiffies;
2568 EXPORT_SYMBOL(printk_timed_ratelimit);
2570 static DEFINE_SPINLOCK(dump_list_lock);
2571 static LIST_HEAD(dump_list);
2574 * kmsg_dump_register - register a kernel log dumper.
2575 * @dumper: pointer to the kmsg_dumper structure
2577 * Adds a kernel log dumper to the system. The dump callback in the
2578 * structure will be called when the kernel oopses or panics and must be
2579 * set. Returns zero on success and %-EINVAL or %-EBUSY otherwise.
2581 int kmsg_dump_register(struct kmsg_dumper *dumper)
2583 unsigned long flags;
2586 /* The dump callback needs to be set */
2590 spin_lock_irqsave(&dump_list_lock, flags);
2591 /* Don't allow registering multiple times */
2592 if (!dumper->registered) {
2593 dumper->registered = 1;
2594 list_add_tail_rcu(&dumper->list, &dump_list);
2597 spin_unlock_irqrestore(&dump_list_lock, flags);
2601 EXPORT_SYMBOL_GPL(kmsg_dump_register);
2604 * kmsg_dump_unregister - unregister a kmsg dumper.
2605 * @dumper: pointer to the kmsg_dumper structure
2607 * Removes a dump device from the system. Returns zero on success and
2608 * %-EINVAL otherwise.
2610 int kmsg_dump_unregister(struct kmsg_dumper *dumper)
2612 unsigned long flags;
2615 spin_lock_irqsave(&dump_list_lock, flags);
2616 if (dumper->registered) {
2617 dumper->registered = 0;
2618 list_del_rcu(&dumper->list);
2621 spin_unlock_irqrestore(&dump_list_lock, flags);
2626 EXPORT_SYMBOL_GPL(kmsg_dump_unregister);
2628 static bool always_kmsg_dump;
2629 module_param_named(always_kmsg_dump, always_kmsg_dump, bool, S_IRUGO | S_IWUSR);
2632 * kmsg_dump - dump kernel log to kernel message dumpers.
2633 * @reason: the reason (oops, panic etc) for dumping
2635 * Call each of the registered dumper's dump() callback, which can
2636 * retrieve the kmsg records with kmsg_dump_get_line() or
2637 * kmsg_dump_get_buffer().
2639 void kmsg_dump(enum kmsg_dump_reason reason)
2641 struct kmsg_dumper *dumper;
2642 unsigned long flags;
2644 if ((reason > KMSG_DUMP_OOPS) && !always_kmsg_dump)
2648 list_for_each_entry_rcu(dumper, &dump_list, list) {
2649 if (dumper->max_reason && reason > dumper->max_reason)
2652 /* initialize iterator with data about the stored records */
2653 dumper->active = true;
2655 raw_spin_lock_irqsave(&logbuf_lock, flags);
2656 dumper->cur_seq = clear_seq;
2657 dumper->cur_idx = clear_idx;
2658 dumper->next_seq = log_next_seq;
2659 dumper->next_idx = log_next_idx;
2660 raw_spin_unlock_irqrestore(&logbuf_lock, flags);
2662 /* invoke dumper which will iterate over records */
2663 dumper->dump(dumper, reason);
2665 /* reset iterator */
2666 dumper->active = false;
2672 * kmsg_dump_get_line_nolock - retrieve one kmsg log line (unlocked version)
2673 * @dumper: registered kmsg dumper
2674 * @syslog: include the "<4>" prefixes
2675 * @line: buffer to copy the line to
2676 * @size: maximum size of the buffer
2677 * @len: length of line placed into buffer
2679 * Start at the beginning of the kmsg buffer, with the oldest kmsg
2680 * record, and copy one record into the provided buffer.
2682 * Consecutive calls will return the next available record moving
2683 * towards the end of the buffer with the youngest messages.
2685 * A return value of FALSE indicates that there are no more records to
2688 * The function is similar to kmsg_dump_get_line(), but grabs no locks.
2690 bool kmsg_dump_get_line_nolock(struct kmsg_dumper *dumper, bool syslog,
2691 char *line, size_t size, size_t *len)
2697 if (!dumper->active)
2700 if (dumper->cur_seq < log_first_seq) {
2701 /* messages are gone, move to first available one */
2702 dumper->cur_seq = log_first_seq;
2703 dumper->cur_idx = log_first_idx;
2707 if (dumper->cur_seq >= log_next_seq)
2710 msg = log_from_idx(dumper->cur_idx);
2711 l = msg_print_text(msg, 0, syslog, line, size);
2713 dumper->cur_idx = log_next(dumper->cur_idx);
2723 * kmsg_dump_get_line - retrieve one kmsg log line
2724 * @dumper: registered kmsg dumper
2725 * @syslog: include the "<4>" prefixes
2726 * @line: buffer to copy the line to
2727 * @size: maximum size of the buffer
2728 * @len: length of line placed into buffer
2730 * Start at the beginning of the kmsg buffer, with the oldest kmsg
2731 * record, and copy one record into the provided buffer.
2733 * Consecutive calls will return the next available record moving
2734 * towards the end of the buffer with the youngest messages.
2736 * A return value of FALSE indicates that there are no more records to
2739 bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog,
2740 char *line, size_t size, size_t *len)
2742 unsigned long flags;
2745 raw_spin_lock_irqsave(&logbuf_lock, flags);
2746 ret = kmsg_dump_get_line_nolock(dumper, syslog, line, size, len);
2747 raw_spin_unlock_irqrestore(&logbuf_lock, flags);
2751 EXPORT_SYMBOL_GPL(kmsg_dump_get_line);
2754 * kmsg_dump_get_buffer - copy kmsg log lines
2755 * @dumper: registered kmsg dumper
2756 * @syslog: include the "<4>" prefixes
2757 * @buf: buffer to copy the line to
2758 * @size: maximum size of the buffer
2759 * @len: length of line placed into buffer
2761 * Start at the end of the kmsg buffer and fill the provided buffer
2762 * with as many of the the *youngest* kmsg records that fit into it.
2763 * If the buffer is large enough, all available kmsg records will be
2764 * copied with a single call.
2766 * Consecutive calls will fill the buffer with the next block of
2767 * available older records, not including the earlier retrieved ones.
2769 * A return value of FALSE indicates that there are no more records to
2772 bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
2773 char *buf, size_t size, size_t *len)
2775 unsigned long flags;
2780 enum log_flags prev;
2784 if (!dumper->active)
2787 raw_spin_lock_irqsave(&logbuf_lock, flags);
2788 if (dumper->cur_seq < log_first_seq) {
2789 /* messages are gone, move to first available one */
2790 dumper->cur_seq = log_first_seq;
2791 dumper->cur_idx = log_first_idx;
2795 if (dumper->cur_seq >= dumper->next_seq) {
2796 raw_spin_unlock_irqrestore(&logbuf_lock, flags);
2800 /* calculate length of entire buffer */
2801 seq = dumper->cur_seq;
2802 idx = dumper->cur_idx;
2804 while (seq < dumper->next_seq) {
2805 struct log *msg = log_from_idx(idx);
2807 l += msg_print_text(msg, prev, true, NULL, 0);
2808 idx = log_next(idx);
2813 /* move first record forward until length fits into the buffer */
2814 seq = dumper->cur_seq;
2815 idx = dumper->cur_idx;
2817 while (l > size && seq < dumper->next_seq) {
2818 struct log *msg = log_from_idx(idx);
2820 l -= msg_print_text(msg, prev, true, NULL, 0);
2821 idx = log_next(idx);
2826 /* last message in next interation */
2832 while (seq < dumper->next_seq) {
2833 struct log *msg = log_from_idx(idx);
2835 l += msg_print_text(msg, prev, syslog, buf + l, size - l);
2836 idx = log_next(idx);
2841 dumper->next_seq = next_seq;
2842 dumper->next_idx = next_idx;
2844 raw_spin_unlock_irqrestore(&logbuf_lock, flags);
2850 EXPORT_SYMBOL_GPL(kmsg_dump_get_buffer);
2853 * kmsg_dump_rewind_nolock - reset the interator (unlocked version)
2854 * @dumper: registered kmsg dumper
2856 * Reset the dumper's iterator so that kmsg_dump_get_line() and
2857 * kmsg_dump_get_buffer() can be called again and used multiple
2858 * times within the same dumper.dump() callback.
2860 * The function is similar to kmsg_dump_rewind(), but grabs no locks.
2862 void kmsg_dump_rewind_nolock(struct kmsg_dumper *dumper)
2864 dumper->cur_seq = clear_seq;
2865 dumper->cur_idx = clear_idx;
2866 dumper->next_seq = log_next_seq;
2867 dumper->next_idx = log_next_idx;
2871 * kmsg_dump_rewind - reset the interator
2872 * @dumper: registered kmsg dumper
2874 * Reset the dumper's iterator so that kmsg_dump_get_line() and
2875 * kmsg_dump_get_buffer() can be called again and used multiple
2876 * times within the same dumper.dump() callback.
2878 void kmsg_dump_rewind(struct kmsg_dumper *dumper)
2880 unsigned long flags;
2882 raw_spin_lock_irqsave(&logbuf_lock, flags);
2883 kmsg_dump_rewind_nolock(dumper);
2884 raw_spin_unlock_irqrestore(&logbuf_lock, flags);
2886 EXPORT_SYMBOL_GPL(kmsg_dump_rewind);
2888 static char dump_stack_arch_desc_str[128];
2891 * dump_stack_set_arch_desc - set arch-specific str to show with task dumps
2892 * @fmt: printf-style format string
2893 * @...: arguments for the format string
2895 * The configured string will be printed right after utsname during task
2896 * dumps. Usually used to add arch-specific system identifiers. If an
2897 * arch wants to make use of such an ID string, it should initialize this
2898 * as soon as possible during boot.
2900 void __init dump_stack_set_arch_desc(const char *fmt, ...)
2904 va_start(args, fmt);
2905 vsnprintf(dump_stack_arch_desc_str, sizeof(dump_stack_arch_desc_str),
2911 * dump_stack_print_info - print generic debug info for dump_stack()
2912 * @log_lvl: log level
2914 * Arch-specific dump_stack() implementations can use this function to
2915 * print out the same debug information as the generic dump_stack().
2917 void dump_stack_print_info(const char *log_lvl)
2919 printk("%sCPU: %d PID: %d Comm: %.20s %s %s %.*s\n",
2920 log_lvl, raw_smp_processor_id(), current->pid, current->comm,
2921 print_tainted(), init_utsname()->release,
2922 (int)strcspn(init_utsname()->version, " "),
2923 init_utsname()->version);
2925 if (dump_stack_arch_desc_str[0] != '\0')
2926 printk("%sHardware name: %s\n",
2927 log_lvl, dump_stack_arch_desc_str);
2929 print_worker_info(log_lvl, current);
2933 * show_regs_print_info - print generic debug info for show_regs()
2934 * @log_lvl: log level
2936 * show_regs() implementations can use this function to print out generic
2937 * debug information.
2939 void show_regs_print_info(const char *log_lvl)
2941 dump_stack_print_info(log_lvl);
2943 printk("%stask: %p ti: %p task.ti: %p\n",
2944 log_lvl, current, current_thread_info(),
2945 task_thread_info(current));