Lines Matching +full:console +full:- +full:size

1 // SPDX-License-Identifier: GPL-2.0-only
10 * to the console. Added hook for sending the console messages
11 * elsewhere, in preparation for a serial line console (someday).
26 #include <linux/console.h>
83 * provides serialisation for access to the entire console
87 struct console *console_drivers;
98 * panic and risk deadlock on console resources.
130 return -EINVAL; in __control_devkmsg()
150 return -EINVAL; in __control_devkmsg()
192 return -EINVAL; in devkmsg_sysctl_set_loglvl()
215 return -EINVAL; in devkmsg_sysctl_set_loglvl()
239 * because spindump/WARN/etc from under console ->lock will in __down_trylock_console_sem()
240 * deadlock in printk()->down_trylock_console_sem() otherwise. in __down_trylock_console_sem()
272 * keeping track if we have the console semaphore held. It's
275 * paths in the console code where we end up in places I want
276 * locked without the console semaphore held).
281 * Array of consoles built from command line options (console=)
288 static int preferred_console = -1;
292 /* Flag: console code may call schedule() */
305 * own meta-data (@info).
307 * Every record meta-data carries the timestamp in microseconds, as well as
309 * messages use LOG_KERN; userspace-injected messages always carry a matching
318 * pairs), to provide userspace with a machine-readable message context.
320 * Examples for well-defined, commonly used property names are:
326 * SUBSYSTEM=pci driver-core subsystem name
328 * Valid characters in property names are [a-zA-Z0-9.-_]. Property names
344 * userspace, it is a kernel-private implementation detail that might
355 * non-prinatable characters are escaped in the "\xff" notation.
391 /* the maximum size of a formatted record (i.e. with prefix added per line) */
394 /* the maximum size for a dropped text message */
397 /* the maximum size allowed to be reserved for a record */
398 #define LOG_LINE_MAX (CONSOLE_LOG_MAX - PREFIX_MAX)
412 * Define the average message size. This only affects the number of
421 _DEFINE_PRINTKRB(printk_rb_static, CONFIG_LOG_BUF_SHIFT - PRB_AVGBITS,
429 * We cannot access per-CPU data (e.g. per-CPU flush irq_work) before
431 * it's safe to access per-CPU data.
443 raw_write_seqcount_latch(&ls->latch); in latched_seq_write()
444 ls->val[0] = val; in latched_seq_write()
445 raw_write_seqcount_latch(&ls->latch); in latched_seq_write()
446 ls->val[1] = val; in latched_seq_write()
457 seq = raw_read_seqcount_latch(&ls->latch); in latched_seq_read_nolock()
459 val = ls->val[idx]; in latched_seq_read_nolock()
460 } while (read_seqcount_latch_retry(&ls->latch, seq)); in latched_seq_read_nolock()
471 /* Return log buffer size */
499 *text_len -= *trunc_msg_len; in truncate_msg()
511 * Unless restricted, we allow "read all" and "get buffer size" in syslog_action_restricted()
538 current->comm, task_pid_nr(current)); in check_syslog_permissions()
541 return -EPERM; in check_syslog_permissions()
553 static ssize_t info_print_ext_header(char *buf, size_t size, in info_print_ext_header() argument
556 u64 ts_usec = info->ts_nsec; in info_print_ext_header()
559 u32 id = info->caller_id; in info_print_ext_header()
569 return scnprintf(buf, size, "%u,%llu,%llu,%c%s;", in info_print_ext_header()
570 (info->facility << 3) | info->level, info->seq, in info_print_ext_header()
571 ts_usec, info->flags & LOG_CONT ? 'c' : '-', caller); in info_print_ext_header()
574 static ssize_t msg_add_ext_text(char *buf, size_t size, in msg_add_ext_text() argument
578 char *p = buf, *e = buf + size; in msg_add_ext_text()
581 /* escape non-printable characters */ in msg_add_ext_text()
586 p += scnprintf(p, e - p, "\\x%02x", c); in msg_add_ext_text()
592 return p - buf; in msg_add_ext_text()
595 static ssize_t msg_add_dict_text(char *buf, size_t size, in msg_add_dict_text() argument
604 len = msg_add_ext_text(buf, size, "", 0, ' '); /* dict prefix */ in msg_add_dict_text()
605 len += msg_add_ext_text(buf + len, size - len, key, strlen(key), '='); in msg_add_dict_text()
606 len += msg_add_ext_text(buf + len, size - len, val, val_len, '\n'); in msg_add_dict_text()
611 static ssize_t msg_print_ext_body(char *buf, size_t size, in msg_print_ext_body() argument
617 len = msg_add_ext_text(buf, size, text, text_len, '\n'); in msg_print_ext_body()
622 len += msg_add_dict_text(buf + len, size - len, "SUBSYSTEM", in msg_print_ext_body()
623 dev_info->subsystem); in msg_print_ext_body()
624 len += msg_add_dict_text(buf + len, size - len, "DEVICE", in msg_print_ext_body()
625 dev_info->device); in msg_print_ext_body()
630 /* /dev/kmsg - userspace message inject/listen interface */
660 struct file *file = iocb->ki_filp; in devkmsg_write()
661 struct devkmsg_user *user = file->private_data; in devkmsg_write()
666 return -EINVAL; in devkmsg_write()
674 if (!___ratelimit(&user->rs, current->comm)) in devkmsg_write()
680 return -ENOMEM; in devkmsg_write()
685 return -EFAULT; in devkmsg_write()
689 * Extract and skip the syslog prefix <[0-9]*>. Coming from userspace in devkmsg_write()
695 * kernel-generated messages from userspace-injected ones. in devkmsg_write()
720 struct devkmsg_user *user = file->private_data; in devkmsg_read()
721 struct printk_record *r = &user->record; in devkmsg_read()
726 return -EBADF; in devkmsg_read()
728 ret = mutex_lock_interruptible(&user->lock); in devkmsg_read()
732 if (!prb_read_valid(prb, atomic64_read(&user->seq), r)) { in devkmsg_read()
733 if (file->f_flags & O_NONBLOCK) { in devkmsg_read()
734 ret = -EAGAIN; in devkmsg_read()
750 atomic64_read(&user->seq), r)); /* LMM(devkmsg_read:A) */ in devkmsg_read()
755 if (r->info->seq != atomic64_read(&user->seq)) { in devkmsg_read()
757 atomic64_set(&user->seq, r->info->seq); in devkmsg_read()
758 ret = -EPIPE; in devkmsg_read()
762 len = info_print_ext_header(user->buf, sizeof(user->buf), r->info); in devkmsg_read()
763 len += msg_print_ext_body(user->buf + len, sizeof(user->buf) - len, in devkmsg_read()
764 &r->text_buf[0], r->info->text_len, in devkmsg_read()
765 &r->info->dev_info); in devkmsg_read()
767 atomic64_set(&user->seq, r->info->seq + 1); in devkmsg_read()
770 ret = -EINVAL; in devkmsg_read()
774 if (copy_to_user(buf, user->buf, len)) { in devkmsg_read()
775 ret = -EFAULT; in devkmsg_read()
780 mutex_unlock(&user->lock); in devkmsg_read()
788 * entire variable length messages (records). Non-standard values are
794 struct devkmsg_user *user = file->private_data; in devkmsg_llseek()
798 return -EBADF; in devkmsg_llseek()
800 return -ESPIPE; in devkmsg_llseek()
805 atomic64_set(&user->seq, prb_first_valid_seq(prb)); in devkmsg_llseek()
810 * like issued by 'dmesg -c'. Reading /dev/kmsg itself in devkmsg_llseek()
813 atomic64_set(&user->seq, latched_seq_read_nolock(&clear_seq)); in devkmsg_llseek()
817 atomic64_set(&user->seq, prb_next_seq(prb)); in devkmsg_llseek()
820 ret = -EINVAL; in devkmsg_llseek()
827 struct devkmsg_user *user = file->private_data; in devkmsg_poll()
836 if (prb_read_valid_info(prb, atomic64_read(&user->seq), &info, NULL)) { in devkmsg_poll()
838 if (info.seq != atomic64_read(&user->seq)) in devkmsg_poll()
853 return -EPERM; in devkmsg_open()
855 /* write-only does not need any file context */ in devkmsg_open()
856 if ((file->f_flags & O_ACCMODE) != O_WRONLY) { in devkmsg_open()
865 return -ENOMEM; in devkmsg_open()
867 ratelimit_default_init(&user->rs); in devkmsg_open()
868 ratelimit_set_flags(&user->rs, RATELIMIT_MSG_ON_RELEASE); in devkmsg_open()
870 mutex_init(&user->lock); in devkmsg_open()
872 prb_rec_init_rd(&user->record, &user->info, in devkmsg_open()
873 &user->text_buf[0], sizeof(user->text_buf)); in devkmsg_open()
875 atomic64_set(&user->seq, prb_first_valid_seq(prb)); in devkmsg_open()
877 file->private_data = user; in devkmsg_open()
883 struct devkmsg_user *user = file->private_data; in devkmsg_release()
888 ratelimit_state_exit(&user->rs); in devkmsg_release()
890 mutex_destroy(&user->lock); in devkmsg_release()
922 * Export struct size and field offsets. User space tools can in log_buf_vmcoreinfo_setup()
955 VMCOREINFO_LENGTH(printk_info_subsystem, sizeof(dev_info->subsystem)); in log_buf_vmcoreinfo_setup()
957 VMCOREINFO_LENGTH(printk_info_device, sizeof(dev_info->device)); in log_buf_vmcoreinfo_setup()
977 static void __init log_buf_len_update(u64 size) in log_buf_len_update() argument
979 if (size > (u64)LOG_BUF_LEN_MAX) { in log_buf_len_update()
980 size = (u64)LOG_BUF_LEN_MAX; in log_buf_len_update()
984 if (size) in log_buf_len_update()
985 size = roundup_pow_of_two(size); in log_buf_len_update()
986 if (size > log_buf_len) in log_buf_len_update()
987 new_log_buf_len = (unsigned long)size; in log_buf_len_update()
993 u64 size; in log_buf_len_setup() local
996 return -EINVAL; in log_buf_len_setup()
998 size = memparse(str, &str); in log_buf_len_setup()
1000 log_buf_len_update(size); in log_buf_len_setup()
1021 cpu_extra = (num_possible_cpus() - 1) * __LOG_CPU_MAX_BUF_LEN; in log_buf_add_cpu()
1031 pr_info("log_buf_len min size: %d bytes\n", __LOG_BUF_LEN); in log_buf_add_cpu()
1050 prb_rec_init_wr(&dest_r, r->info->text_len); in add_to_rb()
1055 memcpy(&dest_r.text_buf[0], &r->text_buf[0], r->info->text_len); in add_to_rb()
1056 dest_r.info->text_len = r->info->text_len; in add_to_rb()
1057 dest_r.info->facility = r->info->facility; in add_to_rb()
1058 dest_r.info->level = r->info->level; in add_to_rb()
1059 dest_r.info->flags = r->info->flags; in add_to_rb()
1060 dest_r.info->ts_nsec = r->info->ts_nsec; in add_to_rb()
1061 dest_r.info->caller_id = r->info->caller_id; in add_to_rb()
1062 memcpy(&dest_r.info->dev_info, &r->info->dev_info, sizeof(dest_r.info->dev_info)); in add_to_rb()
1087 * Some archs call setup_log_buf() multiple times - first is very in setup_log_buf()
1088 * early, e.g. from setup_arch(), and second - when percpu_areas in setup_log_buf()
1151 free -= text_size; in setup_log_buf()
1168 free -= text_size; in setup_log_buf()
1173 prb_next_seq(&printk_rb_static) - seq); in setup_log_buf()
1200 "ignore loglevel setting (prints all kernel messages to the console)");
1244 k--; in boot_delay_msec()
1297 len = print_syslog((info->facility << 3) | info->level, buf); in info_print_prefix()
1300 len += print_time(info->ts_nsec, buf + len); in info_print_prefix()
1302 len += print_caller(info->caller_id, buf + len); in info_print_prefix()
1317 * - Add prefix for each line.
1318 * - Drop truncated lines that no longer fit into the buffer.
1319 * - Add the trailing newline that has been removed in vprintk_store().
1320 * - Add a string terminator.
1323 * return value is @r->text_buf_size - 1;
1332 size_t text_len = r->info->text_len; in record_print_text()
1333 size_t buf_size = r->text_buf_size; in record_print_text()
1334 char *text = r->text_buf; in record_print_text()
1349 prefix_len = info_print_prefix(r->info, syslog, time, prefix); in record_print_text()
1355 * @len: number of bytes prepared in r->text_buf in record_print_text()
1360 line_len = next - text; in record_print_text()
1377 text_len = buf_size - len - prefix_len - 1 - 1; in record_print_text()
1416 text_len -= line_len + 1; in record_print_text()
1425 r->text_buf[len] = 0; in record_print_text()
1444 return ((prefix_len * line_count) + info->text_len + 1); in get_record_print_text_size()
1449 * records up to (but not including) @max_seq fit into @size.
1452 * does not require an upper bound, -1 can be used for @max_seq.
1454 static u64 find_first_fitting_seq(u64 start_seq, u64 max_seq, size_t size, in find_first_fitting_seq() argument
1462 /* Determine the size of the records up to @max_seq. */ in find_first_fitting_seq()
1483 if (len <= size || info.seq >= max_seq) in find_first_fitting_seq()
1485 len -= get_record_print_text_size(&info, line_count, syslog, time); in find_first_fitting_seq()
1491 /* The caller is responsible for making sure @size is greater than 0. */
1492 static int syslog_print(char __user *buf, int size) in syslog_print() argument
1502 return -ENOMEM; in syslog_print()
1546 if (r.info->seq != syslog_seq) { in syslog_print()
1548 syslog_seq = r.info->seq; in syslog_print()
1561 if (n - syslog_partial <= size) { in syslog_print()
1563 syslog_seq = r.info->seq + 1; in syslog_print()
1564 n -= syslog_partial; in syslog_print()
1568 n = size; in syslog_print()
1582 len = -EFAULT; in syslog_print()
1587 size -= n; in syslog_print()
1589 } while (size); in syslog_print()
1596 static int syslog_print_all(char __user *buf, int size, bool clear) in syslog_print_all() argument
1607 return -ENOMEM; in syslog_print_all()
1612 * into the user-provided buffer for this dump. in syslog_print_all()
1614 seq = find_first_fitting_seq(latched_seq_read_nolock(&clear_seq), -1, in syslog_print_all()
1615 size, true, time); in syslog_print_all()
1625 if (len + textlen > size) { in syslog_print_all()
1626 seq--; in syslog_print_all()
1631 len = -EFAULT; in syslog_print_all()
1674 return -EINVAL; in do_syslog()
1678 return -EFAULT; in do_syslog()
1688 return -EINVAL; in do_syslog()
1692 return -EFAULT; in do_syslog()
1699 /* Disable logging to console */ in do_syslog()
1705 /* Enable logging to console */ in do_syslog()
1712 /* Set level of messages printed to console */ in do_syslog()
1715 return -EINVAL; in do_syslog()
1719 /* Implicitly re-enable logging to console */ in do_syslog()
1737 * Short-cut for poll(/"proc/kmsg") which simply checks in do_syslog()
1738 * for pending data, not the size; return the count of in do_syslog()
1741 error = prb_next_seq(prb) - syslog_seq; in do_syslog()
1753 error -= syslog_partial; in do_syslog()
1757 /* Size of the log buffer */ in do_syslog()
1762 error = -EINVAL; in do_syslog()
1775 * Special console_lock variants that help to reduce the risk of soft-lockups.
1790 * console_lock_spinning_enable - mark beginning of code where another
1809 * console_lock_spinning_disable_and_check - mark end of code where another
1851 * console_trylock_spinning - try to get console_lock by busy waiting
1914 * The owner passed the console lock to us. in console_trylock_spinning()
1915 * Since we did not spin on console lock, annotate in console_trylock_spinning()
1925 * Call the specified console driver, asking it to write out the specified
1926 * text and length. If @dropped_text is non-NULL and any records have been
1929 static void call_console_driver(struct console *con, const char *text, size_t len, in call_console_driver()
1934 if (con->dropped && dropped_text) { in call_console_driver()
1937 con->dropped); in call_console_driver()
1938 con->dropped = 0; in call_console_driver()
1939 con->write(con, dropped_text, dropped_len); in call_console_driver()
1942 con->write(con, text, len); in call_console_driver()
1947 * additional NMI context per CPU is also separately tracked. Until per-CPU
1960 * a WARN), but a higher value is used in case some printk-internal errors
2011 (*(recursion_ptr))--; \
2024 while (m--) { in printk_delay()
2038 * printk_parse_prefix - Parse level and control flags.
2068 *level = kern_level - '0'; in printk_parse_prefix()
2083 static u16 printk_sprint(char *text, u16 size, int facility, in printk_sprint() argument
2089 text_len = vscnprintf(text, size, fmt, args); in printk_sprint()
2092 if (text_len && text[text_len - 1] == '\n') { in printk_sprint()
2093 text_len--; in printk_sprint()
2103 text_len -= prefix_len; in printk_sprint()
2171 text_len = printk_sprint(&r.text_buf[r.info->text_len], reserve_size, in vprintk_store()
2173 r.info->text_len += text_len; in vprintk_store()
2176 r.info->flags |= LOG_NEWLINE; in vprintk_store()
2206 r.info->text_len = text_len + trunc_msg_len; in vprintk_store()
2207 r.info->facility = facility; in vprintk_store()
2208 r.info->level = level & 7; in vprintk_store()
2209 r.info->flags = flags & 0x1f; in vprintk_store()
2210 r.info->ts_nsec = ts_nsec; in vprintk_store()
2211 r.info->caller_id = caller_id; in vprintk_store()
2213 memcpy(&r.info->dev_info, dev_info, sizeof(r.info->dev_info)); in vprintk_store()
2254 * The caller may be holding system-critical or in vprintk_emit()
2255 * timing-sensitive locks. Disable preemption during in vprintk_emit()
2262 * Try to acquire and then immediately release the console in vprintk_emit()
2297 static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress);
2316 static ssize_t info_print_ext_header(char *buf, size_t size, in info_print_ext_header() argument
2321 static ssize_t msg_print_ext_body(char *buf, size_t size, in msg_print_ext_body() argument
2326 static void call_console_driver(struct console *con, const char *text, size_t len, in call_console_driver()
2332 static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress) { return true; } in __pr_flush()
2337 struct console *early_console;
2352 early_console->write(early_console, buf, n); in early_printk()
2362 * @c console was defined by the user on the command line. in set_user_specified()
2365 c->user_specified = true; in set_user_specified()
2366 /* At least one console defined by the user on the command line. */ in set_user_specified()
2381 i < MAX_CMDLINECONSOLES && c->name[0]; in __add_preferred_console()
2383 if (strcmp(c->name, name) == 0 && c->index == idx) { in __add_preferred_console()
2391 return -E2BIG; in __add_preferred_console()
2394 strlcpy(c->name, name, sizeof(c->name)); in __add_preferred_console()
2395 c->options = options; in __add_preferred_console()
2399 c->index = idx; in __add_preferred_console()
2414 * Set up a console. Called via do_early_param() in init/main.c
2415 * for each "console=" parameter in the boot command line.
2424 * console="" or console=null have been suggested as a way to in console_setup()
2425 * disable console output. Use ttynull that has been created in console_setup()
2441 strncpy(buf + 4, str, sizeof(buf) - 5); in console_setup()
2443 strncpy(buf, str, sizeof(buf) - 1); in console_setup()
2445 buf[sizeof(buf) - 1] = 0; in console_setup()
2464 __setup("console=", console_setup);
2467 * add_preferred_console - add a device to the list of preferred consoles.
2470 * @options: options for this console
2472 * The last preferred console added will be used for kernel messages
2474 * above to handle user-supplied console arguments; however it can also
2475 * be used by arch-specific code either to override the user or more
2476 * commonly to provide a default console (ie from PROM variables) when
2495 MODULE_PARM_DESC(console_suspend, "suspend console during suspend"
2508 MODULE_PARM_DESC(console_no_auto_verbose, "Disable console loglevel raise to highest on oops/panic/…
2511 * suspend_console - suspend the console subsystem
2519 pr_info("Suspending console(s) (use no_console_suspend to debug)\n"); in suspend_console()
2537 * console_cpu_notify - print deferred console messages after CPU hotplug
2541 * will be printed on the console only if there are CON_ANYTIME consoles.
2556 * console_lock - lock the console system for exclusive use.
2559 * exclusive access to the console system and the console_drivers list.
2576 * console_trylock - try to lock the console system for exclusive use.
2579 * access to the console system and the console_drivers list.
2605 * messages to the console. This reduces the chance that the console is
2623 * Check if the given console is currently capable and allowed to print
2628 static inline bool console_is_usable(struct console *con) in console_is_usable()
2630 if (!(con->flags & CON_ENABLED)) in console_is_usable()
2633 if (!con->write) in console_is_usable()
2637 * Console drivers may assume that per-cpu resources have been in console_is_usable()
2642 !(con->flags & CON_ANYTIME)) in console_is_usable()
2655 * Print one record for the given console. The record printed is whatever
2656 * record is the next available record for the given console.
2658 * @text is a buffer of size CONSOLE_LOG_MAX.
2660 * If extended messages should be printed, @ext_text is a buffer of size
2663 * If dropped messages should be printed, @dropped_text is a buffer of size
2670 * Returns false if the given console has no next record to print, otherwise
2675 static bool console_emit_next_record(struct console *con, char *text, char *ext_text, in console_emit_next_record()
2689 if (!prb_read_valid(prb, con->seq, &r)) in console_emit_next_record()
2692 if (con->seq != r.info->seq) { in console_emit_next_record()
2693 con->dropped += r.info->seq - con->seq; in console_emit_next_record()
2694 con->seq = r.info->seq; in console_emit_next_record()
2697 …pr_warn_once("Too many dropped messages. Suppress messages on non-panic CPUs to prevent livelock.\… in console_emit_next_record()
2701 /* Skip record that has level above the console loglevel. */ in console_emit_next_record()
2702 if (suppress_message_printing(r.info->level)) { in console_emit_next_record()
2703 con->seq++; in console_emit_next_record()
2710 len += msg_print_ext_body(ext_text + len, CONSOLE_EXT_LOG_MAX - len, in console_emit_next_record()
2711 &r.text_buf[0], r.info->text_len, &r.info->dev_info); in console_emit_next_record()
2734 con->seq++; in console_emit_next_record()
2756 * Returns true when there was at least one usable console and all messages
2771 struct console *con; in console_flush_all()
2787 if (con->flags & CON_EXTENDED) { in console_flush_all()
2801 if (con->seq > *next_seq) in console_flush_all()
2802 *next_seq = con->seq; in console_flush_all()
2821 * console_unlock - unlock the console system
2823 * Releases the console_lock which the caller holds on the console system
2824 * and the console driver list.
2826 * While the console_lock was held, console output may have been buffered
2845 * Console drivers are called with interrupts disabled, so in console_unlock()
2848 * console registration path, and should invoke cond_resched() in console_unlock()
2850 * scheduling stall on a slow console leading to RCU stall and in console_unlock()
2875 * console_flush_all() but before unlocking the console. in console_unlock()
2876 * Re-check if there is a new record to flush. If the trylock in console_unlock()
2884 * console_conditional_schedule - yield the CPU if required
2886 * If the console code is currently allowed to sleep, and
2901 struct console *c; in console_unblank()
2916 if ((c->flags & CON_ENABLED) && c->unblank) in console_unblank()
2917 c->unblank(); in console_unblank()
2925 * console_flush_on_panic - flush console content on panic
2933 * If someone else is holding the console lock, trylock will fail in console_flush_on_panic()
2943 struct console *c; in console_flush_on_panic()
2948 c->seq = seq; in console_flush_on_panic()
2954 * Return the console tty driver structure and its associated index
2958 struct console *c; in console_device()
2963 if (!c->device) in console_device()
2965 driver = c->device(c, index); in console_device()
2974 * Prevent further output on the passed console device so that (for example)
2975 * serial drivers can disable console output before suspending a port, and can
2976 * re-enable output afterwards.
2978 void console_stop(struct console *console) in console_stop() argument
2980 __pr_flush(console, 1000, true); in console_stop()
2982 console->flags &= ~CON_ENABLED; in console_stop()
2987 void console_start(struct console *console) in console_start() argument
2990 console->flags |= CON_ENABLED; in console_start()
2992 __pr_flush(console, 1000, true); in console_start()
3001 pr_info("debug: skip boot console de-registration.\n"); in keep_bootcon_setup()
3010 * the newly registered console with any of the ones selected
3017 static int try_enable_preferred_console(struct console *newcon, in try_enable_preferred_console()
3024 i < MAX_CMDLINECONSOLES && c->name[0]; in try_enable_preferred_console()
3026 if (c->user_specified != user_specified) in try_enable_preferred_console()
3028 if (!newcon->match || in try_enable_preferred_console()
3029 newcon->match(newcon, c->name, c->index, c->options) != 0) { in try_enable_preferred_console()
3031 BUILD_BUG_ON(sizeof(c->name) != sizeof(newcon->name)); in try_enable_preferred_console()
3032 if (strcmp(c->name, newcon->name) != 0) in try_enable_preferred_console()
3034 if (newcon->index >= 0 && in try_enable_preferred_console()
3035 newcon->index != c->index) in try_enable_preferred_console()
3037 if (newcon->index < 0) in try_enable_preferred_console()
3038 newcon->index = c->index; in try_enable_preferred_console()
3043 if (newcon->setup && in try_enable_preferred_console()
3044 (err = newcon->setup(newcon, c->options)) != 0) in try_enable_preferred_console()
3047 newcon->flags |= CON_ENABLED; in try_enable_preferred_console()
3049 newcon->flags |= CON_CONSDEV; in try_enable_preferred_console()
3055 * without matching. Accept the pre-enabled consoles only when match() in try_enable_preferred_console()
3058 if (newcon->flags & CON_ENABLED && c->user_specified == user_specified) in try_enable_preferred_console()
3061 return -ENOENT; in try_enable_preferred_console()
3064 /* Try to enable the console unconditionally */
3065 static void try_enable_default_console(struct console *newcon) in try_enable_default_console()
3067 if (newcon->index < 0) in try_enable_default_console()
3068 newcon->index = 0; in try_enable_default_console()
3070 if (newcon->setup && newcon->setup(newcon, NULL) != 0) in try_enable_default_console()
3073 newcon->flags |= CON_ENABLED; in try_enable_default_console()
3075 if (newcon->device) in try_enable_default_console()
3076 newcon->flags |= CON_CONSDEV; in try_enable_default_console()
3081 (con->flags & CON_BOOT) ? "boot" : "", \
3082 con->name, con->index, ##__VA_ARGS__)
3085 * The console driver calls this routine during kernel initialization
3086 * to register the console printing procedure with printk() and to
3088 * console driver was initialized.
3091 * early_printk) - sometimes before setup_arch() completes - be careful
3092 * of what kernel features are used - they may not be initialised yet.
3094 * There are two types of consoles - bootconsoles (early_printk) and
3097 * - Any number of bootconsoles can be registered at any time.
3098 * - As soon as a "real" console is registered, all bootconsoles
3100 * - Once a "real" console is registered, any attempt to register a
3103 void register_console(struct console *newcon) in register_console()
3105 struct console *con; in register_console()
3111 if (WARN(con == newcon, "console '%s%d' already registered\n", in register_console()
3112 con->name, con->index)) in register_console()
3117 if (con->flags & CON_BOOT) in register_console()
3124 if (newcon->flags & CON_BOOT && realcon_enabled) { in register_console()
3126 newcon->name, newcon->index); in register_console()
3131 * See if we want to enable this console driver by default. in register_console()
3133 * Nope when a console is preferred by the command line, device in register_console()
3136 * The first real console with tty binding (driver) wins. More in register_console()
3139 * Note that a console with tty binding will have CON_CONSDEV in register_console()
3143 if (!console_drivers || !console_drivers->device || in register_console()
3144 console_drivers->flags & CON_BOOT) { in register_console()
3149 /* See if this console matches one we selected on the command line */ in register_console()
3153 if (err == -ENOENT) in register_console()
3156 /* printk() messages are not printed to the Braille console. */ in register_console()
3157 if (err || newcon->flags & CON_BRL) in register_console()
3161 * If we have a bootconsole, and are switching to a real console, in register_console()
3162 * don't print everything out again, since when the boot console, and in register_console()
3163 * the real console are the same physical device, it's annoying to in register_console()
3167 ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV)) { in register_console()
3168 newcon->flags &= ~CON_PRINTBUFFER; in register_console()
3172 * Put this console in the list - keep the in register_console()
3176 if ((newcon->flags & CON_CONSDEV) || console_drivers == NULL) { in register_console()
3177 newcon->next = console_drivers; in register_console()
3179 if (newcon->next) in register_console()
3180 newcon->next->flags &= ~CON_CONSDEV; in register_console()
3182 newcon->flags |= CON_CONSDEV; in register_console()
3184 newcon->next = console_drivers->next; in register_console()
3185 console_drivers->next = newcon; in register_console()
3188 newcon->dropped = 0; in register_console()
3189 if (newcon->flags & CON_PRINTBUFFER) { in register_console()
3192 newcon->seq = syslog_seq; in register_console()
3196 newcon->seq = prb_next_seq(prb); in register_console()
3202 * By unregistering the bootconsoles after we enable the real console in register_console()
3203 * we get the "console xxx enabled" message on all the consoles - in register_console()
3204 * boot consoles, real consoles, etc - this is to ensure that end in register_console()
3206 * went to the bootconsole (that they do not see on the real console) in register_console()
3210 ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV) && in register_console()
3213 if (con->flags & CON_BOOT) in register_console()
3219 int unregister_console(struct console *console) in unregister_console() argument
3221 struct console *con; in unregister_console()
3224 con_printk(KERN_INFO, console, "disabled\n"); in unregister_console()
3226 res = _braille_unregister_console(console); in unregister_console()
3232 res = -ENODEV; in unregister_console()
3234 if (console_drivers == console) { in unregister_console()
3235 console_drivers=console->next; in unregister_console()
3239 if (con->next == console) { in unregister_console()
3240 con->next = console->next; in unregister_console()
3251 * If this isn't the last console and it has CON_CONSDEV set, we in unregister_console()
3252 * need to set it on the next preferred console. in unregister_console()
3254 if (console_drivers != NULL && console->flags & CON_CONSDEV) in unregister_console()
3255 console_drivers->flags |= CON_CONSDEV; in unregister_console()
3257 console->flags &= ~CON_ENABLED; in unregister_console()
3261 if (console->exit) in unregister_console()
3262 res = console->exit(console); in unregister_console()
3267 console->flags &= ~CON_ENABLED; in unregister_console()
3275 * Initialize the console device. This is called *early*, so
3290 * set up the console device so that later boot sequences can in console_init()
3294 trace_initcall_level("console"); in console_init()
3310 * module, the real console hasn't registered yet at this point, there will
3311 * be a brief interval in which no messages are logged to the console, which
3316 * get unregistered when the real preferred console is registered.
3320 struct console *con; in printk_late_init()
3324 if (!(con->flags & CON_BOOT)) in printk_late_init()
3329 init_section_contains(con->write, 0) || in printk_late_init()
3330 init_section_contains(con->read, 0) || in printk_late_init()
3331 init_section_contains(con->device, 0) || in printk_late_init()
3332 init_section_contains(con->unblank, 0) || in printk_late_init()
3333 init_section_contains(con->data, 0)) { in printk_late_init()
3339 con->name, con->index); in printk_late_init()
3355 /* If @con is specified, only wait for that console. Otherwise wait for all. */
3356 static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress) in __pr_flush()
3359 struct console *c; in __pr_flush()
3379 printk_seq = c->seq; in __pr_flush()
3381 diff += seq - printk_seq; in __pr_flush()
3407 remaining -= 100; in __pr_flush()
3417 * pr_flush() - Wait for printing threads to catch up.
3422 * A value of 0 for @timeout_ms means no waiting will occur. A value of -1
3428 * Context: Process context. May sleep while acquiring console lock.
3437 * Delayed printk version, for scheduler-internal messages:
3531 * every 5s to make a denial-of-service attack impossible.
3542 * printk_timed_ratelimit - caller-controlled printk ratelimiting
3553 unsigned long elapsed = jiffies - *caller_jiffies; in printk_timed_ratelimit()
3567 * kmsg_dump_register - register a kernel log dumper.
3572 * set. Returns zero on success and %-EINVAL or %-EBUSY otherwise.
3577 int err = -EBUSY; in kmsg_dump_register()
3580 if (!dumper->dump) in kmsg_dump_register()
3581 return -EINVAL; in kmsg_dump_register()
3585 if (!dumper->registered) { in kmsg_dump_register()
3586 dumper->registered = 1; in kmsg_dump_register()
3587 list_add_tail_rcu(&dumper->list, &dump_list); in kmsg_dump_register()
3597 * kmsg_dump_unregister - unregister a kmsg dumper.
3601 * %-EINVAL otherwise.
3606 int err = -EINVAL; in kmsg_dump_unregister()
3609 if (dumper->registered) { in kmsg_dump_unregister()
3610 dumper->registered = 0; in kmsg_dump_unregister()
3611 list_del_rcu(&dumper->list); in kmsg_dump_unregister()
3642 * kmsg_dump - dump kernel log to kernel message dumpers.
3655 enum kmsg_dump_reason max_reason = dumper->max_reason; in kmsg_dump()
3669 dumper->dump(dumper, reason); in kmsg_dump()
3675 * kmsg_dump_get_line - retrieve one kmsg log line
3679 * @size: maximum size of the buffer
3692 char *line, size_t size, size_t *len) in kmsg_dump_get_line() argument
3701 if (iter->cur_seq < min_seq) in kmsg_dump_get_line()
3702 iter->cur_seq = min_seq; in kmsg_dump_get_line()
3704 prb_rec_init_rd(&r, &info, line, size); in kmsg_dump_get_line()
3708 if (!prb_read_valid(prb, iter->cur_seq, &r)) in kmsg_dump_get_line()
3712 if (!prb_read_valid_info(prb, iter->cur_seq, in kmsg_dump_get_line()
3721 iter->cur_seq = r.info->seq + 1; in kmsg_dump_get_line()
3731 * kmsg_dump_get_buffer - copy kmsg log lines
3735 * @size: maximum size of the buffer
3750 char *buf, size_t size, size_t *len_out) in kmsg_dump_get_buffer() argument
3761 if (!buf || !size) in kmsg_dump_get_buffer()
3764 if (iter->cur_seq < min_seq) in kmsg_dump_get_buffer()
3765 iter->cur_seq = min_seq; in kmsg_dump_get_buffer()
3767 if (prb_read_valid_info(prb, iter->cur_seq, &info, NULL)) { in kmsg_dump_get_buffer()
3768 if (info.seq != iter->cur_seq) { in kmsg_dump_get_buffer()
3770 iter->cur_seq = info.seq; in kmsg_dump_get_buffer()
3775 if (iter->cur_seq >= iter->next_seq) in kmsg_dump_get_buffer()
3780 * into the user-provided buffer for this dump. Pass in size-1 in kmsg_dump_get_buffer()
3782 * not write more than size-1 bytes of text into @buf. in kmsg_dump_get_buffer()
3784 seq = find_first_fitting_seq(iter->cur_seq, iter->next_seq, in kmsg_dump_get_buffer()
3785 size - 1, syslog, time); in kmsg_dump_get_buffer()
3793 prb_rec_init_rd(&r, &info, buf, size); in kmsg_dump_get_buffer()
3797 if (r.info->seq >= iter->next_seq) in kmsg_dump_get_buffer()
3803 prb_rec_init_rd(&r, &info, buf + len, size - len); in kmsg_dump_get_buffer()
3806 iter->next_seq = next_seq; in kmsg_dump_get_buffer()
3816 * kmsg_dump_rewind - reset the iterator
3825 iter->cur_seq = latched_seq_read_nolock(&clear_seq); in kmsg_dump_rewind()
3826 iter->next_seq = prb_next_seq(prb); in kmsg_dump_rewind()
3833 static atomic_t printk_cpu_sync_owner = ATOMIC_INIT(-1);
3837 * __printk_cpu_sync_wait() - Busy wait until the printk cpu-reentrant
3846 } while (atomic_read(&printk_cpu_sync_owner) != -1); in __printk_cpu_sync_wait()
3851 * __printk_cpu_sync_try_get() - Try to acquire the printk cpu-reentrant
3887 old = atomic_cmpxchg_acquire(&printk_cpu_sync_owner, -1, in __printk_cpu_sync_try_get()
3889 if (old == -1) { in __printk_cpu_sync_try_get()
3907 * __printk_cpu_sync_put() - Release the printk cpu-reentrant spinning lock.
3944 -1); /* LMM(__printk_cpu_sync_put:B) */ in __printk_cpu_sync_put()