From nobody Tue Sep 16 09:01:23 2025 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 473A7C3DA7A for ; Thu, 5 Jan 2023 10:38:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232892AbjAEKii (ORCPT ); Thu, 5 Jan 2023 05:38:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233060AbjAEKiR (ORCPT ); Thu, 5 Jan 2023 05:38:17 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC37E395E2 for ; Thu, 5 Jan 2023 02:38:16 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1672915095; 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=abSBMFxz6OGnYpZ+uMTv9uCdX0Afe+r827cQ4Qs2ufY=; b=tqehtiMLazk/qWuhSsaz5i2yKpuIumt7UJ/O9IVTFwWS8oUv9OP2KsY25Vyh2Ur2hw5AhE rwJqybiVS56Yz0rcozukcD4ENkQVvWrLwJUMaz4x3cz7Y9gHEo8gBcEmv9bwJ/DM3kiHXl YBViDZDDmjjZCOYK/joLlQjreviSc1YQrKVp5UVeH+EyqGTkx7Dd99G7UU1rHQelKSDbpl yTdxQ5Xk8WlvhcdCmNWYaLJ1Ia2dVVBipBmCBCVXMilZ56bx7SPWWxJy0dH8CC0WKVCmil VmVdaCKkFjMbbW4rjteHr0nLAU9xmfOOF9kOKRNxCjpdQ5aCOjFT+AAIylidcg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1672915095; 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=abSBMFxz6OGnYpZ+uMTv9uCdX0Afe+r827cQ4Qs2ufY=; b=6A/kl4DuJAeDd+nmgvm37gEIK/iEFtiobj2bA8QZuL8FsdR0mmgRRamGvkcbmbZ2eS1ZVc zbGTvoCRfWk/GlDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 1/8] printk: move size limit macros into internal.h Date: Thu, 5 Jan 2023 11:43:28 +0106 Message-Id: <20230105103735.880956-2-john.ogness@linutronix.de> In-Reply-To: <20230105103735.880956-1-john.ogness@linutronix.de> References: <20230105103735.880956-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" The size limit macros are located further down in printk.c and behind ifdef conditionals. This complicates their usage for upcoming changes. Move the macros into internal.h so that they are still invisible outside of printk, but easily accessible for printk. Also, the maximum size of formatted extended messages does not need to be known by any code outside of printk, so move it to internal.h as well. And like CONSOLE_LOG_MAX, for !CONFIG_PRINTK set CONSOLE_EXT_LOG_MAX to 0 to reduce the static memory footprint. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- include/linux/printk.h | 2 -- kernel/printk/internal.h | 24 ++++++++++++++++++++++++ kernel/printk/printk.c | 17 ----------------- 3 files changed, 24 insertions(+), 19 deletions(-) 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/internal.h b/kernel/printk/internal.h index d947ca6c84f9..f394332410c9 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -14,6 +14,24 @@ int devkmsg_sysctl_set_loglvl(struct ctl_table *table, i= nt write, =20 #ifdef CONFIG_PRINTK =20 +#ifdef CONFIG_PRINTK_CALLER +#define PREFIX_MAX 48 +#else +#define PREFIX_MAX 32 +#endif + +/* the maximum size of a formatted record (i.e. with prefix added per line= ) */ +#define CONSOLE_LOG_MAX 1024 + +/* the maximum size of a formatted extended record */ +#define CONSOLE_EXT_LOG_MAX 8192 + +/* the maximum size for a dropped text message */ +#define DROPPED_TEXT_MAX 64 + +/* the maximum size allowed to be reserved for a record */ +#define LOG_LINE_MAX (CONSOLE_LOG_MAX - PREFIX_MAX) + /* Flags for a single printk record. */ enum printk_info_flags { LOG_NEWLINE =3D 2, /* text ended with a newline */ @@ -48,6 +66,12 @@ u16 printk_parse_prefix(const char *text, int *level, enum printk_info_flags *flags); #else =20 +#define PREFIX_MAX 0 +#define CONSOLE_LOG_MAX 0 +#define CONSOLE_EXT_LOG_MAX 0 +#define DROPPED_TEXT_MAX 0 +#define LOG_LINE_MAX 0 + /* * In !PRINTK builds we still export console_sem * semaphore and some of console functions (console_unlock()/etc.), so diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 7decf1e9c486..55bb065de65f 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -465,21 +465,6 @@ static struct latched_seq clear_seq =3D { .val[1] =3D 0, }; =20 -#ifdef CONFIG_PRINTK_CALLER -#define PREFIX_MAX 48 -#else -#define PREFIX_MAX 32 -#endif - -/* 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 - -/* the maximum size allowed to be reserved for a record */ -#define LOG_LINE_MAX (CONSOLE_LOG_MAX - PREFIX_MAX) - #define LOG_LEVEL(v) ((v) & 0x07) #define LOG_FACILITY(v) ((v) >> 3 & 0xff) =20 @@ -2387,8 +2372,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 #define prb_read_valid(rb, seq, r) false --=20 2.30.2 From nobody Tue Sep 16 09:01:23 2025 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 1889BC3DA7A for ; Thu, 5 Jan 2023 10:39:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232894AbjAEKjI (ORCPT ); Thu, 5 Jan 2023 05:39:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233068AbjAEKiS (ORCPT ); Thu, 5 Jan 2023 05:38:18 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 704283D1C1 for ; Thu, 5 Jan 2023 02:38:17 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1672915095; 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=XbYaurIRdFG+/mjMZ4Nnsd0tE8OMeEIDH+uE2KSAjBQ=; b=OyPbJCV/0RK4Z5l8+dTVu6yHvXQ70l1n7PW0gElQzOHS3oez0h793xmtJrG8Ibf+KREW9u 1VzN0lMdCqaDig6Kf2ZAe3Qt9XTeJZ0iw3t+FgCBZawyKGYgyfvVyJ/3hkczitkNPhTTNB j40WbAW8PlxBK7U6nHBp40S4U4M+vcLzVBskrtz34k7jpvzF5gpAPjuRvjPanL64wfkI3G L63FCU3mdkRq1LPWENt2ooY4SFxJq3I/VJSfGa6mvvJ7ENGPikM8x6dUwVeSX4Dh8DWv6u Y3CrDzEDX6gTk6ASE4aCY0iEF6ooJOqUsZzvKQK8dq8vusbhORjPg3ZKH4r1FA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1672915095; 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=XbYaurIRdFG+/mjMZ4Nnsd0tE8OMeEIDH+uE2KSAjBQ=; b=sPVu67nrL/W0LLko+a9J1lMTSZXIt6Pmfe1siI4O6rnww0XwqxREtvcL3y9PhvRfmaMj07 qnH6IGrkUUh9itAw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v4 2/8] console: Use BIT() macros for @flags values Date: Thu, 5 Jan 2023 11:43:29 +0106 Message-Id: <20230105103735.880956-3-john.ogness@linutronix.de> In-Reply-To: <20230105103735.880956-1-john.ogness@linutronix.de> References: <20230105103735.880956-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 9cea254b34b8..ed804dd7c2e8 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 @@ -125,18 +126,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 Tue Sep 16 09:01:23 2025 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 5DAC0C3DA7A for ; Thu, 5 Jan 2023 10:38:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232969AbjAEKiq (ORCPT ); Thu, 5 Jan 2023 05:38:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233062AbjAEKiS (ORCPT ); Thu, 5 Jan 2023 05:38:18 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 841773D9D3 for ; Thu, 5 Jan 2023 02:38:17 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1672915096; 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=Z+UJBfU/8l7fpxJzETJJj+Hr/lkYjP0wgmBYzutEocw=; b=V9egSrOFJEbDO1+JjPphw36K4ufP/XN2d3lp5A8JMAHXg9jcUdL3dbyQp4feXHjXf3k5MK b8+f3ILzJF1dVYm6dCyRtwbPNJkSxI+apJ+oKp+pk3dVYiEuvZA5PgNIb+c4wc/6xNUxwb I5CZ3gDz03F/gjJxWDW8WY4mHk8P8eM8tFNUk7xaAMRyWK7faBap84DbmJant5mvNQvkTj yPNwVHzLL1zfRNk3AiP6ZQEXwbenpIPPscUCYOkG3vAzzRgXa01FZRtgL3ktCSPz9xNiNo mLZv87YHiFbb+WRImmO0dZVcZMGg4Kt4fGIBQfAkIQdm1vXjPK0uZtGCZpsa1Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1672915096; 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=Z+UJBfU/8l7fpxJzETJJj+Hr/lkYjP0wgmBYzutEocw=; b=tzeP+Qq74Q1FePBoqTmV4oz8bIVL4B7nq1CqqR/2JbsAQsxDO6zja9DhMzb6V0q8MZ/Ryw h63Q3Le6yJtQXLAg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v4 3/8] console: Document struct console Date: Thu, 5 Jan 2023 11:43:30 +0106 Message-Id: <20230105103735.880956-4-john.ogness@linutronix.de> In-Reply-To: <20230105103735.880956-1-john.ogness@linutronix.de> References: <20230105103735.880956-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 ed804dd7c2e8..1e36958aa656 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -164,24 +164,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 unreported 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 Tue Sep 16 09:01:23 2025 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 7D011C53210 for ; Thu, 5 Jan 2023 10:38:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233014AbjAEKit (ORCPT ); Thu, 5 Jan 2023 05:38:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233061AbjAEKiS (ORCPT ); Thu, 5 Jan 2023 05:38:18 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E48C53D9D8 for ; Thu, 5 Jan 2023 02:38:17 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1672915096; 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=epyxu67DCygsRaM2cbohQ78lQlFxln6E6vGzGbSHmzc=; b=DBeUxJmuIKj2Ot5084Nv6DwSrx6MMhYUUBMuZAmyQm3lBeOrG5H8JQVDVxT+NNUGyF9nLl YKJ4uSB77XvrZinuhdSlVxr3RrYttZaE6xTnW0gmwrDwoZf+nyJ/jB9tMCi8/UAcPKQvvQ C9hAq0vO8nhzmZUyZiyK8IhWopLYoHuwNum2QoHzt/t77yfPWurFi1aHHEkIgNLzFAfmvL 6mMZWNEtxXO3x3WfFkCPfUzh8ptE5D+DH35iV3T01fderO2PoF4+2PkEXU1E5DC6U8cr0e Q5pS7PhZlMPcdOmNLiKuAurDqkI+AwwKW05F+2S7L5LIh+LW0uv+0KuPwos6mw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1672915096; 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=epyxu67DCygsRaM2cbohQ78lQlFxln6E6vGzGbSHmzc=; b=hNzxCjeqIMbCX0RYEMcC2NSd6eBz/uu20t3htnsLCvMz/0mYqC0UsY2xE6AkOyEcJ8tjoV z0ZD04D4UI9XwMDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 4/8] printk: introduce struct printk_buffers Date: Thu, 5 Jan 2023 11:43:31 +0106 Message-Id: <20230105103735.880956-5-john.ogness@linutronix.de> In-Reply-To: <20230105103735.880956-1-john.ogness@linutronix.de> References: <20230105103735.880956-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" Introduce a new struct printk_buffers to contain all the buffers needed to read and format a printk message for output. Putting the buffers inside a struct reduces the number of buffer pointers that need to be tracked. Also, it allows usage of the sizeof() macro for the buffer sizes, rather than expecting certain sized buffers being passed in. Note that since the output buffer for normal consoles is now CONSOLE_EXT_LOG_MAX instead of CONSOLE_LOG_MAX, multi-line messages that may have been previously truncated will now be printed in full. This should be considered a feature and not a bug since the CONSOLE_LOG_MAX restriction was about limiting static buffer usage rather than limiting printed text. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/internal.h | 10 +++++++ kernel/printk/printk.c | 57 ++++++++++++++++++---------------------- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index f394332410c9..6080d289a342 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -82,3 +82,13 @@ u16 printk_parse_prefix(const char *text, int *level, =20 static inline bool printk_percpu_data_ready(void) { return false; } #endif /* CONFIG_PRINTK */ + +/** + * struct printk_buffers - Buffers to read/format/output printk messages. + * @outbuf: After formatting, contains text to output. + * @scratchbuf: Used as temporary ringbuffer reading and string-print spac= e. + */ +struct printk_buffers { + char outbuf[CONSOLE_EXT_LOG_MAX]; + char scratchbuf[LOG_LINE_MAX]; +}; diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 55bb065de65f..bc5d4574c459 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2728,14 +2728,6 @@ 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. - * - * 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. - * * @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. @@ -2747,17 +2739,33 @@ static void __console_unlock(void) * * 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, bool *handover, = int cookie) { + static char dropped_text[DROPPED_TEXT_MAX]; + static struct printk_buffers pbufs; static int panic_console_dropped; + + bool is_extended =3D console_srcu_read_flags(con) & CON_EXTENDED; + const size_t scratchbuf_sz =3D sizeof(pbufs.scratchbuf); + const size_t outbuf_sz =3D sizeof(pbufs.outbuf); + char *scratchbuf =3D &pbufs.scratchbuf[0]; + char *outbuf =3D &pbufs.outbuf[0]; struct printk_info info; struct printk_record r; unsigned long flags; - char *write_text; size_t len; =20 - prb_rec_init_rd(&r, &info, text, CONSOLE_LOG_MAX); + /* + * Formatting extended messages requires a separate buffer, so use the + * scratch buffer to read in the ringbuffer text. + * + * Formatting normal messages is done in-place, so read the ringbuffer + * text directly into the output buffer. + */ + if (is_extended) + prb_rec_init_rd(&r, &info, scratchbuf, scratchbuf_sz); + else + prb_rec_init_rd(&r, &info, outbuf, outbuf_sz); =20 *handover =3D false; =20 @@ -2779,13 +2787,11 @@ 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 (is_extended) { + len =3D info_print_ext_header(outbuf, outbuf_sz, r.info); + len +=3D msg_print_ext_body(outbuf + len, outbuf_sz - len, &r.text_buf[0], r.info->text_len, &r.info->dev_info); } else { - write_text =3D text; len =3D record_print_text(&r, console_msg_format & MSG_FORMAT_SYSLOG, pr= intk_time); } =20 @@ -2803,7 +2809,8 @@ static bool console_emit_next_record(struct console *= con, char *text, char *ext_ 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, outbuf, len, + is_extended ? NULL : dropped_text); start_critical_timings(); =20 con->seq++; @@ -2839,9 +2846,6 @@ 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]; bool any_usable =3D false; struct console *con; bool any_progress; @@ -2861,16 +2865,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, handover, cookie); =20 /* * If a handover has occurred, the SRCU read lock --=20 2.30.2 From nobody Tue Sep 16 09:01:23 2025 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 DC815C3DA7A for ; Thu, 5 Jan 2023 10:38:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232797AbjAEKiy (ORCPT ); Thu, 5 Jan 2023 05:38:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233074AbjAEKiT (ORCPT ); Thu, 5 Jan 2023 05:38:19 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75D97395DF for ; Thu, 5 Jan 2023 02:38:18 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1672915096; 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=K6Zk/xyTkHlZSXedWM+pYMQGuYWeTvriHXM5QqKd1Wc=; b=3ifzsD2VLb0UnRUZmc2jd0Kxf8DOYPfIyi/qil780zAs/3nncS0rqmUFvGTLEjRM1QQo6R tcUb+sWumldOTsVV+uCRHEm77N+TdAL+oxOijC7mp00YsB3hlFVsNcRkMWPBBu7PrkmFaf rW9c9yekuhG0Qp/z4yf8AohrDjNXT3ojBuePxlzBfl5vFfV3j/NE9QdnIMcA/D1dg50hZR slgCYk8rU6P6SHevvG2M276uMqLU4BixjqnCX7v38AJ+V0JOWDpwPqtHvQYTJtls4c5p1m Jm9bAwvGEvWfPUdEsn/x2s8Av5N3o2asS9mjhmvMACFJw0GOKUihqbArkflriQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1672915096; 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=K6Zk/xyTkHlZSXedWM+pYMQGuYWeTvriHXM5QqKd1Wc=; b=8ptkBRZIkXSNC7TtUxZZmmlo3sejsNalSNJqYR6L5LR7ES7jDazDpEQjzwRVNa/HiOx/y8 wSkdFwleCcEH5EAQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 5/8] printk: introduce printk_get_next_message() and printk_message Date: Thu, 5 Jan 2023 11:43:32 +0106 Message-Id: <20230105103735.880956-6-john.ogness@linutronix.de> In-Reply-To: <20230105103735.880956-1-john.ogness@linutronix.de> References: <20230105103735.880956-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" Code for performing the console output is intermixed with code that is formatting the output for that console. Introduce a new helper function printk_get_next_message() to handle the reading and formatting of the printk text. The helper does not require any locking so that in the future it can be used for other printing contexts as well. This also introduces a new struct printk_message to wrap the struct printk_buffers, adding metadata about its contents. This allows users of printk_get_next_message() to receive all relevant information about the message that was read and formatted. Why is struct printk_message a wrapper struct? It is intentional that a wrapper struct is introduced instead of adding the metadata directly to struct printk_buffers. The upcoming atomic consoles support multiple printing contexts per CPU. This means that while a CPU is formatting a message, it can be interrupted and the interrupting context may also format a (possibly different) message. Since the printk buffers are rather large, there will only be one struct printk_buffers per CPU and it must be shared by the possible contexts of that CPU. If the metadata was part of struct printk_buffers, interrupting contexts would clobber the metadata being prepared by the interrupted context. This could be handled by robustifying the message formatting functions to cope with metadata unexpectedly changing. However, this would require significant amounts of extra data copying, also adding significant complexity to the code. Instead, the metadata can live on the stack of the formatting context and the message formatting functions do not need to be concerned about the metadata changing underneath them. Note that the message formatting functions can handle unexpected text buffer changes. So it is perfectly OK if a shared text buffer is clobbered by an interrupting context. The atomic console implementation will recognize the interruption and avoid printing the (probably garbage) text buffer. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/internal.h | 16 ++++++ kernel/printk/printk.c | 115 +++++++++++++++++++++++++++------------ 2 files changed, 96 insertions(+), 35 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index 6080d289a342..c9bb0cd86372 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -92,3 +92,19 @@ struct printk_buffers { char outbuf[CONSOLE_EXT_LOG_MAX]; char scratchbuf[LOG_LINE_MAX]; }; + +/** + * struct printk_message - Container for a prepared printk message. + * @pbufs: printk buffers used to prepare the message. + * @outbuf_len: The length of prepared text in @pbufs->outbuf to output. T= his + * does not count the terminator. A value of 0 means there is + * nothing to output and this record should be skipped. + * @seq: The sequence number of the record used for @pbufs->outbuf. + * @dropped: The number of dropped records from reading @seq. + */ +struct printk_message { + struct printk_buffers *pbufs; + unsigned int outbuf_len; + u64 seq; + unsigned long dropped; +}; diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index bc5d4574c459..6e2a6d5548e9 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2725,35 +2725,35 @@ static void __console_unlock(void) } =20 /* - * Print one record for the given console. The record printed is whatever - * record is the next available record for the given console. + * Read and format the specified record (or a later record if the specified + * record is not available). * - * @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. + * @pmsg will contain the formatted result. @pmsg->pbufs must point to a + * struct printk_buffers. * - * @cookie is the cookie from the SRCU read lock. + * @seq is the record to read and format. If it is not available, the next + * valid record is read. * - * Returns false if the given console has no next record to print, otherwi= se - * true. + * @is_extended specifies if the message should be formatted for extended + * console output. * - * Requires the console_lock and the SRCU read lock. + * Returns false if no record is available. Otherwise true and all fields + * of @pmsg are valid. (See the documentation of struct printk_message + * for information about the @pmsg fields.) */ -static bool console_emit_next_record(struct console *con, bool *handover, = int cookie) +static bool printk_get_next_message(struct printk_message *pmsg, u64 seq, + bool is_extended) { - static char dropped_text[DROPPED_TEXT_MAX]; - static struct printk_buffers pbufs; static int panic_console_dropped; =20 - bool is_extended =3D console_srcu_read_flags(con) & CON_EXTENDED; - const size_t scratchbuf_sz =3D sizeof(pbufs.scratchbuf); - const size_t outbuf_sz =3D sizeof(pbufs.outbuf); - char *scratchbuf =3D &pbufs.scratchbuf[0]; - char *outbuf =3D &pbufs.outbuf[0]; + struct printk_buffers *pbufs =3D pmsg->pbufs; + const size_t scratchbuf_sz =3D sizeof(pbufs->scratchbuf); + const size_t outbuf_sz =3D sizeof(pbufs->outbuf); + char *scratchbuf =3D &pbufs->scratchbuf[0]; + char *outbuf =3D &pbufs->outbuf[0]; struct printk_info info; struct printk_record r; - unsigned long flags; - size_t len; + size_t len =3D 0; =20 /* * Formatting extended messages requires a separate buffer, so use the @@ -2767,25 +2767,26 @@ static bool console_emit_next_record(struct console= *con, bool *handover, int co else prb_rec_init_rd(&r, &info, outbuf, outbuf_sz); =20 - *handover =3D false; - - if (!prb_read_valid(prb, con->seq, &r)) + if (!prb_read_valid(prb, seq, &r)) 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"); - } + pmsg->seq =3D r.info->seq; + pmsg->dropped =3D r.info->seq - seq; + + /* + * Check for dropped messages in panic here so that printk + * suppression can occur as early as possible if necessary. + */ + if (pmsg->dropped && + 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"); } =20 /* Skip record that has level above the console loglevel. */ - if (suppress_message_printing(r.info->level)) { - con->seq++; - goto skip; - } + if (suppress_message_printing(r.info->level)) + goto out; =20 if (is_extended) { len =3D info_print_ext_header(outbuf, outbuf_sz, r.info); @@ -2794,6 +2795,50 @@ static bool console_emit_next_record(struct console = *con, bool *handover, int co } else { len =3D record_print_text(&r, console_msg_format & MSG_FORMAT_SYSLOG, pr= intk_time); } +out: + pmsg->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. + * + * @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, bool *handover, = int cookie) +{ + static char dropped_text[DROPPED_TEXT_MAX]; + static struct printk_buffers pbufs; + + bool is_extended =3D console_srcu_read_flags(con) & CON_EXTENDED; + char *outbuf =3D &pbufs.outbuf[0]; + struct printk_message pmsg =3D { + .pbufs =3D &pbufs, + }; + unsigned long flags; + + *handover =3D false; + + if (!printk_get_next_message(&pmsg, con->seq, is_extended)) + return false; + + con->dropped +=3D pmsg.dropped; + + /* Skip messages of formatted length 0. */ + if (pmsg.outbuf_len =3D=3D 0) { + con->seq =3D pmsg.seq + 1; + goto skip; + } =20 /* * While actively printing out messages, if another printk() @@ -2809,11 +2854,11 @@ static bool console_emit_next_record(struct console= *con, bool *handover, int co console_lock_spinning_enable(); =20 stop_critical_timings(); /* don't trace print latency */ - call_console_driver(con, outbuf, len, + call_console_driver(con, outbuf, pmsg.outbuf_len, is_extended ? NULL : dropped_text); start_critical_timings(); =20 - con->seq++; + con->seq =3D pmsg.seq + 1; =20 *handover =3D console_lock_spinning_disable_and_check(cookie); printk_safe_exit_irqrestore(flags); --=20 2.30.2 From nobody Tue Sep 16 09:01:23 2025 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 E1EDEC3DA7A for ; Thu, 5 Jan 2023 10:39:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232846AbjAEKjC (ORCPT ); Thu, 5 Jan 2023 05:39:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232758AbjAEKiT (ORCPT ); Thu, 5 Jan 2023 05:38:19 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97697395E2 for ; Thu, 5 Jan 2023 02:38:18 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1672915097; 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=lH1VM4H34bOwtoIoTFBaMJbpQ6UvK3bQhqa9uSgUKBA=; b=lbdv91SVqW1PpYGZ3f4m+7oQK/ZVVMbXGoHXzSoWTRohTQaYDsM4yfN69dHAGYAf36ejbK +rTpFfp8EATTpEuyM05g5joR1ZLaBN1/eBlw/b2dVesKChois511YXmf62iaGjsmYTjaMz s7HlHmspjKWtYeFWfpJIxyVX9OFes2ne87fQ3eIbBAyiLnhXu5ipRYs7aoYYNxkTDNDgRK 9cnS6SkvDtIuRfAcJzhMUOoXrmIwngplbFxABiTBZ/AjrRmYpyX+VH7aTYgNllJhJuijd0 JJlRlguerI040/zO+6VgD5o3HlfV39+x1VuMiLJ99qhkhpa3wnaHNPY3OKSTWA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1672915097; 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=lH1VM4H34bOwtoIoTFBaMJbpQ6UvK3bQhqa9uSgUKBA=; b=a7x+UWqbs+KSNa3o728XdvgdDdv4RhB+KGyPVs8baz15yNWuiRtF61n5hOjv/j8VQnEInA oLQO6Pg7HgVusKAA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 6/8] printk: introduce console_prepend_dropped() for dropped messages Date: Thu, 5 Jan 2023 11:43:33 +0106 Message-Id: <20230105103735.880956-7-john.ogness@linutronix.de> In-Reply-To: <20230105103735.880956-1-john.ogness@linutronix.de> References: <20230105103735.880956-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" Currently "dropped messages" are separately printed immediately before printing the printk message. Since normal consoles are now using an output buffer that is much larger than previously, the "dropped message" could be prepended to the printk message and then output everything in a single write() call. Introduce a helper function console_prepend_dropped() to prepend an existing message with a "dropped message". This simplifies the code by allowing all message formatting to be handled together and then only requires a single write() call to output the full message. And since this helper does not require any locking, it can be used in the future for other console printing contexts as well. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/internal.h | 4 -- kernel/printk/printk.c | 86 ++++++++++++++++++++++++++-------------- 2 files changed, 57 insertions(+), 33 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index c9bb0cd86372..72df730597f1 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -26,9 +26,6 @@ int devkmsg_sysctl_set_loglvl(struct ctl_table *table, in= t write, /* the maximum size of a formatted extended record */ #define CONSOLE_EXT_LOG_MAX 8192 =20 -/* the maximum size for a dropped text message */ -#define DROPPED_TEXT_MAX 64 - /* the maximum size allowed to be reserved for a record */ #define LOG_LINE_MAX (CONSOLE_LOG_MAX - PREFIX_MAX) =20 @@ -69,7 +66,6 @@ u16 printk_parse_prefix(const char *text, int *level, #define PREFIX_MAX 0 #define CONSOLE_LOG_MAX 0 #define CONSOLE_EXT_LOG_MAX 0 -#define DROPPED_TEXT_MAX 0 #define LOG_LINE_MAX 0 =20 /* diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 6e2a6d5548e9..4fb7d29fb05d 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1995,27 +1995,6 @@ static int console_trylock_spinning(void) return 1; } =20 -/* - * 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 @@ -2395,10 +2374,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; } @@ -2724,6 +2699,52 @@ static void __console_unlock(void) up_console_sem(); } =20 +/* + * Prepend the message in @pmsg->pbufs->outbuf with a "dropped message". T= his + * is achieved by shifting the existing message over and inserting the dro= pped + * message. + * + * @pmsg is the printk message to prepend. + * + * @dropped is the dropped count to report in the dropped message. + * + * If the message text in @pmsg->pbufs->outbuf does not have enough space = for + * the dropped message, the message text will be sufficiently truncated. + * + * If @pmsg->pbufs->outbuf is modified, @pmsg->outbuf_len is updated. + */ +static void console_prepend_dropped(struct printk_message *pmsg, unsigned = long dropped) +{ + struct printk_buffers *pbufs =3D pmsg->pbufs; + const size_t scratchbuf_sz =3D sizeof(pbufs->scratchbuf); + const size_t outbuf_sz =3D sizeof(pbufs->outbuf); + char *scratchbuf =3D &pbufs->scratchbuf[0]; + char *outbuf =3D &pbufs->outbuf[0]; + size_t len; + + len =3D snprintf(scratchbuf, scratchbuf_sz, + "** %lu printk messages dropped **\n", dropped); + + /* + * Make sure outbuf is sufficiently large before prepending. + * Keep at least the prefix when the message must be truncated. + * It is a rather theoretical problem when someone tries to + * use a minimalist buffer. + */ + if (WARN_ON_ONCE(len + PREFIX_MAX >=3D outbuf_sz)) + return; + + if (pmsg->outbuf_len + len >=3D outbuf_sz) { + /* Truncate the message, but keep it terminated. */ + pmsg->outbuf_len =3D outbuf_sz - (len + 1); + outbuf[pmsg->outbuf_len] =3D 0; + } + + memmove(outbuf + len, outbuf, pmsg->outbuf_len + 1); + memcpy(outbuf, scratchbuf, len); + pmsg->outbuf_len +=3D len; +} + /* * Read and format the specified record (or a later record if the specified * record is not available). @@ -2817,7 +2838,6 @@ static bool printk_get_next_message(struct printk_mes= sage *pmsg, u64 seq, */ static bool console_emit_next_record(struct console *con, bool *handover, = int cookie) { - static char dropped_text[DROPPED_TEXT_MAX]; static struct printk_buffers pbufs; =20 bool is_extended =3D console_srcu_read_flags(con) & CON_EXTENDED; @@ -2840,6 +2860,11 @@ static bool console_emit_next_record(struct console = *con, bool *handover, int co goto skip; } =20 + if (con->dropped && !is_extended) { + console_prepend_dropped(&pmsg, con->dropped); + con->dropped =3D 0; + } + /* * While actively printing out messages, if another printk() * were to occur on another CPU, it may wait for this one to @@ -2853,9 +2878,12 @@ static bool console_emit_next_record(struct console = *con, bool *handover, int co printk_safe_enter_irqsave(flags); console_lock_spinning_enable(); =20 - stop_critical_timings(); /* don't trace print latency */ - call_console_driver(con, outbuf, pmsg.outbuf_len, - is_extended ? NULL : dropped_text); + /* Do not trace print latency. */ + stop_critical_timings(); + + /* Write everything out to the hardware. */ + con->write(con, outbuf, pmsg.outbuf_len); + start_critical_timings(); =20 con->seq =3D pmsg.seq + 1; --=20 2.30.2 From nobody Tue Sep 16 09:01:23 2025 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 27A75C3DA7A for ; Thu, 5 Jan 2023 10:39:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233194AbjAEKjO (ORCPT ); Thu, 5 Jan 2023 05:39:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233076AbjAEKiU (ORCPT ); Thu, 5 Jan 2023 05:38:20 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00F9D3F100 for ; Thu, 5 Jan 2023 02:38:18 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1672915097; 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=DFngVp9MQgIEtplZg2ethuU38QZaV6s9fRh+JEWhx2k=; b=wE2fq0ItOYe/T63jHnr6N1j++OFCPzFcALhGwI/EE9JbgRzDtO3PTPJuBp8atCCQ0UxD3m 8EYGIZni4kWumz0580TFQX5hWUeQANCq0c4STJoFbWI7uKtuiIqtaOHRxsGLvy9wLzvblA lLZVIoCBeyog7iW9ojMXBn4DRrQJTp6TD/25/wMj6NfodF4EgQ0tJCG4M4OZMZRq3ZPcEK 9yKPqC80FTgepLyFscb5ChwmfH4uTeET9SoaRd1LHl/TrE6MELzpaCUaQ1eVIweGvcgOev Efs9GTblMD5yM4cfrDxDoeAJFR5rIDJPfC8hGyw4XAxJuUCaiQGbse4BYmW56A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1672915097; 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=DFngVp9MQgIEtplZg2ethuU38QZaV6s9fRh+JEWhx2k=; b=NwCHHW9SBE74wrBVwYMTUb/6Ahvf0gJUnQM7cIa7NMnMmIUiEFoxu596f84Op59if2f6hB SoATAqxLlcgzqmCw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 7/8] printk: use printk_buffers for devkmsg Date: Thu, 5 Jan 2023 11:43:34 +0106 Message-Id: <20230105103735.880956-8-john.ogness@linutronix.de> In-Reply-To: <20230105103735.880956-1-john.ogness@linutronix.de> References: <20230105103735.880956-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" Replace the individual @text_buf and @buf buffers in struct devkmsg_user with a struct printk_buffers. This reduces the number of buffers to keep track of. Also, since @text_buf is only used for ringbuffer reading and @buf is only used for output, it maps perfectly to the purpose and fields of struct printk_buffers. As a side-effect, @text_buf was 8kB large, even though it only needed to be the max size of a ringbuffer record. By switching to struct printk_buffers, ~7kB less memory is allocated when opening /dev/kmsg. And since struct printk_buffers will be used now, reduce duplicate code by calling printk_get_next_message() to handle the record reading and formatting. Signed-off-by: John Ogness --- kernel/printk/printk.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 4fb7d29fb05d..e28a3736a399 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -695,15 +695,16 @@ static ssize_t msg_print_ext_body(char *buf, size_t s= ize, return len; } =20 +static bool printk_get_next_message(struct printk_message *pmsg, u64 seq, = bool is_extended); + /* /dev/kmsg - userspace message inject/listen interface */ struct devkmsg_user { atomic64_t seq; struct ratelimit_state rs; struct mutex lock; - char buf[CONSOLE_EXT_LOG_MAX]; =20 + struct printk_buffers pbufs; struct printk_info info; - char text_buf[CONSOLE_EXT_LOG_MAX]; struct printk_record record; }; =20 @@ -787,7 +788,10 @@ static ssize_t devkmsg_read(struct file *file, char __= user *buf, { struct devkmsg_user *user =3D file->private_data; struct printk_record *r =3D &user->record; - size_t len; + char *outbuf =3D &user->pbufs.outbuf[0]; + struct printk_message pmsg =3D { + .pbufs =3D &user->pbufs, + }; ssize_t ret; =20 if (!user) @@ -797,7 +801,7 @@ static ssize_t devkmsg_read(struct file *file, char __u= ser *buf, if (ret) return ret; =20 - if (!prb_read_valid(prb, atomic64_read(&user->seq), r)) { + if (!printk_get_next_message(&pmsg, atomic64_read(&user->seq), true)) { if (file->f_flags & O_NONBLOCK) { ret =3D -EAGAIN; goto out; @@ -820,30 +824,25 @@ static ssize_t devkmsg_read(struct file *file, char _= _user *buf, goto out; } =20 - if (r->info->seq !=3D atomic64_read(&user->seq)) { + if (pmsg.dropped) { /* our last seen message is gone, return error and reset */ - atomic64_set(&user->seq, r->info->seq); + atomic64_set(&user->seq, pmsg.seq); ret =3D -EPIPE; 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, - &r->text_buf[0], r->info->text_len, - &r->info->dev_info); - - atomic64_set(&user->seq, r->info->seq + 1); + atomic64_set(&user->seq, pmsg.seq + 1); =20 - if (len > count) { + if (pmsg.outbuf_len > count) { ret =3D -EINVAL; goto out; } =20 - if (copy_to_user(buf, user->buf, len)) { + if (copy_to_user(buf, outbuf, pmsg.outbuf_len)) { ret =3D -EFAULT; goto out; } - ret =3D len; + ret =3D pmsg.outbuf_len; out: mutex_unlock(&user->lock); return ret; @@ -937,9 +936,6 @@ static int devkmsg_open(struct inode *inode, struct fil= e *file) =20 mutex_init(&user->lock); =20 - prb_rec_init_rd(&user->record, &user->info, - &user->text_buf[0], sizeof(user->text_buf)); - atomic64_set(&user->seq, prb_first_valid_seq(prb)); =20 file->private_data =3D user; --=20 2.30.2 From nobody Tue Sep 16 09:01:23 2025 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 38CB8C53210 for ; Thu, 5 Jan 2023 10:39:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233207AbjAEKjT (ORCPT ); Thu, 5 Jan 2023 05:39:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233089AbjAEKiU (ORCPT ); Thu, 5 Jan 2023 05:38:20 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E7DC40846 for ; Thu, 5 Jan 2023 02:38:19 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1672915097; 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=r6fU919/gET/vGibIv6edf0LDl2+gGzKkiU558NElZ0=; b=QWr1NTFqqoK8H8SNd8zDx09Alfb7iPeu62vbjxkNwlGz24feHXaFo16wfOeNxiEsK65ayo rbov407F8aKEQIHMNBKpxN1NE75D9LcvZtsgG+H8nexyTlkNyvefVB0zaJXoqN+1yBhBEu dfF03GtNfn8QtESq9LSdp0xSrvw69I2dmyvkvR6RUsJrUoUKpw/aoPSvqIvXB4FgdO8Wzp V8e0fX8KoqM4biorJj0rO+R0Npn/ujoVZBzWu6slQbwfWReQaLngI3rkad+up5b0uceCcP zC3djQLa6KZVSJU6djLJ4zXAL5cP+lMPpyC/afHbEIgSu9Xr2fKw3MkIyL0WMA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1672915097; 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=r6fU919/gET/vGibIv6edf0LDl2+gGzKkiU558NElZ0=; b=XE1jMAwVLdFp6mPih+UmQEQOWl7EaUZpkXO+r8giGp5N6K/mzyQwzNHL1P/4IOWaThva/B ZjCcTn8feTphocAg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 8/8] printk: adjust string limit macros Date: Thu, 5 Jan 2023 11:43:35 +0106 Message-Id: <20230105103735.880956-9-john.ogness@linutronix.de> In-Reply-To: <20230105103735.880956-1-john.ogness@linutronix.de> References: <20230105103735.880956-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" The various internal size limit macros have names and/or values that do not fit well to their current usage. Rename the macros so that their purpose is clear and, if needed, provide a more appropriate value. In general, the new macros and values will lead to less memory usage. The new macros are... PRINTK_MESSAGE_MAX: This is the maximum size for a formatted message on a console, devkmsg, or syslog. It does not matter which format the message has (normal or extended). It replaces the use of CONSOLE_EXT_LOG_MAX for console and devkmsg. It replaces the use of CONSOLE_LOG_MAX for syslog. Historically, normal messages have been allowed to print up to 1kB, whereas extended messages have been allowed to print up to 8kB. However, the difference in lengths of these message types is not significant and in multi-line records, normal messages are probably larger. Also, because 1kB is only slightly above the allowed record size, multi-line normal messages could be easily truncated during formatting. This new macro should be significantly larger than the allowed record size to allow sufficient space for extended or multi-line prefix text. A value of 2kB should be plenty of space. For normal messages this represents a doubling of the historically allowed amount. For extended messages it reduces the excessive 8kB size, thus reducing memory usage needed for message formatting. PRINTK_PREFIX_MAX: This is the maximum size allowed for a record prefix (used by console and syslog). It replaces PREFIX_MAX. The value is left unchanged. PRINTKRB_RECORD_MAX: This is the maximum size allowed to be reserved for a record in the ringbuffer. It is used by all readers and writers with the printk ringbuffer. It replaces LOG_LINE_MAX. Previously this was set to "1kB - PREFIX_MAX", which makes some sense if 1kB is the limit for normal message output and prefixes are enabled. However, with the allowance of larger output and the existence of multi-line records, the value is rather bizarre. Round the value up to 1kB. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/internal.h | 27 +++++++++++++-------------- kernel/printk/printk.c | 24 ++++++++++++------------ 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index 72df730597f1..2a17704136f1 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -15,19 +15,19 @@ int devkmsg_sysctl_set_loglvl(struct ctl_table *table, = int write, #ifdef CONFIG_PRINTK =20 #ifdef CONFIG_PRINTK_CALLER -#define PREFIX_MAX 48 +#define PRINTK_PREFIX_MAX 48 #else -#define PREFIX_MAX 32 +#define PRINTK_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 of a formatted extended record */ -#define CONSOLE_EXT_LOG_MAX 8192 +/* + * the maximum size of a formatted record (i.e. with prefix added + * per line and dropped messages or in extended message format) + */ +#define PRINTK_MESSAGE_MAX 2048 =20 /* the maximum size allowed to be reserved for a record */ -#define LOG_LINE_MAX (CONSOLE_LOG_MAX - PREFIX_MAX) +#define PRINTKRB_RECORD_MAX 1024 =20 /* Flags for a single printk record. */ enum printk_info_flags { @@ -63,10 +63,9 @@ u16 printk_parse_prefix(const char *text, int *level, enum printk_info_flags *flags); #else =20 -#define PREFIX_MAX 0 -#define CONSOLE_LOG_MAX 0 -#define CONSOLE_EXT_LOG_MAX 0 -#define LOG_LINE_MAX 0 +#define PRINTK_PREFIX_MAX 0 +#define PRINTK_MESSAGE_MAX 0 +#define PRINTKRB_RECORD_MAX 0 =20 /* * In !PRINTK builds we still export console_sem @@ -85,8 +84,8 @@ static inline bool printk_percpu_data_ready(void) { retur= n false; } * @scratchbuf: Used as temporary ringbuffer reading and string-print spac= e. */ struct printk_buffers { - char outbuf[CONSOLE_EXT_LOG_MAX]; - char scratchbuf[LOG_LINE_MAX]; + char outbuf[PRINTK_MESSAGE_MAX]; + char scratchbuf[PRINTKRB_RECORD_MAX]; }; =20 /** diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index e28a3736a399..e21bfcd1b1ef 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -731,7 +731,7 @@ static ssize_t devkmsg_write(struct kiocb *iocb, struct= iov_iter *from) size_t len =3D iov_iter_count(from); ssize_t ret =3D len; =20 - if (!user || len > LOG_LINE_MAX) + if (!user || len > PRINTKRB_RECORD_MAX) return -EINVAL; =20 /* Ignore when user logging is disabled. */ @@ -1130,7 +1130,7 @@ static unsigned int __init add_to_rb(struct printk_ri= ngbuffer *rb, return prb_record_text_space(&e); } =20 -static char setup_text_buf[LOG_LINE_MAX] __initdata; +static char setup_text_buf[PRINTKRB_RECORD_MAX] __initdata; =20 void __init setup_log_buf(int early) { @@ -1396,7 +1396,7 @@ static size_t record_print_text(struct printk_record = *r, bool syslog, size_t text_len =3D r->info->text_len; size_t buf_size =3D r->text_buf_size; char *text =3D r->text_buf; - char prefix[PREFIX_MAX]; + char prefix[PRINTK_PREFIX_MAX]; bool truncated =3D false; size_t prefix_len; size_t line_len; @@ -1495,7 +1495,7 @@ static size_t get_record_print_text_size(struct print= k_info *info, unsigned int line_count, bool syslog, bool time) { - char prefix[PREFIX_MAX]; + char prefix[PRINTK_PREFIX_MAX]; size_t prefix_len; =20 prefix_len =3D info_print_prefix(info, syslog, time, prefix); @@ -1561,11 +1561,11 @@ static int syslog_print(char __user *buf, int size) int len =3D 0; u64 seq; =20 - text =3D kmalloc(CONSOLE_LOG_MAX, GFP_KERNEL); + text =3D kmalloc(PRINTK_MESSAGE_MAX, GFP_KERNEL); if (!text) return -ENOMEM; =20 - prb_rec_init_rd(&r, &info, text, CONSOLE_LOG_MAX); + prb_rec_init_rd(&r, &info, text, PRINTK_MESSAGE_MAX); =20 mutex_lock(&syslog_lock); =20 @@ -1666,7 +1666,7 @@ static int syslog_print_all(char __user *buf, int siz= e, bool clear) u64 seq; bool time; =20 - text =3D kmalloc(CONSOLE_LOG_MAX, GFP_KERNEL); + text =3D kmalloc(PRINTK_MESSAGE_MAX, GFP_KERNEL); if (!text) return -ENOMEM; =20 @@ -1678,7 +1678,7 @@ static int syslog_print_all(char __user *buf, int siz= e, bool clear) seq =3D find_first_fitting_seq(latched_seq_read_nolock(&clear_seq), -1, size, true, time); =20 - prb_rec_init_rd(&r, &info, text, CONSOLE_LOG_MAX); + prb_rec_init_rd(&r, &info, text, PRINTK_MESSAGE_MAX); =20 len =3D 0; prb_for_each_record(seq, prb, seq, &r) { @@ -2201,8 +2201,8 @@ int vprintk_store(int facility, int level, reserve_size =3D vsnprintf(&prefix_buf[0], sizeof(prefix_buf), fmt, args2= ) + 1; va_end(args2); =20 - if (reserve_size > LOG_LINE_MAX) - reserve_size =3D LOG_LINE_MAX; + if (reserve_size > PRINTKRB_RECORD_MAX) + reserve_size =3D PRINTKRB_RECORD_MAX; =20 /* Extract log level or control flags. */ if (facility =3D=3D 0) @@ -2216,7 +2216,7 @@ int vprintk_store(int facility, int level, =20 if (flags & LOG_CONT) { prb_rec_init_wr(&r, reserve_size); - if (prb_reserve_in_last(&e, prb, &r, caller_id, LOG_LINE_MAX)) { + if (prb_reserve_in_last(&e, prb, &r, caller_id, PRINTKRB_RECORD_MAX)) { text_len =3D printk_sprint(&r.text_buf[r.info->text_len], reserve_size, facility, &flags, fmt, args); r.info->text_len +=3D text_len; @@ -2727,7 +2727,7 @@ static void console_prepend_dropped(struct printk_mes= sage *pmsg, unsigned long d * It is a rather theoretical problem when someone tries to * use a minimalist buffer. */ - if (WARN_ON_ONCE(len + PREFIX_MAX >=3D outbuf_sz)) + if (WARN_ON_ONCE(len + PRINTK_PREFIX_MAX >=3D outbuf_sz)) return; =20 if (pmsg->outbuf_len + len >=3D outbuf_sz) { --=20 2.30.2