Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'printk-for-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux

Pull printk updates from Petr Mladek:

- Refactor printk code for formatting messages that are shown on
consoles. This is a preparatory step for introducing atomic consoles
which could not share the global buffers

- Prevent memory leak when removing printk index in debugfs

- Dump also the newest printk message by the sample gdbmacro

- Fix a compiler warning

* tag 'printk-for-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux:
printf: fix errname.c list
kernel/printk/index.c: fix memory leak with using debugfs_lookup()
printk: Use scnprintf() to print the message about the dropped messages on a console
printk: adjust string limit macros
printk: use printk_buffers for devkmsg
printk: introduce console_prepend_dropped() for dropped messages
printk: introduce printk_get_next_message() and printk_message
printk: introduce struct printk_buffers
console: Document struct console
console: Use BIT() macros for @flags values
printk: move size limit macros into internal.h
docs: gdbmacros: print newest record

+314 -169
+1 -1
Documentation/admin-guide/kdump/gdbmacros.txt
··· 312 312 set var $prev_flags = $info->flags 313 313 end 314 314 315 - set var $id = ($id + 1) & $id_mask 316 315 if ($id == $end_id) 317 316 loop_break 318 317 end 318 + set var $id = ($id + 1) & $id_mask 319 319 end 320 320 end 321 321 document dmesg
+73 -27
include/linux/console.h
··· 15 15 #define _LINUX_CONSOLE_H_ 1 16 16 17 17 #include <linux/atomic.h> 18 + #include <linux/bits.h> 18 19 #include <linux/rculist.h> 19 20 #include <linux/types.h> 20 21 ··· 126 125 /* 127 126 * The interface for a console, or any other device that wants to capture 128 127 * console messages (printer driver?) 129 - * 130 - * If a console driver is marked CON_BOOT then it will be auto-unregistered 131 - * when the first real console is registered. This is for early-printk drivers. 132 128 */ 133 129 134 - #define CON_PRINTBUFFER (1) 135 - #define CON_CONSDEV (2) /* Preferred console, /dev/console */ 136 - #define CON_ENABLED (4) 137 - #define CON_BOOT (8) 138 - #define CON_ANYTIME (16) /* Safe to call when cpu is offline */ 139 - #define CON_BRL (32) /* Used for a braille device */ 140 - #define CON_EXTENDED (64) /* Use the extended output format a la /dev/kmsg */ 130 + /** 131 + * cons_flags - General console flags 132 + * @CON_PRINTBUFFER: Used by newly registered consoles to avoid duplicate 133 + * output of messages that were already shown by boot 134 + * consoles or read by userspace via syslog() syscall. 135 + * @CON_CONSDEV: Indicates that the console driver is backing 136 + * /dev/console. 137 + * @CON_ENABLED: Indicates if a console is allowed to print records. If 138 + * false, the console also will not advance to later 139 + * records. 140 + * @CON_BOOT: Marks the console driver as early console driver which 141 + * is used during boot before the real driver becomes 142 + * available. It will be automatically unregistered 143 + * when the real console driver is registered unless 144 + * "keep_bootcon" parameter is used. 145 + * @CON_ANYTIME: A misnomed historical flag which tells the core code 146 + * that the legacy @console::write callback can be invoked 147 + * on a CPU which is marked OFFLINE. That is misleading as 148 + * it suggests that there is no contextual limit for 149 + * invoking the callback. The original motivation was 150 + * readiness of the per-CPU areas. 151 + * @CON_BRL: Indicates a braille device which is exempt from 152 + * receiving the printk spam for obvious reasons. 153 + * @CON_EXTENDED: The console supports the extended output format of 154 + * /dev/kmesg which requires a larger output buffer. 155 + */ 156 + enum cons_flags { 157 + CON_PRINTBUFFER = BIT(0), 158 + CON_CONSDEV = BIT(1), 159 + CON_ENABLED = BIT(2), 160 + CON_BOOT = BIT(3), 161 + CON_ANYTIME = BIT(4), 162 + CON_BRL = BIT(5), 163 + CON_EXTENDED = BIT(6), 164 + }; 141 165 166 + /** 167 + * struct console - The console descriptor structure 168 + * @name: The name of the console driver 169 + * @write: Write callback to output messages (Optional) 170 + * @read: Read callback for console input (Optional) 171 + * @device: The underlying TTY device driver (Optional) 172 + * @unblank: Callback to unblank the console (Optional) 173 + * @setup: Callback for initializing the console (Optional) 174 + * @exit: Callback for teardown of the console (Optional) 175 + * @match: Callback for matching a console (Optional) 176 + * @flags: Console flags. See enum cons_flags 177 + * @index: Console index, e.g. port number 178 + * @cflag: TTY control mode flags 179 + * @ispeed: TTY input speed 180 + * @ospeed: TTY output speed 181 + * @seq: Sequence number of the next ringbuffer record to print 182 + * @dropped: Number of unreported dropped ringbuffer records 183 + * @data: Driver private data 184 + * @node: hlist node for the console list 185 + */ 142 186 struct console { 143 - char name[16]; 144 - void (*write)(struct console *, const char *, unsigned); 145 - int (*read)(struct console *, char *, unsigned); 146 - struct tty_driver *(*device)(struct console *, int *); 147 - void (*unblank)(void); 148 - int (*setup)(struct console *, char *); 149 - int (*exit)(struct console *); 150 - int (*match)(struct console *, char *name, int idx, char *options); 151 - short flags; 152 - short index; 153 - int cflag; 154 - uint ispeed; 155 - uint ospeed; 156 - u64 seq; 157 - unsigned long dropped; 158 - void *data; 159 - struct hlist_node node; 187 + char name[16]; 188 + void (*write)(struct console *co, const char *s, unsigned int count); 189 + int (*read)(struct console *co, char *s, unsigned int count); 190 + struct tty_driver *(*device)(struct console *co, int *index); 191 + void (*unblank)(void); 192 + int (*setup)(struct console *co, char *options); 193 + int (*exit)(struct console *co); 194 + int (*match)(struct console *co, char *name, int idx, char *options); 195 + short flags; 196 + short index; 197 + int cflag; 198 + uint ispeed; 199 + uint ospeed; 200 + u64 seq; 201 + unsigned long dropped; 202 + void *data; 203 + struct hlist_node node; 160 204 }; 161 205 162 206 #ifdef CONFIG_LOCKDEP
-2
include/linux/printk.h
··· 44 44 return buffer; 45 45 } 46 46 47 - #define CONSOLE_EXT_LOG_MAX 8192 48 - 49 47 /* printk's without a loglevel use this.. */ 50 48 #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT 51 49
+1 -1
kernel/printk/index.c
··· 145 145 #ifdef CONFIG_MODULES 146 146 static void pi_remove_file(struct module *mod) 147 147 { 148 - debugfs_remove(debugfs_lookup(pi_get_module_name(mod), dfs_index)); 148 + debugfs_lookup_and_remove(pi_get_module_name(mod), dfs_index); 149 149 } 150 150 151 151 static int pi_module_notify(struct notifier_block *nb, unsigned long op,
+45
kernel/printk/internal.h
··· 14 14 15 15 #ifdef CONFIG_PRINTK 16 16 17 + #ifdef CONFIG_PRINTK_CALLER 18 + #define PRINTK_PREFIX_MAX 48 19 + #else 20 + #define PRINTK_PREFIX_MAX 32 21 + #endif 22 + 23 + /* 24 + * the maximum size of a formatted record (i.e. with prefix added 25 + * per line and dropped messages or in extended message format) 26 + */ 27 + #define PRINTK_MESSAGE_MAX 2048 28 + 29 + /* the maximum size allowed to be reserved for a record */ 30 + #define PRINTKRB_RECORD_MAX 1024 31 + 17 32 /* Flags for a single printk record. */ 18 33 enum printk_info_flags { 19 34 LOG_NEWLINE = 2, /* text ended with a newline */ ··· 63 48 enum printk_info_flags *flags); 64 49 #else 65 50 51 + #define PRINTK_PREFIX_MAX 0 52 + #define PRINTK_MESSAGE_MAX 0 53 + #define PRINTKRB_RECORD_MAX 0 54 + 66 55 /* 67 56 * In !PRINTK builds we still export console_sem 68 57 * semaphore and some of console functions (console_unlock()/etc.), so ··· 77 58 78 59 static inline bool printk_percpu_data_ready(void) { return false; } 79 60 #endif /* CONFIG_PRINTK */ 61 + 62 + /** 63 + * struct printk_buffers - Buffers to read/format/output printk messages. 64 + * @outbuf: After formatting, contains text to output. 65 + * @scratchbuf: Used as temporary ringbuffer reading and string-print space. 66 + */ 67 + struct printk_buffers { 68 + char outbuf[PRINTK_MESSAGE_MAX]; 69 + char scratchbuf[PRINTKRB_RECORD_MAX]; 70 + }; 71 + 72 + /** 73 + * struct printk_message - Container for a prepared printk message. 74 + * @pbufs: printk buffers used to prepare the message. 75 + * @outbuf_len: The length of prepared text in @pbufs->outbuf to output. This 76 + * does not count the terminator. A value of 0 means there is 77 + * nothing to output and this record should be skipped. 78 + * @seq: The sequence number of the record used for @pbufs->outbuf. 79 + * @dropped: The number of dropped records from reading @seq. 80 + */ 81 + struct printk_message { 82 + struct printk_buffers *pbufs; 83 + unsigned int outbuf_len; 84 + u64 seq; 85 + unsigned long dropped; 86 + };
+180 -130
kernel/printk/printk.c
··· 466 466 .val[1] = 0, 467 467 }; 468 468 469 - #ifdef CONFIG_PRINTK_CALLER 470 - #define PREFIX_MAX 48 471 - #else 472 - #define PREFIX_MAX 32 473 - #endif 474 - 475 - /* the maximum size of a formatted record (i.e. with prefix added per line) */ 476 - #define CONSOLE_LOG_MAX 1024 477 - 478 - /* the maximum size for a dropped text message */ 479 - #define DROPPED_TEXT_MAX 64 480 - 481 - /* the maximum size allowed to be reserved for a record */ 482 - #define LOG_LINE_MAX (CONSOLE_LOG_MAX - PREFIX_MAX) 483 - 484 469 #define LOG_LEVEL(v) ((v) & 0x07) 485 470 #define LOG_FACILITY(v) ((v) >> 3 & 0xff) 486 471 ··· 696 711 return len; 697 712 } 698 713 714 + static bool printk_get_next_message(struct printk_message *pmsg, u64 seq, 715 + bool is_extended, bool may_supress); 716 + 699 717 /* /dev/kmsg - userspace message inject/listen interface */ 700 718 struct devkmsg_user { 701 719 atomic64_t seq; 702 720 struct ratelimit_state rs; 703 721 struct mutex lock; 704 - char buf[CONSOLE_EXT_LOG_MAX]; 705 - 706 - struct printk_info info; 707 - char text_buf[CONSOLE_EXT_LOG_MAX]; 708 - struct printk_record record; 722 + struct printk_buffers pbufs; 709 723 }; 710 724 711 725 static __printf(3, 4) __cold ··· 730 746 size_t len = iov_iter_count(from); 731 747 ssize_t ret = len; 732 748 733 - if (!user || len > LOG_LINE_MAX) 749 + if (!user || len > PRINTKRB_RECORD_MAX) 734 750 return -EINVAL; 735 751 736 752 /* Ignore when user logging is disabled. */ ··· 786 802 size_t count, loff_t *ppos) 787 803 { 788 804 struct devkmsg_user *user = file->private_data; 789 - struct printk_record *r = &user->record; 790 - size_t len; 805 + char *outbuf = &user->pbufs.outbuf[0]; 806 + struct printk_message pmsg = { 807 + .pbufs = &user->pbufs, 808 + }; 791 809 ssize_t ret; 792 810 793 811 if (!user) ··· 799 813 if (ret) 800 814 return ret; 801 815 802 - if (!prb_read_valid(prb, atomic64_read(&user->seq), r)) { 816 + if (!printk_get_next_message(&pmsg, atomic64_read(&user->seq), true, false)) { 803 817 if (file->f_flags & O_NONBLOCK) { 804 818 ret = -EAGAIN; 805 819 goto out; ··· 816 830 * This pairs with __wake_up_klogd:A. 817 831 */ 818 832 ret = wait_event_interruptible(log_wait, 819 - prb_read_valid(prb, 820 - atomic64_read(&user->seq), r)); /* LMM(devkmsg_read:A) */ 833 + printk_get_next_message(&pmsg, atomic64_read(&user->seq), true, 834 + false)); /* LMM(devkmsg_read:A) */ 821 835 if (ret) 822 836 goto out; 823 837 } 824 838 825 - if (r->info->seq != atomic64_read(&user->seq)) { 839 + if (pmsg.dropped) { 826 840 /* our last seen message is gone, return error and reset */ 827 - atomic64_set(&user->seq, r->info->seq); 841 + atomic64_set(&user->seq, pmsg.seq); 828 842 ret = -EPIPE; 829 843 goto out; 830 844 } 831 845 832 - len = info_print_ext_header(user->buf, sizeof(user->buf), r->info); 833 - len += msg_print_ext_body(user->buf + len, sizeof(user->buf) - len, 834 - &r->text_buf[0], r->info->text_len, 835 - &r->info->dev_info); 846 + atomic64_set(&user->seq, pmsg.seq + 1); 836 847 837 - atomic64_set(&user->seq, r->info->seq + 1); 838 - 839 - if (len > count) { 848 + if (pmsg.outbuf_len > count) { 840 849 ret = -EINVAL; 841 850 goto out; 842 851 } 843 852 844 - if (copy_to_user(buf, user->buf, len)) { 853 + if (copy_to_user(buf, outbuf, pmsg.outbuf_len)) { 845 854 ret = -EFAULT; 846 855 goto out; 847 856 } 848 - ret = len; 857 + ret = pmsg.outbuf_len; 849 858 out: 850 859 mutex_unlock(&user->lock); 851 860 return ret; ··· 933 952 ratelimit_set_flags(&user->rs, RATELIMIT_MSG_ON_RELEASE); 934 953 935 954 mutex_init(&user->lock); 936 - 937 - prb_rec_init_rd(&user->record, &user->info, 938 - &user->text_buf[0], sizeof(user->text_buf)); 939 955 940 956 atomic64_set(&user->seq, prb_first_valid_seq(prb)); 941 957 ··· 1128 1150 return prb_record_text_space(&e); 1129 1151 } 1130 1152 1131 - static char setup_text_buf[LOG_LINE_MAX] __initdata; 1153 + static char setup_text_buf[PRINTKRB_RECORD_MAX] __initdata; 1132 1154 1133 1155 void __init setup_log_buf(int early) 1134 1156 { ··· 1394 1416 size_t text_len = r->info->text_len; 1395 1417 size_t buf_size = r->text_buf_size; 1396 1418 char *text = r->text_buf; 1397 - char prefix[PREFIX_MAX]; 1419 + char prefix[PRINTK_PREFIX_MAX]; 1398 1420 bool truncated = false; 1399 1421 size_t prefix_len; 1400 1422 size_t line_len; ··· 1493 1515 unsigned int line_count, 1494 1516 bool syslog, bool time) 1495 1517 { 1496 - char prefix[PREFIX_MAX]; 1518 + char prefix[PRINTK_PREFIX_MAX]; 1497 1519 size_t prefix_len; 1498 1520 1499 1521 prefix_len = info_print_prefix(info, syslog, time, prefix); ··· 1559 1581 int len = 0; 1560 1582 u64 seq; 1561 1583 1562 - text = kmalloc(CONSOLE_LOG_MAX, GFP_KERNEL); 1584 + text = kmalloc(PRINTK_MESSAGE_MAX, GFP_KERNEL); 1563 1585 if (!text) 1564 1586 return -ENOMEM; 1565 1587 1566 - prb_rec_init_rd(&r, &info, text, CONSOLE_LOG_MAX); 1588 + prb_rec_init_rd(&r, &info, text, PRINTK_MESSAGE_MAX); 1567 1589 1568 1590 mutex_lock(&syslog_lock); 1569 1591 ··· 1664 1686 u64 seq; 1665 1687 bool time; 1666 1688 1667 - text = kmalloc(CONSOLE_LOG_MAX, GFP_KERNEL); 1689 + text = kmalloc(PRINTK_MESSAGE_MAX, GFP_KERNEL); 1668 1690 if (!text) 1669 1691 return -ENOMEM; 1670 1692 ··· 1676 1698 seq = find_first_fitting_seq(latched_seq_read_nolock(&clear_seq), -1, 1677 1699 size, true, time); 1678 1700 1679 - prb_rec_init_rd(&r, &info, text, CONSOLE_LOG_MAX); 1701 + prb_rec_init_rd(&r, &info, text, PRINTK_MESSAGE_MAX); 1680 1702 1681 1703 len = 0; 1682 1704 prb_for_each_record(seq, prb, seq, &r) { ··· 1991 2013 } 1992 2014 1993 2015 /* 1994 - * Call the specified console driver, asking it to write out the specified 1995 - * text and length. If @dropped_text is non-NULL and any records have been 1996 - * dropped, a dropped message will be written out first. 1997 - */ 1998 - static void call_console_driver(struct console *con, const char *text, size_t len, 1999 - char *dropped_text) 2000 - { 2001 - size_t dropped_len; 2002 - 2003 - if (con->dropped && dropped_text) { 2004 - dropped_len = snprintf(dropped_text, DROPPED_TEXT_MAX, 2005 - "** %lu printk messages dropped **\n", 2006 - con->dropped); 2007 - con->dropped = 0; 2008 - con->write(con, dropped_text, dropped_len); 2009 - } 2010 - 2011 - con->write(con, text, len); 2012 - } 2013 - 2014 - /* 2015 2016 * Recursion is tracked separately on each CPU. If NMIs are supported, an 2016 2017 * additional NMI context per CPU is also separately tracked. Until per-CPU 2017 2018 * is available, a separate "early tracking" is performed. ··· 2200 2243 reserve_size = vsnprintf(&prefix_buf[0], sizeof(prefix_buf), fmt, args2) + 1; 2201 2244 va_end(args2); 2202 2245 2203 - if (reserve_size > LOG_LINE_MAX) 2204 - reserve_size = LOG_LINE_MAX; 2246 + if (reserve_size > PRINTKRB_RECORD_MAX) 2247 + reserve_size = PRINTKRB_RECORD_MAX; 2205 2248 2206 2249 /* Extract log level or control flags. */ 2207 2250 if (facility == 0) ··· 2215 2258 2216 2259 if (flags & LOG_CONT) { 2217 2260 prb_rec_init_wr(&r, reserve_size); 2218 - if (prb_reserve_in_last(&e, prb, &r, caller_id, LOG_LINE_MAX)) { 2261 + if (prb_reserve_in_last(&e, prb, &r, caller_id, PRINTKRB_RECORD_MAX)) { 2219 2262 text_len = printk_sprint(&r.text_buf[r.info->text_len], reserve_size, 2220 2263 facility, &flags, fmt, args); 2221 2264 r.info->text_len += text_len; ··· 2346 2389 2347 2390 #else /* CONFIG_PRINTK */ 2348 2391 2349 - #define CONSOLE_LOG_MAX 0 2350 - #define DROPPED_TEXT_MAX 0 2351 2392 #define printk_time false 2352 2393 2353 2394 #define prb_read_valid(rb, seq, r) false ··· 2369 2414 struct dev_printk_info *dev_info) { return 0; } 2370 2415 static void console_lock_spinning_enable(void) { } 2371 2416 static int console_lock_spinning_disable_and_check(int cookie) { return 0; } 2372 - static void call_console_driver(struct console *con, const char *text, size_t len, 2373 - char *dropped_text) 2374 - { 2375 - } 2376 2417 static bool suppress_message_printing(int level) { return false; } 2377 2418 static bool pr_flush(int timeout_ms, bool reset_on_progress) { return true; } 2378 2419 static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress) { return true; } ··· 2695 2744 } 2696 2745 2697 2746 /* 2747 + * Prepend the message in @pmsg->pbufs->outbuf with a "dropped message". This 2748 + * is achieved by shifting the existing message over and inserting the dropped 2749 + * message. 2750 + * 2751 + * @pmsg is the printk message to prepend. 2752 + * 2753 + * @dropped is the dropped count to report in the dropped message. 2754 + * 2755 + * If the message text in @pmsg->pbufs->outbuf does not have enough space for 2756 + * the dropped message, the message text will be sufficiently truncated. 2757 + * 2758 + * If @pmsg->pbufs->outbuf is modified, @pmsg->outbuf_len is updated. 2759 + */ 2760 + #ifdef CONFIG_PRINTK 2761 + static void console_prepend_dropped(struct printk_message *pmsg, unsigned long dropped) 2762 + { 2763 + struct printk_buffers *pbufs = pmsg->pbufs; 2764 + const size_t scratchbuf_sz = sizeof(pbufs->scratchbuf); 2765 + const size_t outbuf_sz = sizeof(pbufs->outbuf); 2766 + char *scratchbuf = &pbufs->scratchbuf[0]; 2767 + char *outbuf = &pbufs->outbuf[0]; 2768 + size_t len; 2769 + 2770 + len = scnprintf(scratchbuf, scratchbuf_sz, 2771 + "** %lu printk messages dropped **\n", dropped); 2772 + 2773 + /* 2774 + * Make sure outbuf is sufficiently large before prepending. 2775 + * Keep at least the prefix when the message must be truncated. 2776 + * It is a rather theoretical problem when someone tries to 2777 + * use a minimalist buffer. 2778 + */ 2779 + if (WARN_ON_ONCE(len + PRINTK_PREFIX_MAX >= outbuf_sz)) 2780 + return; 2781 + 2782 + if (pmsg->outbuf_len + len >= outbuf_sz) { 2783 + /* Truncate the message, but keep it terminated. */ 2784 + pmsg->outbuf_len = outbuf_sz - (len + 1); 2785 + outbuf[pmsg->outbuf_len] = 0; 2786 + } 2787 + 2788 + memmove(outbuf + len, outbuf, pmsg->outbuf_len + 1); 2789 + memcpy(outbuf, scratchbuf, len); 2790 + pmsg->outbuf_len += len; 2791 + } 2792 + #else 2793 + #define console_prepend_dropped(pmsg, dropped) 2794 + #endif /* CONFIG_PRINTK */ 2795 + 2796 + /* 2797 + * Read and format the specified record (or a later record if the specified 2798 + * record is not available). 2799 + * 2800 + * @pmsg will contain the formatted result. @pmsg->pbufs must point to a 2801 + * struct printk_buffers. 2802 + * 2803 + * @seq is the record to read and format. If it is not available, the next 2804 + * valid record is read. 2805 + * 2806 + * @is_extended specifies if the message should be formatted for extended 2807 + * console output. 2808 + * 2809 + * @may_supress specifies if records may be skipped based on loglevel. 2810 + * 2811 + * Returns false if no record is available. Otherwise true and all fields 2812 + * of @pmsg are valid. (See the documentation of struct printk_message 2813 + * for information about the @pmsg fields.) 2814 + */ 2815 + static bool printk_get_next_message(struct printk_message *pmsg, u64 seq, 2816 + bool is_extended, bool may_suppress) 2817 + { 2818 + static int panic_console_dropped; 2819 + 2820 + struct printk_buffers *pbufs = pmsg->pbufs; 2821 + const size_t scratchbuf_sz = sizeof(pbufs->scratchbuf); 2822 + const size_t outbuf_sz = sizeof(pbufs->outbuf); 2823 + char *scratchbuf = &pbufs->scratchbuf[0]; 2824 + char *outbuf = &pbufs->outbuf[0]; 2825 + struct printk_info info; 2826 + struct printk_record r; 2827 + size_t len = 0; 2828 + 2829 + /* 2830 + * Formatting extended messages requires a separate buffer, so use the 2831 + * scratch buffer to read in the ringbuffer text. 2832 + * 2833 + * Formatting normal messages is done in-place, so read the ringbuffer 2834 + * text directly into the output buffer. 2835 + */ 2836 + if (is_extended) 2837 + prb_rec_init_rd(&r, &info, scratchbuf, scratchbuf_sz); 2838 + else 2839 + prb_rec_init_rd(&r, &info, outbuf, outbuf_sz); 2840 + 2841 + if (!prb_read_valid(prb, seq, &r)) 2842 + return false; 2843 + 2844 + pmsg->seq = r.info->seq; 2845 + pmsg->dropped = r.info->seq - seq; 2846 + 2847 + /* 2848 + * Check for dropped messages in panic here so that printk 2849 + * suppression can occur as early as possible if necessary. 2850 + */ 2851 + if (pmsg->dropped && 2852 + panic_in_progress() && 2853 + panic_console_dropped++ > 10) { 2854 + suppress_panic_printk = 1; 2855 + pr_warn_once("Too many dropped messages. Suppress messages on non-panic CPUs to prevent livelock.\n"); 2856 + } 2857 + 2858 + /* Skip record that has level above the console loglevel. */ 2859 + if (may_suppress && suppress_message_printing(r.info->level)) 2860 + goto out; 2861 + 2862 + if (is_extended) { 2863 + len = info_print_ext_header(outbuf, outbuf_sz, r.info); 2864 + len += msg_print_ext_body(outbuf + len, outbuf_sz - len, 2865 + &r.text_buf[0], r.info->text_len, &r.info->dev_info); 2866 + } else { 2867 + len = record_print_text(&r, console_msg_format & MSG_FORMAT_SYSLOG, printk_time); 2868 + } 2869 + out: 2870 + pmsg->outbuf_len = len; 2871 + return true; 2872 + } 2873 + 2874 + /* 2698 2875 * Print one record for the given console. The record printed is whatever 2699 2876 * record is the next available record for the given console. 2700 - * 2701 - * @text is a buffer of size CONSOLE_LOG_MAX. 2702 - * 2703 - * If extended messages should be printed, @ext_text is a buffer of size 2704 - * CONSOLE_EXT_LOG_MAX. Otherwise @ext_text must be NULL. 2705 - * 2706 - * If dropped messages should be printed, @dropped_text is a buffer of size 2707 - * DROPPED_TEXT_MAX. Otherwise @dropped_text must be NULL. 2708 2877 * 2709 2878 * @handover will be set to true if a printk waiter has taken over the 2710 2879 * console_lock, in which case the caller is no longer holding both the ··· 2837 2766 * 2838 2767 * Requires the console_lock and the SRCU read lock. 2839 2768 */ 2840 - static bool console_emit_next_record(struct console *con, char *text, char *ext_text, 2841 - char *dropped_text, bool *handover, int cookie) 2769 + static bool console_emit_next_record(struct console *con, bool *handover, int cookie) 2842 2770 { 2843 - static int panic_console_dropped; 2844 - struct printk_info info; 2845 - struct printk_record r; 2846 - unsigned long flags; 2847 - char *write_text; 2848 - size_t len; 2771 + static struct printk_buffers pbufs; 2849 2772 2850 - prb_rec_init_rd(&r, &info, text, CONSOLE_LOG_MAX); 2773 + bool is_extended = console_srcu_read_flags(con) & CON_EXTENDED; 2774 + char *outbuf = &pbufs.outbuf[0]; 2775 + struct printk_message pmsg = { 2776 + .pbufs = &pbufs, 2777 + }; 2778 + unsigned long flags; 2851 2779 2852 2780 *handover = false; 2853 2781 2854 - if (!prb_read_valid(prb, con->seq, &r)) 2782 + if (!printk_get_next_message(&pmsg, con->seq, is_extended, true)) 2855 2783 return false; 2856 2784 2857 - if (con->seq != r.info->seq) { 2858 - con->dropped += r.info->seq - con->seq; 2859 - con->seq = r.info->seq; 2860 - if (panic_in_progress() && panic_console_dropped++ > 10) { 2861 - suppress_panic_printk = 1; 2862 - pr_warn_once("Too many dropped messages. Suppress messages on non-panic CPUs to prevent livelock.\n"); 2863 - } 2864 - } 2785 + con->dropped += pmsg.dropped; 2865 2786 2866 - /* Skip record that has level above the console loglevel. */ 2867 - if (suppress_message_printing(r.info->level)) { 2868 - con->seq++; 2787 + /* Skip messages of formatted length 0. */ 2788 + if (pmsg.outbuf_len == 0) { 2789 + con->seq = pmsg.seq + 1; 2869 2790 goto skip; 2870 2791 } 2871 2792 2872 - if (ext_text) { 2873 - write_text = ext_text; 2874 - len = info_print_ext_header(ext_text, CONSOLE_EXT_LOG_MAX, r.info); 2875 - len += msg_print_ext_body(ext_text + len, CONSOLE_EXT_LOG_MAX - len, 2876 - &r.text_buf[0], r.info->text_len, &r.info->dev_info); 2877 - } else { 2878 - write_text = text; 2879 - len = record_print_text(&r, console_msg_format & MSG_FORMAT_SYSLOG, printk_time); 2793 + if (con->dropped && !is_extended) { 2794 + console_prepend_dropped(&pmsg, con->dropped); 2795 + con->dropped = 0; 2880 2796 } 2881 2797 2882 2798 /* ··· 2879 2821 printk_safe_enter_irqsave(flags); 2880 2822 console_lock_spinning_enable(); 2881 2823 2882 - stop_critical_timings(); /* don't trace print latency */ 2883 - call_console_driver(con, write_text, len, dropped_text); 2824 + /* Do not trace print latency. */ 2825 + stop_critical_timings(); 2826 + 2827 + /* Write everything out to the hardware. */ 2828 + con->write(con, outbuf, pmsg.outbuf_len); 2829 + 2884 2830 start_critical_timings(); 2885 2831 2886 - con->seq++; 2832 + con->seq = pmsg.seq + 1; 2887 2833 2888 2834 *handover = console_lock_spinning_disable_and_check(cookie); 2889 2835 printk_safe_exit_irqrestore(flags); ··· 2920 2858 */ 2921 2859 static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handover) 2922 2860 { 2923 - static char dropped_text[DROPPED_TEXT_MAX]; 2924 - static char ext_text[CONSOLE_EXT_LOG_MAX]; 2925 - static char text[CONSOLE_LOG_MAX]; 2926 2861 bool any_usable = false; 2927 2862 struct console *con; 2928 2863 bool any_progress; ··· 2939 2880 continue; 2940 2881 any_usable = true; 2941 2882 2942 - if (console_srcu_read_flags(con) & CON_EXTENDED) { 2943 - /* Extended consoles do not print "dropped messages". */ 2944 - progress = console_emit_next_record(con, &text[0], 2945 - &ext_text[0], NULL, 2946 - handover, cookie); 2947 - } else { 2948 - progress = console_emit_next_record(con, &text[0], 2949 - NULL, &dropped_text[0], 2950 - handover, cookie); 2951 - } 2883 + progress = console_emit_next_record(con, handover, cookie); 2952 2884 2953 2885 /* 2954 2886 * If a handover has occurred, the SRCU read lock
+14 -8
lib/errname.c
··· 21 21 E(EADDRNOTAVAIL), 22 22 E(EADV), 23 23 E(EAFNOSUPPORT), 24 + E(EAGAIN), /* EWOULDBLOCK */ 24 25 E(EALREADY), 25 26 E(EBADE), 26 27 E(EBADF), ··· 32 31 E(EBADSLT), 33 32 E(EBFONT), 34 33 E(EBUSY), 35 - #ifdef ECANCELLED 36 - E(ECANCELLED), 37 - #endif 34 + E(ECANCELED), /* ECANCELLED */ 38 35 E(ECHILD), 39 36 E(ECHRNG), 40 37 E(ECOMM), 41 38 E(ECONNABORTED), 39 + E(ECONNREFUSED), /* EREFUSED */ 42 40 E(ECONNRESET), 41 + E(EDEADLK), /* EDEADLOCK */ 42 + #if EDEADLK != EDEADLOCK /* mips, sparc, powerpc */ 43 43 E(EDEADLOCK), 44 + #endif 44 45 E(EDESTADDRREQ), 45 46 E(EDOM), 46 47 E(EDOTDOT), ··· 169 166 E(EUSERS), 170 167 E(EXDEV), 171 168 E(EXFULL), 172 - 173 - E(ECANCELED), /* ECANCELLED */ 174 - E(EAGAIN), /* EWOULDBLOCK */ 175 - E(ECONNREFUSED), /* EREFUSED */ 176 - E(EDEADLK), /* EDEADLOCK */ 177 169 }; 178 170 #undef E 171 + 172 + #ifdef EREFUSED /* parisc */ 173 + static_assert(EREFUSED == ECONNREFUSED); 174 + #endif 175 + #ifdef ECANCELLED /* parisc */ 176 + static_assert(ECANCELLED == ECANCELED); 177 + #endif 178 + static_assert(EAGAIN == EWOULDBLOCK); /* everywhere */ 179 179 180 180 #define E(err) [err - 512 + BUILD_BUG_ON_ZERO(err < 512 || err > 550)] = "-" #err 181 181 static const char *names_512[] = {