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/syscalls.h>
36 #include <linux/kexec.h>
37 #include <linux/kdb.h>
38 #include <linux/ratelimit.h>
39 #include <linux/kmsg_dump.h>
40 #include <linux/syslog.h>
41 #include <linux/cpu.h>
42 #include <linux/notifier.h>
43 #include <linux/rculist.h>
44 #include <linux/poll.h>
46 #include <asm/uaccess.h>
48 #define CREATE_TRACE_POINTS
49 #include <trace/events/printk.h>
52 * Architectures can override it:
54 void asmlinkage
__attribute__((weak
)) early_printk(const char *fmt
, ...)
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 DECLARE_WAIT_QUEUE_HEAD(log_wait
);
67 int console_printk
[4] = {
68 DEFAULT_CONSOLE_LOGLEVEL
, /* console_loglevel */
69 DEFAULT_MESSAGE_LOGLEVEL
, /* default_message_loglevel */
70 MINIMUM_CONSOLE_LOGLEVEL
, /* minimum_console_loglevel */
71 DEFAULT_CONSOLE_LOGLEVEL
, /* default_console_loglevel */
75 * Low level drivers may need that to know if they can schedule in
76 * their unblank() callback or not. So let's export it.
79 EXPORT_SYMBOL(oops_in_progress
);
82 * console_sem protects the console_drivers list, and also
83 * provides serialisation for access to the entire console
86 static DEFINE_SEMAPHORE(console_sem
);
87 struct console
*console_drivers
;
88 EXPORT_SYMBOL_GPL(console_drivers
);
91 * This is used for debugging the mess that is the VT code by
92 * keeping track if we have the console semaphore held. It's
93 * definitely not the perfect debug tool (we don't know if _WE_
94 * hold it are racing, but it helps tracking those weird code
95 * path in the console code where we end up in places I want
96 * locked without the console sempahore held
98 static int console_locked
, console_suspended
;
101 * If exclusive_console is non-NULL then only this console is to be printed to.
103 static struct console
*exclusive_console
;
106 * Array of consoles built from command line options (console=)
108 struct console_cmdline
110 char name
[8]; /* Name of the driver */
111 int index
; /* Minor dev. to use */
112 char *options
; /* Options for the driver */
113 #ifdef CONFIG_A11Y_BRAILLE_CONSOLE
114 char *brl_options
; /* Options for braille driver */
118 #define MAX_CMDLINECONSOLES 8
120 static struct console_cmdline console_cmdline
[MAX_CMDLINECONSOLES
];
121 static int selected_console
= -1;
122 static int preferred_console
= -1;
123 int console_set_on_cmdline
;
124 EXPORT_SYMBOL(console_set_on_cmdline
);
126 /* Flag: console code may call schedule() */
127 static int console_may_schedule
;
130 * The printk log buffer consists of a chain of concatenated variable
131 * length records. Every record starts with a record header, containing
132 * the overall length of the record.
134 * The heads to the first and last entry in the buffer, as well as the
135 * sequence numbers of these both entries are maintained when messages
138 * If the heads indicate available messages, the length in the header
139 * tells the start next message. A length == 0 for the next message
140 * indicates a wrap-around to the beginning of the buffer.
142 * Every record carries the monotonic timestamp in microseconds, as well as
143 * the standard userspace syslog level and syslog facility. The usual
144 * kernel messages use LOG_KERN; userspace-injected messages always carry
145 * a matching syslog facility, by default LOG_USER. The origin of every
146 * message can be reliably determined that way.
148 * The human readable log message directly follows the message header. The
149 * length of the message text is stored in the header, the stored message
152 * Optionally, a message can carry a dictionary of properties (key/value pairs),
153 * to provide userspace with a machine-readable message context.
155 * Examples for well-defined, commonly used property names are:
156 * DEVICE=b12:8 device identifier
160 * +sound:card0 subsystem:devname
161 * SUBSYSTEM=pci driver-core subsystem name
163 * Valid characters in property names are [a-zA-Z0-9.-_]. The plain text value
164 * follows directly after a '=' character. Every property is terminated by
165 * a '\0' character. The last property is not terminated.
167 * Example of a message structure:
168 * 0000 ff 8f 00 00 00 00 00 00 monotonic time in nsec
169 * 0008 34 00 record is 52 bytes long
170 * 000a 0b 00 text is 11 bytes long
171 * 000c 1f 00 dictionary is 23 bytes long
172 * 000e 03 00 LOG_KERN (facility) LOG_ERR (level)
173 * 0010 69 74 27 73 20 61 20 6c "it's a l"
175 * 001b 44 45 56 49 43 "DEVIC"
176 * 45 3d 62 38 3a 32 00 44 "E=b8:2\0D"
177 * 52 49 56 45 52 3d 62 75 "RIVER=bu"
179 * 0032 00 00 00 padding to next message header
181 * The 'struct log' buffer header must never be directly exported to
182 * userspace, it is a kernel-private implementation detail that might
183 * need to be changed in the future, when the requirements change.
185 * /dev/kmsg exports the structured data in the following line format:
186 * "level,sequnum,timestamp;<message text>\n"
188 * The optional key/value pairs are attached as continuation lines starting
189 * with a space character and terminated by a newline. All possible
190 * non-prinatable characters are escaped in the "\xff" notation.
192 * Users of the export format should ignore possible additional values
193 * separated by ',', and find the message after the ';' character.
197 LOG_NOCONS
= 1, /* already flushed, do not print to console */
198 LOG_NEWLINE
= 2, /* text ended with a newline */
199 LOG_PREFIX
= 4, /* text started with a prefix */
200 LOG_CONT
= 8, /* text is a fragment of a continuation line */
204 u64 ts_nsec
; /* timestamp in nanoseconds */
205 u16 len
; /* length of entire record */
206 u16 text_len
; /* length of text buffer */
207 u16 dict_len
; /* length of dictionary buffer */
208 u8 facility
; /* syslog facility */
209 u8 flags
:5; /* internal record flags */
210 u8 level
:3; /* syslog level */
214 * The logbuf_lock protects kmsg buffer, indices, counters. It is also
215 * used in interesting ways to provide interlocking in console_unlock();
217 static DEFINE_RAW_SPINLOCK(logbuf_lock
);
220 /* the next printk record to read by syslog(READ) or /proc/kmsg */
221 static u64 syslog_seq
;
222 static u32 syslog_idx
;
223 static enum log_flags syslog_prev
;
224 static size_t syslog_partial
;
226 /* index and sequence number of the first record stored in the buffer */
227 static u64 log_first_seq
;
228 static u32 log_first_idx
;
230 /* index and sequence number of the next record to store in the buffer */
231 static u64 log_next_seq
;
232 static u32 log_next_idx
;
234 /* the next printk record to read after the last 'clear' command */
235 static u64 clear_seq
;
236 static u32 clear_idx
;
238 #define PREFIX_MAX 32
239 #define LOG_LINE_MAX 1024 - PREFIX_MAX
242 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
245 #define LOG_ALIGN __alignof__(struct log)
247 #define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT)
248 static char __log_buf
[__LOG_BUF_LEN
] __aligned(LOG_ALIGN
);
249 static char *log_buf
= __log_buf
;
250 static u32 log_buf_len
= __LOG_BUF_LEN
;
252 /* cpu currently holding logbuf_lock */
253 static volatile unsigned int logbuf_cpu
= UINT_MAX
;
255 /* human readable text of the record */
256 static char *log_text(const struct log
*msg
)
258 return (char *)msg
+ sizeof(struct log
);
261 /* optional key/value pair dictionary attached to the record */
262 static char *log_dict(const struct log
*msg
)
264 return (char *)msg
+ sizeof(struct log
) + msg
->text_len
;
267 /* get record by index; idx must point to valid msg */
268 static struct log
*log_from_idx(u32 idx
)
270 struct log
*msg
= (struct log
*)(log_buf
+ idx
);
273 * A length == 0 record is the end of buffer marker. Wrap around and
274 * read the message at the start of the buffer.
277 return (struct log
*)log_buf
;
281 /* get next record; idx must point to valid msg */
282 static u32
log_next(u32 idx
)
284 struct log
*msg
= (struct log
*)(log_buf
+ idx
);
286 /* length == 0 indicates the end of the buffer; wrap */
288 * A length == 0 record is the end of buffer marker. Wrap around and
289 * read the message at the start of the buffer as *this* one, and
290 * return the one after that.
293 msg
= (struct log
*)log_buf
;
296 return idx
+ msg
->len
;
299 /* insert record into the buffer, discard old ones, update heads */
300 static void log_store(int facility
, int level
,
301 enum log_flags flags
, u64 ts_nsec
,
302 const char *dict
, u16 dict_len
,
303 const char *text
, u16 text_len
)
308 /* number of '\0' padding bytes to next message */
309 size
= sizeof(struct log
) + text_len
+ dict_len
;
310 pad_len
= (-size
) & (LOG_ALIGN
- 1);
313 while (log_first_seq
< log_next_seq
) {
316 if (log_next_idx
> log_first_idx
)
317 free
= max(log_buf_len
- log_next_idx
, log_first_idx
);
319 free
= log_first_idx
- log_next_idx
;
321 if (free
> size
+ sizeof(struct log
))
324 /* drop old messages until we have enough contiuous space */
325 log_first_idx
= log_next(log_first_idx
);
329 if (log_next_idx
+ size
+ sizeof(struct log
) >= log_buf_len
) {
331 * This message + an additional empty header does not fit
332 * at the end of the buffer. Add an empty header with len == 0
333 * to signify a wrap around.
335 memset(log_buf
+ log_next_idx
, 0, sizeof(struct log
));
340 msg
= (struct log
*)(log_buf
+ log_next_idx
);
341 memcpy(log_text(msg
), text
, text_len
);
342 msg
->text_len
= text_len
;
343 memcpy(log_dict(msg
), dict
, dict_len
);
344 msg
->dict_len
= dict_len
;
345 msg
->facility
= facility
;
346 msg
->level
= level
& 7;
347 msg
->flags
= flags
& 0x1f;
349 msg
->ts_nsec
= ts_nsec
;
351 msg
->ts_nsec
= local_clock();
352 memset(log_dict(msg
) + dict_len
, 0, pad_len
);
353 msg
->len
= sizeof(struct log
) + text_len
+ dict_len
+ pad_len
;
356 log_next_idx
+= msg
->len
;
360 /* /dev/kmsg - userspace message inject/listen interface */
361 struct devkmsg_user
{
369 static ssize_t
devkmsg_writev(struct kiocb
*iocb
, const struct iovec
*iv
,
370 unsigned long count
, loff_t pos
)
374 int level
= default_message_loglevel
;
375 int facility
= 1; /* LOG_USER */
376 size_t len
= iov_length(iv
, count
);
379 if (len
> LOG_LINE_MAX
)
381 buf
= kmalloc(len
+1, GFP_KERNEL
);
386 for (i
= 0; i
< count
; i
++) {
387 if (copy_from_user(line
, iv
[i
].iov_base
, iv
[i
].iov_len
))
389 line
+= iv
[i
].iov_len
;
393 * Extract and skip the syslog prefix <[0-9]*>. Coming from userspace
394 * the decimal value represents 32bit, the lower 3 bit are the log
395 * level, the rest are the log facility.
397 * If no prefix or no userspace facility is specified, we
398 * enforce LOG_USER, to be able to reliably distinguish
399 * kernel-generated messages from userspace-injected ones.
402 if (line
[0] == '<') {
405 i
= simple_strtoul(line
+1, &endp
, 10);
406 if (endp
&& endp
[0] == '>') {
417 printk_emit(facility
, level
, NULL
, 0, "%s", line
);
423 static ssize_t
devkmsg_read(struct file
*file
, char __user
*buf
,
424 size_t count
, loff_t
*ppos
)
426 struct devkmsg_user
*user
= file
->private_data
;
437 ret
= mutex_lock_interruptible(&user
->lock
);
440 raw_spin_lock_irq(&logbuf_lock
);
441 while (user
->seq
== log_next_seq
) {
442 if (file
->f_flags
& O_NONBLOCK
) {
444 raw_spin_unlock_irq(&logbuf_lock
);
448 raw_spin_unlock_irq(&logbuf_lock
);
449 ret
= wait_event_interruptible(log_wait
,
450 user
->seq
!= log_next_seq
);
453 raw_spin_lock_irq(&logbuf_lock
);
456 if (user
->seq
< log_first_seq
) {
457 /* our last seen message is gone, return error and reset */
458 user
->idx
= log_first_idx
;
459 user
->seq
= log_first_seq
;
461 raw_spin_unlock_irq(&logbuf_lock
);
465 msg
= log_from_idx(user
->idx
);
466 ts_usec
= msg
->ts_nsec
;
467 do_div(ts_usec
, 1000);
470 * If we couldn't merge continuation line fragments during the print,
471 * export the stored flags to allow an optional external merge of the
472 * records. Merging the records isn't always neccessarily correct, like
473 * when we hit a race during printing. In most cases though, it produces
474 * better readable output. 'c' in the record flags mark the first
475 * fragment of a line, '+' the following.
477 if (msg
->flags
& LOG_CONT
&& !(user
->prev
& LOG_CONT
))
479 else if ((msg
->flags
& LOG_CONT
) ||
480 ((user
->prev
& LOG_CONT
) && !(msg
->flags
& LOG_PREFIX
)))
483 len
= sprintf(user
->buf
, "%u,%llu,%llu,%c;",
484 (msg
->facility
<< 3) | msg
->level
,
485 user
->seq
, ts_usec
, cont
);
486 user
->prev
= msg
->flags
;
488 /* escape non-printable characters */
489 for (i
= 0; i
< msg
->text_len
; i
++) {
490 unsigned char c
= log_text(msg
)[i
];
492 if (c
< ' ' || c
>= 127 || c
== '\\')
493 len
+= sprintf(user
->buf
+ len
, "\\x%02x", c
);
495 user
->buf
[len
++] = c
;
497 user
->buf
[len
++] = '\n';
502 for (i
= 0; i
< msg
->dict_len
; i
++) {
503 unsigned char c
= log_dict(msg
)[i
];
506 user
->buf
[len
++] = ' ';
511 user
->buf
[len
++] = '\n';
516 if (c
< ' ' || c
>= 127 || c
== '\\') {
517 len
+= sprintf(user
->buf
+ len
, "\\x%02x", c
);
521 user
->buf
[len
++] = c
;
523 user
->buf
[len
++] = '\n';
526 user
->idx
= log_next(user
->idx
);
528 raw_spin_unlock_irq(&logbuf_lock
);
535 if (copy_to_user(buf
, user
->buf
, len
)) {
541 mutex_unlock(&user
->lock
);
545 static loff_t
devkmsg_llseek(struct file
*file
, loff_t offset
, int whence
)
547 struct devkmsg_user
*user
= file
->private_data
;
555 raw_spin_lock_irq(&logbuf_lock
);
558 /* the first record */
559 user
->idx
= log_first_idx
;
560 user
->seq
= log_first_seq
;
564 * The first record after the last SYSLOG_ACTION_CLEAR,
565 * like issued by 'dmesg -c'. Reading /dev/kmsg itself
566 * changes no global state, and does not clear anything.
568 user
->idx
= clear_idx
;
569 user
->seq
= clear_seq
;
572 /* after the last record */
573 user
->idx
= log_next_idx
;
574 user
->seq
= log_next_seq
;
579 raw_spin_unlock_irq(&logbuf_lock
);
583 static unsigned int devkmsg_poll(struct file
*file
, poll_table
*wait
)
585 struct devkmsg_user
*user
= file
->private_data
;
589 return POLLERR
|POLLNVAL
;
591 poll_wait(file
, &log_wait
, wait
);
593 raw_spin_lock_irq(&logbuf_lock
);
594 if (user
->seq
< log_next_seq
) {
595 /* return error when data has vanished underneath us */
596 if (user
->seq
< log_first_seq
)
597 ret
= POLLIN
|POLLRDNORM
|POLLERR
|POLLPRI
;
598 ret
= POLLIN
|POLLRDNORM
;
600 raw_spin_unlock_irq(&logbuf_lock
);
605 static int devkmsg_open(struct inode
*inode
, struct file
*file
)
607 struct devkmsg_user
*user
;
610 /* write-only does not need any file context */
611 if ((file
->f_flags
& O_ACCMODE
) == O_WRONLY
)
614 err
= security_syslog(SYSLOG_ACTION_READ_ALL
);
618 user
= kmalloc(sizeof(struct devkmsg_user
), GFP_KERNEL
);
622 mutex_init(&user
->lock
);
624 raw_spin_lock_irq(&logbuf_lock
);
625 user
->idx
= log_first_idx
;
626 user
->seq
= log_first_seq
;
627 raw_spin_unlock_irq(&logbuf_lock
);
629 file
->private_data
= user
;
633 static int devkmsg_release(struct inode
*inode
, struct file
*file
)
635 struct devkmsg_user
*user
= file
->private_data
;
640 mutex_destroy(&user
->lock
);
645 const struct file_operations kmsg_fops
= {
646 .open
= devkmsg_open
,
647 .read
= devkmsg_read
,
648 .aio_write
= devkmsg_writev
,
649 .llseek
= devkmsg_llseek
,
650 .poll
= devkmsg_poll
,
651 .release
= devkmsg_release
,
656 * This appends the listed symbols to /proc/vmcoreinfo
658 * /proc/vmcoreinfo is used by various utiilties, like crash and makedumpfile to
659 * obtain access to symbols that are otherwise very difficult to locate. These
660 * symbols are specifically used so that utilities can access and extract the
661 * dmesg log from a vmcore file after a crash.
663 void log_buf_kexec_setup(void)
665 VMCOREINFO_SYMBOL(log_buf
);
666 VMCOREINFO_SYMBOL(log_buf_len
);
667 VMCOREINFO_SYMBOL(log_first_idx
);
668 VMCOREINFO_SYMBOL(log_next_idx
);
672 /* requested log_buf_len from kernel cmdline */
673 static unsigned long __initdata new_log_buf_len
;
675 /* save requested log_buf_len since it's too early to process it */
676 static int __init
log_buf_len_setup(char *str
)
678 unsigned size
= memparse(str
, &str
);
681 size
= roundup_pow_of_two(size
);
682 if (size
> log_buf_len
)
683 new_log_buf_len
= size
;
687 early_param("log_buf_len", log_buf_len_setup
);
689 void __init
setup_log_buf(int early
)
695 if (!new_log_buf_len
)
701 mem
= memblock_alloc(new_log_buf_len
, PAGE_SIZE
);
704 new_log_buf
= __va(mem
);
706 new_log_buf
= alloc_bootmem_nopanic(new_log_buf_len
);
709 if (unlikely(!new_log_buf
)) {
710 pr_err("log_buf_len: %ld bytes not available\n",
715 raw_spin_lock_irqsave(&logbuf_lock
, flags
);
716 log_buf_len
= new_log_buf_len
;
717 log_buf
= new_log_buf
;
719 free
= __LOG_BUF_LEN
- log_next_idx
;
720 memcpy(log_buf
, __log_buf
, __LOG_BUF_LEN
);
721 raw_spin_unlock_irqrestore(&logbuf_lock
, flags
);
723 pr_info("log_buf_len: %d\n", log_buf_len
);
724 pr_info("early log buf free: %d(%d%%)\n",
725 free
, (free
* 100) / __LOG_BUF_LEN
);
728 #ifdef CONFIG_BOOT_PRINTK_DELAY
730 static int boot_delay
; /* msecs delay after each printk during bootup */
731 static unsigned long long loops_per_msec
; /* based on boot_delay */
733 static int __init
boot_delay_setup(char *str
)
737 lpj
= preset_lpj
? preset_lpj
: 1000000; /* some guess */
738 loops_per_msec
= (unsigned long long)lpj
/ 1000 * HZ
;
740 get_option(&str
, &boot_delay
);
741 if (boot_delay
> 10 * 1000)
744 pr_debug("boot_delay: %u, preset_lpj: %ld, lpj: %lu, "
745 "HZ: %d, loops_per_msec: %llu\n",
746 boot_delay
, preset_lpj
, lpj
, HZ
, loops_per_msec
);
749 __setup("boot_delay=", boot_delay_setup
);
751 static void boot_delay_msec(void)
753 unsigned long long k
;
754 unsigned long timeout
;
756 if (boot_delay
== 0 || system_state
!= SYSTEM_BOOTING
)
759 k
= (unsigned long long)loops_per_msec
* boot_delay
;
761 timeout
= jiffies
+ msecs_to_jiffies(boot_delay
);
766 * use (volatile) jiffies to prevent
767 * compiler reduction; loop termination via jiffies
768 * is secondary and may or may not happen.
770 if (time_after(jiffies
, timeout
))
772 touch_nmi_watchdog();
776 static inline void boot_delay_msec(void)
781 #ifdef CONFIG_SECURITY_DMESG_RESTRICT
782 int dmesg_restrict
= 1;
787 static int syslog_action_restricted(int type
)
791 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
792 return type
!= SYSLOG_ACTION_READ_ALL
&& type
!= SYSLOG_ACTION_SIZE_BUFFER
;
795 static int check_syslog_permissions(int type
, bool from_file
)
798 * If this is from /proc/kmsg and we've already opened it, then we've
799 * already done the capabilities checks at open time.
801 if (from_file
&& type
!= SYSLOG_ACTION_OPEN
)
804 if (syslog_action_restricted(type
)) {
805 if (capable(CAP_SYSLOG
))
807 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
808 if (capable(CAP_SYS_ADMIN
)) {
809 printk_once(KERN_WARNING
"%s (%d): "
810 "Attempt to access syslog with CAP_SYS_ADMIN "
811 "but no CAP_SYSLOG (deprecated).\n",
812 current
->comm
, task_pid_nr(current
));
820 #if defined(CONFIG_PRINTK_TIME)
821 static bool printk_time
= 1;
823 static bool printk_time
;
825 module_param_named(time
, printk_time
, bool, S_IRUGO
| S_IWUSR
);
827 static size_t print_time(u64 ts
, char *buf
)
829 unsigned long rem_nsec
;
837 rem_nsec
= do_div(ts
, 1000000000);
838 return sprintf(buf
, "[%5lu.%06lu] ",
839 (unsigned long)ts
, rem_nsec
/ 1000);
842 static size_t print_prefix(const struct log
*msg
, bool syslog
, char *buf
)
845 unsigned int prefix
= (msg
->facility
<< 3) | msg
->level
;
849 len
+= sprintf(buf
, "<%u>", prefix
);
854 else if (prefix
> 99)
861 len
+= print_time(msg
->ts_nsec
, buf
? buf
+ len
: NULL
);
865 static size_t msg_print_text(const struct log
*msg
, enum log_flags prev
,
866 bool syslog
, char *buf
, size_t size
)
868 const char *text
= log_text(msg
);
869 size_t text_size
= msg
->text_len
;
874 if ((prev
& LOG_CONT
) && !(msg
->flags
& LOG_PREFIX
))
877 if (msg
->flags
& LOG_CONT
) {
878 if ((prev
& LOG_CONT
) && !(prev
& LOG_NEWLINE
))
881 if (!(msg
->flags
& LOG_NEWLINE
))
886 const char *next
= memchr(text
, '\n', text_size
);
890 text_len
= next
- text
;
892 text_size
-= next
- text
;
894 text_len
= text_size
;
898 if (print_prefix(msg
, syslog
, NULL
) +
899 text_len
+ 1 >= size
- len
)
903 len
+= print_prefix(msg
, syslog
, buf
+ len
);
904 memcpy(buf
+ len
, text
, text_len
);
909 /* SYSLOG_ACTION_* buffer size only calculation */
911 len
+= print_prefix(msg
, syslog
, NULL
);
924 static int syslog_print(char __user
*buf
, int size
)
930 text
= kmalloc(LOG_LINE_MAX
+ PREFIX_MAX
, GFP_KERNEL
);
938 raw_spin_lock_irq(&logbuf_lock
);
939 if (syslog_seq
< log_first_seq
) {
940 /* messages are gone, move to first one */
941 syslog_seq
= log_first_seq
;
942 syslog_idx
= log_first_idx
;
946 if (syslog_seq
== log_next_seq
) {
947 raw_spin_unlock_irq(&logbuf_lock
);
951 skip
= syslog_partial
;
952 msg
= log_from_idx(syslog_idx
);
953 n
= msg_print_text(msg
, syslog_prev
, true, text
,
954 LOG_LINE_MAX
+ PREFIX_MAX
);
955 if (n
- syslog_partial
<= size
) {
956 /* message fits into buffer, move forward */
957 syslog_idx
= log_next(syslog_idx
);
959 syslog_prev
= msg
->flags
;
963 /* partial read(), remember position */
968 raw_spin_unlock_irq(&logbuf_lock
);
973 if (copy_to_user(buf
, text
+ skip
, n
)) {
988 static int syslog_print_all(char __user
*buf
, int size
, bool clear
)
993 text
= kmalloc(LOG_LINE_MAX
+ PREFIX_MAX
, GFP_KERNEL
);
997 raw_spin_lock_irq(&logbuf_lock
);
1002 enum log_flags prev
;
1004 if (clear_seq
< log_first_seq
) {
1005 /* messages are gone, move to first available one */
1006 clear_seq
= log_first_seq
;
1007 clear_idx
= log_first_idx
;
1011 * Find first record that fits, including all following records,
1012 * into the user-provided buffer for this dump.
1017 while (seq
< log_next_seq
) {
1018 struct log
*msg
= log_from_idx(idx
);
1020 len
+= msg_print_text(msg
, prev
, true, NULL
, 0);
1021 idx
= log_next(idx
);
1025 /* move first record forward until length fits into the buffer */
1029 while (len
> size
&& seq
< log_next_seq
) {
1030 struct log
*msg
= log_from_idx(idx
);
1032 len
-= msg_print_text(msg
, prev
, true, NULL
, 0);
1033 idx
= log_next(idx
);
1037 /* last message fitting into this dump */
1038 next_seq
= log_next_seq
;
1042 while (len
>= 0 && seq
< next_seq
) {
1043 struct log
*msg
= log_from_idx(idx
);
1046 textlen
= msg_print_text(msg
, prev
, true, text
,
1047 LOG_LINE_MAX
+ PREFIX_MAX
);
1052 idx
= log_next(idx
);
1056 raw_spin_unlock_irq(&logbuf_lock
);
1057 if (copy_to_user(buf
+ len
, text
, textlen
))
1061 raw_spin_lock_irq(&logbuf_lock
);
1063 if (seq
< log_first_seq
) {
1064 /* messages are gone, move to next one */
1065 seq
= log_first_seq
;
1066 idx
= log_first_idx
;
1073 clear_seq
= log_next_seq
;
1074 clear_idx
= log_next_idx
;
1076 raw_spin_unlock_irq(&logbuf_lock
);
1082 int do_syslog(int type
, char __user
*buf
, int len
, bool from_file
)
1085 static int saved_console_loglevel
= -1;
1088 error
= check_syslog_permissions(type
, from_file
);
1092 error
= security_syslog(type
);
1097 case SYSLOG_ACTION_CLOSE
: /* Close log */
1099 case SYSLOG_ACTION_OPEN
: /* Open log */
1101 case SYSLOG_ACTION_READ
: /* Read from log */
1103 if (!buf
|| len
< 0)
1108 if (!access_ok(VERIFY_WRITE
, buf
, len
)) {
1112 error
= wait_event_interruptible(log_wait
,
1113 syslog_seq
!= log_next_seq
);
1116 error
= syslog_print(buf
, len
);
1118 /* Read/clear last kernel messages */
1119 case SYSLOG_ACTION_READ_CLEAR
:
1122 /* Read last kernel messages */
1123 case SYSLOG_ACTION_READ_ALL
:
1125 if (!buf
|| len
< 0)
1130 if (!access_ok(VERIFY_WRITE
, buf
, len
)) {
1134 error
= syslog_print_all(buf
, len
, clear
);
1136 /* Clear ring buffer */
1137 case SYSLOG_ACTION_CLEAR
:
1138 syslog_print_all(NULL
, 0, true);
1140 /* Disable logging to console */
1141 case SYSLOG_ACTION_CONSOLE_OFF
:
1142 if (saved_console_loglevel
== -1)
1143 saved_console_loglevel
= console_loglevel
;
1144 console_loglevel
= minimum_console_loglevel
;
1146 /* Enable logging to console */
1147 case SYSLOG_ACTION_CONSOLE_ON
:
1148 if (saved_console_loglevel
!= -1) {
1149 console_loglevel
= saved_console_loglevel
;
1150 saved_console_loglevel
= -1;
1153 /* Set level of messages printed to console */
1154 case SYSLOG_ACTION_CONSOLE_LEVEL
:
1156 if (len
< 1 || len
> 8)
1158 if (len
< minimum_console_loglevel
)
1159 len
= minimum_console_loglevel
;
1160 console_loglevel
= len
;
1161 /* Implicitly re-enable logging to console */
1162 saved_console_loglevel
= -1;
1165 /* Number of chars in the log buffer */
1166 case SYSLOG_ACTION_SIZE_UNREAD
:
1167 raw_spin_lock_irq(&logbuf_lock
);
1168 if (syslog_seq
< log_first_seq
) {
1169 /* messages are gone, move to first one */
1170 syslog_seq
= log_first_seq
;
1171 syslog_idx
= log_first_idx
;
1177 * Short-cut for poll(/"proc/kmsg") which simply checks
1178 * for pending data, not the size; return the count of
1179 * records, not the length.
1181 error
= log_next_idx
- syslog_idx
;
1183 u64 seq
= syslog_seq
;
1184 u32 idx
= syslog_idx
;
1185 enum log_flags prev
= syslog_prev
;
1188 while (seq
< log_next_seq
) {
1189 struct log
*msg
= log_from_idx(idx
);
1191 error
+= msg_print_text(msg
, prev
, true, NULL
, 0);
1192 idx
= log_next(idx
);
1196 error
-= syslog_partial
;
1198 raw_spin_unlock_irq(&logbuf_lock
);
1200 /* Size of the log buffer */
1201 case SYSLOG_ACTION_SIZE_BUFFER
:
1202 error
= log_buf_len
;
1212 SYSCALL_DEFINE3(syslog
, int, type
, char __user
*, buf
, int, len
)
1214 return do_syslog(type
, buf
, len
, SYSLOG_FROM_CALL
);
1217 #ifdef CONFIG_KGDB_KDB
1218 /* kdb dmesg command needs access to the syslog buffer. do_syslog()
1219 * uses locks so it cannot be used during debugging. Just tell kdb
1220 * where the start and end of the physical and logical logs are. This
1221 * is equivalent to do_syslog(3).
1223 void kdb_syslog_data(char *syslog_data
[4])
1225 syslog_data
[0] = log_buf
;
1226 syslog_data
[1] = log_buf
+ log_buf_len
;
1227 syslog_data
[2] = log_buf
+ log_first_idx
;
1228 syslog_data
[3] = log_buf
+ log_next_idx
;
1230 #endif /* CONFIG_KGDB_KDB */
1232 static bool __read_mostly ignore_loglevel
;
1234 static int __init
ignore_loglevel_setup(char *str
)
1236 ignore_loglevel
= 1;
1237 printk(KERN_INFO
"debug: ignoring loglevel setting.\n");
1242 early_param("ignore_loglevel", ignore_loglevel_setup
);
1243 module_param(ignore_loglevel
, bool, S_IRUGO
| S_IWUSR
);
1244 MODULE_PARM_DESC(ignore_loglevel
, "ignore loglevel setting, to"
1245 "print all kernel messages to the console.");
1248 * Call the console drivers, asking them to write out
1249 * log_buf[start] to log_buf[end - 1].
1250 * The console_lock must be held.
1252 static void call_console_drivers(int level
, const char *text
, size_t len
)
1254 struct console
*con
;
1256 trace_console(text
, 0, len
, len
);
1258 if (level
>= console_loglevel
&& !ignore_loglevel
)
1260 if (!console_drivers
)
1263 for_each_console(con
) {
1264 if (exclusive_console
&& con
!= exclusive_console
)
1266 if (!(con
->flags
& CON_ENABLED
))
1270 if (!cpu_online(smp_processor_id()) &&
1271 !(con
->flags
& CON_ANYTIME
))
1273 con
->write(con
, text
, len
);
1278 * Zap console related locks when oopsing. Only zap at most once
1279 * every 10 seconds, to leave time for slow consoles to print a
1282 static void zap_locks(void)
1284 static unsigned long oops_timestamp
;
1286 if (time_after_eq(jiffies
, oops_timestamp
) &&
1287 !time_after(jiffies
, oops_timestamp
+ 30 * HZ
))
1290 oops_timestamp
= jiffies
;
1293 /* If a crash is occurring, make sure we can't deadlock */
1294 raw_spin_lock_init(&logbuf_lock
);
1295 /* And make sure that we print immediately */
1296 sema_init(&console_sem
, 1);
1299 /* Check if we have any console registered that can be called early in boot. */
1300 static int have_callable_console(void)
1302 struct console
*con
;
1304 for_each_console(con
)
1305 if (con
->flags
& CON_ANYTIME
)
1312 * Can we actually use the console at this time on this cpu?
1314 * Console drivers may assume that per-cpu resources have
1315 * been allocated. So unless they're explicitly marked as
1316 * being able to cope (CON_ANYTIME) don't call them until
1317 * this CPU is officially up.
1319 static inline int can_use_console(unsigned int cpu
)
1321 return cpu_online(cpu
) || have_callable_console();
1325 * Try to get console ownership to actually show the kernel
1326 * messages from a 'printk'. Return true (and with the
1327 * console_lock held, and 'console_locked' set) if it
1328 * is successful, false otherwise.
1330 * This gets called with the 'logbuf_lock' spinlock held and
1331 * interrupts disabled. It should return with 'lockbuf_lock'
1332 * released but interrupts still disabled.
1334 static int console_trylock_for_printk(unsigned int cpu
)
1335 __releases(&logbuf_lock
)
1337 int retval
= 0, wake
= 0;
1339 if (console_trylock()) {
1343 * If we can't use the console, we need to release
1344 * the console semaphore by hand to avoid flushing
1345 * the buffer. We need to hold the console semaphore
1346 * in order to do this test safely.
1348 if (!can_use_console(cpu
)) {
1354 logbuf_cpu
= UINT_MAX
;
1357 raw_spin_unlock(&logbuf_lock
);
1361 int printk_delay_msec __read_mostly
;
1363 static inline void printk_delay(void)
1365 if (unlikely(printk_delay_msec
)) {
1366 int m
= printk_delay_msec
;
1370 touch_nmi_watchdog();
1376 * Continuation lines are buffered, and not committed to the record buffer
1377 * until the line is complete, or a race forces it. The line fragments
1378 * though, are printed immediately to the consoles to ensure everything has
1379 * reached the console in case of a kernel crash.
1381 static struct cont
{
1382 char buf
[LOG_LINE_MAX
];
1383 size_t len
; /* length == 0 means unused buffer */
1384 size_t cons
; /* bytes written to console */
1385 struct task_struct
*owner
; /* task of first print*/
1386 u64 ts_nsec
; /* time of first print */
1387 u8 level
; /* log level of first message */
1388 u8 facility
; /* log level of first message */
1389 bool flushed
:1; /* buffer sealed and committed */
1392 static void cont_flush(enum log_flags flags
)
1399 log_store(cont
.facility
, cont
.level
, LOG_NOCONS
| flags
,
1400 cont
.ts_nsec
, NULL
, 0, cont
.buf
, cont
.len
);
1402 cont
.flushed
= true;
1405 static bool cont_add(int facility
, int level
, const char *text
, size_t len
)
1407 if (cont
.len
&& cont
.flushed
)
1410 if (cont
.len
+ len
> sizeof(cont
.buf
)) {
1411 /* the line gets too long, split it up in separate records */
1412 cont_flush(LOG_CONT
);
1417 cont
.facility
= facility
;
1419 cont
.owner
= current
;
1420 cont
.ts_nsec
= local_clock();
1422 cont
.flushed
= false;
1425 memcpy(cont
.buf
+ cont
.len
, text
, len
);
1430 static size_t cont_print_text(char *text
, size_t size
)
1435 if (cont
.cons
== 0) {
1436 textlen
+= print_time(cont
.ts_nsec
, text
);
1440 len
= cont
.len
- cont
.cons
;
1444 memcpy(text
+ textlen
, cont
.buf
+ cont
.cons
, len
);
1446 cont
.cons
= cont
.len
;
1450 text
[textlen
++] = '\n';
1451 /* got everything, release buffer */
1457 asmlinkage
int vprintk_emit(int facility
, int level
,
1458 const char *dict
, size_t dictlen
,
1459 const char *fmt
, va_list args
)
1461 static int recursion_bug
;
1462 static char textbuf
[LOG_LINE_MAX
];
1463 char *text
= textbuf
;
1465 enum log_flags lflags
= 0;
1466 unsigned long flags
;
1468 int printed_len
= 0;
1473 /* This stops the holder of console_sem just where we want him */
1474 local_irq_save(flags
);
1475 this_cpu
= smp_processor_id();
1478 * Ouch, printk recursed into itself!
1480 if (unlikely(logbuf_cpu
== this_cpu
)) {
1482 * If a crash is occurring during printk() on this CPU,
1483 * then try to get the crash message out but make sure
1484 * we can't deadlock. Otherwise just return to avoid the
1485 * recursion and return - but flag the recursion so that
1486 * it can be printed at the next appropriate moment:
1488 if (!oops_in_progress
&& !lockdep_recursing(current
)) {
1490 goto out_restore_irqs
;
1496 raw_spin_lock(&logbuf_lock
);
1497 logbuf_cpu
= this_cpu
;
1499 if (recursion_bug
) {
1500 static const char recursion_msg
[] =
1501 "BUG: recent printk recursion!";
1504 printed_len
+= strlen(recursion_msg
);
1505 /* emit KERN_CRIT message */
1506 log_store(0, 2, LOG_PREFIX
|LOG_NEWLINE
, 0,
1507 NULL
, 0, recursion_msg
, printed_len
);
1511 * The printf needs to come first; we need the syslog
1512 * prefix which might be passed-in as a parameter.
1514 text_len
= vscnprintf(text
, sizeof(textbuf
), fmt
, args
);
1516 /* mark and strip a trailing newline */
1517 if (text_len
&& text
[text_len
-1] == '\n') {
1519 lflags
|= LOG_NEWLINE
;
1522 /* strip syslog prefix and extract log level or control flags */
1523 if (text
[0] == '<' && text
[1] && text
[2] == '>') {
1527 level
= text
[1] - '0';
1528 case 'd': /* KERN_DEFAULT */
1529 lflags
|= LOG_PREFIX
;
1530 case 'c': /* KERN_CONT */
1537 level
= default_message_loglevel
;
1540 lflags
|= LOG_PREFIX
|LOG_NEWLINE
;
1542 if (!(lflags
& LOG_NEWLINE
)) {
1544 * Flush the conflicting buffer. An earlier newline was missing,
1545 * or another task also prints continuation lines.
1547 if (cont
.len
&& (lflags
& LOG_PREFIX
|| cont
.owner
!= current
))
1550 /* buffer line if possible, otherwise store it right away */
1551 if (!cont_add(facility
, level
, text
, text_len
))
1552 log_store(facility
, level
, lflags
| LOG_CONT
, 0,
1553 dict
, dictlen
, text
, text_len
);
1555 bool stored
= false;
1558 * If an earlier newline was missing and it was the same task,
1559 * either merge it with the current buffer and flush, or if
1560 * there was a race with interrupts (prefix == true) then just
1561 * flush it out and store this line separately.
1563 if (cont
.len
&& cont
.owner
== current
) {
1564 if (!(lflags
& LOG_PREFIX
))
1565 stored
= cont_add(facility
, level
, text
, text_len
);
1570 log_store(facility
, level
, lflags
, 0,
1571 dict
, dictlen
, text
, text_len
);
1573 printed_len
+= text_len
;
1576 * Try to acquire and then immediately release the console semaphore.
1577 * The release will print out buffers and wake up /dev/kmsg and syslog()
1580 * The console_trylock_for_printk() function will release 'logbuf_lock'
1581 * regardless of whether it actually gets the console semaphore or not.
1583 if (console_trylock_for_printk(this_cpu
))
1588 local_irq_restore(flags
);
1592 EXPORT_SYMBOL(vprintk_emit
);
1594 asmlinkage
int vprintk(const char *fmt
, va_list args
)
1596 return vprintk_emit(0, -1, NULL
, 0, fmt
, args
);
1598 EXPORT_SYMBOL(vprintk
);
1600 asmlinkage
int printk_emit(int facility
, int level
,
1601 const char *dict
, size_t dictlen
,
1602 const char *fmt
, ...)
1607 va_start(args
, fmt
);
1608 r
= vprintk_emit(facility
, level
, dict
, dictlen
, fmt
, args
);
1613 EXPORT_SYMBOL(printk_emit
);
1616 * printk - print a kernel message
1617 * @fmt: format string
1619 * This is printk(). It can be called from any context. We want it to work.
1621 * We try to grab the console_lock. If we succeed, it's easy - we log the
1622 * output and call the console drivers. If we fail to get the semaphore, we
1623 * place the output into the log buffer and return. The current holder of
1624 * the console_sem will notice the new output in console_unlock(); and will
1625 * send it to the consoles before releasing the lock.
1627 * One effect of this deferred printing is that code which calls printk() and
1628 * then changes console_loglevel may break. This is because console_loglevel
1629 * is inspected when the actual printing occurs.
1634 * See the vsnprintf() documentation for format string extensions over C99.
1636 asmlinkage
int printk(const char *fmt
, ...)
1641 #ifdef CONFIG_KGDB_KDB
1642 if (unlikely(kdb_trap_printk
)) {
1643 va_start(args
, fmt
);
1644 r
= vkdb_printf(fmt
, args
);
1649 va_start(args
, fmt
);
1650 r
= vprintk_emit(0, -1, NULL
, 0, fmt
, args
);
1655 EXPORT_SYMBOL(printk
);
1657 #else /* CONFIG_PRINTK */
1659 #define LOG_LINE_MAX 0
1660 #define PREFIX_MAX 0
1661 #define LOG_LINE_MAX 0
1662 static u64 syslog_seq
;
1663 static u32 syslog_idx
;
1664 static enum log_flags syslog_prev
;
1665 static u64 log_first_seq
;
1666 static u32 log_first_idx
;
1667 static u64 log_next_seq
;
1668 static struct cont
{
1674 static struct log
*log_from_idx(u32 idx
) { return NULL
; }
1675 static u32
log_next(u32 idx
) { return 0; }
1676 static void call_console_drivers(int level
, const char *text
, size_t len
) {}
1677 static size_t msg_print_text(const struct log
*msg
, enum log_flags prev
,
1678 bool syslog
, char *buf
, size_t size
) { return 0; }
1679 static size_t cont_print_text(char *text
, size_t size
) { return 0; }
1681 #endif /* CONFIG_PRINTK */
1683 static int __add_preferred_console(char *name
, int idx
, char *options
,
1686 struct console_cmdline
*c
;
1690 * See if this tty is not yet registered, and
1691 * if we have a slot free.
1693 for (i
= 0; i
< MAX_CMDLINECONSOLES
&& console_cmdline
[i
].name
[0]; i
++)
1694 if (strcmp(console_cmdline
[i
].name
, name
) == 0 &&
1695 console_cmdline
[i
].index
== idx
) {
1697 selected_console
= i
;
1700 if (i
== MAX_CMDLINECONSOLES
)
1703 selected_console
= i
;
1704 c
= &console_cmdline
[i
];
1705 strlcpy(c
->name
, name
, sizeof(c
->name
));
1706 c
->options
= options
;
1707 #ifdef CONFIG_A11Y_BRAILLE_CONSOLE
1708 c
->brl_options
= brl_options
;
1714 * Set up a list of consoles. Called from init/main.c
1716 static int __init
console_setup(char *str
)
1718 char buf
[sizeof(console_cmdline
[0].name
) + 4]; /* 4 for index */
1719 char *s
, *options
, *brl_options
= NULL
;
1722 #ifdef CONFIG_A11Y_BRAILLE_CONSOLE
1723 if (!memcmp(str
, "brl,", 4)) {
1726 } else if (!memcmp(str
, "brl=", 4)) {
1727 brl_options
= str
+ 4;
1728 str
= strchr(brl_options
, ',');
1730 printk(KERN_ERR
"need port name after brl=\n");
1738 * Decode str into name, index, options.
1740 if (str
[0] >= '0' && str
[0] <= '9') {
1741 strcpy(buf
, "ttyS");
1742 strncpy(buf
+ 4, str
, sizeof(buf
) - 5);
1744 strncpy(buf
, str
, sizeof(buf
) - 1);
1746 buf
[sizeof(buf
) - 1] = 0;
1747 if ((options
= strchr(str
, ',')) != NULL
)
1750 if (!strcmp(str
, "ttya"))
1751 strcpy(buf
, "ttyS0");
1752 if (!strcmp(str
, "ttyb"))
1753 strcpy(buf
, "ttyS1");
1755 for (s
= buf
; *s
; s
++)
1756 if ((*s
>= '0' && *s
<= '9') || *s
== ',')
1758 idx
= simple_strtoul(s
, NULL
, 10);
1761 __add_preferred_console(buf
, idx
, options
, brl_options
);
1762 console_set_on_cmdline
= 1;
1765 __setup("console=", console_setup
);
1768 * add_preferred_console - add a device to the list of preferred consoles.
1769 * @name: device name
1770 * @idx: device index
1771 * @options: options for this console
1773 * The last preferred console added will be used for kernel messages
1774 * and stdin/out/err for init. Normally this is used by console_setup
1775 * above to handle user-supplied console arguments; however it can also
1776 * be used by arch-specific code either to override the user or more
1777 * commonly to provide a default console (ie from PROM variables) when
1778 * the user has not supplied one.
1780 int add_preferred_console(char *name
, int idx
, char *options
)
1782 return __add_preferred_console(name
, idx
, options
, NULL
);
1785 int update_console_cmdline(char *name
, int idx
, char *name_new
, int idx_new
, char *options
)
1787 struct console_cmdline
*c
;
1790 for (i
= 0; i
< MAX_CMDLINECONSOLES
&& console_cmdline
[i
].name
[0]; i
++)
1791 if (strcmp(console_cmdline
[i
].name
, name
) == 0 &&
1792 console_cmdline
[i
].index
== idx
) {
1793 c
= &console_cmdline
[i
];
1794 strlcpy(c
->name
, name_new
, sizeof(c
->name
));
1795 c
->name
[sizeof(c
->name
) - 1] = 0;
1796 c
->options
= options
;
1804 bool console_suspend_enabled
= 1;
1805 EXPORT_SYMBOL(console_suspend_enabled
);
1807 static int __init
console_suspend_disable(char *str
)
1809 console_suspend_enabled
= 0;
1812 __setup("no_console_suspend", console_suspend_disable
);
1813 module_param_named(console_suspend
, console_suspend_enabled
,
1814 bool, S_IRUGO
| S_IWUSR
);
1815 MODULE_PARM_DESC(console_suspend
, "suspend console during suspend"
1816 " and hibernate operations");
1819 * suspend_console - suspend the console subsystem
1821 * This disables printk() while we go into suspend states
1823 void suspend_console(void)
1825 if (!console_suspend_enabled
)
1827 printk("Suspending console(s) (use no_console_suspend to debug)\n");
1829 console_suspended
= 1;
1833 void resume_console(void)
1835 if (!console_suspend_enabled
)
1838 console_suspended
= 0;
1843 * console_cpu_notify - print deferred console messages after CPU hotplug
1844 * @self: notifier struct
1845 * @action: CPU hotplug event
1848 * If printk() is called from a CPU that is not online yet, the messages
1849 * will be spooled but will not show up on the console. This function is
1850 * called when a new CPU comes online (or fails to come up), and ensures
1851 * that any such output gets printed.
1853 static int __cpuinit
console_cpu_notify(struct notifier_block
*self
,
1854 unsigned long action
, void *hcpu
)
1860 case CPU_DOWN_FAILED
:
1861 case CPU_UP_CANCELED
:
1869 * console_lock - lock the console system for exclusive use.
1871 * Acquires a lock which guarantees that the caller has
1872 * exclusive access to the console system and the console_drivers list.
1874 * Can sleep, returns nothing.
1876 void console_lock(void)
1878 BUG_ON(in_interrupt());
1880 if (console_suspended
)
1883 console_may_schedule
= 1;
1885 EXPORT_SYMBOL(console_lock
);
1888 * console_trylock - try to lock the console system for exclusive use.
1890 * Tried to acquire a lock which guarantees that the caller has
1891 * exclusive access to the console system and the console_drivers list.
1893 * returns 1 on success, and 0 on failure to acquire the lock.
1895 int console_trylock(void)
1897 if (down_trylock(&console_sem
))
1899 if (console_suspended
) {
1904 console_may_schedule
= 0;
1907 EXPORT_SYMBOL(console_trylock
);
1909 int is_console_locked(void)
1911 return console_locked
;
1915 * Delayed printk version, for scheduler-internal messages:
1917 #define PRINTK_BUF_SIZE 512
1919 #define PRINTK_PENDING_WAKEUP 0x01
1920 #define PRINTK_PENDING_SCHED 0x02
1922 static DEFINE_PER_CPU(int, printk_pending
);
1923 static DEFINE_PER_CPU(char [PRINTK_BUF_SIZE
], printk_sched_buf
);
1925 void printk_tick(void)
1927 if (__this_cpu_read(printk_pending
)) {
1928 int pending
= __this_cpu_xchg(printk_pending
, 0);
1929 if (pending
& PRINTK_PENDING_SCHED
) {
1930 char *buf
= __get_cpu_var(printk_sched_buf
);
1931 printk(KERN_WARNING
"[sched_delayed] %s", buf
);
1933 if (pending
& PRINTK_PENDING_WAKEUP
)
1934 wake_up_interruptible(&log_wait
);
1938 int printk_needs_cpu(int cpu
)
1940 if (cpu_is_offline(cpu
))
1942 return __this_cpu_read(printk_pending
);
1945 void wake_up_klogd(void)
1947 if (waitqueue_active(&log_wait
))
1948 this_cpu_or(printk_pending
, PRINTK_PENDING_WAKEUP
);
1951 /* the next printk record to write to the console */
1952 static u64 console_seq
;
1953 static u32 console_idx
;
1954 static enum log_flags console_prev
;
1957 * console_unlock - unlock the console system
1959 * Releases the console_lock which the caller holds on the console system
1960 * and the console driver list.
1962 * While the console_lock was held, console output may have been buffered
1963 * by printk(). If this is the case, console_unlock(); emits
1964 * the output prior to releasing the lock.
1966 * If there is output waiting, we wake /dev/kmsg and syslog() users.
1968 * console_unlock(); may be called from any context.
1970 void console_unlock(void)
1972 static char text
[LOG_LINE_MAX
+ PREFIX_MAX
];
1973 static u64 seen_seq
;
1974 unsigned long flags
;
1975 bool wake_klogd
= false;
1978 if (console_suspended
) {
1983 console_may_schedule
= 0;
1985 /* flush buffered message fragment immediately to console */
1986 raw_spin_lock_irqsave(&logbuf_lock
, flags
);
1987 if (cont
.len
&& (cont
.cons
< cont
.len
|| cont
.flushed
)) {
1990 len
= cont_print_text(text
, sizeof(text
));
1991 raw_spin_unlock(&logbuf_lock
);
1992 stop_critical_timings();
1993 call_console_drivers(cont
.level
, text
, len
);
1994 start_critical_timings();
1995 local_irq_restore(flags
);
1997 raw_spin_unlock_irqrestore(&logbuf_lock
, flags
);
2005 raw_spin_lock_irqsave(&logbuf_lock
, flags
);
2006 if (seen_seq
!= log_next_seq
) {
2008 seen_seq
= log_next_seq
;
2011 if (console_seq
< log_first_seq
) {
2012 /* messages are gone, move to first one */
2013 console_seq
= log_first_seq
;
2014 console_idx
= log_first_idx
;
2018 if (console_seq
== log_next_seq
)
2021 msg
= log_from_idx(console_idx
);
2022 if (msg
->flags
& LOG_NOCONS
) {
2024 * Skip record we have buffered and already printed
2025 * directly to the console when we received it.
2027 console_idx
= log_next(console_idx
);
2030 * We will get here again when we register a new
2031 * CON_PRINTBUFFER console. Clear the flag so we
2032 * will properly dump everything later.
2034 msg
->flags
&= ~LOG_NOCONS
;
2039 len
= msg_print_text(msg
, console_prev
, false,
2040 text
, sizeof(text
));
2041 console_idx
= log_next(console_idx
);
2043 console_prev
= msg
->flags
;
2044 raw_spin_unlock(&logbuf_lock
);
2046 stop_critical_timings(); /* don't trace print latency */
2047 call_console_drivers(level
, text
, len
);
2048 start_critical_timings();
2049 local_irq_restore(flags
);
2053 /* Release the exclusive_console once it is used */
2054 if (unlikely(exclusive_console
))
2055 exclusive_console
= NULL
;
2057 raw_spin_unlock(&logbuf_lock
);
2062 * Someone could have filled up the buffer again, so re-check if there's
2063 * something to flush. In case we cannot trylock the console_sem again,
2064 * there's a new owner and the console_unlock() from them will do the
2065 * flush, no worries.
2067 raw_spin_lock(&logbuf_lock
);
2068 retry
= console_seq
!= log_next_seq
;
2069 raw_spin_unlock_irqrestore(&logbuf_lock
, flags
);
2071 if (retry
&& console_trylock())
2077 EXPORT_SYMBOL(console_unlock
);
2080 * console_conditional_schedule - yield the CPU if required
2082 * If the console code is currently allowed to sleep, and
2083 * if this CPU should yield the CPU to another task, do
2086 * Must be called within console_lock();.
2088 void __sched
console_conditional_schedule(void)
2090 if (console_may_schedule
)
2093 EXPORT_SYMBOL(console_conditional_schedule
);
2095 void console_unblank(void)
2100 * console_unblank can no longer be called in interrupt context unless
2101 * oops_in_progress is set to 1..
2103 if (oops_in_progress
) {
2104 if (down_trylock(&console_sem
) != 0)
2110 console_may_schedule
= 0;
2112 if ((c
->flags
& CON_ENABLED
) && c
->unblank
)
2118 * Return the console tty driver structure and its associated index
2120 struct tty_driver
*console_device(int *index
)
2123 struct tty_driver
*driver
= NULL
;
2126 for_each_console(c
) {
2129 driver
= c
->device(c
, index
);
2138 * Prevent further output on the passed console device so that (for example)
2139 * serial drivers can disable console output before suspending a port, and can
2140 * re-enable output afterwards.
2142 void console_stop(struct console
*console
)
2145 console
->flags
&= ~CON_ENABLED
;
2148 EXPORT_SYMBOL(console_stop
);
2150 void console_start(struct console
*console
)
2153 console
->flags
|= CON_ENABLED
;
2156 EXPORT_SYMBOL(console_start
);
2158 static int __read_mostly keep_bootcon
;
2160 static int __init
keep_bootcon_setup(char *str
)
2163 printk(KERN_INFO
"debug: skip boot console de-registration.\n");
2168 early_param("keep_bootcon", keep_bootcon_setup
);
2171 * The console driver calls this routine during kernel initialization
2172 * to register the console printing procedure with printk() and to
2173 * print any messages that were printed by the kernel before the
2174 * console driver was initialized.
2176 * This can happen pretty early during the boot process (because of
2177 * early_printk) - sometimes before setup_arch() completes - be careful
2178 * of what kernel features are used - they may not be initialised yet.
2180 * There are two types of consoles - bootconsoles (early_printk) and
2181 * "real" consoles (everything which is not a bootconsole) which are
2182 * handled differently.
2183 * - Any number of bootconsoles can be registered at any time.
2184 * - As soon as a "real" console is registered, all bootconsoles
2185 * will be unregistered automatically.
2186 * - Once a "real" console is registered, any attempt to register a
2187 * bootconsoles will be rejected
2189 void register_console(struct console
*newcon
)
2192 unsigned long flags
;
2193 struct console
*bcon
= NULL
;
2196 * before we register a new CON_BOOT console, make sure we don't
2197 * already have a valid console
2199 if (console_drivers
&& newcon
->flags
& CON_BOOT
) {
2200 /* find the last or real console */
2201 for_each_console(bcon
) {
2202 if (!(bcon
->flags
& CON_BOOT
)) {
2203 printk(KERN_INFO
"Too late to register bootconsole %s%d\n",
2204 newcon
->name
, newcon
->index
);
2210 if (console_drivers
&& console_drivers
->flags
& CON_BOOT
)
2211 bcon
= console_drivers
;
2213 if (preferred_console
< 0 || bcon
|| !console_drivers
)
2214 preferred_console
= selected_console
;
2216 if (newcon
->early_setup
)
2217 newcon
->early_setup();
2220 * See if we want to use this console driver. If we
2221 * didn't select a console we take the first one
2222 * that registers here.
2224 if (preferred_console
< 0) {
2225 if (newcon
->index
< 0)
2227 if (newcon
->setup
== NULL
||
2228 newcon
->setup(newcon
, NULL
) == 0) {
2229 newcon
->flags
|= CON_ENABLED
;
2230 if (newcon
->device
) {
2231 newcon
->flags
|= CON_CONSDEV
;
2232 preferred_console
= 0;
2238 * See if this console matches one we selected on
2241 for (i
= 0; i
< MAX_CMDLINECONSOLES
&& console_cmdline
[i
].name
[0];
2243 if (strcmp(console_cmdline
[i
].name
, newcon
->name
) != 0)
2245 if (newcon
->index
>= 0 &&
2246 newcon
->index
!= console_cmdline
[i
].index
)
2248 if (newcon
->index
< 0)
2249 newcon
->index
= console_cmdline
[i
].index
;
2250 #ifdef CONFIG_A11Y_BRAILLE_CONSOLE
2251 if (console_cmdline
[i
].brl_options
) {
2252 newcon
->flags
|= CON_BRL
;
2253 braille_register_console(newcon
,
2254 console_cmdline
[i
].index
,
2255 console_cmdline
[i
].options
,
2256 console_cmdline
[i
].brl_options
);
2260 if (newcon
->setup
&&
2261 newcon
->setup(newcon
, console_cmdline
[i
].options
) != 0)
2263 newcon
->flags
|= CON_ENABLED
;
2264 newcon
->index
= console_cmdline
[i
].index
;
2265 if (i
== selected_console
) {
2266 newcon
->flags
|= CON_CONSDEV
;
2267 preferred_console
= selected_console
;
2272 if (!(newcon
->flags
& CON_ENABLED
))
2276 * If we have a bootconsole, and are switching to a real console,
2277 * don't print everything out again, since when the boot console, and
2278 * the real console are the same physical device, it's annoying to
2279 * see the beginning boot messages twice
2281 if (bcon
&& ((newcon
->flags
& (CON_CONSDEV
| CON_BOOT
)) == CON_CONSDEV
))
2282 newcon
->flags
&= ~CON_PRINTBUFFER
;
2285 * Put this console in the list - keep the
2286 * preferred driver at the head of the list.
2289 if ((newcon
->flags
& CON_CONSDEV
) || console_drivers
== NULL
) {
2290 newcon
->next
= console_drivers
;
2291 console_drivers
= newcon
;
2293 newcon
->next
->flags
&= ~CON_CONSDEV
;
2295 newcon
->next
= console_drivers
->next
;
2296 console_drivers
->next
= newcon
;
2298 if (newcon
->flags
& CON_PRINTBUFFER
) {
2300 * console_unlock(); will print out the buffered messages
2303 raw_spin_lock_irqsave(&logbuf_lock
, flags
);
2304 console_seq
= syslog_seq
;
2305 console_idx
= syslog_idx
;
2306 console_prev
= syslog_prev
;
2307 raw_spin_unlock_irqrestore(&logbuf_lock
, flags
);
2309 * We're about to replay the log buffer. Only do this to the
2310 * just-registered console to avoid excessive message spam to
2311 * the already-registered consoles.
2313 exclusive_console
= newcon
;
2316 console_sysfs_notify();
2319 * By unregistering the bootconsoles after we enable the real console
2320 * we get the "console xxx enabled" message on all the consoles -
2321 * boot consoles, real consoles, etc - this is to ensure that end
2322 * users know there might be something in the kernel's log buffer that
2323 * went to the bootconsole (that they do not see on the real console)
2326 ((newcon
->flags
& (CON_CONSDEV
| CON_BOOT
)) == CON_CONSDEV
) &&
2328 /* we need to iterate through twice, to make sure we print
2329 * everything out, before we unregister the console(s)
2331 printk(KERN_INFO
"console [%s%d] enabled, bootconsole disabled\n",
2332 newcon
->name
, newcon
->index
);
2333 for_each_console(bcon
)
2334 if (bcon
->flags
& CON_BOOT
)
2335 unregister_console(bcon
);
2337 printk(KERN_INFO
"%sconsole [%s%d] enabled\n",
2338 (newcon
->flags
& CON_BOOT
) ? "boot" : "" ,
2339 newcon
->name
, newcon
->index
);
2342 EXPORT_SYMBOL(register_console
);
2344 int unregister_console(struct console
*console
)
2346 struct console
*a
, *b
;
2349 #ifdef CONFIG_A11Y_BRAILLE_CONSOLE
2350 if (console
->flags
& CON_BRL
)
2351 return braille_unregister_console(console
);
2355 if (console_drivers
== console
) {
2356 console_drivers
=console
->next
;
2358 } else if (console_drivers
) {
2359 for (a
=console_drivers
->next
, b
=console_drivers
;
2360 a
; b
=a
, a
=b
->next
) {
2370 * If this isn't the last console and it has CON_CONSDEV set, we
2371 * need to set it on the next preferred console.
2373 if (console_drivers
!= NULL
&& console
->flags
& CON_CONSDEV
)
2374 console_drivers
->flags
|= CON_CONSDEV
;
2377 console_sysfs_notify();
2380 EXPORT_SYMBOL(unregister_console
);
2382 static int __init
printk_late_init(void)
2384 struct console
*con
;
2386 for_each_console(con
) {
2387 if (!keep_bootcon
&& con
->flags
& CON_BOOT
) {
2388 printk(KERN_INFO
"turn off boot console %s%d\n",
2389 con
->name
, con
->index
);
2390 unregister_console(con
);
2393 hotcpu_notifier(console_cpu_notify
, 0);
2396 late_initcall(printk_late_init
);
2398 #if defined CONFIG_PRINTK
2400 int printk_sched(const char *fmt
, ...)
2402 unsigned long flags
;
2407 local_irq_save(flags
);
2408 buf
= __get_cpu_var(printk_sched_buf
);
2410 va_start(args
, fmt
);
2411 r
= vsnprintf(buf
, PRINTK_BUF_SIZE
, fmt
, args
);
2414 __this_cpu_or(printk_pending
, PRINTK_PENDING_SCHED
);
2415 local_irq_restore(flags
);
2421 * printk rate limiting, lifted from the networking subsystem.
2423 * This enforces a rate limit: not more than 10 kernel messages
2424 * every 5s to make a denial-of-service attack impossible.
2426 DEFINE_RATELIMIT_STATE(printk_ratelimit_state
, 5 * HZ
, 10);
2428 int __printk_ratelimit(const char *func
)
2430 return ___ratelimit(&printk_ratelimit_state
, func
);
2432 EXPORT_SYMBOL(__printk_ratelimit
);
2435 * printk_timed_ratelimit - caller-controlled printk ratelimiting
2436 * @caller_jiffies: pointer to caller's state
2437 * @interval_msecs: minimum interval between prints
2439 * printk_timed_ratelimit() returns true if more than @interval_msecs
2440 * milliseconds have elapsed since the last time printk_timed_ratelimit()
2443 bool printk_timed_ratelimit(unsigned long *caller_jiffies
,
2444 unsigned int interval_msecs
)
2446 if (*caller_jiffies
== 0
2447 || !time_in_range(jiffies
, *caller_jiffies
,
2449 + msecs_to_jiffies(interval_msecs
))) {
2450 *caller_jiffies
= jiffies
;
2455 EXPORT_SYMBOL(printk_timed_ratelimit
);
2457 static DEFINE_SPINLOCK(dump_list_lock
);
2458 static LIST_HEAD(dump_list
);
2461 * kmsg_dump_register - register a kernel log dumper.
2462 * @dumper: pointer to the kmsg_dumper structure
2464 * Adds a kernel log dumper to the system. The dump callback in the
2465 * structure will be called when the kernel oopses or panics and must be
2466 * set. Returns zero on success and %-EINVAL or %-EBUSY otherwise.
2468 int kmsg_dump_register(struct kmsg_dumper
*dumper
)
2470 unsigned long flags
;
2473 /* The dump callback needs to be set */
2477 spin_lock_irqsave(&dump_list_lock
, flags
);
2478 /* Don't allow registering multiple times */
2479 if (!dumper
->registered
) {
2480 dumper
->registered
= 1;
2481 list_add_tail_rcu(&dumper
->list
, &dump_list
);
2484 spin_unlock_irqrestore(&dump_list_lock
, flags
);
2488 EXPORT_SYMBOL_GPL(kmsg_dump_register
);
2491 * kmsg_dump_unregister - unregister a kmsg dumper.
2492 * @dumper: pointer to the kmsg_dumper structure
2494 * Removes a dump device from the system. Returns zero on success and
2495 * %-EINVAL otherwise.
2497 int kmsg_dump_unregister(struct kmsg_dumper
*dumper
)
2499 unsigned long flags
;
2502 spin_lock_irqsave(&dump_list_lock
, flags
);
2503 if (dumper
->registered
) {
2504 dumper
->registered
= 0;
2505 list_del_rcu(&dumper
->list
);
2508 spin_unlock_irqrestore(&dump_list_lock
, flags
);
2513 EXPORT_SYMBOL_GPL(kmsg_dump_unregister
);
2515 static bool always_kmsg_dump
;
2516 module_param_named(always_kmsg_dump
, always_kmsg_dump
, bool, S_IRUGO
| S_IWUSR
);
2519 * kmsg_dump - dump kernel log to kernel message dumpers.
2520 * @reason: the reason (oops, panic etc) for dumping
2522 * Call each of the registered dumper's dump() callback, which can
2523 * retrieve the kmsg records with kmsg_dump_get_line() or
2524 * kmsg_dump_get_buffer().
2526 void kmsg_dump(enum kmsg_dump_reason reason
)
2528 struct kmsg_dumper
*dumper
;
2529 unsigned long flags
;
2531 if ((reason
> KMSG_DUMP_OOPS
) && !always_kmsg_dump
)
2535 list_for_each_entry_rcu(dumper
, &dump_list
, list
) {
2536 if (dumper
->max_reason
&& reason
> dumper
->max_reason
)
2539 /* initialize iterator with data about the stored records */
2540 dumper
->active
= true;
2542 raw_spin_lock_irqsave(&logbuf_lock
, flags
);
2543 dumper
->cur_seq
= clear_seq
;
2544 dumper
->cur_idx
= clear_idx
;
2545 dumper
->next_seq
= log_next_seq
;
2546 dumper
->next_idx
= log_next_idx
;
2547 raw_spin_unlock_irqrestore(&logbuf_lock
, flags
);
2549 /* invoke dumper which will iterate over records */
2550 dumper
->dump(dumper
, reason
);
2552 /* reset iterator */
2553 dumper
->active
= false;
2559 * kmsg_dump_get_line - retrieve one kmsg log line
2560 * @dumper: registered kmsg dumper
2561 * @syslog: include the "<4>" prefixes
2562 * @line: buffer to copy the line to
2563 * @size: maximum size of the buffer
2564 * @len: length of line placed into buffer
2566 * Start at the beginning of the kmsg buffer, with the oldest kmsg
2567 * record, and copy one record into the provided buffer.
2569 * Consecutive calls will return the next available record moving
2570 * towards the end of the buffer with the youngest messages.
2572 * A return value of FALSE indicates that there are no more records to
2575 bool kmsg_dump_get_line(struct kmsg_dumper
*dumper
, bool syslog
,
2576 char *line
, size_t size
, size_t *len
)
2578 unsigned long flags
;
2583 if (!dumper
->active
)
2586 raw_spin_lock_irqsave(&logbuf_lock
, flags
);
2587 if (dumper
->cur_seq
< log_first_seq
) {
2588 /* messages are gone, move to first available one */
2589 dumper
->cur_seq
= log_first_seq
;
2590 dumper
->cur_idx
= log_first_idx
;
2594 if (dumper
->cur_seq
>= log_next_seq
) {
2595 raw_spin_unlock_irqrestore(&logbuf_lock
, flags
);
2599 msg
= log_from_idx(dumper
->cur_idx
);
2600 l
= msg_print_text(msg
, 0, syslog
, line
, size
);
2602 dumper
->cur_idx
= log_next(dumper
->cur_idx
);
2605 raw_spin_unlock_irqrestore(&logbuf_lock
, flags
);
2611 EXPORT_SYMBOL_GPL(kmsg_dump_get_line
);
2614 * kmsg_dump_get_buffer - copy kmsg log lines
2615 * @dumper: registered kmsg dumper
2616 * @syslog: include the "<4>" prefixes
2617 * @buf: buffer to copy the line to
2618 * @size: maximum size of the buffer
2619 * @len: length of line placed into buffer
2621 * Start at the end of the kmsg buffer and fill the provided buffer
2622 * with as many of the the *youngest* kmsg records that fit into it.
2623 * If the buffer is large enough, all available kmsg records will be
2624 * copied with a single call.
2626 * Consecutive calls will fill the buffer with the next block of
2627 * available older records, not including the earlier retrieved ones.
2629 * A return value of FALSE indicates that there are no more records to
2632 bool kmsg_dump_get_buffer(struct kmsg_dumper
*dumper
, bool syslog
,
2633 char *buf
, size_t size
, size_t *len
)
2635 unsigned long flags
;
2640 enum log_flags prev
;
2644 if (!dumper
->active
)
2647 raw_spin_lock_irqsave(&logbuf_lock
, flags
);
2648 if (dumper
->cur_seq
< log_first_seq
) {
2649 /* messages are gone, move to first available one */
2650 dumper
->cur_seq
= log_first_seq
;
2651 dumper
->cur_idx
= log_first_idx
;
2655 if (dumper
->cur_seq
>= dumper
->next_seq
) {
2656 raw_spin_unlock_irqrestore(&logbuf_lock
, flags
);
2660 /* calculate length of entire buffer */
2661 seq
= dumper
->cur_seq
;
2662 idx
= dumper
->cur_idx
;
2664 while (seq
< dumper
->next_seq
) {
2665 struct log
*msg
= log_from_idx(idx
);
2667 l
+= msg_print_text(msg
, prev
, true, NULL
, 0);
2668 idx
= log_next(idx
);
2673 /* move first record forward until length fits into the buffer */
2674 seq
= dumper
->cur_seq
;
2675 idx
= dumper
->cur_idx
;
2677 while (l
> size
&& seq
< dumper
->next_seq
) {
2678 struct log
*msg
= log_from_idx(idx
);
2680 l
-= msg_print_text(msg
, prev
, true, NULL
, 0);
2681 idx
= log_next(idx
);
2686 /* last message in next interation */
2692 while (seq
< dumper
->next_seq
) {
2693 struct log
*msg
= log_from_idx(idx
);
2695 l
+= msg_print_text(msg
, prev
, syslog
, buf
+ l
, size
- l
);
2696 idx
= log_next(idx
);
2701 dumper
->next_seq
= next_seq
;
2702 dumper
->next_idx
= next_idx
;
2704 raw_spin_unlock_irqrestore(&logbuf_lock
, flags
);
2710 EXPORT_SYMBOL_GPL(kmsg_dump_get_buffer
);
2713 * kmsg_dump_rewind - reset the interator
2714 * @dumper: registered kmsg dumper
2716 * Reset the dumper's iterator so that kmsg_dump_get_line() and
2717 * kmsg_dump_get_buffer() can be called again and used multiple
2718 * times within the same dumper.dump() callback.
2720 void kmsg_dump_rewind(struct kmsg_dumper
*dumper
)
2722 unsigned long flags
;
2724 raw_spin_lock_irqsave(&logbuf_lock
, flags
);
2725 dumper
->cur_seq
= clear_seq
;
2726 dumper
->cur_idx
= clear_idx
;
2727 dumper
->next_seq
= log_next_seq
;
2728 dumper
->next_idx
= log_next_idx
;
2729 raw_spin_unlock_irqrestore(&logbuf_lock
, flags
);
2731 EXPORT_SYMBOL_GPL(kmsg_dump_rewind
);