Skip to content

Commit 03a749e

Browse files
jognesspmladek
authored andcommitted
printk: move buffer definitions into console_emit_next_record() caller
Extended consoles print extended messages and do not print messages about dropped records. Non-extended consoles print "normal" messages as well as extra messages about dropped records. Currently the buffers for these various message types are defined within the functions that might use them and their usage is based upon the CON_EXTENDED flag. This will be a problem when moving to kthread printers because each printer must be able to provide its own buffers. Move all the message buffer definitions outside of console_emit_next_record(). The caller knows if extended or dropped messages should be printed and can specify the appropriate buffers to use. The console_emit_next_record() and call_console_driver() functions can know what to print based on whether specified buffers are non-NULL. With this change, buffer definition/allocation/specification is separated from the code that does the various types of string printing. Signed-off-by: John Ogness <john.ogness@linutronix.de> Reviewed-by: Petr Mladek <pmladek@suse.com> Signed-off-by: Petr Mladek <pmladek@suse.com> Link: https://lore.kernel.org/r/20220421212250.565456-11-john.ogness@linutronix.de
1 parent a699449 commit 03a749e

File tree

1 file changed

+43
-17
lines changed

1 file changed

+43
-17
lines changed

kernel/printk/printk.c

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ static struct latched_seq clear_seq = {
394394
/* the maximum size of a formatted record (i.e. with prefix added per line) */
395395
#define CONSOLE_LOG_MAX 1024
396396

397+
/* the maximum size for a dropped text message */
398+
#define DROPPED_TEXT_MAX 64
399+
397400
/* the maximum size allowed to be reserved for a record */
398401
#define LOG_LINE_MAX (CONSOLE_LOG_MAX - PREFIX_MAX)
399402

@@ -1923,18 +1926,18 @@ static int console_trylock_spinning(void)
19231926

19241927
/*
19251928
* Call the specified console driver, asking it to write out the specified
1926-
* text and length. For non-extended consoles, if any records have been
1929+
* text and length. If @dropped_text is non-NULL and any records have been
19271930
* dropped, a dropped message will be written out first.
19281931
*/
1929-
static void call_console_driver(struct console *con, const char *text, size_t len)
1932+
static void call_console_driver(struct console *con, const char *text, size_t len,
1933+
char *dropped_text)
19301934
{
1931-
static char dropped_text[64];
19321935
size_t dropped_len;
19331936

19341937
trace_console_rcuidle(text, len);
19351938

1936-
if (con->dropped && !(con->flags & CON_EXTENDED)) {
1937-
dropped_len = snprintf(dropped_text, sizeof(dropped_text),
1939+
if (con->dropped && dropped_text) {
1940+
dropped_len = snprintf(dropped_text, DROPPED_TEXT_MAX,
19381941
"** %lu printk messages dropped **\n",
19391942
con->dropped);
19401943
con->dropped = 0;
@@ -2296,6 +2299,7 @@ EXPORT_SYMBOL(_printk);
22962299
#else /* CONFIG_PRINTK */
22972300

22982301
#define CONSOLE_LOG_MAX 0
2302+
#define DROPPED_TEXT_MAX 0
22992303
#define printk_time false
23002304

23012305
#define prb_read_valid(rb, seq, r) false
@@ -2319,7 +2323,10 @@ static ssize_t msg_print_ext_body(char *buf, size_t size,
23192323
struct dev_printk_info *dev_info) { return 0; }
23202324
static void console_lock_spinning_enable(void) { }
23212325
static int console_lock_spinning_disable_and_check(void) { return 0; }
2322-
static void call_console_driver(struct console *con, const char *text, size_t len) { }
2326+
static void call_console_driver(struct console *con, const char *text, size_t len,
2327+
char *dropped_text)
2328+
{
2329+
}
23232330
static bool suppress_message_printing(int level) { return false; }
23242331

23252332
#endif /* CONFIG_PRINTK */
@@ -2644,6 +2651,14 @@ static void __console_unlock(void)
26442651
* Print one record for the given console. The record printed is whatever
26452652
* record is the next available record for the given console.
26462653
*
2654+
* @text is a buffer of size CONSOLE_LOG_MAX.
2655+
*
2656+
* If extended messages should be printed, @ext_text is a buffer of size
2657+
* CONSOLE_EXT_LOG_MAX. Otherwise @ext_text must be NULL.
2658+
*
2659+
* If dropped messages should be printed, @dropped_text is a buffer of size
2660+
* DROPPED_TEXT_MAX. Otherwise @dropped_text must be NULL.
2661+
*
26472662
* @handover will be set to true if a printk waiter has taken over the
26482663
* console_lock, in which case the caller is no longer holding the
26492664
* console_lock. Otherwise it is set to false.
@@ -2653,18 +2668,17 @@ static void __console_unlock(void)
26532668
*
26542669
* Requires the console_lock.
26552670
*/
2656-
static bool console_emit_next_record(struct console *con, bool *handover)
2671+
static bool console_emit_next_record(struct console *con, char *text, char *ext_text,
2672+
char *dropped_text, bool *handover)
26572673
{
2658-
static char ext_text[CONSOLE_EXT_LOG_MAX];
2659-
static char text[CONSOLE_LOG_MAX];
26602674
static int panic_console_dropped;
26612675
struct printk_info info;
26622676
struct printk_record r;
26632677
unsigned long flags;
26642678
char *write_text;
26652679
size_t len;
26662680

2667-
prb_rec_init_rd(&r, &info, text, sizeof(text));
2681+
prb_rec_init_rd(&r, &info, text, CONSOLE_LOG_MAX);
26682682

26692683
*handover = false;
26702684

@@ -2686,13 +2700,13 @@ static bool console_emit_next_record(struct console *con, bool *handover)
26862700
goto skip;
26872701
}
26882702

2689-
if (con->flags & CON_EXTENDED) {
2690-
write_text = &ext_text[0];
2691-
len = info_print_ext_header(ext_text, sizeof(ext_text), r.info);
2692-
len += msg_print_ext_body(ext_text + len, sizeof(ext_text) - len,
2703+
if (ext_text) {
2704+
write_text = ext_text;
2705+
len = info_print_ext_header(ext_text, CONSOLE_EXT_LOG_MAX, r.info);
2706+
len += msg_print_ext_body(ext_text + len, CONSOLE_EXT_LOG_MAX - len,
26932707
&r.text_buf[0], r.info->text_len, &r.info->dev_info);
26942708
} else {
2695-
write_text = &text[0];
2709+
write_text = text;
26962710
len = record_print_text(&r, console_msg_format & MSG_FORMAT_SYSLOG, printk_time);
26972711
}
26982712

@@ -2710,7 +2724,7 @@ static bool console_emit_next_record(struct console *con, bool *handover)
27102724
console_lock_spinning_enable();
27112725

27122726
stop_critical_timings(); /* don't trace print latency */
2713-
call_console_driver(con, write_text, len);
2727+
call_console_driver(con, write_text, len, dropped_text);
27142728
start_critical_timings();
27152729

27162730
con->seq++;
@@ -2746,6 +2760,9 @@ static bool console_emit_next_record(struct console *con, bool *handover)
27462760
*/
27472761
static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handover)
27482762
{
2763+
static char dropped_text[DROPPED_TEXT_MAX];
2764+
static char ext_text[CONSOLE_EXT_LOG_MAX];
2765+
static char text[CONSOLE_LOG_MAX];
27492766
bool any_usable = false;
27502767
struct console *con;
27512768
bool any_progress;
@@ -2763,7 +2780,16 @@ static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove
27632780
continue;
27642781
any_usable = true;
27652782

2766-
progress = console_emit_next_record(con, handover);
2783+
if (con->flags & CON_EXTENDED) {
2784+
/* Extended consoles do not print "dropped messages". */
2785+
progress = console_emit_next_record(con, &text[0],
2786+
&ext_text[0], NULL,
2787+
handover);
2788+
} else {
2789+
progress = console_emit_next_record(con, &text[0],
2790+
NULL, &dropped_text[0],
2791+
handover);
2792+
}
27672793
if (*handover)
27682794
return false;
27692795

0 commit comments

Comments
 (0)