From nobody Mon Apr 6 10:45:00 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 B104AC07E9D for ; Sat, 24 Sep 2022 00:05:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232971AbiIXAFH (ORCPT ); Fri, 23 Sep 2022 20:05:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232964AbiIXAFE (ORCPT ); Fri, 23 Sep 2022 20:05:04 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 687019E8A8 for ; Fri, 23 Sep 2022 17:04:57 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663977896; 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=TiH+o7JC41DdZ3lwu3cXiKJzKZkxqWA+Jud7hMuF9gA=; b=pFGs3MumAKqyjmH+l1KzRd31GIN3NwCRBmrL4IK+kkJfFIF3HGbKRcU6x17/ER90jiOvmH 9kbSmpJWvDW6LWdcaNMJEwAd881GJuKf/kESYfjvpEv6emMTrG8bM/F0R9LYdqT10oOaX0 a+64EYlYfeyyEM++gUgiN0xZTaSmNPeB1A4VJUuN6CWrstq1srFzFcMbWkbGuEOrxX/4AQ ARAh+pBSMzjD1W3Y6kW6wVZmzEnO4zHxYyWJ+l/OTu97IoTMFO7zv9JEVi4z2Qr5aXbqu3 2Pd/N3hFPbM/L3vebmOdOmBXTQGceB6J2vUnCfzhXKk+d2fUQxZ3l1XbL9GShg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663977896; 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=TiH+o7JC41DdZ3lwu3cXiKJzKZkxqWA+Jud7hMuF9gA=; b=iXszll3pfPqc1GP/P+hO0F9vQwXwpSBQjOIr2P6fq43Fe4y0cIetm3OL3IIU9NvjIPXeUI Lhpp1/LVHRpl2uCQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk 01/18] printk: Make pr_flush() static Date: Sat, 24 Sep 2022 02:10:37 +0206 Message-Id: <20220924000454.3319186-2-john.ogness@linutronix.de> In-Reply-To: <20220924000454.3319186-1-john.ogness@linutronix.de> References: <20220924000454.3319186-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 No user outside the printk code and no reason to export this. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Sergey Senozhatsky Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- include/linux/printk.h | 7 ------- kernel/printk/printk.c | 5 +++-- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/include/linux/printk.h b/include/linux/printk.h index cf7d666ab1f8..8c81806c2e99 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -169,8 +169,6 @@ extern void __printk_safe_exit(void); #define printk_deferred_enter __printk_safe_enter #define printk_deferred_exit __printk_safe_exit =20 -extern bool pr_flush(int timeout_ms, bool reset_on_progress); - /* * Please don't use printk_ratelimit(), because it shares ratelimiting sta= te * with all other unrelated printk_ratelimit() callsites. Instead use @@ -221,11 +219,6 @@ static inline void printk_deferred_exit(void) { } =20 -static inline bool pr_flush(int timeout_ms, bool reset_on_progress) -{ - return true; -} - static inline int printk_ratelimit(void) { return 0; diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index a1a81fd9889b..14d7d39d118d 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2296,6 +2296,7 @@ asmlinkage __visible int _printk(const char *fmt, ...) } EXPORT_SYMBOL(_printk); =20 +static bool pr_flush(int timeout_ms, bool reset_on_progress); static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_= progress); =20 #else /* CONFIG_PRINTK */ @@ -2330,6 +2331,7 @@ static void call_console_driver(struct console *con, = const char *text, size_t le { } 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; } =20 #endif /* CONFIG_PRINTK */ @@ -3438,11 +3440,10 @@ static bool __pr_flush(struct console *con, int tim= eout_ms, bool reset_on_progre * Context: Process context. May sleep while acquiring console lock. * Return: true if all enabled printers are caught up. */ -bool pr_flush(int timeout_ms, bool reset_on_progress) +static bool pr_flush(int timeout_ms, bool reset_on_progress) { return __pr_flush(NULL, timeout_ms, reset_on_progress); } -EXPORT_SYMBOL(pr_flush); =20 /* * Delayed printk version, for scheduler-internal messages: --=20 2.30.2 From nobody Mon Apr 6 10:45:00 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 767EDC04A95 for ; Sat, 24 Sep 2022 00:05:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233000AbiIXAFM (ORCPT ); Fri, 23 Sep 2022 20:05:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232959AbiIXAFE (ORCPT ); Fri, 23 Sep 2022 20:05:04 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67A839DFAB; Fri, 23 Sep 2022 17:04:58 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663977896; 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=5V3Z6AhMdpsVP4d3DckyHZHpUKQGjS72cEceALWthyY=; b=YbT35guZgiSYqZPsZ7HEpaJ0sOvKpQbPePGoaeyTUm7H/wO1/IFAkSjQMkNg4HoC1rMjla jOG2WQmkJFxhuw2YenY92/zVcdEBo8eSRyStxb7OnII/aJAGAhnWzSRDfyJebHiDKEtYsH VNDjMh4g98gPQQl/3zb/cwRcC7g7EU9DyDPbTqF/6nqU9EH06kz9Dc6JPBe3Kgtp2H0HBH dzs1e8znzH4R2m53tahOEpKMFCwYjvzSFUCrkVqO/G6He6rIqI0eJfHtg/e0V6xFjFnvHn e5shoEqTJMDYCVlN2zoS/cBXquWRftl9TI/0+Iz99De6KVyJMNk7i3vBAsXKLA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663977896; 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=5V3Z6AhMdpsVP4d3DckyHZHpUKQGjS72cEceALWthyY=; b=bbbCxJXlhztbHC/ejFyxV3FY+WbK3/0ecpHf3f2KN7q4Su9QrnsgmRYIkGnOJILcTg0FE5 gaPedLj1PMB++VDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH printk 02/18] printk: Declare log_wait properly Date: Sat, 24 Sep 2022 02:10:38 +0206 Message-Id: <20220924000454.3319186-3-john.ogness@linutronix.de> In-Reply-To: <20220924000454.3319186-1-john.ogness@linutronix.de> References: <20220924000454.3319186-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 kernel/printk/printk.c:365:1: warning: symbol 'log_wait' was not declared. = Should it be static? Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Sergey Senozhatsky Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- fs/proc/kmsg.c | 2 -- include/linux/syslog.h | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/proc/kmsg.c b/fs/proc/kmsg.c index b38ad552887f..9d6950ac10fe 100644 --- a/fs/proc/kmsg.c +++ b/fs/proc/kmsg.c @@ -18,8 +18,6 @@ #include #include =20 -extern wait_queue_head_t log_wait; - static int kmsg_open(struct inode * inode, struct file * file) { return do_syslog(SYSLOG_ACTION_OPEN, NULL, 0, SYSLOG_FROM_PROC); diff --git a/include/linux/syslog.h b/include/linux/syslog.h index 86af908e2663..955f80e34d4f 100644 --- a/include/linux/syslog.h +++ b/include/linux/syslog.h @@ -8,6 +8,8 @@ #ifndef _LINUX_SYSLOG_H #define _LINUX_SYSLOG_H =20 +#include + /* Close the log. Currently a NOP. */ #define SYSLOG_ACTION_CLOSE 0 /* Open the log. Currently a NOP. */ @@ -35,5 +37,6 @@ #define SYSLOG_FROM_PROC 1 =20 int do_syslog(int type, char __user *buf, int count, int source); +extern wait_queue_head_t log_wait; =20 #endif /* _LINUX_SYSLOG_H */ --=20 2.30.2 From nobody Mon Apr 6 10:45:00 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 D7AF9C04A95 for ; Sat, 24 Sep 2022 00:05:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230325AbiIXAFV (ORCPT ); Fri, 23 Sep 2022 20:05:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232966AbiIXAFE (ORCPT ); Fri, 23 Sep 2022 20:05:04 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 733F0A00FF for ; Fri, 23 Sep 2022 17:04:58 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663977897; 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=ANY7oAkpA4R+I+XGrqgPZ6kGY4GmDX82gw1T7525iA0=; b=vWpBFONAv4/pzgToS4exU/1LlRMHRX/eFC/G8EjzVbk4qt7O55zPP8Io1MlY2o43xH3R8N D6Z50QOWAGoucWZdPtuo8K1AMuL5sZhlQAa/VMvKwxwhhgocUt+cago7hmr4f4rmGDcfzx jPP22HktWEsAa7bqYF544nzTaxufQIMMtKLBwgSPJFXjaCkg5TvsmEMGzbyrxRm7ypea5k 7FtE69OsKSIYC2Xt0s95VVphm+cTW0p88tUtctnTKQU7pTDOoiU8ZuNAKxczekEn3C6mqp iXrV30l/xzsujtizv+b/6PV3ysTFoHNcas32lsriZcy/yfxGMsGuOH/x9j9u9A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663977897; 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=ANY7oAkpA4R+I+XGrqgPZ6kGY4GmDX82gw1T7525iA0=; b=8RqLTYIcL6OsOGdep88T4tVlmPLozZRv2jX5XRRZ/CVZtYb+cnuIpqv0gwK5kuXSZ9Fzde pQLdpmU+n6wumFAw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk 03/18] printk: Remove write only variable nr_ext_console_drivers Date: Sat, 24 Sep 2022 02:10:39 +0206 Message-Id: <20220924000454.3319186-4-john.ogness@linutronix.de> In-Reply-To: <20220924000454.3319186-1-john.ogness@linutronix.de> References: <20220924000454.3319186-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 Commit a699449bb13b ("printk: refactor and rework printing logic") removed the need for @nr_ext_console_drivers. Remove the unneeded variable. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Sergey Senozhatsky Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 14d7d39d118d..d6bba2ea14e8 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -220,9 +220,6 @@ int devkmsg_sysctl_set_loglvl(struct ctl_table *table, = int write, } #endif /* CONFIG_PRINTK && CONFIG_SYSCTL */ =20 -/* Number of registered extended console drivers. */ -static int nr_ext_console_drivers; - /* * Helper macros to handle lockdep when locking/unlocking console_sem. We = use * macros instead of functions so that _RET_IP_ contains useful informatio= n. @@ -3188,9 +3185,6 @@ void register_console(struct console *newcon) console_drivers->next =3D newcon; } =20 - if (newcon->flags & CON_EXTENDED) - nr_ext_console_drivers++; - newcon->dropped =3D 0; if (newcon->flags & CON_PRINTBUFFER) { /* Get a consistent copy of @syslog_seq. */ @@ -3256,9 +3250,6 @@ int unregister_console(struct console *console) if (res) goto out_disable_unlock; =20 - if (console->flags & CON_EXTENDED) - nr_ext_console_drivers--; - /* * If this isn't the last console and it has CON_CONSDEV set, we * need to set it on the next preferred console. --=20 2.30.2 From nobody Mon Apr 6 10:45:00 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 766B5C07E9D for ; Sat, 24 Sep 2022 00:05:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232350AbiIXAF0 (ORCPT ); Fri, 23 Sep 2022 20:05:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232978AbiIXAFF (ORCPT ); Fri, 23 Sep 2022 20:05:05 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7364DA50C5 for ; Fri, 23 Sep 2022 17:04:59 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663977897; 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=AsqRBJKkojptCjVN+/9KUBsCalgAOrjbKzUf0AGU4sQ=; b=IWFjD1IWPGbwSq1Yr9k8bqwJQpfi7e1GcVgHtChWxHDfAgAzQXMn8Yb7k205GL8Yj3oyxW E5Cxa2BHjWcjcwdafY4HFYPMr26krLWmprZMbdoGJBVpTh07aYuFaa02HkEgNdg0oTZxNW ZK1n9cUWXJpqqCuiXwi0tzFTUQZAK8vuTZwvOIucbaDWFc52vBlePLPH9Zh6/sDh82awvt 2pRIoc00UjU8DQUsMkiJTYuO9uecetoc7P3AuNOvXjJ4NPubm0Q1GyzC1lkIpbYww5+7/l u3yf+OiyGfqrZVX76Y2sDQnZ7AFqgqgwr7iv90+1XgmaUIORSFQZlIcc/wOOVw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663977897; 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=AsqRBJKkojptCjVN+/9KUBsCalgAOrjbKzUf0AGU4sQ=; b=f2AkD2lCoI9N9yB73ZnCGPZwbiWUyJkAqjH9LguSpaHRi7eazC7NsAhQXDY9ht2VLRnOom Nfy/TzgiB4V2GiDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk 04/18] printk: Remove bogus comment vs. boot consoles Date: Sat, 24 Sep 2022 02:10:40 +0206 Message-Id: <20220924000454.3319186-5-john.ogness@linutronix.de> In-Reply-To: <20220924000454.3319186-1-john.ogness@linutronix.de> References: <20220924000454.3319186-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 The comment about unregistering boot consoles is just not matching the reality. Remove it. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Sergey Senozhatsky Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index d6bba2ea14e8..770511b89504 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3209,9 +3209,6 @@ void register_console(struct console *newcon) if (bootcon_enabled && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) =3D=3D CON_CONSDEV) && !keep_bootcon) { - /* We need to iterate through all boot consoles, to make - * sure we print everything out, before we unregister them. - */ for_each_console(con) if (con->flags & CON_BOOT) unregister_console(con); --=20 2.30.2 From nobody Mon Apr 6 10:45:00 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 24871C6FA86 for ; Sat, 24 Sep 2022 00:06:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232187AbiIXAF6 (ORCPT ); Fri, 23 Sep 2022 20:05:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232587AbiIXAFK (ORCPT ); Fri, 23 Sep 2022 20:05:10 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F3BC9E8A8 for ; Fri, 23 Sep 2022 17:05:06 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663977898; 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=NMMv3ujjFTuj7Yj8Tuz38djTJjcTqnAf2UGtNPcHZZ8=; b=BTT8x0Z/8tuiYDkMQCoydRasISqP+nkfk5473rWmNxM69PeQFni1HtvbT+ohwJ2f0N1xIe HI5gSnGguvwL3mgFJaUlR83KCn4NAOOy4rLfPKzOTDgiF4BOSRgdyiTmStqMoNRzSR7KiR /UEJwlFKMJXZDUTOfT/elHMNKQ73Sqafj3+KSbS+IVC84fCS5m4MrqiZP1uJyJvDOG4Y1Z 3e70/ThbfXyATHV/RpaH/ILeVZgxQq8/XSR/Hhh8tDkiy0xgViJeo+55vljOHhrwcOTXkS gJMJtKUjBoaSEZjOKWYCFZoeyuW9J3HaCTEFFZfT9mEoLXJC8hgyDQWrOqK1ZA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663977898; 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=NMMv3ujjFTuj7Yj8Tuz38djTJjcTqnAf2UGtNPcHZZ8=; b=Ghlq7f9+kXjKdt8w5EojdUKNMT8lt5kHGZkYWVpkGFRuJBYCIBM2sP3pSR2hDgRE6DvahN jA/bgS1Bja5v6ADw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk 05/18] printk: Mark __printk percpu data ready __ro_after_init Date: Sat, 24 Sep 2022 02:10:41 +0206 Message-Id: <20220924000454.3319186-6-john.ogness@linutronix.de> In-Reply-To: <20220924000454.3319186-1-john.ogness@linutronix.de> References: <20220924000454.3319186-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 This variable cannot change post boot. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Sergey Senozhatsky Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 770511b89504..e4f1e7478b52 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -430,7 +430,7 @@ static struct printk_ringbuffer *prb =3D &printk_rb_sta= tic; * per_cpu_areas are initialised. This variable is set to true when * it's safe to access per-CPU data. */ -static bool __printk_percpu_data_ready __read_mostly; +static bool __printk_percpu_data_ready __ro_after_init; =20 bool printk_percpu_data_ready(void) { --=20 2.30.2 From nobody Mon Apr 6 10:45:00 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 BE48BC07E9D for ; Sat, 24 Sep 2022 00:05:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232596AbiIXAFq (ORCPT ); Fri, 23 Sep 2022 20:05:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232997AbiIXAFL (ORCPT ); Fri, 23 Sep 2022 20:05:11 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 562ECA50C5 for ; Fri, 23 Sep 2022 17:05:06 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663977898; 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=19twU3lQfNuvUm9JND8TvG6rBZFGKcSPH9RyFrZuYhQ=; b=lqetqNRvqeJqLk8TBA11OGuf2NUa6RHrjlEyJz6gz4r+c8kBjyRL4nRzG+BW3/VCuRUeoY wg8wRvVkF5t15eiKwmpBE/BwM+8kDtg06vlf4vUPXoQwYADxDQSR2VD2h12ctlhVx1+0LR jZQVnE4JiHijrL7Sn8XD6RJScn1p5cT5AtGWUPmSLeAcbS0m/tA22U0Amrm89mDe8a6+is nZ0jGgyKz8REztYSusY/AXexeHX8I3W7WHKnQ0B+PIvjhj+K8Ju9pYcMLLmAd2NG3EVDCH WLiN+JaJEyeZH9CtC74KWFN4YXmOC8XBGWY4q9mZ32Xg42Shcys9fjjJUTppAg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663977898; 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=19twU3lQfNuvUm9JND8TvG6rBZFGKcSPH9RyFrZuYhQ=; b=PnSeZAOK90thATM65Hp/yFXp9CjpHPOhtAVLF/An+huTzDUUsRLvdFBK4JiUQr0DQyth1Z sacn3uM1K6kLTaAA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk 06/18] printk: Protect [un]register_console() with a mutex Date: Sat, 24 Sep 2022 02:10:42 +0206 Message-Id: <20220924000454.3319186-7-john.ogness@linutronix.de> In-Reply-To: <20220924000454.3319186-1-john.ogness@linutronix.de> References: <20220924000454.3319186-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 Unprotected list walks are a brilliant idea. Especially in the context of hotpluggable consoles. The new list lock provides not only synchronization for console list manipulation, but also for manipulation of console->flags: console_list_lock(); console_lock(); /* may now manipulate the console list and/or console->flags */ console_unlock(); console_list_unlock(); Therefore it is safe to iterate the console list and read console->flags if holding either the console lock or the console list lock. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Sergey Senozhatsky --- include/linux/console.h | 30 +++++++++++++-- kernel/printk/printk.c | 84 ++++++++++++++++++++++++++++++++++------- 2 files changed, 98 insertions(+), 16 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index 8c1686e2c233..24344f9b0bc1 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -157,10 +157,34 @@ struct console { struct console *next; }; =20 -/* - * for_each_console() allows you to iterate on each console +#ifdef CONFIG_LOCKDEP +extern void lockdep_assert_console_list_lock_held(void); +#else +static inline void lockdep_assert_console_list_lock_held(void) { } +#endif + +extern void console_list_lock(void) __acquires(console_mutex); +extern void console_list_unlock(void) __releases(console_mutex); + +/** + * for_each_registered_console() - Iterator over registered consoles + * @con: struct console pointer used as loop cursor + * + * Requires console_list_lock to be held. Can only be invoked from + * preemptible context. + */ +#define for_each_registered_console(con) \ + lockdep_assert_console_list_lock_held(); \ + for (con =3D console_drivers; con !=3D NULL; con =3D con->next) + +/** + * for_each_console() - Iterator over registered consoles + * @con: struct console pointer used as loop cursor + * + * Requires console_lock to be held which guarantees that the + * list is immutable. */ -#define for_each_console(con) \ +#define for_each_console(con) \ for (con =3D console_drivers; con !=3D NULL; con =3D con->next) =20 extern int console_set_on_cmdline; diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index e4f1e7478b52..8c56f6071873 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -79,10 +79,17 @@ int oops_in_progress; EXPORT_SYMBOL(oops_in_progress); =20 /* - * console_sem protects the console_drivers list, and also - * provides serialisation for access to the entire console - * driver system. + * console_sem protects the console_drivers list, and also provides + * serialization for access to the entire console driver system. + * + * console_mutex serializes register/unregister. + * + * console_sem must be taken inside a console_mutex locked section + * for any list manipulation in order to keep the console BKL + * machinery happy. This requirement also applies to manipulation + * of console->flags. */ +static DEFINE_MUTEX(console_mutex); static DEFINE_SEMAPHORE(console_sem); struct console *console_drivers; EXPORT_SYMBOL_GPL(console_drivers); @@ -103,6 +110,12 @@ static int __read_mostly suppress_panic_printk; static struct lockdep_map console_lock_dep_map =3D { .name =3D "console_lock" }; + +void lockdep_assert_console_list_lock_held(void) +{ + lockdep_assert_held(&console_mutex); +} + #endif =20 enum devkmsg_log_bits { @@ -220,6 +233,28 @@ int devkmsg_sysctl_set_loglvl(struct ctl_table *table,= int write, } #endif /* CONFIG_PRINTK && CONFIG_SYSCTL */ =20 +/** + * console_list_lock - Lock the console list + * + * For non-console related list walks, e.g. procfs, sysfs... + */ +void console_list_lock(void) +{ + mutex_lock(&console_mutex); +} +EXPORT_SYMBOL(console_list_lock); + +/** + * console_list_unlock - Unlock the console list + * + * Counterpart to console_list_lock() + */ +void console_list_unlock(void) +{ + mutex_unlock(&console_mutex); +} +EXPORT_SYMBOL(console_list_unlock); + /* * Helper macros to handle lockdep when locking/unlocking console_sem. We = use * macros instead of functions so that _RET_IP_ contains useful informatio= n. @@ -2978,17 +3013,21 @@ struct tty_driver *console_device(int *index) void console_stop(struct console *console) { __pr_flush(console, 1000, true); + console_list_lock(); console_lock(); console->flags &=3D ~CON_ENABLED; console_unlock(); + console_list_unlock(); } EXPORT_SYMBOL(console_stop); =20 void console_start(struct console *console) { + console_list_lock(); console_lock(); console->flags |=3D CON_ENABLED; console_unlock(); + console_list_unlock(); __pr_flush(console, 1000, true); } EXPORT_SYMBOL(console_start); @@ -3081,6 +3120,8 @@ static void try_enable_default_console(struct console= *newcon) (con->flags & CON_BOOT) ? "boot" : "", \ con->name, con->index, ##__VA_ARGS__) =20 +static int console_unregister_locked(struct console *console); + /* * The console driver calls this routine during kernel initialization * to register the console printing procedure with printk() and to @@ -3107,13 +3148,14 @@ void register_console(struct console *newcon) bool realcon_enabled =3D false; int err; =20 - for_each_console(con) { + console_list_lock(); + for_each_registered_console(con) { if (WARN(con =3D=3D newcon, "console '%s%d' already registered\n", con->name, con->index)) - return; + goto unlock; } =20 - for_each_console(con) { + for_each_registered_console(con) { if (con->flags & CON_BOOT) bootcon_enabled =3D true; else @@ -3124,7 +3166,7 @@ void register_console(struct console *newcon) if (newcon->flags & CON_BOOT && realcon_enabled) { pr_info("Too late to register bootconsole %s%d\n", newcon->name, newcon->index); - return; + goto unlock; } =20 /* @@ -3155,7 +3197,7 @@ void register_console(struct console *newcon) =20 /* printk() messages are not printed to the Braille console. */ if (err || newcon->flags & CON_BRL) - return; + goto unlock; =20 /* * If we have a bootconsole, and are switching to a real console, @@ -3209,14 +3251,17 @@ void register_console(struct console *newcon) if (bootcon_enabled && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) =3D=3D CON_CONSDEV) && !keep_bootcon) { - for_each_console(con) + for_each_console(con) { if (con->flags & CON_BOOT) - unregister_console(con); + console_unregister_locked(con); + } } +unlock: + console_list_unlock(); } EXPORT_SYMBOL(register_console); =20 -int unregister_console(struct console *console) +static int console_unregister_locked(struct console *console) { struct console *con; int res; @@ -3269,6 +3314,16 @@ int unregister_console(struct console *console) =20 return res; } + +int unregister_console(struct console *console) +{ + int res; + + console_list_lock(); + res =3D console_unregister_locked(console); + console_list_unlock(); + return res; +} EXPORT_SYMBOL(unregister_console); =20 /* @@ -3320,7 +3375,8 @@ static int __init printk_late_init(void) struct console *con; int ret; =20 - for_each_console(con) { + console_list_lock(); + for_each_registered_console(con) { if (!(con->flags & CON_BOOT)) continue; =20 @@ -3337,9 +3393,11 @@ static int __init printk_late_init(void) */ pr_warn("bootconsole [%s%d] uses init memory and must be disabled even = before the real one is ready\n", con->name, con->index); - unregister_console(con); + console_unregister_locked(con); } } + console_list_unlock(); + ret =3D cpuhp_setup_state_nocalls(CPUHP_PRINTK_DEAD, "printk:dead", NULL, console_cpu_notify); WARN_ON(ret < 0); --=20 2.30.2 From nobody Mon Apr 6 10:45:00 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 4D9D4C07E9D for ; Sat, 24 Sep 2022 00:05:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231535AbiIXAFl (ORCPT ); Fri, 23 Sep 2022 20:05:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232999AbiIXAFL (ORCPT ); Fri, 23 Sep 2022 20:05:11 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51F50A405A; Fri, 23 Sep 2022 17:05:06 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663977899; 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=z4OGWc0QkUJ6JpVm6AppOXfX1G2JfqpiTA52+HrwtTY=; b=wo5y13ZPqu7DG6xhkiOjxCXrMVZOmvijPkCUMdYOJ31rMot8dZf8lnPnndgkqQZYsRRDNt WcmpGX3QbCsXgfqhOZ/s0OqTaoRUq9H+WrPRTlbqbt3ndKez5/S3bqJIkepkMudA5sV10r qoAXPDOwTvLKsqeD2aXLPrBY3Pj7pKQk9H9QAn/3C473rVtbmlVWnprk2M9aFDw58A4s+j 3rvoe1SnJtb1eoJesQ28wBHlgFJXHEo2Kp5SbtxIIJn2A+GCmw+/zJp9XNhb4I3p8rhH3I zhtUXfV6wrrVy6nIhaGnJ6NvGP2FWWU3CsDNS8LjzfSM6oEn1cpyo6UH+NOGYQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663977899; 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=z4OGWc0QkUJ6JpVm6AppOXfX1G2JfqpiTA52+HrwtTY=; b=uY274NzrecLhyeA7K/R69mxN8EakigvmJU+z/05LIgT426Zvq92N4bWZKZIy8fTjRCVtO5 5Cwa0yC0zEZz2tDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , linux-fsdevel@vger.kernel.org Subject: [PATCH printk 07/18] printk: Convert console list walks for readers to list lock Date: Sat, 24 Sep 2022 02:10:43 +0206 Message-Id: <20220924000454.3319186-8-john.ogness@linutronix.de> In-Reply-To: <20220924000454.3319186-1-john.ogness@linutronix.de> References: <20220924000454.3319186-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 Facilities which expose console information to sysfs or procfs can use the new list protection to keep the list stable. No need to hold console lock. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Sergey Senozhatsky Reviewed-by: Greg Kroah-Hartman --- drivers/tty/tty_io.c | 6 +++--- fs/proc/consoles.c | 6 +++--- kernel/printk/printk.c | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 8fec1d8648f5..6fa142155b94 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -3535,8 +3535,8 @@ static ssize_t show_cons_active(struct device *dev, struct console *c; ssize_t count =3D 0; =20 - console_lock(); - for_each_console(c) { + console_list_lock(); + for_each_registered_console(c) { if (!c->device) continue; if (!c->write) @@ -3560,7 +3560,7 @@ static ssize_t show_cons_active(struct device *dev, =20 count +=3D sprintf(buf + count, "%c", i ? ' ':'\n'); } - console_unlock(); + console_list_unlock(); =20 return count; } diff --git a/fs/proc/consoles.c b/fs/proc/consoles.c index dfe6ce3505ce..6775056eecd5 100644 --- a/fs/proc/consoles.c +++ b/fs/proc/consoles.c @@ -63,8 +63,8 @@ static void *c_start(struct seq_file *m, loff_t *pos) struct console *con; loff_t off =3D 0; =20 - console_lock(); - for_each_console(con) + console_list_lock(); + for_each_registered_console(con) if (off++ =3D=3D *pos) break; =20 @@ -80,7 +80,7 @@ static void *c_next(struct seq_file *m, void *v, loff_t *= pos) =20 static void c_stop(struct seq_file *m, void *v) { - console_unlock(); + console_list_unlock(); } =20 static const struct seq_operations consoles_op =3D { diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 8c56f6071873..80a728ef9d96 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2990,18 +2990,18 @@ void console_flush_on_panic(enum con_flush_mode mod= e) */ struct tty_driver *console_device(int *index) { - struct console *c; struct tty_driver *driver =3D NULL; + struct console *c; =20 - console_lock(); - for_each_console(c) { + console_list_lock(); + for_each_registered_console(c) { if (!c->device) continue; driver =3D c->device(c, index); if (driver) break; } - console_unlock(); + console_list_unlock(); return driver; } =20 --=20 2.30.2 From nobody Mon Apr 6 10:45:00 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 60925C07E9D for ; Sat, 24 Sep 2022 00:05:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233061AbiIXAFb (ORCPT ); Fri, 23 Sep 2022 20:05:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232124AbiIXAFK (ORCPT ); Fri, 23 Sep 2022 20:05:10 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EA8A9AFA8; Fri, 23 Sep 2022 17:05:06 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663977900; 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=WB3BybeSJAXwy9sZVb/waLS+Dyffg8F8NybWwGa1X/A=; b=xcriPjgLQzRYZ4xUbtrjHhhbSY6X8gfZJ30zvTyo5dN8Exk7uj2MmjaWOSJlNRl7Kx7QgB 9zQMGBTGy3Igy87KJJoiQBMEBq1ZfUyJ3+ONwK3Q2gWgYzXNwtard3Pe2VWpuYp1AjVYud g4vXL5kWEDF7Xo1JpP+wPHuBA6Biyoynv4rES/A0LDxmt5x3U6Khr0Gb1dCj357zAK5TrC 1x5uAsDfEZkZMo21gLUlF5sJX5MVPGjKTRNRPvpHjKdH4vn54Jxdxv93lMZv4COb/J/lqF 2N+8ZBtK8RV+utbDmp1JekmGb65ZIrgEh4rTStW8s+HKiMPBgXfBMmkIZL6g/A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663977900; 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=WB3BybeSJAXwy9sZVb/waLS+Dyffg8F8NybWwGa1X/A=; b=zrUfFUWtkjjZ3Z3lX1frvgxG5HxmxzTiAMVgTfy0X477YaoYnRe+pIKC81HrwV1A1YFwfh Q9yqPZQbhwkJzJCQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, "James E.J. Bottomley" , Helge Deller , Sven Schnelle , John David Anglin , "Eric W. Biederman" , Julia Lawall , linux-parisc@vger.kernel.org Subject: [PATCH printk 08/18] parisc: Put console abuse into one place Date: Sat, 24 Sep 2022 02:10:44 +0206 Message-Id: <20220924000454.3319186-9-john.ogness@linutronix.de> In-Reply-To: <20220924000454.3319186-1-john.ogness@linutronix.de> References: <20220924000454.3319186-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 PARISC has a hope based mechanism to restore consoles in case of a HPMC (machine check exception) which is scattered over several places. Move it into one place to make further changes simpler and add comments. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Sergey Senozhatsky Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- arch/parisc/include/asm/pdc.h | 2 +- arch/parisc/kernel/pdc_cons.c | 38 ++++++++++++++++++++++++++++------- arch/parisc/kernel/traps.c | 17 +++++----------- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/arch/parisc/include/asm/pdc.h b/arch/parisc/include/asm/pdc.h index b643092d4b98..12bffd8a5d05 100644 --- a/arch/parisc/include/asm/pdc.h +++ b/arch/parisc/include/asm/pdc.h @@ -20,7 +20,7 @@ extern unsigned long parisc_pat_pdc_cap; /* PDC capabilit= ies (PAT) */ #define PDC_TYPE_SNAKE 2 /* Doesn't support SYSTEM_MAP */ =20 void pdc_console_init(void); /* in pdc_console.c */ -void pdc_console_restart(void); +void pdc_console_restart(bool hpmc); =20 void setup_pdc(void); /* in inventory.c */ =20 diff --git a/arch/parisc/kernel/pdc_cons.c b/arch/parisc/kernel/pdc_cons.c index 2661cdd256ae..9a0c0932d2f9 100644 --- a/arch/parisc/kernel/pdc_cons.c +++ b/arch/parisc/kernel/pdc_cons.c @@ -237,20 +237,44 @@ void __init pdc_console_init(void) =20 =20 /* - * Used for emergencies. Currently only used if an HPMC occurs. If an - * HPMC occurs, it is possible that the current console may not be - * properly initialised after the PDC IO reset. This routine unregisters - * all of the current consoles, reinitializes the pdc console and - * registers it. + * + * + * Used for emergencies. + * + * - If an HPMC occurs, it is possible that the current console may not be + * properly initialised after the PDC IO reset. This routine unregisters + * all of the current consoles, reinitializes the pdc console and regis= ters + * it. + * + * - Maybe the kernel hasn't booted very far yet and hasn't been able + * to initialize the serial or STI console. In that case we should + * re-enable the pdc console, so that the user will be able to + * identify the problem. + * + * + * + * The above is all wishful thinking: + * + * - Invoking [un]register_console() from exception contexts is obviously + * unsafe. + * + * - If the HPMC left the machine in unpleasant state and the pdc console + * was already initialized, but later removed due to CON_BOOT then this + * will do nothing. + * + * Pretend that any of the below works in the same way as we pretend that + * any of PARISC works. */ - -void pdc_console_restart(void) +void pdc_console_restart(bool hpmc) { struct console *console; =20 if (pdc_console_initialized) return; =20 + if (!hpmc && console_drivers) + return; + /* If we've already seen the output, don't bother to print it again */ if (console_drivers !=3D NULL) pdc_cons.flags &=3D ~CON_PRINTBUFFER; diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c index b78f1b9d45c1..81e23f589d3d 100644 --- a/arch/parisc/kernel/traps.c +++ b/arch/parisc/kernel/traps.c @@ -235,17 +235,12 @@ void die_if_kernel(char *str, struct pt_regs *regs, l= ong err) " (__)\\ )\\/\\\n" " U ||----w |\n" " || ||\n"); -=09 + /* unlock the pdc lock if necessary */ pdc_emergency_unlock(); =20 - /* maybe the kernel hasn't booted very far yet and hasn't been able=20 - * to initialize the serial or STI console. In that case we should=20 - * re-enable the pdc console, so that the user will be able to=20 - * identify the problem. */ - if (!console_drivers) - pdc_console_restart(); -=09 + pdc_console_restart(false); + if (err) printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n", current->comm, task_pid_nr(current), str, err); @@ -429,9 +424,7 @@ void parisc_terminate(char *msg, struct pt_regs *regs, = int code, unsigned long o /* unlock the pdc lock if necessary */ pdc_emergency_unlock(); =20 - /* restart pdc console if necessary */ - if (!console_drivers) - pdc_console_restart(); + pdc_console_restart(false); =20 /* Not all paths will gutter the processor... */ switch(code){ @@ -483,7 +476,7 @@ void notrace handle_interruption(int code, struct pt_re= gs *regs) int si_code; =20 if (code =3D=3D 1) - pdc_console_restart(); /* switch back to pdc if HPMC */ + pdc_console_restart(true); /* switch back to pdc if HPMC */ else if (!irqs_disabled_flags(regs->gr[0])) local_irq_enable(); =20 --=20 2.30.2 From nobody Mon Apr 6 10:45:00 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 6017CC07E9D for ; Sat, 24 Sep 2022 00:05:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233040AbiIXAFz (ORCPT ); Fri, 23 Sep 2022 20:05:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232315AbiIXAFK (ORCPT ); Fri, 23 Sep 2022 20:05:10 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F1C89DFAB; Fri, 23 Sep 2022 17:05:06 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663977901; 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=z4lcvDU/MemQOUY1h+3uqj4PoL4kor3zog3zDG/QSnM=; b=R2t99lC/EqCbqaf4XF8cFgE7FcfLjsAb+kOQ1Wfu6XGekrw/NG4KpclPNhRdYDcMjxba9S 78wtU8Ef2nRNsdoPjknjYM97lBHcPccJzPh241MNm5DeUXghIbK2Jp/Ezbmtgg/FZpwuE2 AVMTTTn5/Oprhvg3BBwZ7ddjTB23kOCIegspaNmHwvknTV2/n9FuEI/tTNP97VY3G3G9gq QtgvZF1bWUY91LCrfZ1ohbqtKc/gAfCur1rGkbJ6bVKnf+WVlnZC6mQuvsw5P7HPWEPWI2 2fuY49WOYSv6DT7AQUzsTYH1uDNqC86UTmVNkaxH7WnCSrp84o4SwlY4WIzd9g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663977901; 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=z4lcvDU/MemQOUY1h+3uqj4PoL4kor3zog3zDG/QSnM=; b=q7Tw6vty0oiILbyIcxbEZIBR6eTBTnRqhvzIU7ymOMavEnHnaBtUi5gMC7dJEYydCUR6Uj CRe60J2Koibhy6BQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Greg Kroah-Hartman , Jiri Slaby , kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org Subject: [PATCH printk 09/18] serial: kgdboc: Lock console list in probe function Date: Sat, 24 Sep 2022 02:10:45 +0206 Message-Id: <20220924000454.3319186-10-john.ogness@linutronix.de> In-Reply-To: <20220924000454.3319186-1-john.ogness@linutronix.de> References: <20220924000454.3319186-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 Unprotected list walks are not necessarily safe. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Sergey Senozhatsky Reviewed-by: Douglas Anderson Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- drivers/tty/serial/kgdboc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c index 79b7db8580e0..af2aa76bae15 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -193,7 +193,8 @@ static int configure_kgdboc(void) if (!p) goto noconfig; =20 - for_each_console(cons) { + console_list_lock(); + for_each_registered_console(cons) { int idx; if (cons->device && cons->device(cons, &idx) =3D=3D p && idx =3D=3D tty_line) { @@ -201,6 +202,7 @@ static int configure_kgdboc(void) break; } } + console_list_unlock(); =20 kgdb_tty_driver =3D p; kgdb_tty_line =3D tty_line; --=20 2.30.2 From nobody Mon Apr 6 10:45:00 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 E932FC04A95 for ; Sat, 24 Sep 2022 00:06:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233064AbiIXAGD (ORCPT ); Fri, 23 Sep 2022 20:06:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233002AbiIXAFM (ORCPT ); Fri, 23 Sep 2022 20:05:12 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A97DB02B9; Fri, 23 Sep 2022 17:05:06 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663977901; 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=wmQTrIsrazpPIyD8N/ImSAVVwbH1mqHErna9k27Vvaw=; b=e0HL7iVSFrWDEyWd93pKTysu+f2PtjV3UFX2E17ouIqnFgtgYHj2JwYv2DJpGHFeLeQ3ld MCM414BiK2Y3yDjf149S6h7A2iKBukElbmL8Fx+8e0sPzdpxSUabOQYTK4KjD2bSusFYnP //N/XuNoVWXLv6GGGBV6UOQkBD+XfX0rptum628w3mUuvC8YGt0WaymrGmYMZDiBqax5Me Rggwzu8njK/aSMcmvP10yWtRrHV4bUJBQdZnWnzqiXp9tAjhEgNDoHxBmN+uFi/uXa+Mos JdYY7EdmpHm6MrGtdgVzyLDiJyHObnss252/czGO/8zUHjIBcIgYIQW0F8EU1g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663977901; 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=wmQTrIsrazpPIyD8N/ImSAVVwbH1mqHErna9k27Vvaw=; b=b9MI9BO/qiKg/DT4XFHp9Pb+3i4omPO4qdqEr0ElztkwrozUgg0NcEq8KTBgK/v0k0uPW1 l2r6ueyffq6bMOAw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Greg Kroah-Hartman , Jiri Slaby , Aaron Tomlin , Luis Chamberlain , kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org Subject: [PATCH printk 10/18] kgbd: Pretend that console list walk is safe Date: Sat, 24 Sep 2022 02:10:46 +0206 Message-Id: <20220924000454.3319186-11-john.ogness@linutronix.de> In-Reply-To: <20220924000454.3319186-1-john.ogness@linutronix.de> References: <20220924000454.3319186-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 Provide a special list iterator macro for KGDB to allow unprotected list walks and add a few comments to explain the hope based approach. Preperatory change for changing the console list to hlist and adding lockdep asserts to regular list walks. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Sergey Senozhatsky Reviewed-by: Aaron Tomlin Reviewed-by: Greg Kroah-Hartman --- drivers/tty/serial/kgdboc.c | 5 ++++- include/linux/console.h | 10 ++++++++++ kernel/debug/kdb/kdb_io.c | 7 ++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c index af2aa76bae15..57a5fd27dffe 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -462,10 +462,13 @@ static void kgdboc_earlycon_pre_exp_handler(void) * we have no other choice so we keep using it. Since not all * serial drivers might be OK with this, print a warning once per * boot if we detect this case. + * + * Pretend that walking the console list is safe... */ - for_each_console(con) + for_each_console_kgdb(con) { if (con =3D=3D kgdboc_earlycon_io_ops.cons) return; + } =20 already_warned =3D true; pr_warn("kgdboc_earlycon is still using bootconsole\n"); diff --git a/include/linux/console.h b/include/linux/console.h index 24344f9b0bc1..86a6125512b9 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -187,6 +187,16 @@ extern void console_list_unlock(void) __releases(conso= le_mutex); #define for_each_console(con) \ for (con =3D console_drivers; con !=3D NULL; con =3D con->next) =20 +/** + * for_each_console_kgdb() - Iterator over registered consoles for KGDB + * @con: struct console pointer used as loop cursor + * + * Has no serialization requirements and KGDB pretends that this is safe. + * Don't use outside of the KGDB fairy tale land! + */ +#define for_each_console_kgdb(con) \ + for (con =3D console_drivers; con !=3D NULL; con =3D con->next) + extern int console_set_on_cmdline; extern struct console *early_console; =20 diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 67d3c48a1522..fb3775e61a3b 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -558,7 +558,12 @@ static void kdb_msg_write(const char *msg, int msg_len) cp++; } =20 - for_each_console(c) { + /* + * This is a completely unprotected list walk designed by the + * wishful thinking department. See the oops_in_progress comment + * below - especially the encourage section... + */ + for_each_console_kgdb(c) { if (!(c->flags & CON_ENABLED)) continue; if (c =3D=3D dbg_io_ops->cons) --=20 2.30.2 From nobody Mon Apr 6 10:45:00 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 C9334C04A95 for ; Sat, 24 Sep 2022 00:06:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233004AbiIXAGJ (ORCPT ); Fri, 23 Sep 2022 20:06:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233001AbiIXAFM (ORCPT ); Fri, 23 Sep 2022 20:05:12 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59BCAA5712; Fri, 23 Sep 2022 17:05:06 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663977902; 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=hP5hgE3NqqWAe7NsJh2Zg4V0BgzlJ82nPhD5UvfqL1c=; b=ZhjExFnt3DHjT6MAszFYGWDIA+0wrrgI55Wiz/TKYY7681Ifuj3NZatGKcFv+V24ss9EjN nnN9VuHE8djfIzuxXeCAdrKVQOc/0xQsbQrV5VjLH4H7CKvhj7lJqUDSMyZR+v2oXKPm4g mg5J3lbKrVhB7xaO/OyzCU+4uaOUax0b6jptRyy1YtTSeYgoavf4QsCfgoRUrhjFRO/9Cw si5NANo0SfuQKZa0SxWsUgAHo7Z4S/V5jcUjseRBxZ3PVlQDW/zwxV188OF+jONkAwtDJG c3qc5d4tUUa2jFibijWRl822uD7E8F8enucx2ScKdzT04dnZEGxZvJwkFIIMwg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663977902; 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=hP5hgE3NqqWAe7NsJh2Zg4V0BgzlJ82nPhD5UvfqL1c=; b=p6mv1TLxByq/wgGx21NhPWw2upD3WUZ/VdIJV4lxWZ71oHLwkrysDugo/cKRsLctIcetVH U7JbpTDTxH/BM/Bw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, "James E.J. Bottomley" , Helge Deller , Greg Kroah-Hartman , linux-parisc@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH printk 11/18] printk: Convert console_drivers list to hlist Date: Sat, 24 Sep 2022 02:10:47 +0206 Message-Id: <20220924000454.3319186-12-john.ogness@linutronix.de> In-Reply-To: <20220924000454.3319186-1-john.ogness@linutronix.de> References: <20220924000454.3319186-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 open coded single linked list with a hlist so a conversion to SRCU protected list walks can reuse the existing primitives. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman --- arch/parisc/kernel/pdc_cons.c | 19 +++---- fs/proc/consoles.c | 5 +- include/linux/console.h | 15 ++++-- kernel/printk/printk.c | 99 +++++++++++++++++++---------------- 4 files changed, 75 insertions(+), 63 deletions(-) diff --git a/arch/parisc/kernel/pdc_cons.c b/arch/parisc/kernel/pdc_cons.c index 9a0c0932d2f9..3f9abf0263ee 100644 --- a/arch/parisc/kernel/pdc_cons.c +++ b/arch/parisc/kernel/pdc_cons.c @@ -147,13 +147,8 @@ static int __init pdc_console_tty_driver_init(void) =20 struct console *tmp; =20 - console_lock(); - for_each_console(tmp) - if (tmp =3D=3D &pdc_cons) - break; - console_unlock(); - - if (!tmp) { + /* Pretend that this works as much as it pretended to work historically */ + if (hlist_unhashed_lockless(&pdc_cons.node)) { printk(KERN_INFO "PDC console driver not registered anymore, not creatin= g %s\n", pdc_cons.name); return -ENODEV; } @@ -272,15 +267,17 @@ void pdc_console_restart(bool hpmc) if (pdc_console_initialized) return; =20 - if (!hpmc && console_drivers) + if (!hpmc && !hlist_empty(&console_list)) return; =20 /* If we've already seen the output, don't bother to print it again */ - if (console_drivers !=3D NULL) + if (!hlist_empty(&console_list)) pdc_cons.flags &=3D ~CON_PRINTBUFFER; =20 - while ((console =3D console_drivers) !=3D NULL) - unregister_console(console_drivers); + while (!hlist_empty(&console_list)) { + unregister_console(READ_ONCE(hlist_entry(console_list.first, + struct console, node))); + } =20 /* force registering the pdc console */ pdc_console_init_force(); diff --git a/fs/proc/consoles.c b/fs/proc/consoles.c index 6775056eecd5..70994d1e52f6 100644 --- a/fs/proc/consoles.c +++ b/fs/proc/consoles.c @@ -74,8 +74,11 @@ static void *c_start(struct seq_file *m, loff_t *pos) static void *c_next(struct seq_file *m, void *v, loff_t *pos) { struct console *con =3D v; + ++*pos; - return con->next; + hlist_for_each_entry_continue(con, node) + break; + return con; } =20 static void c_stop(struct seq_file *m, void *v) diff --git a/include/linux/console.h b/include/linux/console.h index 86a6125512b9..1e3d0a50cef1 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -15,6 +15,7 @@ #define _LINUX_CONSOLE_H_ 1 =20 #include +#include #include =20 struct vc_data; @@ -154,15 +155,19 @@ struct console { u64 seq; unsigned long dropped; void *data; - struct console *next; + struct hlist_node node; }; =20 #ifdef CONFIG_LOCKDEP +extern void lockdep_assert_console_lock_held(void); extern void lockdep_assert_console_list_lock_held(void); #else +static inline void lockdep_assert_console_lock_held(void) { } static inline void lockdep_assert_console_list_lock_held(void) { } #endif =20 +extern struct hlist_head console_list; + extern void console_list_lock(void) __acquires(console_mutex); extern void console_list_unlock(void) __releases(console_mutex); =20 @@ -175,7 +180,7 @@ extern void console_list_unlock(void) __releases(consol= e_mutex); */ #define for_each_registered_console(con) \ lockdep_assert_console_list_lock_held(); \ - for (con =3D console_drivers; con !=3D NULL; con =3D con->next) + hlist_for_each_entry(con, &console_list, node) =20 /** * for_each_console() - Iterator over registered consoles @@ -185,7 +190,8 @@ extern void console_list_unlock(void) __releases(consol= e_mutex); * list is immutable. */ #define for_each_console(con) \ - for (con =3D console_drivers; con !=3D NULL; con =3D con->next) + lockdep_assert_console_lock_held(); \ + hlist_for_each_entry(con, &console_list, node) =20 /** * for_each_console_kgdb() - Iterator over registered consoles for KGDB @@ -195,7 +201,7 @@ extern void console_list_unlock(void) __releases(consol= e_mutex); * Don't use outside of the KGDB fairy tale land! */ #define for_each_console_kgdb(con) \ - for (con =3D console_drivers; con !=3D NULL; con =3D con->next) + hlist_for_each_entry(con, &console_list, node) =20 extern int console_set_on_cmdline; extern struct console *early_console; @@ -208,7 +214,6 @@ enum con_flush_mode { extern int add_preferred_console(char *name, int idx, char *options); extern void register_console(struct console *); extern int unregister_console(struct console *); -extern struct console *console_drivers; extern void console_lock(void); extern int console_trylock(void); extern void console_unlock(void); diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 80a728ef9d96..f1d31dcbd6ba 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -79,20 +79,20 @@ int oops_in_progress; EXPORT_SYMBOL(oops_in_progress); =20 /* - * console_sem protects the console_drivers list, and also provides - * serialization for access to the entire console driver system. + * console_sem protects onsole_list, and also provides serialization for + * access to the entire console driver system. * * console_mutex serializes register/unregister. * * console_sem must be taken inside a console_mutex locked section - * for any list manipulation in order to keep the console BKL + * for any console_list manipulation in order to keep the console BKL * machinery happy. This requirement also applies to manipulation * of console->flags. */ static DEFINE_MUTEX(console_mutex); static DEFINE_SEMAPHORE(console_sem); -struct console *console_drivers; -EXPORT_SYMBOL_GPL(console_drivers); +HLIST_HEAD(console_list); +EXPORT_SYMBOL_GPL(console_list); =20 /* * System may need to suppress printk message under certain @@ -111,6 +111,11 @@ static struct lockdep_map console_lock_dep_map =3D { .name =3D "console_lock" }; =20 +void lockdep_assert_console_lock_held(void) +{ + lockdep_assert(lock_is_held(&console_lock_dep_map)); +} + void lockdep_assert_console_list_lock_held(void) { lockdep_assert_held(&console_mutex); @@ -2591,7 +2596,7 @@ static int console_cpu_notify(unsigned int cpu) * console_lock - lock the console system for exclusive use. * * Acquires a lock which guarantees that the caller has - * exclusive access to the console system and the console_drivers list. + * exclusive access to the console system and console_list. * * Can sleep, returns nothing. */ @@ -2611,7 +2616,7 @@ EXPORT_SYMBOL(console_lock); * console_trylock - try to lock the console system for exclusive use. * * Try to acquire a lock which guarantees that the caller has exclusive - * access to the console system and the console_drivers list. + * access to the console system and console_list. * * returns 1 on success, and 0 on failure to acquire the lock. */ @@ -2979,7 +2984,15 @@ void console_flush_on_panic(enum con_flush_mode mode) u64 seq; =20 seq =3D prb_first_valid_seq(prb); - for_each_console(c) + /* + * This cannot use for_each_console() because it's not established + * that the current context has console locked and neither there is + * a guarantee that there is no concurrency in that case. + * + * Open code it for documentation purposes and pretend that + * it works. + */ + hlist_for_each_entry(c, &console_list, node) c->seq =3D seq; } console_unlock(); @@ -3120,6 +3133,9 @@ static void try_enable_default_console(struct console= *newcon) (con->flags & CON_BOOT) ? "boot" : "", \ con->name, con->index, ##__VA_ARGS__) =20 +#define cons_first() \ + hlist_entry(console_list.first, struct console, node) + static int console_unregister_locked(struct console *console); =20 /* @@ -3182,8 +3198,8 @@ void register_console(struct console *newcon) * flag set and will be first in the list. */ if (preferred_console < 0) { - if (!console_drivers || !console_drivers->device || - console_drivers->flags & CON_BOOT) { + if (hlist_empty(&console_list) || !cons_first()->device || + cons_first()->flags & CON_BOOT) { try_enable_default_console(newcon); } } @@ -3211,21 +3227,17 @@ void register_console(struct console *newcon) } =20 /* - * Put this console in the list - keep the - * preferred driver at the head of the list. + * Put this console in the list and keep the referred driver at the + * head of the list. */ console_lock(); - if ((newcon->flags & CON_CONSDEV) || console_drivers =3D=3D NULL) { - newcon->next =3D console_drivers; - console_drivers =3D newcon; - if (newcon->next) - newcon->next->flags &=3D ~CON_CONSDEV; - /* Ensure this flag is always set for the head of the list */ - newcon->flags |=3D CON_CONSDEV; - } else { - newcon->next =3D console_drivers->next; - console_drivers->next =3D newcon; - } + if (newcon->flags & CON_CONSDEV || hlist_empty(&console_list)) + hlist_add_head(&newcon->node, &console_list); + else + hlist_add_behind(&newcon->node, console_list.first); + + /* Ensure this flag is always set for the head of the list */ + cons_first()->flags |=3D CON_CONSDEV; =20 newcon->dropped =3D 0; if (newcon->flags & CON_PRINTBUFFER) { @@ -3251,7 +3263,9 @@ void register_console(struct console *newcon) if (bootcon_enabled && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) =3D=3D CON_CONSDEV) && !keep_bootcon) { - for_each_console(con) { + struct hlist_node *tmp; + + hlist_for_each_entry_safe(con, tmp, &console_list, node) { if (con->flags & CON_BOOT) console_unregister_locked(con); } @@ -3263,7 +3277,6 @@ EXPORT_SYMBOL(register_console); =20 static int console_unregister_locked(struct console *console) { - struct console *con; int res; =20 con_printk(KERN_INFO, console, "disabled\n"); @@ -3274,32 +3287,28 @@ static int console_unregister_locked(struct console= *console) if (res > 0) return 0; =20 - res =3D -ENODEV; console_lock(); - if (console_drivers =3D=3D console) { - console_drivers=3Dconsole->next; - res =3D 0; - } else { - for_each_console(con) { - if (con->next =3D=3D console) { - con->next =3D console->next; - res =3D 0; - break; - } - } - } =20 - if (res) - goto out_disable_unlock; + /* Disable it unconditionally */ + console->flags &=3D ~CON_ENABLED; + + if (hlist_unhashed(&console->node)) + goto out_unlock; + + hlist_del_init(&console->node); =20 /* + * * If this isn't the last console and it has CON_CONSDEV set, we * need to set it on the next preferred console. + * + * + * The above makes no sense as there is no guarantee that the next + * console has any device attached. Oh well.... */ - if (console_drivers !=3D NULL && console->flags & CON_CONSDEV) - console_drivers->flags |=3D CON_CONSDEV; + if (!hlist_empty(&console_list) && console->flags & CON_CONSDEV) + cons_first()->flags |=3D CON_CONSDEV; =20 - console->flags &=3D ~CON_ENABLED; console_unlock(); console_sysfs_notify(); =20 @@ -3308,10 +3317,8 @@ static int console_unregister_locked(struct console = *console) =20 return res; =20 -out_disable_unlock: - console->flags &=3D ~CON_ENABLED; +out_unlock: console_unlock(); - return res; } =20 --=20 2.30.2 From nobody Mon Apr 6 10:45:00 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 A7621C04A95 for ; Sat, 24 Sep 2022 00:05:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232779AbiIXAFu (ORCPT ); Fri, 23 Sep 2022 20:05:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232981AbiIXAFL (ORCPT ); Fri, 23 Sep 2022 20:05:11 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51119A2220 for ; Fri, 23 Sep 2022 17:05:06 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663977903; 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=DfVMZJNRNmUcXs0AcEgf8PmYZBx9ybi5NZy3duOSBFA=; b=Zow98vZHUhmdqMsJES3M8pCx7McItBn90Y/GKqk3vKRNbclqVUaov3IAkPienr20Ndlrxu tYBHN9v1A4lJ0U8xdPow1fcAHflWhjwTXU+GNT3/goFE8SgWLeDIWCKXfmv6nhT6pp4jhK MQeBQsq0B3rpi/gOn/n1cbHN2dHAxr4ZK8YRQJk12mMH3tvrUGNflxfBrYQ7fC212nSzpU vC8OXucQG03GD5u0f9R5nhZhGmvXqjVBRdhae9d9oupqMd5XZ4Vbu/ekXePHk7HhNBNl6U aBXR2vC9C0nWcmS/clVrc1wwPs3dMYnIPTJKA0rD40OABRS11H0FrmrRSRKxSQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663977903; 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=DfVMZJNRNmUcXs0AcEgf8PmYZBx9ybi5NZy3duOSBFA=; b=qb7loi7gRnwUl6Y/52LX2Rz/INvaxFAKfEz5BoDrnfE/NNdN0SBbAXEool0QD9LHVeRXYZ dXfaJ+cbHx2U9IBA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk 12/18] printk: Prepare for SCRU console list protection Date: Sat, 24 Sep 2022 02:10:48 +0206 Message-Id: <20220924000454.3319186-13-john.ogness@linutronix.de> In-Reply-To: <20220924000454.3319186-1-john.ogness@linutronix.de> References: <20220924000454.3319186-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 Provide a SRCU protected variant to walk the console list. Preperatory change for a new console infrastructure which operates independent of console BKL. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Sergey Senozhatsky --- include/linux/console.h | 14 +++++++++++++- kernel/printk/printk.c | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index 1e3d0a50cef1..dc0df9d9e7d9 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -15,7 +15,7 @@ #define _LINUX_CONSOLE_H_ 1 =20 #include -#include +#include #include =20 struct vc_data; @@ -161,6 +161,7 @@ struct console { #ifdef CONFIG_LOCKDEP extern void lockdep_assert_console_lock_held(void); extern void lockdep_assert_console_list_lock_held(void); +extern bool console_srcu_read_lock_is_held(void); #else static inline void lockdep_assert_console_lock_held(void) { } static inline void lockdep_assert_console_list_lock_held(void) { } @@ -171,6 +172,17 @@ extern struct hlist_head console_list; extern void console_list_lock(void) __acquires(console_mutex); extern void console_list_unlock(void) __releases(console_mutex); =20 +/** + * for_each_console_srcu() - Iterator over registered consoles + * @con: struct console pointer used as loop cursor + * + * Requires console_srcu_read_lock to be held. Can be invoked from + * any context. + */ +#define for_each_console_srcu(con) \ + hlist_for_each_entry_srcu(con, &console_list, node, \ + console_srcu_read_lock_is_held()) + /** * for_each_registered_console() - Iterator over registered consoles * @con: struct console pointer used as loop cursor diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index f1d31dcbd6ba..7e6d1cd34452 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -93,6 +93,7 @@ static DEFINE_MUTEX(console_mutex); static DEFINE_SEMAPHORE(console_sem); HLIST_HEAD(console_list); EXPORT_SYMBOL_GPL(console_list); +DEFINE_STATIC_SRCU(console_srcu); =20 /* * System may need to suppress printk message under certain @@ -121,6 +122,10 @@ void lockdep_assert_console_list_lock_held(void) lockdep_assert_held(&console_mutex); } =20 +bool console_srcu_read_lock_is_held(void) +{ + return srcu_read_lock_held(&console_srcu); +} #endif =20 enum devkmsg_log_bits { @@ -3232,9 +3237,9 @@ void register_console(struct console *newcon) */ console_lock(); if (newcon->flags & CON_CONSDEV || hlist_empty(&console_list)) - hlist_add_head(&newcon->node, &console_list); + hlist_add_head_rcu(&newcon->node, &console_list); else - hlist_add_behind(&newcon->node, console_list.first); + hlist_add_behind_rcu(&newcon->node, console_list.first); =20 /* Ensure this flag is always set for the head of the list */ cons_first()->flags |=3D CON_CONSDEV; @@ -3250,6 +3255,7 @@ void register_console(struct console *newcon) newcon->seq =3D prb_next_seq(prb); } console_unlock(); + /* No need to synchronize SRCU here! */ console_sysfs_notify(); =20 /* @@ -3295,7 +3301,7 @@ static int console_unregister_locked(struct console *= console) if (hlist_unhashed(&console->node)) goto out_unlock; =20 - hlist_del_init(&console->node); + hlist_del_init_rcu(&console->node); =20 /* * @@ -3310,6 +3316,10 @@ static int console_unregister_locked(struct console = *console) cons_first()->flags |=3D CON_CONSDEV; =20 console_unlock(); + + /* Ensure that all SRCU list walks have completed */ + synchronize_srcu(&console_srcu); + console_sysfs_notify(); =20 if (console->exit) --=20 2.30.2 From nobody Mon Apr 6 10:45:00 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 DFB3AC04A95 for ; Sat, 24 Sep 2022 00:05:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232869AbiIXAFg (ORCPT ); Fri, 23 Sep 2022 20:05:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232977AbiIXAFL (ORCPT ); Fri, 23 Sep 2022 20:05:11 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50704A00FF for ; Fri, 23 Sep 2022 17:05:06 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663977903; 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=wFxBj/7Cwv+l8jbrElsJozenhe25KvbQeObQTTb9s44=; b=PtZbcifWrYlUJnCh/nYiLHegyU3pOQE2MzDRtKEPyugn+iUtdN+2p7gUFn3KBAXMnqUEcw DNgrwSVspJQ6PQZaIGIobyjWFoQZ/2D67xRIVYll6LrryVbWhD/L7FLz21J2NA3T2iN80F ADWD1shpEyJchkZX2zKKPa47vbJFVlGO4ntUvscBZc8y4QSrysIEMqwguJW72yyEkbQG9x ZyB6Bwtx6qmSBhFet5QMz+Wp43C2H9OW7qCsPDqnSylYuUH9AwQydTX/WJ7/JPommRXGdZ kjNpQ9mjgM/52KOf2hQkTF281W0uT5QcmTYHuQWyTYBpZWFlVuI0u1DFUoqX3Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663977903; 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=wFxBj/7Cwv+l8jbrElsJozenhe25KvbQeObQTTb9s44=; b=jgRrlrJtt6YEu8bhuqsaWVwwoyDhFmY7chaNEhatxeXIUF8tw2Jxk30J0Z69TzMiDx09jO PC65BfeYfKkZMfCw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk 13/18] printk: Move buffer size defines Date: Sat, 24 Sep 2022 02:10:49 +0206 Message-Id: <20220924000454.3319186-14-john.ogness@linutronix.de> In-Reply-To: <20220924000454.3319186-1-john.ogness@linutronix.de> References: <20220924000454.3319186-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. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Sergey Senozhatsky --- include/linux/console.h | 14 ++++++++++++++ include/linux/printk.h | 2 -- kernel/printk/printk.c | 8 -------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index dc0df9d9e7d9..3bb5bc62e154 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 + +/* The maximum size for a dropped text message */ +#define DROPPED_TEXT_MAX 64 +#else +#define CONSOLE_LOG_MAX 0 +#define DROPPED_TEXT_MAX 0 +#endif + +/* The maximum size of an 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 7e6d1cd34452..65e9903d066f 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -433,12 +433,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 - /* the maximum size allowed to be reserved for a record */ #define LOG_LINE_MAX (CONSOLE_LOG_MAX - PREFIX_MAX) =20 @@ -2343,8 +2337,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 Mon Apr 6 10:45:00 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 3F1B3C07E9D for ; Sat, 24 Sep 2022 00:06:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233137AbiIXAGL (ORCPT ); Fri, 23 Sep 2022 20:06:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232959AbiIXAFM (ORCPT ); Fri, 23 Sep 2022 20:05:12 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C297D33CA for ; Fri, 23 Sep 2022 17:05:06 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663977904; 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=wNgrSZ2OGE1ZcTDR6ScZab8YT3+EG0Nnd7/A9t2uS7k=; b=XKNIg73wEnHG16+eSKTWfVTJUDOSUZQD9/ZQ1qxyh5+kmutvwlSuAM+g4UmR/Kh4/h3Lwy gB8N0T+ADUxZfG0r0wgO9T7Banvn+zOL5qTP1uju825a4ZUhEgGizR2t7FEMQDCbtBeB2S pie+UB/SuRjH3o/g7NoOv/LYWjkcMgVOk6q1JFyxfv6KiajRjR5Pwc030CrZQKlMBfKULC Bftp6qKO6KMFMLvtr43s5etqK8aVen8+c7YJBp3TGvSrNxD7gjI0Iad6mLL9jOoC4Uoh3F X41AEll5jRiKyGP8bhhtpgRcQN4tgW0Qatdwn8IcXSJ1FBXGQfqYO4ICEyOmGw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663977904; 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=wNgrSZ2OGE1ZcTDR6ScZab8YT3+EG0Nnd7/A9t2uS7k=; b=6hiCZndz3RSsX6T+VCzGWe1MeMk4920P8DOw2MA+k5VJgmXxoJJFxzWWqJsOXdcK448BAn YODkZ67swoUsRkAw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk 14/18] printk: Document struct console Date: Sat, 24 Sep 2022 02:10:50 +0206 Message-Id: <20220924000454.3319186-15-john.ogness@linutronix.de> In-Reply-To: <20220924000454.3319186-1-john.ogness@linutronix.de> References: <20220924000454.3319186-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 docbook comments to struct console. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Sergey Senozhatsky --- include/linux/console.h | 95 +++++++++++++++++++++++++++++------------ 1 file changed, 68 insertions(+), 27 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index 3bb5bc62e154..8ec24fe097d3 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,37 +140,77 @@ 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: On register, start from the oldest dmesg record + * @CON_CONSDEV: Questionable historical leftover to denote which console + * driver is the preferred console which is defining what + * backs up /dev/console + * @CON_ENABLED: Indicates if a console is allowed to print records. If fa= lse, + * 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 unless the early console + * command line parameter for this console has the 'keep' option set. + * @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's misleading as it suggests that there + * is no contextual limit for invoking the callback. + * @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 record 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 - 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 *, 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; }; =20 #ifdef CONFIG_LOCKDEP --=20 2.30.2 From nobody Mon Apr 6 10:45:00 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 EFB9CC07E9D for ; Sat, 24 Sep 2022 00:06:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233139AbiIXAGS (ORCPT ); Fri, 23 Sep 2022 20:06:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233017AbiIXAFN (ORCPT ); Fri, 23 Sep 2022 20:05:13 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16409105D5B for ; Fri, 23 Sep 2022 17:05:12 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663977905; 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=5h7zixATd3WpCb7P+Y08NqGrb+Fb5oQOQ9ihWYJOO5k=; b=H17dFKuKhT9Lp9Q4+/UbrwIXCcApT4fvLMAxpq7EnVbGkimHzqBWkAKTBRAJum7YnMSxHG vhyYuDgrXdAmAL6mbvbq4t+x9A5l1Rtpm/nJ8Q8DTNRzmxoBWH1HuOTHOytOLdYsv44x+Y a2Em3tJjbiOgpRVZUNU+R25WG2UYcLhRSNnmRVqsjU2I4ehQo307+mjJiF4utT5UZcA9sQ fRqapy9yhDlhvJudHV2GLqCfX8pTXOVhmBwFZ4rh08QT216Z4jvGZgbgZYD31BNCYf++na qQc8C+tajmDQwze4hE/17DUb/HH1utNuhjF1AmnTzIH7oCa2cGBQyaM35ILylw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663977905; 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=5h7zixATd3WpCb7P+Y08NqGrb+Fb5oQOQ9ihWYJOO5k=; b=L9VjFKU9GQuqZI2R+r4dxWI8JAmys1BTBglboFPZzTbZiSK3oWd9Ex3t7rBSwM2vVenTkI C6Vp9viA8gKQO5DQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk 15/18] printk: Add struct cons_text_buf Date: Sat, 24 Sep 2022 02:10:51 +0206 Message-Id: <20220924000454.3319186-16-john.ogness@linutronix.de> In-Reply-To: <20220924000454.3319186-1-john.ogness@linutronix.de> References: <20220924000454.3319186-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 and extended formatting. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Sergey Senozhatsky --- include/linux/console.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/console.h b/include/linux/console.h index 8ec24fe097d3..05c7325e98f9 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -173,6 +173,20 @@ enum cons_flags { CON_EXTENDED =3D BIT(6), }; =20 +/** + * struct cons_text_buf - console output text buffer + * @ext_text: Buffer for extended log format text + * @dropped_text: Buffer for dropped text + * @text: Buffer for ringbuffer text + */ +struct cons_text_buf { + union { + char ext_text[CONSOLE_EXT_LOG_MAX]; + char dropped_text[DROPPED_TEXT_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 Mon Apr 6 10:45:00 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 BF287C04A95 for ; Sat, 24 Sep 2022 00:06:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233155AbiIXAGW (ORCPT ); Fri, 23 Sep 2022 20:06:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233025AbiIXAFN (ORCPT ); Fri, 23 Sep 2022 20:05:13 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1645E109511 for ; Fri, 23 Sep 2022 17:05:12 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663977905; 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=F0Yr9YW9TkpwabOV/sHvy2PFM1n82pdEktGbtb5murQ=; b=pRspcof7dev0g0OhwKuoPG86gDWlJ1ZEhtPbx6gyoLUo39VTSMywDrerPzLG6K/ItIx+Bv apeM5DVHv5ctqgLlpggdpnJSTlKiVA2FbAg43SwOoX611jCRp6EqXNo8m9tdaQU9Az7gvL 0D4Htso+MATZ6pQ4ST4aEjS8cEFol1Huz4FhKswLxgzewkKNslm8hjMI9fYwlEfXt47Zci m3uGtkpSLq2hHTCyzBgkCflWaGN9NdyE6mOFhrwf7HeLKmcM/3uW8JxwNY9dR7snM7MAFh Q7w6xCOxhq6U2gc1rHvaD56bIh/dE3Tmqz41wffwmzMLSNVayOuczuug9UJ5Kw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663977905; 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=F0Yr9YW9TkpwabOV/sHvy2PFM1n82pdEktGbtb5murQ=; b=VpTag6ljA+TeusULrPuefsh0OY8EKJGqTb1bkBdw4OKmqq/skFEd8GfEGrWclajSyoI5RA 1SmU1dq3YkrIsfDw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk 16/18] printk: Use struct cons_text_buf Date: Sat, 24 Sep 2022 02:10:52 +0206 Message-Id: <20220924000454.3319186-17-john.ogness@linutronix.de> In-Reply-To: <20220924000454.3319186-1-john.ogness@linutronix.de> References: <20220924000454.3319186-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 cons_text_buf. Note that the buffer size of devkmsg_user.text_buf, when replaced with cons_text_buf.text, reduces from CONSOLE_EXT_LOG_MAX to CONSOLE_LOG_MAX. However, the buffer is only used to read ringbuffer records, which have a maximum size of LOG_LINE_MAX (CONSOLE_LOG_MAX - PREFIX_MAX). Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Sergey Senozhatsky --- kernel/printk/printk.c | 50 ++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 65e9903d066f..9cbd44e9fc45 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -671,11 +671,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 cons_text_buf txtbuf; }; =20 static __printf(3, 4) __cold @@ -758,6 +756,8 @@ static ssize_t devkmsg_read(struct file *file, char __u= ser *buf, { struct devkmsg_user *user =3D file->private_data; struct printk_record *r =3D &user->record; + char *outbuf =3D user->txtbuf.ext_text; + const int maxlen =3D sizeof(user->txtbuf.ext_text); size_t len; ssize_t ret; =20 @@ -798,8 +798,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(outbuf, maxlen, r->info); + len +=3D msg_print_ext_body(outbuf + len, maxlen - len, &r->text_buf[0], r->info->text_len, &r->info->dev_info); =20 @@ -810,7 +810,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, outbuf, len)) { ret =3D -EFAULT; goto out; } @@ -909,7 +909,8 @@ 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->txtbuf.text, + sizeof(user->txtbuf.text)); =20 atomic64_set(&user->seq, prb_first_valid_seq(prb)); =20 @@ -2709,8 +2710,8 @@ static void __console_unlock(void) * * Requires the console_lock. */ -static bool console_emit_next_record(struct console *con, char *text, char= *ext_text, - char *dropped_text, bool *handover) +static bool console_emit_next_record(struct console *con, struct cons_text= _buf *txtbuf, + bool *handover, bool extmsg) { static int panic_console_dropped; struct printk_info info; @@ -2719,7 +2720,7 @@ static bool console_emit_next_record(struct console *= con, char *text, char *ext_ char *write_text; size_t len; =20 - prb_rec_init_rd(&r, &info, text, CONSOLE_LOG_MAX); + prb_rec_init_rd(&r, &info, txtbuf->text, CONSOLE_LOG_MAX); =20 *handover =3D false; =20 @@ -2741,13 +2742,13 @@ 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 (extmsg) { + write_text =3D txtbuf->ext_text; + len =3D info_print_ext_header(write_text, CONSOLE_EXT_LOG_MAX, r.info); + len +=3D msg_print_ext_body(write_text + len, CONSOLE_EXT_LOG_MAX - len, &r.text_buf[0], r.info->text_len, &r.info->dev_info); } else { - write_text =3D text; + write_text =3D txtbuf->text; len =3D record_print_text(&r, console_msg_format & MSG_FORMAT_SYSLOG, pr= intk_time); } =20 @@ -2765,7 +2766,7 @@ 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, write_text, len, extmsg ? NULL : txtbuf->dropped= _text); start_critical_timings(); =20 con->seq++; @@ -2801,9 +2802,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 cons_text_buf txtbuf; bool any_usable =3D false; struct console *con; bool any_progress; @@ -2821,16 +2820,9 @@ static bool console_flush_all(bool do_cond_resched, = u64 *next_seq, bool *handove continue; any_usable =3D true; =20 - if (con->flags & CON_EXTENDED) { - /* Extended consoles do not print "dropped messages". */ - progress =3D console_emit_next_record(con, &text[0], - &ext_text[0], NULL, - handover); - } else { - progress =3D console_emit_next_record(con, &text[0], - NULL, &dropped_text[0], - handover); - } + progress =3D console_emit_next_record(con, &txtbuf, handover, + con->flags & CON_EXTENDED); + if (*handover) return false; =20 --=20 2.30.2 From nobody Mon Apr 6 10:45:00 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 6B26CC07E9D for ; Sat, 24 Sep 2022 00:06:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233159AbiIXAGc (ORCPT ); Fri, 23 Sep 2022 20:06:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233034AbiIXAFP (ORCPT ); Fri, 23 Sep 2022 20:05:15 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0C909DFAB for ; Fri, 23 Sep 2022 17:05:12 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663977906; 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=78lWKQLJRfdW9hexh7XAr98bJYw2kzBvk5KGdMnrw6M=; b=H1F61iegmWvk2aynS76wM7c/ppzek30gCbggDPvqxy9jWDyTWbBZ9Zn+SLglw37vgtUpcl H6N8gT5d+Tg94ugyLxfhyrpKwftkPgA5JJZjHiLxZPuAxUKngNtuEJpnjZz64DrpASZiw5 iApAv/6rFAmeMSTVXm17XSQklmgN64PLyLqKHIj/lhuLQ7P0V9XfY/oOBOWyUCRPvhD/9T 8Y4rtHL8fPVM4if/o7tJWv9/qHOYOdKaQiF524IgNepwCTQwQto1XMu1Tv9rh959PDcWCe zY3hadxb/+pMlcOUt6FRCAB4kxEl9C8hbyFlHTL2eAGgIa3LZadeRRs91kAJjw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663977906; 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=78lWKQLJRfdW9hexh7XAr98bJYw2kzBvk5KGdMnrw6M=; b=OLc7JapXHMP6Nx403kcO39avxOt27MZgw8hmcHEvSPKl1yMmPGy6gLx7QYZZYTuXJJSuqK CRKkJaPSKJ2DhGDQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk 17/18] printk: Use an output descriptor struct for emit Date: Sat, 24 Sep 2022 02:10:53 +0206 Message-Id: <20220924000454.3319186-18-john.ogness@linutronix.de> In-Reply-To: <20220924000454.3319186-1-john.ogness@linutronix.de> References: <20220924000454.3319186-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 infrastrucure 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 Reviewed-by: Greg Kroah-Hartman --- include/linux/console.h | 15 +++++++ kernel/printk/printk.c | 88 ++++++++++++++++++++++++++++++----------- 2 files changed, 79 insertions(+), 24 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index 05c7325e98f9..590ab62c01d9 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -187,6 +187,21 @@ struct cons_text_buf { char text[CONSOLE_LOG_MAX]; }; =20 +/** + * struct cons_outbuf_desc - console output buffer descriptor + * @txtbuf: Pointer to buffer for storing the text + * @outbuf: Pointer to the position in @buffer for + * writing it out to the device + * @len: Message length + * @extmsg: Select extended format printing + */ +struct cons_outbuf_desc { + struct cons_text_buf *txtbuf; + char *outbuf; + unsigned int len; + bool 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 9cbd44e9fc45..c9207d81b90c 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2689,40 +2689,39 @@ static void __console_unlock(void) up_console_sem(); } =20 -/* - * 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. + +/** + * cons_fill_outbuf - Fill the output buffer with the next record + * @con: The console to print on + * @desc: Pointer to the output descriptor * - * If dropped messages should be printed, @dropped_text is a buffer of size - * DROPPED_TEXT_MAX. Otherwise @dropped_text must be NULL. + * The output descriptor contains all information which is necessary + * to print (buffer pointer, extended format selector...). * - * @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 the - * console_lock. Otherwise it is set to false. + * Returns: False if there is no pending record in the ringbuffer + * True if there is a pending record in the ringbuffer. * - * Returns false if the given console has no next record to print, otherwi= se - * true. + * When the return value is true, then the caller has to check + * @desc->outbuf. If not NULL it points to the first character to write to + * the device and @desc->len contains the length of the message. * - * Requires the console_lock. + * If it is NULL then records have been dropped or skipped and con->seq + * has been forwarded so the caller can try to print the next record. */ -static bool console_emit_next_record(struct console *con, struct cons_text= _buf *txtbuf, - bool *handover, bool extmsg) +static bool cons_fill_outbuf(struct console *con, struct cons_outbuf_desc = *desc) { static int panic_console_dropped; + + struct cons_text_buf *txtbuf =3D desc->txtbuf; struct printk_info info; struct printk_record r; - unsigned long flags; char *write_text; size_t len; =20 - prb_rec_init_rd(&r, &info, txtbuf->text, CONSOLE_LOG_MAX); + desc->outbuf =3D NULL; + desc->len =3D 0; =20 - *handover =3D false; + prb_rec_init_rd(&r, &info, txtbuf->text, CONSOLE_LOG_MAX); =20 if (!prb_read_valid(prb, con->seq, &r)) return false; @@ -2739,10 +2738,10 @@ static bool console_emit_next_record(struct console= *con, struct cons_text_buf * /* Skip record that has level above the console loglevel. */ if (suppress_message_printing(r.info->level)) { con->seq++; - goto skip; + return true; } =20 - if (extmsg) { + if (desc->extmsg) { write_text =3D txtbuf->ext_text; len =3D info_print_ext_header(write_text, CONSOLE_EXT_LOG_MAX, r.info); len +=3D msg_print_ext_body(write_text + len, CONSOLE_EXT_LOG_MAX - len, @@ -2752,6 +2751,47 @@ static bool console_emit_next_record(struct console = *con, struct cons_text_buf * len =3D record_print_text(&r, console_msg_format & MSG_FORMAT_SYSLOG, pr= intk_time); } =20 + desc->len =3D len; + desc->outbuf =3D write_text; + return true; +} + +/** + * console_emit_next_record - Print one record for the given console + * @con: The console to print on + * @txtbuf: Pointer to the output buffer + * @handover: Pointer to Handover handshake storage + * @extmsg: Selects extended message format + * + * 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 the + * console_lock. Otherwise it is set to false. + * + * Returns false if the given console has no next record to print, otherwi= se + * true. + * + * Requires the console_lock. + */ +static bool console_emit_next_record(struct console *con, struct cons_text= _buf *txtbuf, + bool *handover, bool extmsg) +{ + struct cons_outbuf_desc desc =3D { + .txtbuf =3D txtbuf, + .extmsg =3D extmsg, + }; + unsigned long flags; + + *handover =3D false; + + if (!cons_fill_outbuf(con, &desc)) + return false; + + if (!desc.outbuf) + goto skip; + /* * While actively printing out messages, if another printk() * were to occur on another CPU, it may wait for this one to @@ -2766,7 +2806,7 @@ static bool console_emit_next_record(struct console *= con, struct cons_text_buf * console_lock_spinning_enable(); =20 stop_critical_timings(); /* don't trace print latency */ - call_console_driver(con, write_text, len, extmsg ? NULL : txtbuf->dropped= _text); + call_console_driver(con, desc.outbuf, desc.len, extmsg ? NULL : txtbuf->d= ropped_text); start_critical_timings(); =20 con->seq++; --=20 2.30.2 From nobody Mon Apr 6 10:45:00 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 67EADC07E9D for ; Sat, 24 Sep 2022 00:06:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233163AbiIXAG0 (ORCPT ); Fri, 23 Sep 2022 20:06:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233027AbiIXAFO (ORCPT ); Fri, 23 Sep 2022 20:05:14 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 164B4109512 for ; Fri, 23 Sep 2022 17:05:12 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663977906; 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=NvlJ13+bxfsEO2TjTOyMfmjGv2moKuWTyvjwKl7xhmU=; b=kCD0/dKQVs2h8YRmwAm5XdNlXlLkxQNzC09V2CkWaWUAGZ/YCcbcxazVjpahQaeLy1K0m8 JtwMh8pZ6dywhyR3F83oX/u4jAypstKQ655kgNMwexSCgvSWk7PBg1NsUNV1WT90e0lJQl VfHDzCVVbpy3UZpoYkTn43yo7PkKoKL2q/25pQAPutcsmJmkZnPfwVasBli8RTjy34wOSh 1uTPfuUBd7e8Fggqv9UBGUk9Hvu1tsMjCDkWks/Glh15FQz7JJXon68ohyFF/51+LzHo+F ybFJA02D+SlIxYAqqGV1cK3R5HfXUrSG/ZXQSoOctVNt8MAmlnd5+J6E7dGioA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663977906; 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=NvlJ13+bxfsEO2TjTOyMfmjGv2moKuWTyvjwKl7xhmU=; b=x7qBz4LVF7T7QL7ous/E392mWz8ageWoy86Cuo3KZF3stG9lQnLKeaRiKse2MxVDrGOkBp X4bf6QQIPMbuvxBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk 18/18] printk: Handle dropped message smarter Date: Sat, 24 Sep 2022 02:10:54 +0206 Message-Id: <20220924000454.3319186-19-john.ogness@linutronix.de> In-Reply-To: <20220924000454.3319186-1-john.ogness@linutronix.de> References: <20220924000454.3319186-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 No need for an extra buffer type. Regular formatting which needs the '$N messages dropped' printout can sprintf() it into the unused extended text buffer. As a further simplification move the 'dropped' message right in front of the actual record text and let the write function output it in one go. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman --- include/linux/console.h | 12 +++--- kernel/printk/printk.c | 86 +++++++++++++++++++++++++++-------------- 2 files changed, 61 insertions(+), 37 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index 590ab62c01d9..83563694cc82 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -176,28 +176,26 @@ enum cons_flags { /** * struct cons_text_buf - console output text buffer * @ext_text: Buffer for extended log format text - * @dropped_text: Buffer for dropped text * @text: Buffer for ringbuffer text */ struct cons_text_buf { - union { - char ext_text[CONSOLE_EXT_LOG_MAX]; - char dropped_text[DROPPED_TEXT_MAX]; - }; - char text[CONSOLE_LOG_MAX]; -}; + char ext_text[CONSOLE_EXT_LOG_MAX]; + char text[CONSOLE_LOG_MAX]; +} __no_randomize_layout; =20 /** * struct cons_outbuf_desc - console output buffer descriptor * @txtbuf: Pointer to buffer for storing the text * @outbuf: Pointer to the position in @buffer for * writing it out to the device + * @dropped: The dropped count * @len: Message length * @extmsg: Select extended format printing */ struct cons_outbuf_desc { struct cons_text_buf *txtbuf; char *outbuf; + unsigned long dropped; unsigned int len; bool extmsg; }; diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index c9207d81b90c..14ddd5c9363f 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1961,27 +1961,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 @@ -2361,10 +2340,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(void) { 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; } @@ -2689,6 +2664,46 @@ static void __console_unlock(void) up_console_sem(); } =20 +/** + * cons_print_dropped - Print 'dropped' message if required + * @desc: Pointer to the output descriptor + * + * Prints the 'dropped' message info the output buffer if @desc->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 print into it at the beginning and move the resulting string + * just in front of the regular text buffer so that the message can + * be printed in one go. + * + * In case of a message this returns with @desc->outbuf and @desc->len + * updated. If no message is required then @desc is not modified. + */ +static void cons_print_dropped(struct cons_outbuf_desc *desc) +{ + struct cons_text_buf *txtbuf =3D desc->txtbuf; + size_t len; + + if (!desc->dropped || desc->extmsg) + return; + + if (WARN_ON_ONCE(desc->outbuf !=3D txtbuf->text)) + return; + + /* Print it into ext_text which is unused */ + len =3D snprintf(txtbuf->ext_text, DROPPED_TEXT_MAX, + "** %lu printk messages dropped **\n", desc->dropped); + desc->dropped =3D 0; + + /* Copy it just below text so it goes out with one write */ + memcpy(txtbuf->text - len, txtbuf->ext_text, len); + + /* Update the descriptor */ + desc->len +=3D len; + desc->outbuf -=3D len; +} + =20 /** * cons_fill_outbuf - Fill the output buffer with the next record @@ -2742,17 +2757,26 @@ static bool cons_fill_outbuf(struct console *con, s= truct cons_outbuf_desc *desc) } =20 if (desc->extmsg) { + /* + * Extended messages do not require "dropped" message + * as that can be seen from the sequence number + */ write_text =3D txtbuf->ext_text; len =3D info_print_ext_header(write_text, CONSOLE_EXT_LOG_MAX, r.info); len +=3D msg_print_ext_body(write_text + len, CONSOLE_EXT_LOG_MAX - len, &r.text_buf[0], r.info->text_len, &r.info->dev_info); + desc->len =3D len; + desc->outbuf =3D write_text; } else { - write_text =3D txtbuf->text; len =3D record_print_text(&r, console_msg_format & MSG_FORMAT_SYSLOG, pr= intk_time); + + desc->len =3D len; + desc->outbuf =3D txtbuf->text; + desc->dropped =3D con->dropped; + cons_print_dropped(desc); + con->dropped =3D desc->dropped; } =20 - desc->len =3D len; - desc->outbuf =3D write_text; return true; } =20 @@ -2805,8 +2829,10 @@ static bool console_emit_next_record(struct console = *con, struct cons_text_buf * printk_safe_enter_irqsave(flags); console_lock_spinning_enable(); =20 - stop_critical_timings(); /* don't trace print latency */ - call_console_driver(con, desc.outbuf, desc.len, extmsg ? NULL : txtbuf->d= ropped_text); + /* don't trace print latency */ + stop_critical_timings(); + /* Write everything out to the hardware */ + con->write(con, desc.outbuf, desc.len); start_critical_timings(); =20 con->seq++; --=20 2.30.2