Lines Matching +full:pmsg +full:- +full:size

1 // SPDX-License-Identifier: GPL-2.0-only
85 * console_mutex protects console_list updates and console->flags updates.
92 * console_sem protects updates to console->seq
148 return -EINVAL; in __control_devkmsg()
168 return -EINVAL; in __control_devkmsg()
210 return -EINVAL; in devkmsg_sysctl_set_loglvl()
233 return -EINVAL; in devkmsg_sysctl_set_loglvl()
242 * console_list_lock - Lock the console list
244 * For console list or console->flags updates
254 * Detecting if this context is really in the read-side critical in console_list_lock()
266 * console_list_unlock - Unlock the console list
277 * console_srcu_read_lock - Register a new reader for the
278 * SRCU-protected console list
293 * console_srcu_read_unlock - Unregister an old reader from
294 * the SRCU-protected console list
322 * because spindump/WARN/etc from under console ->lock will in __down_trylock_console_sem()
323 * deadlock in printk()->down_trylock_console_sem() otherwise. in __down_trylock_console_sem()
394 static int preferred_console = -1;
411 * own meta-data (@info).
413 * Every record meta-data carries the timestamp in microseconds, as well as
415 * messages use LOG_KERN; userspace-injected messages always carry a matching
424 * pairs), to provide userspace with a machine-readable message context.
426 * Examples for well-defined, commonly used property names are:
432 * SUBSYSTEM=pci driver-core subsystem name
434 * Valid characters in property names are [a-zA-Z0-9.-_]. Property names
450 * userspace, it is a kernel-private implementation detail that might
461 * non-prinatable characters are escaped in the "\xff" notation.
532 * Define the average message size. This only affects the number of
541 _DEFINE_PRINTKRB(printk_rb_static, CONFIG_LOG_BUF_SHIFT - PRB_AVGBITS,
549 * We cannot access per-CPU data (e.g. per-CPU flush irq_work) before
551 * it's safe to access per-CPU data.
563 raw_write_seqcount_latch(&ls->latch); in latched_seq_write()
564 ls->val[0] = val; in latched_seq_write()
565 raw_write_seqcount_latch(&ls->latch); in latched_seq_write()
566 ls->val[1] = val; in latched_seq_write()
577 seq = raw_read_seqcount_latch(&ls->latch); in latched_seq_read_nolock()
579 val = ls->val[idx]; in latched_seq_read_nolock()
580 } while (raw_read_seqcount_latch_retry(&ls->latch, seq)); in latched_seq_read_nolock()
591 /* Return log buffer size */
619 *text_len -= *trunc_msg_len; in truncate_msg()
631 * Unless restricted, we allow "read all" and "get buffer size" in syslog_action_restricted()
650 return -EPERM; in check_syslog_permissions()
662 static ssize_t info_print_ext_header(char *buf, size_t size, in info_print_ext_header() argument
665 u64 ts_usec = info->ts_nsec; in info_print_ext_header()
668 u32 id = info->caller_id; in info_print_ext_header()
678 return scnprintf(buf, size, "%u,%llu,%llu,%c%s;", in info_print_ext_header()
679 (info->facility << 3) | info->level, info->seq, in info_print_ext_header()
680 ts_usec, info->flags & LOG_CONT ? 'c' : '-', caller); in info_print_ext_header()
683 static ssize_t msg_add_ext_text(char *buf, size_t size, in msg_add_ext_text() argument
687 char *p = buf, *e = buf + size; in msg_add_ext_text()
690 /* escape non-printable characters */ in msg_add_ext_text()
695 p += scnprintf(p, e - p, "\\x%02x", c); in msg_add_ext_text()
701 return p - buf; in msg_add_ext_text()
704 static ssize_t msg_add_dict_text(char *buf, size_t size, in msg_add_dict_text() argument
713 len = msg_add_ext_text(buf, size, "", 0, ' '); /* dict prefix */ in msg_add_dict_text()
714 len += msg_add_ext_text(buf + len, size - len, key, strlen(key), '='); in msg_add_dict_text()
715 len += msg_add_ext_text(buf + len, size - len, val, val_len, '\n'); in msg_add_dict_text()
720 static ssize_t msg_print_ext_body(char *buf, size_t size, in msg_print_ext_body() argument
726 len = msg_add_ext_text(buf, size, text, text_len, '\n'); in msg_print_ext_body()
731 len += msg_add_dict_text(buf + len, size - len, "SUBSYSTEM", in msg_print_ext_body()
732 dev_info->subsystem); in msg_print_ext_body()
733 len += msg_add_dict_text(buf + len, size - len, "DEVICE", in msg_print_ext_body()
734 dev_info->device); in msg_print_ext_body()
739 /* /dev/kmsg - userspace message inject/listen interface */
765 struct file *file = iocb->ki_filp; in devkmsg_write()
766 struct devkmsg_user *user = file->private_data; in devkmsg_write()
771 return -EINVAL; in devkmsg_write()
779 if (!___ratelimit(&user->rs, current->comm)) in devkmsg_write()
785 return -ENOMEM; in devkmsg_write()
790 return -EFAULT; in devkmsg_write()
794 * Extract and skip the syslog prefix <[0-9]*>. Coming from userspace in devkmsg_write()
800 * kernel-generated messages from userspace-injected ones. in devkmsg_write()
825 struct devkmsg_user *user = file->private_data; in devkmsg_read()
826 char *outbuf = &user->pbufs.outbuf[0]; in devkmsg_read()
827 struct printk_message pmsg = { in devkmsg_read() local
828 .pbufs = &user->pbufs, in devkmsg_read()
832 ret = mutex_lock_interruptible(&user->lock); in devkmsg_read()
836 if (!printk_get_next_message(&pmsg, atomic64_read(&user->seq), true, false)) { in devkmsg_read()
837 if (file->f_flags & O_NONBLOCK) { in devkmsg_read()
838 ret = -EAGAIN; in devkmsg_read()
853 printk_get_next_message(&pmsg, atomic64_read(&user->seq), true, in devkmsg_read()
859 if (pmsg.dropped) { in devkmsg_read()
861 atomic64_set(&user->seq, pmsg.seq); in devkmsg_read()
862 ret = -EPIPE; in devkmsg_read()
866 atomic64_set(&user->seq, pmsg.seq + 1); in devkmsg_read()
868 if (pmsg.outbuf_len > count) { in devkmsg_read()
869 ret = -EINVAL; in devkmsg_read()
873 if (copy_to_user(buf, outbuf, pmsg.outbuf_len)) { in devkmsg_read()
874 ret = -EFAULT; in devkmsg_read()
877 ret = pmsg.outbuf_len; in devkmsg_read()
879 mutex_unlock(&user->lock); in devkmsg_read()
887 * entire variable length messages (records). Non-standard values are
893 struct devkmsg_user *user = file->private_data; in devkmsg_llseek()
897 return -ESPIPE; in devkmsg_llseek()
902 atomic64_set(&user->seq, prb_first_valid_seq(prb)); in devkmsg_llseek()
907 * like issued by 'dmesg -c'. Reading /dev/kmsg itself in devkmsg_llseek()
910 atomic64_set(&user->seq, latched_seq_read_nolock(&clear_seq)); in devkmsg_llseek()
914 atomic64_set(&user->seq, prb_next_seq(prb)); in devkmsg_llseek()
917 ret = -EINVAL; in devkmsg_llseek()
924 struct devkmsg_user *user = file->private_data; in devkmsg_poll()
930 if (prb_read_valid_info(prb, atomic64_read(&user->seq), &info, NULL)) { in devkmsg_poll()
932 if (info.seq != atomic64_read(&user->seq)) in devkmsg_poll()
947 return -EPERM; in devkmsg_open()
949 /* write-only does not need any file context */ in devkmsg_open()
950 if ((file->f_flags & O_ACCMODE) != O_WRONLY) { in devkmsg_open()
959 return -ENOMEM; in devkmsg_open()
961 ratelimit_default_init(&user->rs); in devkmsg_open()
962 ratelimit_set_flags(&user->rs, RATELIMIT_MSG_ON_RELEASE); in devkmsg_open()
964 mutex_init(&user->lock); in devkmsg_open()
966 atomic64_set(&user->seq, prb_first_valid_seq(prb)); in devkmsg_open()
968 file->private_data = user; in devkmsg_open()
974 struct devkmsg_user *user = file->private_data; in devkmsg_release()
976 ratelimit_state_exit(&user->rs); in devkmsg_release()
978 mutex_destroy(&user->lock); in devkmsg_release()
1010 * Export struct size and field offsets. User space tools can in log_buf_vmcoreinfo_setup()
1043 VMCOREINFO_LENGTH(printk_info_subsystem, sizeof(dev_info->subsystem)); in log_buf_vmcoreinfo_setup()
1045 VMCOREINFO_LENGTH(printk_info_device, sizeof(dev_info->device)); in log_buf_vmcoreinfo_setup()
1065 static void __init log_buf_len_update(u64 size) in log_buf_len_update() argument
1067 if (size > (u64)LOG_BUF_LEN_MAX) { in log_buf_len_update()
1068 size = (u64)LOG_BUF_LEN_MAX; in log_buf_len_update()
1072 if (size) in log_buf_len_update()
1073 size = roundup_pow_of_two(size); in log_buf_len_update()
1074 if (size > log_buf_len) in log_buf_len_update()
1075 new_log_buf_len = (unsigned long)size; in log_buf_len_update()
1081 u64 size; in log_buf_len_setup() local
1084 return -EINVAL; in log_buf_len_setup()
1086 size = memparse(str, &str); in log_buf_len_setup()
1088 log_buf_len_update(size); in log_buf_len_setup()
1109 cpu_extra = (num_possible_cpus() - 1) * __LOG_CPU_MAX_BUF_LEN; in log_buf_add_cpu()
1119 pr_info("log_buf_len min size: %d bytes\n", __LOG_BUF_LEN); in log_buf_add_cpu()
1138 prb_rec_init_wr(&dest_r, r->info->text_len); in add_to_rb()
1143 memcpy(&dest_r.text_buf[0], &r->text_buf[0], r->info->text_len); in add_to_rb()
1144 dest_r.info->text_len = r->info->text_len; in add_to_rb()
1145 dest_r.info->facility = r->info->facility; in add_to_rb()
1146 dest_r.info->level = r->info->level; in add_to_rb()
1147 dest_r.info->flags = r->info->flags; in add_to_rb()
1148 dest_r.info->ts_nsec = r->info->ts_nsec; in add_to_rb()
1149 dest_r.info->caller_id = r->info->caller_id; in add_to_rb()
1150 memcpy(&dest_r.info->dev_info, &r->info->dev_info, sizeof(dest_r.info->dev_info)); in add_to_rb()
1175 * Some archs call setup_log_buf() multiple times - first is very in setup_log_buf()
1176 * early, e.g. from setup_arch(), and second - when percpu_areas in setup_log_buf()
1239 free -= text_size; in setup_log_buf()
1256 free -= text_size; in setup_log_buf()
1261 prb_next_seq(&printk_rb_static) - seq); in setup_log_buf()
1332 k--; in boot_delay_msec()
1385 len = print_syslog((info->facility << 3) | info->level, buf); in info_print_prefix()
1388 len += print_time(info->ts_nsec, buf + len); in info_print_prefix()
1390 len += print_caller(info->caller_id, buf + len); in info_print_prefix()
1405 * - Add prefix for each line.
1406 * - Drop truncated lines that no longer fit into the buffer.
1407 * - Add the trailing newline that has been removed in vprintk_store().
1408 * - Add a string terminator.
1411 * return value is @r->text_buf_size - 1;
1420 size_t text_len = r->info->text_len; in record_print_text()
1421 size_t buf_size = r->text_buf_size; in record_print_text()
1422 char *text = r->text_buf; in record_print_text()
1437 prefix_len = info_print_prefix(r->info, syslog, time, prefix); in record_print_text()
1443 * @len: number of bytes prepared in r->text_buf in record_print_text()
1448 line_len = next - text; in record_print_text()
1465 text_len = buf_size - len - prefix_len - 1 - 1; in record_print_text()
1504 text_len -= line_len + 1; in record_print_text()
1513 r->text_buf[len] = 0; in record_print_text()
1532 return ((prefix_len * line_count) + info->text_len + 1); in get_record_print_text_size()
1537 * records up to (but not including) @max_seq fit into @size.
1540 * does not require an upper bound, -1 can be used for @max_seq.
1542 static u64 find_first_fitting_seq(u64 start_seq, u64 max_seq, size_t size, in find_first_fitting_seq() argument
1550 /* Determine the size of the records up to @max_seq. */ in find_first_fitting_seq()
1571 if (len <= size || info.seq >= max_seq) in find_first_fitting_seq()
1573 len -= get_record_print_text_size(&info, line_count, syslog, time); in find_first_fitting_seq()
1579 /* The caller is responsible for making sure @size is greater than 0. */
1580 static int syslog_print(char __user *buf, int size) in syslog_print() argument
1590 return -ENOMEM; in syslog_print()
1634 if (r.info->seq != syslog_seq) { in syslog_print()
1636 syslog_seq = r.info->seq; in syslog_print()
1649 if (n - syslog_partial <= size) { in syslog_print()
1651 syslog_seq = r.info->seq + 1; in syslog_print()
1652 n -= syslog_partial; in syslog_print()
1656 n = size; in syslog_print()
1670 len = -EFAULT; in syslog_print()
1675 size -= n; in syslog_print()
1677 } while (size); in syslog_print()
1684 static int syslog_print_all(char __user *buf, int size, bool clear) in syslog_print_all() argument
1695 return -ENOMEM; in syslog_print_all()
1700 * into the user-provided buffer for this dump. in syslog_print_all()
1702 seq = find_first_fitting_seq(latched_seq_read_nolock(&clear_seq), -1, in syslog_print_all()
1703 size, true, time); in syslog_print_all()
1712 if (len + textlen > size) { in syslog_print_all()
1713 seq--; in syslog_print_all()
1718 len = -EFAULT; in syslog_print_all()
1761 return -EINVAL; in do_syslog()
1765 return -EFAULT; in do_syslog()
1775 return -EINVAL; in do_syslog()
1779 return -EFAULT; in do_syslog()
1802 return -EINVAL; in do_syslog()
1806 /* Implicitly re-enable logging to console */ in do_syslog()
1824 * Short-cut for poll(/"proc/kmsg") which simply checks in do_syslog()
1825 * for pending data, not the size; return the count of in do_syslog()
1828 error = prb_next_seq(prb) - syslog_seq; in do_syslog()
1840 error -= syslog_partial; in do_syslog()
1844 /* Size of the log buffer */ in do_syslog()
1849 error = -EINVAL; in do_syslog()
1862 * Special console_lock variants that help to reduce the risk of soft-lockups.
1877 * console_lock_spinning_enable - mark beginning of code where another
1889 * Non-panic CPUs abandon the flush anyway. in console_lock_spinning_enable()
1891 * Just keep the lockdep annotation. The panic-CPU should avoid in console_lock_spinning_enable()
1909 * console_lock_spinning_disable_and_check - mark end of code where another
1974 * console_trylock_spinning - try to get console_lock by busy waiting
2055 * additional NMI context per CPU is also separately tracked. Until per-CPU
2068 * a WARN), but a higher value is used in case some printk-internal errors
2119 (*(recursion_ptr))--; \
2132 while (m--) { in printk_delay()
2146 * printk_parse_prefix - Parse level and control flags.
2176 *level = kern_level - '0'; in printk_parse_prefix()
2191 static u16 printk_sprint(char *text, u16 size, int facility, in printk_sprint() argument
2197 text_len = vscnprintf(text, size, fmt, args); in printk_sprint()
2200 if (text_len && text[text_len - 1] == '\n') { in printk_sprint()
2201 text_len--; in printk_sprint()
2211 text_len -= prefix_len; in printk_sprint()
2279 text_len = printk_sprint(&r.text_buf[r.info->text_len], reserve_size, in vprintk_store()
2281 r.info->text_len += text_len; in vprintk_store()
2284 r.info->flags |= LOG_NEWLINE; in vprintk_store()
2314 r.info->text_len = text_len + trunc_msg_len; in vprintk_store()
2315 r.info->facility = facility; in vprintk_store()
2316 r.info->level = level & 7; in vprintk_store()
2317 r.info->flags = flags & 0x1f; in vprintk_store()
2318 r.info->ts_nsec = ts_nsec; in vprintk_store()
2319 r.info->caller_id = caller_id; in vprintk_store()
2321 memcpy(&r.info->dev_info, dev_info, sizeof(r.info->dev_info)); in vprintk_store()
2336 * This acts as a one-way switch to allow legacy consoles to print from
2366 * non-panic CPUs are generating any messages, they will be in vprintk_emit()
2393 * The caller may be holding system-critical or in vprintk_emit()
2394 * timing-sensitive locks. Disable preemption during in vprintk_emit()
2473 early_console->write(early_console, buf, n); in early_printk()
2486 c->user_specified = true; in set_user_specified()
2499 return -EINVAL; in __add_preferred_console()
2508 return -EINVAL; in __add_preferred_console()
2515 i < MAX_CMDLINECONSOLES && (c->name[0] || c->devname[0]); in __add_preferred_console()
2517 if ((name && strcmp(c->name, name) == 0 && c->index == idx) || in __add_preferred_console()
2518 (devname && strcmp(c->devname, devname) == 0)) { in __add_preferred_console()
2526 return -E2BIG; in __add_preferred_console()
2530 strscpy(c->name, name); in __add_preferred_console()
2532 strscpy(c->devname, devname); in __add_preferred_console()
2533 c->options = options; in __add_preferred_console()
2537 c->index = idx; in __add_preferred_console()
2610 idx = -1; in console_setup()
2622 * add_preferred_console - add a device to the list of preferred consoles.
2629 * above to handle user-supplied console arguments; however it can also
2630 * be used by arch-specific code either to override the user or more
2640 * match_devname_and_update_preferred_console - Update a preferred console
2667 return -EINVAL; in match_devname_and_update_preferred_console()
2669 for (i = 0; i < MAX_CMDLINECONSOLES && (c->name[0] || c->devname[0]); in match_devname_and_update_preferred_console()
2671 if (!strcmp(devname, c->devname)) { in match_devname_and_update_preferred_console()
2674 strscpy(c->name, name); in match_devname_and_update_preferred_console()
2675 c->index = idx; in match_devname_and_update_preferred_console()
2680 return -ENOENT; in match_devname_and_update_preferred_console()
2711 * suspend_console - suspend the console subsystem
2726 console_srcu_write_flags(con, con->flags | CON_SUSPENDED); in suspend_console()
2748 console_srcu_write_flags(con, con->flags & ~CON_SUSPENDED); in resume_console()
2768 * console_cpu_notify - print deferred console messages after CPU hotplug
2793 * console_lock - block the console subsystem from printing
2815 * console_trylock - try to block the console subsystem from printing
2850 * Prepend the message in @pmsg->pbufs->outbuf. This is achieved by shifting
2853 * @pmsg is the original printk message.
2856 * If there is not enough space in @pmsg->pbufs->outbuf, the existing
2859 * If @pmsg->pbufs->outbuf is modified, @pmsg->outbuf_len is updated.
2862 static void console_prepend_message(struct printk_message *pmsg, const char *fmt, ...) in console_prepend_message() argument
2864 struct printk_buffers *pbufs = pmsg->pbufs; in console_prepend_message()
2865 const size_t scratchbuf_sz = sizeof(pbufs->scratchbuf); in console_prepend_message()
2866 const size_t outbuf_sz = sizeof(pbufs->outbuf); in console_prepend_message()
2867 char *scratchbuf = &pbufs->scratchbuf[0]; in console_prepend_message()
2868 char *outbuf = &pbufs->outbuf[0]; in console_prepend_message()
2885 if (pmsg->outbuf_len + len >= outbuf_sz) { in console_prepend_message()
2887 pmsg->outbuf_len = outbuf_sz - (len + 1); in console_prepend_message()
2888 outbuf[pmsg->outbuf_len] = 0; in console_prepend_message()
2891 memmove(outbuf + len, outbuf, pmsg->outbuf_len + 1); in console_prepend_message()
2893 pmsg->outbuf_len += len; in console_prepend_message()
2897 * Prepend the message in @pmsg->pbufs->outbuf with a "dropped message".
2898 * @pmsg->outbuf_len is updated appropriately.
2900 * @pmsg is the printk message to prepend.
2904 void console_prepend_dropped(struct printk_message *pmsg, unsigned long dropped) in console_prepend_dropped() argument
2906 console_prepend_message(pmsg, "** %lu printk messages dropped **\n", dropped); in console_prepend_dropped()
2910 * Prepend the message in @pmsg->pbufs->outbuf with a "replay message".
2911 * @pmsg->outbuf_len is updated appropriately.
2913 * @pmsg is the printk message to prepend.
2915 void console_prepend_replay(struct printk_message *pmsg) in console_prepend_replay() argument
2917 console_prepend_message(pmsg, "** replaying previous printk message **\n"); in console_prepend_replay()
2924 * @pmsg will contain the formatted result. @pmsg->pbufs must point to a
2936 * of @pmsg are valid. (See the documentation of struct printk_message
2937 * for information about the @pmsg fields.)
2939 bool printk_get_next_message(struct printk_message *pmsg, u64 seq, in printk_get_next_message() argument
2942 struct printk_buffers *pbufs = pmsg->pbufs; in printk_get_next_message()
2943 const size_t scratchbuf_sz = sizeof(pbufs->scratchbuf); in printk_get_next_message()
2944 const size_t outbuf_sz = sizeof(pbufs->outbuf); in printk_get_next_message()
2945 char *scratchbuf = &pbufs->scratchbuf[0]; in printk_get_next_message()
2946 char *outbuf = &pbufs->outbuf[0]; in printk_get_next_message()
2955 * Formatting normal messages is done in-place, so read the ringbuffer in printk_get_next_message()
2966 pmsg->seq = r.info->seq; in printk_get_next_message()
2967 pmsg->dropped = r.info->seq - seq; in printk_get_next_message()
2970 if (may_suppress && suppress_message_printing(r.info->level)) in printk_get_next_message()
2975 len += msg_print_ext_body(outbuf + len, outbuf_sz - len, in printk_get_next_message()
2976 &r.text_buf[0], r.info->text_len, &r.info->dev_info); in printk_get_next_message()
2981 pmsg->outbuf_len = len; in printk_get_next_message()
3014 * Used as the printk buffers for non-panic, serialized console printing.
3039 struct printk_message pmsg = { in console_emit_next_record() local
3046 if (!printk_get_next_message(&pmsg, con->seq, is_extended, true)) in console_emit_next_record()
3049 con->dropped += pmsg.dropped; in console_emit_next_record()
3052 if (pmsg.outbuf_len == 0) { in console_emit_next_record()
3053 con->seq = pmsg.seq + 1; in console_emit_next_record()
3057 if (con->dropped && !is_extended) { in console_emit_next_record()
3058 console_prepend_dropped(&pmsg, con->dropped); in console_emit_next_record()
3059 con->dropped = 0; in console_emit_next_record()
3072 con->write(con, outbuf, pmsg.outbuf_len); in console_emit_next_record()
3073 con->seq = pmsg.seq + 1; in console_emit_next_record()
3092 con->write(con, outbuf, pmsg.outbuf_len); in console_emit_next_record()
3097 con->seq = pmsg.seq + 1; in console_emit_next_record()
3181 printk_seq = con->seq; in console_flush_all()
3255 * Re-check if there is a new record to flush. If the trylock in __console_flush_and_unlock()
3262 * console_unlock - unblock the legacy console subsystem from printing
3286 * console_conditional_schedule - yield the CPU if required
3315 if ((console_srcu_read_flags(c) & CON_ENABLED) && c->unblank) { in console_unblank()
3329 * In that case, attempt a trylock as best-effort. in console_unblank()
3332 /* Semaphores are not NMI-safe. */ in console_unblank()
3352 if ((console_srcu_read_flags(c) & CON_ENABLED) && c->unblank) in console_unblank()
3353 c->unblank(); in console_unblank()
3391 c->seq = seq; in __console_rewind_all()
3398 * console_flush_on_panic - flush console content on panic
3413 * - if it is contended, it must be ignored anyway in console_flush_on_panic()
3414 * - console_lock() and console_trylock() block and fail in console_flush_on_panic()
3415 * respectively in panic for non-panic CPUs in console_flush_on_panic()
3416 * - semaphores are not NMI-safe in console_flush_on_panic()
3456 if (!c->device) in console_device()
3458 driver = c->device(c, index); in console_device()
3471 * re-enable output afterwards.
3477 console_srcu_write_flags(console, console->flags & ~CON_ENABLED); in console_stop()
3496 console_srcu_write_flags(console, console->flags | CON_ENABLED); in console_start()
3497 is_nbcon = console->flags & CON_NBCON; in console_start()
3560 printk_seq = con->seq; in legacy_kthread_should_wakeup()
3606 sched_set_normal(printk_legacy_kthread, -20); in legacy_kthread_create()
3612 * printk_kthreads_shutdown - shutdown all threaded printers
3627 if (con->flags & CON_NBCON) in printk_kthreads_shutdown()
3670 if (con->flags & CON_NBCON) in printk_kthreads_check_locked()
3698 if (!(con->flags & CON_NBCON)) in printk_kthreads_check_locked()
3727 pr_info("debug: skip boot console de-registration.\n"); in keep_bootcon_setup()
3738 if (!newcon->setup) in console_call_setup()
3743 err = newcon->setup(newcon, options); in console_call_setup()
3765 i < MAX_CMDLINECONSOLES && (c->name[0] || c->devname[0]); in try_enable_preferred_console()
3768 if (!c->name[0]) in try_enable_preferred_console()
3770 if (c->user_specified != user_specified) in try_enable_preferred_console()
3772 if (!newcon->match || in try_enable_preferred_console()
3773 newcon->match(newcon, c->name, c->index, c->options) != 0) { in try_enable_preferred_console()
3775 BUILD_BUG_ON(sizeof(c->name) != sizeof(newcon->name)); in try_enable_preferred_console()
3776 if (strcmp(c->name, newcon->name) != 0) in try_enable_preferred_console()
3778 if (newcon->index >= 0 && in try_enable_preferred_console()
3779 newcon->index != c->index) in try_enable_preferred_console()
3781 if (newcon->index < 0) in try_enable_preferred_console()
3782 newcon->index = c->index; in try_enable_preferred_console()
3787 err = console_call_setup(newcon, c->options); in try_enable_preferred_console()
3791 newcon->flags |= CON_ENABLED; in try_enable_preferred_console()
3793 newcon->flags |= CON_CONSDEV; in try_enable_preferred_console()
3799 * without matching. Accept the pre-enabled consoles only when match() in try_enable_preferred_console()
3802 if (newcon->flags & CON_ENABLED && c->user_specified == user_specified) in try_enable_preferred_console()
3805 return -ENOENT; in try_enable_preferred_console()
3811 if (newcon->index < 0) in try_enable_default_console()
3812 newcon->index = 0; in try_enable_default_console()
3817 newcon->flags |= CON_ENABLED; in try_enable_default_console()
3819 if (newcon->device) in try_enable_default_console()
3820 newcon->flags |= CON_CONSDEV; in try_enable_default_console()
3830 if (newcon->flags & (CON_PRINTBUFFER | CON_BOOT)) { in get_init_console_seq()
3850 * guarantee safe access to console->seq. in get_init_console_seq()
3875 if (!(con->flags & CON_BOOT) || in get_init_console_seq()
3876 !(con->flags & CON_ENABLED)) { in get_init_console_seq()
3880 if (con->flags & CON_NBCON) in get_init_console_seq()
3883 seq = con->seq; in get_init_console_seq()
3909 * early_printk) - sometimes before setup_arch() completes - be careful
3910 * of what kernel features are used - they may not be initialised yet.
3912 * There are two types of consoles - bootconsoles (early_printk) and
3915 * - Any number of bootconsoles can be registered at any time.
3916 * - As soon as a "real" console is registered, all bootconsoles
3918 * - Once a "real" console is registered, any attempt to register a
3923 bool use_device_lock = (newcon->flags & CON_NBCON) && newcon->write_atomic; in register_console()
3935 con->name, con->index)) { in register_console()
3939 if (con->flags & CON_BOOT) in register_console()
3946 if ((newcon->flags & CON_BOOT) && realcon_registered) { in register_console()
3948 newcon->name, newcon->index); in register_console()
3952 if (newcon->flags & CON_NBCON) { in register_console()
3974 if (hlist_empty(&console_list) || !console_first()->device || in register_console()
3975 console_first()->flags & CON_BOOT) { in register_console()
3984 if (err == -ENOENT) in register_console()
3988 if (err || newcon->flags & CON_BRL) { in register_console()
3989 if (newcon->flags & CON_NBCON) in register_console()
4001 ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV)) { in register_console()
4002 newcon->flags &= ~CON_PRINTBUFFER; in register_console()
4005 newcon->dropped = 0; in register_console()
4008 if (newcon->flags & CON_NBCON) { in register_console()
4013 newcon->seq = init_seq; in register_console()
4016 if (newcon->flags & CON_BOOT) in register_console()
4030 newcon->device_lock(newcon, &flags); in register_console()
4033 * Put this console in the list - keep the in register_console()
4038 newcon->flags |= CON_CONSDEV; in register_console()
4039 hlist_add_head_rcu(&newcon->node, &console_list); in register_console()
4041 } else if (newcon->flags & CON_CONSDEV) { in register_console()
4043 console_srcu_write_flags(console_first(), console_first()->flags & ~CON_CONSDEV); in register_console()
4044 hlist_add_head_rcu(&newcon->node, &console_list); in register_console()
4047 hlist_add_behind_rcu(&newcon->node, console_list.first); in register_console()
4058 newcon->device_unlock(newcon, flags); in register_console()
4064 * we get the "console xxx enabled" message on all the consoles - in register_console()
4065 * boot consoles, real consoles, etc - this is to ensure that end in register_console()
4071 ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV) && in register_console()
4076 if (con->flags & CON_BOOT) in register_console()
4091 bool use_device_lock = (console->flags & CON_NBCON) && console->write_atomic; in unregister_console_locked()
4110 res = -ENODEV; in unregister_console_locked()
4111 else if (console_is_usable(console, console->flags, true)) in unregister_console_locked()
4115 console_srcu_write_flags(console, console->flags & ~CON_ENABLED); in unregister_console_locked()
4125 console->device_lock(console, &flags); in unregister_console_locked()
4127 hlist_del_init_rcu(&console->node); in unregister_console_locked()
4130 console->device_unlock(console, flags); in unregister_console_locked()
4141 if (!hlist_empty(&console_list) && console->flags & CON_CONSDEV) in unregister_console_locked()
4142 console_srcu_write_flags(console_first(), console_first()->flags | CON_CONSDEV); in unregister_console_locked()
4151 if (console->flags & CON_NBCON) in unregister_console_locked()
4156 if (console->exit) in unregister_console_locked()
4157 res = console->exit(console); in unregister_console_locked()
4164 if (c->flags & CON_BOOT) in unregister_console_locked()
4167 if (c->flags & CON_NBCON) in unregister_console_locked()
4197 * console_force_preferred_locked - force a registered console preferred
4216 * Delete, but do not re-initialize the entry. This allows the console in console_force_preferred_locked()
4220 hlist_del_rcu(&con->node); in console_force_preferred_locked()
4225 * list pointer can be re-initialized. in console_force_preferred_locked()
4229 con->flags |= CON_CONSDEV; in console_force_preferred_locked()
4230 WARN_ON(!con->device); in console_force_preferred_locked()
4233 console_srcu_write_flags(cur_pref_con, cur_pref_con->flags & ~CON_CONSDEV); in console_force_preferred_locked()
4234 hlist_add_head_rcu(&con->node, &console_list); in console_force_preferred_locked()
4290 if (!(con->flags & CON_BOOT)) in printk_late_init()
4295 init_section_contains(con->write, 0) || in printk_late_init()
4296 init_section_contains(con->read, 0) || in printk_late_init()
4297 init_section_contains(con->device, 0) || in printk_late_init()
4298 init_section_contains(con->unblank, 0) || in printk_late_init()
4299 init_section_contains(con->data, 0)) { in printk_late_init()
4305 con->name, con->index); in printk_late_init()
4362 * console->seq. Releasing console_lock flushes more in __pr_flush()
4394 printk_seq = c->seq; in __pr_flush()
4398 diff += seq - printk_seq; in __pr_flush()
4414 slept_jiffies = jiffies - begin_jiffies; in __pr_flush()
4416 remaining_jiffies -= min(slept_jiffies, remaining_jiffies); in __pr_flush()
4425 * pr_flush() - Wait for printing threads to catch up.
4430 * A value of 0 for @timeout_ms means no waiting will occur. A value of -1
4445 * Delayed printk version, for scheduler-internal messages:
4499 * wake_up_klogd - Wake kernel logging daemon
4514 * defer_console_output - Wake kernel logging daemon and trigger
4560 * every 5s to make a denial-of-service attack impossible.
4571 * printk_timed_ratelimit - caller-controlled printk ratelimiting
4582 unsigned long elapsed = jiffies - *caller_jiffies; in printk_timed_ratelimit()
4596 * kmsg_dump_register - register a kernel log dumper.
4601 * set. Returns zero on success and %-EINVAL or %-EBUSY otherwise.
4606 int err = -EBUSY; in kmsg_dump_register()
4609 if (!dumper->dump) in kmsg_dump_register()
4610 return -EINVAL; in kmsg_dump_register()
4614 if (!dumper->registered) { in kmsg_dump_register()
4615 dumper->registered = 1; in kmsg_dump_register()
4616 list_add_tail_rcu(&dumper->list, &dump_list); in kmsg_dump_register()
4626 * kmsg_dump_unregister - unregister a kmsg dumper.
4630 * %-EINVAL otherwise.
4635 int err = -EINVAL; in kmsg_dump_unregister()
4638 if (dumper->registered) { in kmsg_dump_unregister()
4639 dumper->registered = 0; in kmsg_dump_unregister()
4640 list_del_rcu(&dumper->list); in kmsg_dump_unregister()
4671 * kmsg_dump_desc - dump kernel log to kernel message dumpers.
4689 enum kmsg_dump_reason max_reason = dumper->max_reason; in kmsg_dump_desc()
4703 dumper->dump(dumper, &detail); in kmsg_dump_desc()
4709 * kmsg_dump_get_line - retrieve one kmsg log line
4713 * @size: maximum size of the buffer
4726 char *line, size_t size, size_t *len) in kmsg_dump_get_line() argument
4735 if (iter->cur_seq < min_seq) in kmsg_dump_get_line()
4736 iter->cur_seq = min_seq; in kmsg_dump_get_line()
4738 prb_rec_init_rd(&r, &info, line, size); in kmsg_dump_get_line()
4742 if (!prb_read_valid(prb, iter->cur_seq, &r)) in kmsg_dump_get_line()
4746 if (!prb_read_valid_info(prb, iter->cur_seq, in kmsg_dump_get_line()
4755 iter->cur_seq = r.info->seq + 1; in kmsg_dump_get_line()
4765 * kmsg_dump_get_buffer - copy kmsg log lines
4769 * @size: maximum size of the buffer
4784 char *buf, size_t size, size_t *len_out) in kmsg_dump_get_buffer() argument
4795 if (!buf || !size) in kmsg_dump_get_buffer()
4798 if (iter->cur_seq < min_seq) in kmsg_dump_get_buffer()
4799 iter->cur_seq = min_seq; in kmsg_dump_get_buffer()
4801 if (prb_read_valid_info(prb, iter->cur_seq, &info, NULL)) { in kmsg_dump_get_buffer()
4802 if (info.seq != iter->cur_seq) { in kmsg_dump_get_buffer()
4804 iter->cur_seq = info.seq; in kmsg_dump_get_buffer()
4809 if (iter->cur_seq >= iter->next_seq) in kmsg_dump_get_buffer()
4814 * into the user-provided buffer for this dump. Pass in size-1 in kmsg_dump_get_buffer()
4816 * not write more than size-1 bytes of text into @buf. in kmsg_dump_get_buffer()
4818 seq = find_first_fitting_seq(iter->cur_seq, iter->next_seq, in kmsg_dump_get_buffer()
4819 size - 1, syslog, time); in kmsg_dump_get_buffer()
4827 prb_rec_init_rd(&r, &info, buf, size); in kmsg_dump_get_buffer()
4830 if (r.info->seq >= iter->next_seq) in kmsg_dump_get_buffer()
4836 prb_rec_init_rd(&r, &info, buf + len, size - len); in kmsg_dump_get_buffer()
4839 iter->next_seq = next_seq; in kmsg_dump_get_buffer()
4849 * kmsg_dump_rewind - reset the iterator
4858 iter->cur_seq = latched_seq_read_nolock(&clear_seq); in kmsg_dump_rewind()
4859 iter->next_seq = prb_next_seq(prb); in kmsg_dump_rewind()
4864 * console_try_replay_all - try to replay kernel log on consoles
4892 static atomic_t printk_cpu_sync_owner = ATOMIC_INIT(-1);
4896 * __printk_cpu_sync_wait() - Busy wait until the printk cpu-reentrant
4905 } while (atomic_read(&printk_cpu_sync_owner) != -1); in __printk_cpu_sync_wait()
4910 * __printk_cpu_sync_try_get() - Try to acquire the printk cpu-reentrant
4946 old = atomic_cmpxchg_acquire(&printk_cpu_sync_owner, -1, in __printk_cpu_sync_try_get()
4948 if (old == -1) { in __printk_cpu_sync_try_get()
4966 * __printk_cpu_sync_put() - Release the printk cpu-reentrant spinning lock.
5003 -1); /* LMM(__printk_cpu_sync_put:B) */ in __printk_cpu_sync_put()