From nobody Thu Apr 16 03:45:22 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B215AC4332F for ; Wed, 23 Nov 2022 23:14:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229735AbiKWXOQ (ORCPT ); Wed, 23 Nov 2022 18:14:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbiKWXON (ORCPT ); Wed, 23 Nov 2022 18:14:13 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48BB49B3B0 for ; Wed, 23 Nov 2022 15:14:12 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669245250; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/iaK6Q3VBEVIk95GUMPiu3drrm6jETQodWaJtL9sezc=; b=RPvCHbzeTnVF+1dfTWNpp1u2Ja4oUusnLtx0+NH6sMCxYoOR02JlqMlu3LV9oTETqz4j9n t9Wc/t26f4+a2isGNtBY6ZtXYv9rwvZifPRr+uPZTZ/t7tdUF6eIBaLN6S51VLoT14la88 0LplEnL7XKetw/yLNGMg2E5S/M+D2wzXpJucFLxf2w5ma2O2O2DcP1j+NpSWc7I4+q8TXJ NXs2eeNoeJnOYk23Gj56igQeMgwz4zJlv9LW5qk33hmFyG18sYzE0NYjS+/w1X13Z3SWZ4 76uWOnvJA2OcNSdqvW1ig1eiOkLmFlIHsEm2ym5SwmtL1R9J+L5cMliwc7i19A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669245250; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/iaK6Q3VBEVIk95GUMPiu3drrm6jETQodWaJtL9sezc=; b=69B7EmoOEwgiqYg29s+3eHdc8AjiAjVWVTXwWTObH4kfEJ8gT1qdFR7VycoxkUJPky/uGu ADMt+2TjjCRTz7DQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v2 1/7] printk: Move buffer size defines Date: Thu, 24 Nov 2022 00:19:54 +0106 Message-Id: <20221123231400.614679-2-john.ogness@linutronix.de> In-Reply-To: <20221123231400.614679-1-john.ogness@linutronix.de> References: <20221123231400.614679-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Move the buffer size defines to console.h in preparation of adding a buffer structure. The new buffer structure will be embedded within struct console. Therefore console.h was chosen as the new home for these defines. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness --- include/linux/console.h | 14 ++++++++++++++ include/linux/printk.h | 2 -- kernel/printk/printk.c | 4 ---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index 9cea254b34b8..799fc3216aad 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -122,6 +122,20 @@ static inline int con_debug_leave(void) #define CM_ERASE (2) #define CM_MOVE (3) =20 +#ifdef CONFIG_PRINTK + +/* The maximum size of a formatted record (i.e. with prefix added per line= ) */ +#define CONSOLE_LOG_MAX 1024 + +#else + +#define CONSOLE_LOG_MAX 0 + +#endif + +/* The maximum size of a formatted extended record */ +#define CONSOLE_EXT_LOG_MAX 8192 + /* * The interface for a console, or any other device that wants to capture * console messages (printer driver?) diff --git a/include/linux/printk.h b/include/linux/printk.h index 8c81806c2e99..8ef499ab3c1e 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -44,8 +44,6 @@ static inline const char *printk_skip_headers(const char = *buffer) return buffer; } =20 -#define CONSOLE_EXT_LOG_MAX 8192 - /* printk's without a loglevel use this.. */ #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT =20 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 9ec101766471..a4854a60e6d8 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -471,9 +471,6 @@ static struct latched_seq clear_seq =3D { #define PREFIX_MAX 32 #endif =20 -/* the maximum size of a formatted record (i.e. with prefix added per line= ) */ -#define CONSOLE_LOG_MAX 1024 - /* the maximum size for a dropped text message */ #define DROPPED_TEXT_MAX 64 =20 @@ -2387,7 +2384,6 @@ static bool __pr_flush(struct console *con, int timeo= ut_ms, bool reset_on_progre =20 #else /* CONFIG_PRINTK */ =20 -#define CONSOLE_LOG_MAX 0 #define DROPPED_TEXT_MAX 0 #define printk_time false =20 --=20 2.30.2 From nobody Thu Apr 16 03:45:22 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9665C433FE for ; Wed, 23 Nov 2022 23:14:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229823AbiKWXOY (ORCPT ); Wed, 23 Nov 2022 18:14:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229607AbiKWXOO (ORCPT ); Wed, 23 Nov 2022 18:14:14 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E2F0B8572 for ; Wed, 23 Nov 2022 15:14:13 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669245251; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F3opJ7HlbeLq3ffu10RUcIJy4CWkVQ7ilUuqExGzyjQ=; b=dqKa6Wr1Wdtr4Pf6qxKwBGE8yTiS7HowAJnEYkCsZBht7qIyYlU5t6DYmzm13I2y+RtbTV GQmYX/78A+otM0IMGWAFs+Y5Yzio/l6x2vEFdNBI5LS6YHUYLcaYyphjdnirY4nnEkW9uI XtGAsuz649cQinBcrr2jDcHqvLZSF+nLyDRCRE3J57uru/WsBNw8CLF2dRVCuxh30J9ojw g9LEF8wT0kdeROQt6PLP47saUTwI24kWk8sx2xRXnHWkD9K5TQpbDMEzysrC8DcD6Zv491 EZ/gDsWJRgHC6y0TL9wTL9WZa8XdioUUiR6bAklSK4lHnKwJ1xb6QN5FiF3gww== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669245251; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F3opJ7HlbeLq3ffu10RUcIJy4CWkVQ7ilUuqExGzyjQ=; b=W1ydZ2KGZJWegCfX3wzYey2lDEjnY0PfPIF0wpO9cLHp6C/dqNGjtEdLsYkchSQ65Qk7t2 lwhG+M7/4iWYbFDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v2 2/7] console: Use BIT() macros for @flags values Date: Thu, 24 Nov 2022 00:19:55 +0106 Message-Id: <20221123231400.614679-3-john.ogness@linutronix.de> In-Reply-To: <20221123231400.614679-1-john.ogness@linutronix.de> References: <20221123231400.614679-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Rather than manually calculating powers of 2, use the BIT() macros. Also take this opportunatity to cleanup and restructure the value comments into proper kerneldoc comments. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- include/linux/console.h | 46 ++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index 799fc3216aad..f7a14ea6bae0 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -15,6 +15,7 @@ #define _LINUX_CONSOLE_H_ 1 =20 #include +#include #include #include =20 @@ -139,18 +140,43 @@ static inline int con_debug_leave(void) /* * The interface for a console, or any other device that wants to capture * console messages (printer driver?) - * - * If a console driver is marked CON_BOOT then it will be auto-unregistered - * when the first real console is registered. This is for early-printk dr= ivers. */ =20 -#define CON_PRINTBUFFER (1) -#define CON_CONSDEV (2) /* Preferred console, /dev/console */ -#define CON_ENABLED (4) -#define CON_BOOT (8) -#define CON_ANYTIME (16) /* Safe to call when cpu is offline */ -#define CON_BRL (32) /* Used for a braille device */ -#define CON_EXTENDED (64) /* Use the extended output format a la /dev/kmsg= */ +/** + * cons_flags - General console flags + * @CON_PRINTBUFFER: Used by newly registered consoles to avoid duplicate + * output of messages that were already shown by boot + * consoles or read by userspace via syslog() syscall. + * @CON_CONSDEV: Indicates that the console driver is backing + * /dev/console. + * @CON_ENABLED: Indicates if a console is allowed to print records. If + * false, the console also will not advance to later + * records. + * @CON_BOOT: Marks the console driver as early console driver which + * is used during boot before the real driver becomes + * available. It will be automatically unregistered + * when the real console driver is registered unless + * "keep_bootcon" parameter is used. + * @CON_ANYTIME: A misnomed historical flag which tells the core code + * that the legacy @console::write callback can be invoked + * on a CPU which is marked OFFLINE. That is misleading as + * it suggests that there is no contextual limit for + * invoking the callback. The original motivation was + * readiness of the per-CPU areas. + * @CON_BRL: Indicates a braille device which is exempt from + * receiving the printk spam for obvious reasons. + * @CON_EXTENDED: The console supports the extended output format of + * /dev/kmesg which requires a larger output buffer. + */ +enum cons_flags { + CON_PRINTBUFFER =3D BIT(0), + CON_CONSDEV =3D BIT(1), + CON_ENABLED =3D BIT(2), + CON_BOOT =3D BIT(3), + CON_ANYTIME =3D BIT(4), + CON_BRL =3D BIT(5), + CON_EXTENDED =3D BIT(6), +}; =20 struct console { char name[16]; --=20 2.30.2 From nobody Thu Apr 16 03:45:22 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91B9BC4332F for ; Wed, 23 Nov 2022 23:14:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229846AbiKWXO2 (ORCPT ); Wed, 23 Nov 2022 18:14:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229700AbiKWXOP (ORCPT ); Wed, 23 Nov 2022 18:14:15 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 652D9BCDF1 for ; Wed, 23 Nov 2022 15:14:14 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669245252; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j15phA1lmvkZMkDgT4Ymay4UivTflRDgylXp+daG2hk=; b=tC75imPv7KTPVlhTdENOrDnePftFnntPZqtOo7lXs8ITaY4oNHRqw1ZsSB5hamb6Bkb0gd 2zixhJ0bY3k88YMItL69goWwRxiL4CESyvF+ZytQQOa1BxxrQC1P5U1/dQ2LW++qbXgy4p htcVDjnh50BOPr4dOSv9hCzNjCIWA1Z5wY/0/tVjfbm+v6rehUDBoOBcrl+XSOypLI7hvU yMygGWWhxw5Do3Nq5gzqNgFZ4WFXwpombaPzhZIQkqo9LWY9lm3zm9gpuvqPRMyOdCwKqV FtLs0esGtSBhJurR5GSasRoXVcUm/o8hXLRTEZFPpJK8Ox/BgbhowIb51C6lVQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669245252; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j15phA1lmvkZMkDgT4Ymay4UivTflRDgylXp+daG2hk=; b=HjI+6lRUyAYxQIumILednEjKM+aPeEeewy5p9ga2fhkB5bUNDm/Q2UScBZniOqI6yz1ggy wAec0LLVJTqzfpCQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v2 3/7] console: Document struct console Date: Thu, 24 Nov 2022 00:19:56 +0106 Message-Id: <20221123231400.614679-4-john.ogness@linutronix.de> In-Reply-To: <20221123231400.614679-1-john.ogness@linutronix.de> References: <20221123231400.614679-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Add kerneldoc comments to struct console. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- include/linux/console.h | 54 ++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index f7a14ea6bae0..b2cf256c23b6 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -178,24 +178,44 @@ enum cons_flags { CON_EXTENDED =3D BIT(6), }; =20 +/** + * struct console - The console descriptor structure + * @name: The name of the console driver + * @write: Write callback to output messages (Optional) + * @read: Read callback for console input (Optional) + * @device: The underlying TTY device driver (Optional) + * @unblank: Callback to unblank the console (Optional) + * @setup: Callback for initializing the console (Optional) + * @exit: Callback for teardown of the console (Optional) + * @match: Callback for matching a console (Optional) + * @flags: Console flags. See enum cons_flags + * @index: Console index, e.g. port number + * @cflag: TTY control mode flags + * @ispeed: TTY input speed + * @ospeed: TTY output speed + * @seq: Sequence number of the next ringbuffer record to print + * @dropped: Number of dropped ringbuffer records + * @data: Driver private data + * @node: hlist node for the console list + */ struct console { - char name[16]; - void (*write)(struct console *, const char *, unsigned); - int (*read)(struct console *, char *, unsigned); - struct tty_driver *(*device)(struct console *, int *); - void (*unblank)(void); - int (*setup)(struct console *, char *); - int (*exit)(struct console *); - int (*match)(struct console *, char *name, int idx, char *options); - short flags; - short index; - int cflag; - uint ispeed; - uint ospeed; - u64 seq; - unsigned long dropped; - void *data; - struct hlist_node node; + char name[16]; + void (*write)(struct console *co, const char *s, unsigned int count); + int (*read)(struct console *co, char *s, unsigned int count); + struct tty_driver *(*device)(struct console *co, int *index); + void (*unblank)(void); + int (*setup)(struct console *co, char *options); + int (*exit)(struct console *co); + int (*match)(struct console *co, char *name, int idx, char *options); + short flags; + short index; + int cflag; + uint ispeed; + uint ospeed; + u64 seq; + unsigned long dropped; + void *data; + struct hlist_node node; }; =20 #ifdef CONFIG_LOCKDEP --=20 2.30.2 From nobody Thu Apr 16 03:45:22 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AD5DC433FE for ; Wed, 23 Nov 2022 23:14:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229886AbiKWXOb (ORCPT ); Wed, 23 Nov 2022 18:14:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229732AbiKWXOQ (ORCPT ); Wed, 23 Nov 2022 18:14:16 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B7136BDEE for ; Wed, 23 Nov 2022 15:14:15 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669245253; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aHekk7rHrVj5L5T/94RT0HyGLRna0DzwZs8ha+Ccyvw=; b=rUgi9ajh583f3DafswGx6DnJgtX1nVcRAI0OyvdmARANW4/vl6t1tWVQkHydEMakuWWC11 USYMG+Gs8LFd4tcL6UReH+pZX4mBlHObcxMHf+AKL9UvcdGeq2e4uRKAyK3le2jXCfAyts n+ppQ+9SW7jvNmqXyvoh7/2iWz/RAsfVn06Qu+ag4MlIBbVKOFMMx4XUWSPL24cMJhemaG KDXxrR6MbH+huS7Ii4ul3e2XVCASSvMolb6UQO103ehl3MO+mKu5qQCgzzgM2anf/BKsWW YlLxKESOAulXbigFgHDL6LRpLI/6nlI5QTGHxhVtPG9bqEfXBWEvBZnAfNkWtg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669245253; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aHekk7rHrVj5L5T/94RT0HyGLRna0DzwZs8ha+Ccyvw=; b=2GHZKoSrpfphmj+qCrBjg2+U05bc9CFtPkG0ZSPQaa+D8zKrUOuD28SZDr66qVARIhuUIb dM9dzZOLn74ztsCw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v2 4/7] printk: Add struct console_buffers Date: Thu, 24 Nov 2022 00:19:57 +0106 Message-Id: <20221123231400.614679-5-john.ogness@linutronix.de> In-Reply-To: <20221123231400.614679-1-john.ogness@linutronix.de> References: <20221123231400.614679-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Create a data structure to replace the open coded separate buffers for regular, extended, and dropped message formatting. A separate @ext_text buffer is needed because info_print_ext_header() and msg_print_ext_body() are not able to add the needed extra information in-place. @ext_text can be used for dropped text because they are never used at the same time. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- include/linux/console.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/linux/console.h b/include/linux/console.h index b2cf256c23b6..641c1ca7fb67 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -178,6 +178,16 @@ enum cons_flags { CON_EXTENDED =3D BIT(6), }; =20 +/** + * struct console_buffers - console output text buffers + * @ext_text: Buffer for extended log format or dropped text + * @text: Buffer for ringbuffer text + */ +struct console_buffers { + char ext_text[CONSOLE_EXT_LOG_MAX]; + char text[CONSOLE_LOG_MAX]; +}; + /** * struct console - The console descriptor structure * @name: The name of the console driver --=20 2.30.2 From nobody Thu Apr 16 03:45:22 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 577E7C4332F for ; Wed, 23 Nov 2022 23:14:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229894AbiKWXOe (ORCPT ); Wed, 23 Nov 2022 18:14:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229753AbiKWXOR (ORCPT ); Wed, 23 Nov 2022 18:14:17 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 739ABB8572 for ; Wed, 23 Nov 2022 15:14:16 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669245254; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JpOUi4hZM07oyPRVgjxj+qDi5g9936QFYUmsuEbCZ8s=; b=QQn/XAVQEtN5GlT1O7T6LLtNJGecVagnIyP5bepPSTYdXmr9caQK312pU7kF61/zQHHcja SITbmNu+NfbGQzajqSW0KhBJija/Civf4YGMl9GMK7VGxFZ1UzOPUH6/3izLQesNK4nSKI cCH+i0f/CPc62Ly9Z1e0loHmoWj62+VehtwdI7nJJDD7USQGjTfdUHUI0A8ocwTd/Z4Syh CJvFUVqyqdBA9tosW41VhcW3AfHQ/Dt68t7tCnCKwQcOaQFaRJevGTway0B/IIFvdYYLA/ vyZbj7BK2O69Ckaf6KBlEJTHvnrBMM52YAW1SSLCgGmGV1g8qRobFX2Gkd7yBg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669245254; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JpOUi4hZM07oyPRVgjxj+qDi5g9936QFYUmsuEbCZ8s=; b=Nu0tMTfqSA6a0V+xGV40DqsroZQ5CWfNxABHcURW2PrGgPxY251ku8vWm9PNS0vXGjTjWE Z6CTBuVoFpRmZaCw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 5/7] printk: Use struct console_buffers Date: Thu, 24 Nov 2022 00:19:58 +0106 Message-Id: <20221123231400.614679-6-john.ogness@linutronix.de> In-Reply-To: <20221123231400.614679-1-john.ogness@linutronix.de> References: <20221123231400.614679-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Replace the separately allocated output buffers with a single instance of struct console_buffers. Note that the buffer size of devkmsg_user.text_buf, when replaced with console_buffers.text, reduces from CONSOLE_EXT_LOG_MAX to CONSOLE_LOG_MAX. However, the buffer is only used to read ringbuffer records. These records have a maximum size of LOG_LINE_MAX, which is defined as CONSOLE_LOG_MAX - PREFIX_MAX. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness --- kernel/printk/printk.c | 68 ++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index a4854a60e6d8..750559171e30 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -712,11 +712,9 @@ struct devkmsg_user { atomic64_t seq; struct ratelimit_state rs; struct mutex lock; - char buf[CONSOLE_EXT_LOG_MAX]; - struct printk_info info; - char text_buf[CONSOLE_EXT_LOG_MAX]; struct printk_record record; + struct console_buffers cbufs; }; =20 static __printf(3, 4) __cold @@ -798,6 +796,8 @@ static ssize_t devkmsg_read(struct file *file, char __u= ser *buf, size_t count, loff_t *ppos) { struct devkmsg_user *user =3D file->private_data; + const int ext_text_size =3D sizeof(user->cbufs.ext_text); + char *ext_text =3D &user->cbufs.ext_text[0]; struct printk_record *r =3D &user->record; size_t len; ssize_t ret; @@ -839,8 +839,8 @@ static ssize_t devkmsg_read(struct file *file, char __u= ser *buf, goto out; } =20 - len =3D info_print_ext_header(user->buf, sizeof(user->buf), r->info); - len +=3D msg_print_ext_body(user->buf + len, sizeof(user->buf) - len, + len =3D info_print_ext_header(ext_text, ext_text_size, r->info); + len +=3D msg_print_ext_body(ext_text + len, ext_text_size - len, &r->text_buf[0], r->info->text_len, &r->info->dev_info); =20 @@ -851,7 +851,7 @@ static ssize_t devkmsg_read(struct file *file, char __u= ser *buf, goto out; } =20 - if (copy_to_user(buf, user->buf, len)) { + if (copy_to_user(buf, ext_text, len)) { ret =3D -EFAULT; goto out; } @@ -950,7 +950,7 @@ static int devkmsg_open(struct inode *inode, struct fil= e *file) mutex_init(&user->lock); =20 prb_rec_init_rd(&user->record, &user->info, - &user->text_buf[0], sizeof(user->text_buf)); + &user->cbufs.text[0], sizeof(user->cbufs.text)); =20 atomic64_set(&user->seq, prb_first_valid_seq(prb)); =20 @@ -2007,6 +2007,10 @@ static int console_trylock_spinning(void) return 1; } =20 +#if DROPPED_TEXT_MAX > CONSOLE_EXT_LOG_MAX +#error "DROPPED_TEXT_MAX too large for console_buffers->ext_text" +#endif + /* * Call the specified console driver, asking it to write out the specified * text and length. If @dropped_text is non-NULL and any records have been @@ -2741,36 +2745,32 @@ static void __console_unlock(void) * Print one record for the given console. The record printed is whatever * record is the next available record for the given console. * - * @text is a buffer of size CONSOLE_LOG_MAX. + * @cbufs is the console buffers used to string-print the formatted messag= es. * - * If extended messages should be printed, @ext_text is a buffer of size - * CONSOLE_EXT_LOG_MAX. Otherwise @ext_text must be NULL. - * - * If dropped messages should be printed, @dropped_text is a buffer of size - * DROPPED_TEXT_MAX. Otherwise @dropped_text must be NULL. + * @cookie is the cookie from entering the SRCU read-side critical section. * * @handover will be set to true if a printk waiter has taken over the * console_lock, in which case the caller is no longer holding both the * console_lock and the SRCU read lock. Otherwise it is set to false. * - * @cookie is the cookie from the SRCU read lock. - * * Returns false if the given console has no next record to print, otherwi= se * true. * * Requires the console_lock and the SRCU read lock. */ -static bool console_emit_next_record(struct console *con, char *text, char= *ext_text, - char *dropped_text, bool *handover, int cookie) +static bool console_emit_next_record(struct console *con, struct console_b= uffers *cbufs, + int cookie, bool *handover) { static int panic_console_dropped; struct printk_info info; struct printk_record r; + size_t write_text_size; unsigned long flags; + char *dropped_text; char *write_text; size_t len; =20 - prb_rec_init_rd(&r, &info, text, CONSOLE_LOG_MAX); + prb_rec_init_rd(&r, &info, &cbufs->text[0], sizeof(cbufs->text)); =20 *handover =3D false; =20 @@ -2792,13 +2792,20 @@ static bool console_emit_next_record(struct console= *con, char *text, char *ext_ goto skip; } =20 - if (ext_text) { - write_text =3D ext_text; - len =3D info_print_ext_header(ext_text, CONSOLE_EXT_LOG_MAX, r.info); - len +=3D msg_print_ext_body(ext_text + len, CONSOLE_EXT_LOG_MAX - len, + if (console_srcu_read_flags(con) & CON_EXTENDED) { + /* Extended consoles do not print "dropped messages". */ + dropped_text =3D NULL; + + write_text =3D &cbufs->ext_text[0]; + write_text_size =3D sizeof(cbufs->ext_text); + len =3D info_print_ext_header(write_text, write_text_size, r.info); + len +=3D msg_print_ext_body(write_text + len, write_text_size - len, &r.text_buf[0], r.info->text_len, &r.info->dev_info); } else { - write_text =3D text; + /* @ext_text is unused. Use it for "dropped messages". */ + dropped_text =3D &cbufs->ext_text[0]; + + write_text =3D &cbufs->text[0]; len =3D record_print_text(&r, console_msg_format & MSG_FORMAT_SYSLOG, pr= intk_time); } =20 @@ -2852,9 +2859,7 @@ static bool console_emit_next_record(struct console *= con, char *text, char *ext_ */ static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *h= andover) { - static char dropped_text[DROPPED_TEXT_MAX]; - static char ext_text[CONSOLE_EXT_LOG_MAX]; - static char text[CONSOLE_LOG_MAX]; + static struct console_buffers cbufs; bool any_usable =3D false; struct console *con; bool any_progress; @@ -2874,16 +2879,7 @@ static bool console_flush_all(bool do_cond_resched, = u64 *next_seq, bool *handove continue; any_usable =3D true; =20 - if (console_srcu_read_flags(con) & CON_EXTENDED) { - /* Extended consoles do not print "dropped messages". */ - progress =3D console_emit_next_record(con, &text[0], - &ext_text[0], NULL, - handover, cookie); - } else { - progress =3D console_emit_next_record(con, &text[0], - NULL, &dropped_text[0], - handover, cookie); - } + progress =3D console_emit_next_record(con, &cbufs, cookie, handover); =20 /* * If a handover has occurred, the SRCU read lock --=20 2.30.2 From nobody Thu Apr 16 03:45:22 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9261EC433FE for ; Wed, 23 Nov 2022 23:14:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229904AbiKWXOk (ORCPT ); Wed, 23 Nov 2022 18:14:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229766AbiKWXOT (ORCPT ); Wed, 23 Nov 2022 18:14:19 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAEC8D14D9 for ; Wed, 23 Nov 2022 15:14:17 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669245255; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/+ga5EsQ4Q0dD6QKcBL7AASWXoGeU5dLsOdcdIgzrhs=; b=ENbn+NVeyH3goCHcBewID4TRhVV6TmCCFuuG2iQfD7h0paqLwG/rHRTVm1q9gCCJFpJTMa XC3fJbUgQO2BVeUKwUGj9GTVtD+kJFSTqMyoy1XQSk5gjLSInHpVDfPvw5Ov35XK3Efs07 zhifff4+2qJBwOYPv/ciWdEXfB9Iw203sWEWg9MJ76MtDjfzINAoXuSXOa89Do2mohtUjI RdtdklCZXjOMAZ/S9BhnIMAxE+Rm1hhqKGRnb8+rPnBb0F1TksbGO2WGtn3fh90srC5fP0 DkeAZjjbICwMpxJEpL4H/FvOu6bHKMJNjJ0aIQXQpL6Tx4NK06OFd3YIa2+m0g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669245255; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/+ga5EsQ4Q0dD6QKcBL7AASWXoGeU5dLsOdcdIgzrhs=; b=mTgAe5Nxh1q4mgK3PfLQ6P+S/ViwtZ4ERFiuk8l/2jxdxCU6/uzf7eMa7aa4MvbCPqnN4m 9o2HKk52WW56qzBA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v2 6/7] printk: Use an output buffer descriptor struct for emit Date: Thu, 24 Nov 2022 00:19:59 +0106 Message-Id: <20221123231400.614679-7-john.ogness@linutronix.de> In-Reply-To: <20221123231400.614679-1-john.ogness@linutronix.de> References: <20221123231400.614679-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner To prepare for a new console infrastructure that is independent of the console BKL, wrap the output mode into a descriptor struct so the new infrastructure can share the emit code that dumps the ringbuffer record into the output text buffers. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness --- include/linux/console.h | 15 ++++++ kernel/printk/printk.c | 107 ++++++++++++++++++++++++++++------------ 2 files changed, 90 insertions(+), 32 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index 641c1ca7fb67..32614011a950 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -188,6 +188,21 @@ struct console_buffers { char text[CONSOLE_LOG_MAX]; }; =20 +/** + * struct console_message - console output buffer descriptor + * @cbufs: Pointer to console buffers storing the record text + * @outbuf: Pointer to the text buffer to be used for writing out + * to the device + * @outbuf_len: Length of text at @outbuf + * @is_extmsg: True if this is an extended format message + */ +struct console_message { + struct console_buffers *cbufs; + char *outbuf; + unsigned int outbuf_len; + bool is_extmsg; +}; + /** * struct console - The console descriptor structure * @name: The name of the console driver diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 750559171e30..dd1d8599ce5a 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2741,11 +2741,76 @@ static void __console_unlock(void) up_console_sem(); } =20 +/** + * console_get_next_message - Fill the output buffer with the next record + * @con: The console to print on + * @cmsg: Pointer to the output buffer descriptor + * + * Return: False if there is no pending record in the ringbuffer. + * True if there is a pending record in the ringbuffer. + * + * When the return value is true, then the caller must check + * @cmsg->outbuf. If not NULL it points to the first character to write + * to the device and @cmsg->outbuf_len contains the length of the message. + * If it is NULL then the record will be skipped. + */ +static bool console_get_next_message(struct console *con, struct console_m= essage *cmsg) +{ + struct console_buffers *cbufs =3D cmsg->cbufs; + static int panic_console_dropped; + struct printk_info info; + struct printk_record r; + size_t write_text_size; + char *write_text; + size_t len; + + cmsg->outbuf =3D NULL; + cmsg->outbuf_len =3D 0; + + prb_rec_init_rd(&r, &info, &cbufs->text[0], sizeof(cbufs->text)); + + if (!prb_read_valid(prb, con->seq, &r)) + return false; + + if (con->seq !=3D r.info->seq) { + con->dropped +=3D r.info->seq - con->seq; + con->seq =3D r.info->seq; + if (panic_in_progress() && panic_console_dropped++ > 10) { + suppress_panic_printk =3D 1; + pr_warn_once("Too many dropped messages. Suppress messages on non-panic= CPUs to prevent livelock.\n"); + } + } + + /* + * Skip record that has level above the console loglevel. + * Return true so the caller knows a record exists and + * leave cmsg->outbuf NULL so the caller knows the record + * is being skipped. + */ + if (suppress_message_printing(r.info->level)) + return true; + + if (cmsg->is_extmsg) { + write_text =3D &cbufs->ext_text[0]; + write_text_size =3D sizeof(cbufs->ext_text); + len =3D info_print_ext_header(write_text, write_text_size, r.info); + len +=3D msg_print_ext_body(write_text + len, write_text_size - len, + &r.text_buf[0], r.info->text_len, &r.info->dev_info); + } else { + write_text =3D &cbufs->text[0]; + len =3D record_print_text(&r, console_msg_format & MSG_FORMAT_SYSLOG, pr= intk_time); + } + + cmsg->outbuf =3D write_text; + cmsg->outbuf_len =3D len; + return true; +} + /* * Print one record for the given console. The record printed is whatever * record is the next available record for the given console. * - * @cbufs is the console buffers used to string-print the formatted messag= es. + * @cbufs is the console buffers to use for string-printing the message. * * @cookie is the cookie from entering the SRCU read-side critical section. * @@ -2761,52 +2826,30 @@ static void __console_unlock(void) static bool console_emit_next_record(struct console *con, struct console_b= uffers *cbufs, int cookie, bool *handover) { - static int panic_console_dropped; - struct printk_info info; - struct printk_record r; - size_t write_text_size; + struct console_message cmsg =3D { + .cbufs =3D cbufs, + .is_extmsg =3D console_srcu_read_flags(con) & CON_EXTENDED, + }; unsigned long flags; char *dropped_text; - char *write_text; - size_t len; - - prb_rec_init_rd(&r, &info, &cbufs->text[0], sizeof(cbufs->text)); =20 *handover =3D false; =20 - if (!prb_read_valid(prb, con->seq, &r)) + if (!console_get_next_message(con, &cmsg)) return false; =20 - if (con->seq !=3D r.info->seq) { - con->dropped +=3D r.info->seq - con->seq; - con->seq =3D r.info->seq; - if (panic_in_progress() && panic_console_dropped++ > 10) { - suppress_panic_printk =3D 1; - pr_warn_once("Too many dropped messages. Suppress messages on non-panic= CPUs to prevent livelock.\n"); - } - } - - /* Skip record that has level above the console loglevel. */ - if (suppress_message_printing(r.info->level)) { + if (!cmsg.outbuf) { + /* Skipping this record. */ con->seq++; goto skip; } =20 - if (console_srcu_read_flags(con) & CON_EXTENDED) { + if (cmsg.is_extmsg) { /* Extended consoles do not print "dropped messages". */ dropped_text =3D NULL; - - write_text =3D &cbufs->ext_text[0]; - write_text_size =3D sizeof(cbufs->ext_text); - len =3D info_print_ext_header(write_text, write_text_size, r.info); - len +=3D msg_print_ext_body(write_text + len, write_text_size - len, - &r.text_buf[0], r.info->text_len, &r.info->dev_info); } else { /* @ext_text is unused. Use it for "dropped messages". */ dropped_text =3D &cbufs->ext_text[0]; - - write_text =3D &cbufs->text[0]; - len =3D record_print_text(&r, console_msg_format & MSG_FORMAT_SYSLOG, pr= intk_time); } =20 /* @@ -2823,7 +2866,7 @@ static bool console_emit_next_record(struct console *= con, struct console_buffers console_lock_spinning_enable(); =20 stop_critical_timings(); /* don't trace print latency */ - call_console_driver(con, write_text, len, dropped_text); + call_console_driver(con, cmsg.outbuf, cmsg.outbuf_len, dropped_text); start_critical_timings(); =20 con->seq++; --=20 2.30.2 From nobody Thu Apr 16 03:45:22 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A1F4C4332F for ; Wed, 23 Nov 2022 23:14:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229934AbiKWXOn (ORCPT ); Wed, 23 Nov 2022 18:14:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229797AbiKWXOU (ORCPT ); Wed, 23 Nov 2022 18:14:20 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11019D14E8 for ; Wed, 23 Nov 2022 15:14:19 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669245256; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0qJ3iGikvuTukQn/cCJfO+65/fD4hTu0WWCBxLF08iQ=; b=qFG7KOKPIOGPVQw4I4QTVM52nnmpM91ysQ6T70Acjrw1gpl0mSL1hKuzjaYH3IyrBdHtv6 oh/j557mygD9WK7tfw/fKTKt1veJRrSPK/tfHkUVK2/aD1rCsP9TA24uV7U6CwgM+UnHK3 33M0kpa68PuW0Ut2XgbpCvlM5j5RRdPeszmPqkKCBPHHmvZTE/TT/ad9TN6LxRbxPV5DUv WpwG0pluX/88uGy/c12JMEfAt+cQjzIfzZQ3Qg2oVIXdDCmxYEh75Xm/C23581Dg3PZEZw Cc1NwxIkCOATcuq59S94MuFyyppOkXrb0C0tO/A08yqCqgTUkZ/Ci6ANn0QXGQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669245256; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0qJ3iGikvuTukQn/cCJfO+65/fD4hTu0WWCBxLF08iQ=; b=SDLoP6aDtGO+Fh77Cy+vmar1/O+F8pe4MEZi8b2SuHvnnXV3AVCXOa3UDf8N3bIdogk61N B3dJyH5e3wquaECg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 7/7] printk: Handle dropped message smarter Date: Thu, 24 Nov 2022 00:20:00 +0106 Message-Id: <20221123231400.614679-8-john.ogness@linutronix.de> In-Reply-To: <20221123231400.614679-1-john.ogness@linutronix.de> References: <20221123231400.614679-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner If a 'dropped message' is to be printed, move the record text to be directly appended to the 'dropped message' and let console->write() output it in one go. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness --- kernel/printk/printk.c | 125 +++++++++++++++++++++++++++-------------- 1 file changed, 82 insertions(+), 43 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index dd1d8599ce5a..c4b148a7d114 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2007,31 +2007,6 @@ static int console_trylock_spinning(void) return 1; } =20 -#if DROPPED_TEXT_MAX > CONSOLE_EXT_LOG_MAX -#error "DROPPED_TEXT_MAX too large for console_buffers->ext_text" -#endif - -/* - * Call the specified console driver, asking it to write out the specified - * text and length. If @dropped_text is non-NULL and any records have been - * dropped, a dropped message will be written out first. - */ -static void call_console_driver(struct console *con, const char *text, siz= e_t len, - char *dropped_text) -{ - size_t dropped_len; - - if (con->dropped && dropped_text) { - dropped_len =3D snprintf(dropped_text, DROPPED_TEXT_MAX, - "** %lu printk messages dropped **\n", - con->dropped); - con->dropped =3D 0; - con->write(con, dropped_text, dropped_len); - } - - con->write(con, text, len); -} - /* * Recursion is tracked separately on each CPU. If NMIs are supported, an * additional NMI context per CPU is also separately tracked. Until per-CPU @@ -2412,10 +2387,6 @@ static ssize_t msg_print_ext_body(char *buf, size_t = size, struct dev_printk_info *dev_info) { return 0; } static void console_lock_spinning_enable(void) { } static int console_lock_spinning_disable_and_check(int cookie) { return 0;= } -static void call_console_driver(struct console *con, const char *text, siz= e_t len, - char *dropped_text) -{ -} static bool suppress_message_printing(int level) { return false; } static bool pr_flush(int timeout_ms, bool reset_on_progress) { return true= ; } static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_= progress) { return true; } @@ -2741,6 +2712,60 @@ static void __console_unlock(void) up_console_sem(); } =20 +/* + * A maximum dropped message together with a maximum regular message + * must be able to fit within console_buffers->ext_text. + */ +#if DROPPED_TEXT_MAX > (CONSOLE_EXT_LOG_MAX - CONSOLE_LOG_MAX) +#error "DROPPED_TEXT_MAX too large for console_buffers->ext_text" +#endif + +/** + * msg_print_dropped - Prepend a "dropped message" if required + * @desc: Pointer to the output descriptor + * @dropped: The number of dropped messages to report + * + * Inserts the "dropped message" into the output buffer if @dropped is + * not 0 and the regular format is requested. Extended format does not + * need this message because it prints the sequence numbers. + * + * In regular format, the extended message buffer is not in use. So + * string-print the dropped message there and move the record text to be + * appended to the dropped message. The extended message buffer is much + * larger and can accommodate both messages. + * + * In case a dropped message is needed, this returns with @desc->outbuf + * and @desc->len updated. The caller is responsible for tracking and + * resetting the dropped count. If no dropped message is required then + * @desc is not modified. + */ +static void msg_print_dropped(struct console_message *cmsg, unsigned long = dropped) +{ + struct console_buffers *cbufs =3D cmsg->cbufs; + char *ext_text =3D &cbufs->ext_text[0]; + size_t len; + + if (!dropped || cmsg->is_extmsg) + return; + + if (WARN_ON_ONCE(cmsg->outbuf !=3D &cbufs->text[0])) + return; + + /* Print it into ext_text, which is unused. */ + len =3D snprintf(ext_text, DROPPED_TEXT_MAX, + "** %lu printk messages dropped **\n", dropped); + + /* + * Append the record text to the dropped message so that it + * goes out with one write. + */ + memcpy(ext_text + len, &cbufs->text[0], cmsg->outbuf_len); + + /* Update the output buffer descriptor. */ + cmsg->outbuf =3D ext_text; + cmsg->outbuf_len +=3D len; +} + /** * console_get_next_message - Fill the output buffer with the next record * @con: The console to print on @@ -2796,13 +2821,32 @@ static bool console_get_next_message(struct console= *con, struct console_message len =3D info_print_ext_header(write_text, write_text_size, r.info); len +=3D msg_print_ext_body(write_text + len, write_text_size - len, &r.text_buf[0], r.info->text_len, &r.info->dev_info); + + cmsg->outbuf =3D write_text; + cmsg->outbuf_len =3D len; + + /* + * Extended consoles do not print "dropped messages" + * as that can be seen from the sequence number. + */ } else { - write_text =3D &cbufs->text[0]; len =3D record_print_text(&r, console_msg_format & MSG_FORMAT_SYSLOG, pr= intk_time); + + cmsg->outbuf =3D &cbufs->text[0]; + cmsg->outbuf_len =3D len; + + if (con->dropped) { + /* + * It is expected that @outbuf and @outbuf_len are + * already set. They will be updated after inserting + * the "dropped message". + */ + msg_print_dropped(cmsg, con->dropped); + + con->dropped =3D 0; + } } =20 - cmsg->outbuf =3D write_text; - cmsg->outbuf_len =3D len; return true; } =20 @@ -2831,7 +2875,6 @@ static bool console_emit_next_record(struct console *= con, struct console_buffers .is_extmsg =3D console_srcu_read_flags(con) & CON_EXTENDED, }; unsigned long flags; - char *dropped_text; =20 *handover =3D false; =20 @@ -2844,14 +2887,6 @@ static bool console_emit_next_record(struct console = *con, struct console_buffers goto skip; } =20 - if (cmsg.is_extmsg) { - /* Extended consoles do not print "dropped messages". */ - dropped_text =3D NULL; - } else { - /* @ext_text is unused. Use it for "dropped messages". */ - dropped_text =3D &cbufs->ext_text[0]; - } - /* * While actively printing out messages, if another printk() * were to occur on another CPU, it may wait for this one to @@ -2865,8 +2900,12 @@ static bool console_emit_next_record(struct console = *con, struct console_buffers printk_safe_enter_irqsave(flags); console_lock_spinning_enable(); =20 - stop_critical_timings(); /* don't trace print latency */ - call_console_driver(con, cmsg.outbuf, cmsg.outbuf_len, dropped_text); + /* Do not trace print latency. */ + stop_critical_timings(); + + /* Write everything out to the hardware. */ + con->write(con, cmsg.outbuf, cmsg.outbuf_len); + start_critical_timings(); =20 con->seq++; --=20 2.30.2