From patchwork Mon Jul 10 13:45:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 117931 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp5043435vqx; Mon, 10 Jul 2023 06:58:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlFYl/QUf6mC856BUaqZwIg/wjTAXVEsE8TJJ0uQNSyKFngqtItLISoi0xJbgV/j0EItRab/ X-Received: by 2002:a05:6a00:1709:b0:67c:5c21:b430 with SMTP id h9-20020a056a00170900b0067c5c21b430mr17200561pfc.33.1688997527977; Mon, 10 Jul 2023 06:58:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688997527; cv=none; d=google.com; s=arc-20160816; b=H+xQPq5OCYh7tRfzmxXOiWxZ7k7Ll3P/cvfX4Eutygg9ot+Cu9mp0lCIxjKw2GH3cU HR25AyQ3Yl9SRwbyV7PY4msKl9ueXJBGK0mwj7O+1KxoLf+x2PcqC2qEArX7KBRikenF ZIdrhDZUbjqn0zz/+AYvihF0uPhUqrx6KtyPuUNjWJkezPsMli2LGqj5ZBklSkC5KkWE VjiMSCx4LKq8gbD5nTUG1ZzbsgMiIDowpqzdTmzuojSyOYRU5fniYVvfs7aOZ8bTddBS dkgkQjeug2E7KshSQGXmhBLOkB1p9c+P4BayWwoCuIxs2T1lgIn/11OkTXVbcVEF2eCz 9/zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=B9NLpZDV0rDJscklMexuqubYAOrVOVFP5G0SfhKaC40=; fh=snfNmeYpwN2wMIrLpkrEvSNSjBz+ljiy3c1UurUR8io=; b=ZRnUAzM4yHZ0rmyGAplQR7JiiP4RiVWXOCPzHX1MNoFiXKZ+/9Ru82FI0P7ejfhKKJ LTkGvWsdk/jQ86J4h5c1lU3dJpKtXp1Kmzck75Z1xIA0x33QIW5v8rry7HxiYv5Sw3XJ /mGXlYXdtAtEMP0+SAMuGOLaiYX3sc2ds/ZWnvgNJO7gFjalI5PB5cuc6hzpnYn2nTcB 655pp52H+2///NZtNR5wvSwfI2tiqox9h5bUWDczrOnuLWl29rCpkbDNQTdNuQgn3Jci srRl9NCHDk17gb1SPAHlywDmbKe0t0mCNYzQzSblVNpfVdvurqiM1ykYvjSz70pqDhCx /wVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mPH34seK; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=MimllhSt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h22-20020a056a00231600b0067f9d269213si9219081pfh.171.2023.07.10.06.58.34; Mon, 10 Jul 2023 06:58:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mPH34seK; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=MimllhSt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232991AbjGJNpf (ORCPT + 99 others); Mon, 10 Jul 2023 09:45:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229907AbjGJNpb (ORCPT ); Mon, 10 Jul 2023 09:45:31 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97E31FB for ; Mon, 10 Jul 2023 06:45:29 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1688996727; 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=B9NLpZDV0rDJscklMexuqubYAOrVOVFP5G0SfhKaC40=; b=mPH34seK6EKd96789117404thhQ8iF13OLpNr8Rr4KlkQwNJABW99gTYK+7HnIjltRHnN+ 2yJBLZcArEG9Xrwkd0d3MiWAydDpHP2tGyam99KieBiEmInY5CgsIn9vHkwsUk48Ee7eTR zNXJ3sN2/CVr6hYmUfI8t+JcrOZTuJDijmKzFRqMq5CrrEl6NacvXqO8OgPDyAx+LvFEt1 ubf3eSzQxZ1WFEW5moucTAYNP/I+xcORGxd3pkhprECltFA9rFynae9SUdxlVFYQRNtgXP 7eZX3/eMHsZSZlnvQUf8ctTN32aOL3r+d9aTnkOWLj0gjRn2yIF/TpORQgS1FA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1688996727; 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=B9NLpZDV0rDJscklMexuqubYAOrVOVFP5G0SfhKaC40=; b=MimllhStnyB8UVIm3i7qxoahyZlF7eOmcJSKU+Xf2Frp7wMCiRdG+vr3tcFXyKXVdnFhAQ reR+NH86j4GeIbDw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Aaron Tomlin , kgdb-bugreport@lists.sourceforge.net Subject: [PATCH printk v2 1/5] kdb: do not assume write() callback available Date: Mon, 10 Jul 2023 15:51:20 +0206 Message-Id: <20230710134524.25232-2-john.ogness@linutronix.de> In-Reply-To: <20230710134524.25232-1-john.ogness@linutronix.de> References: <20230710134524.25232-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771042271775428271 X-GMAIL-MSGID: 1771042271775428271 It is allowed for consoles to provide no write() callback. For example ttynull does this. Check if a write() callback is available before using it. Signed-off-by: John Ogness Reviewed-by: Petr Mladek Reviewed-by: Douglas Anderson Reviewed-by: Daniel Thompson Reviewed-by: Sergey Senozhatsky Acked-by: Daniel Thompson --- kernel/debug/kdb/kdb_io.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 5c7e9ba7cd6b..e9139dfc1f0a 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -576,6 +576,8 @@ static void kdb_msg_write(const char *msg, int msg_len) continue; if (c == dbg_io_ops->cons) continue; + if (!c->write) + continue; /* * Set oops_in_progress to encourage the console drivers to * disregard their internal spin locks: in the current calling From patchwork Mon Jul 10 13:45:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 117932 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp5043715vqx; Mon, 10 Jul 2023 06:59:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlEhh0QCNwyD/v73+BPJbtOgliPVDSx3GGDSGu/BMgBzTx4mg026Ly+wc1o1DFRXc69BLS0O X-Received: by 2002:a05:6a20:42a3:b0:131:38ef:d9c0 with SMTP id o35-20020a056a2042a300b0013138efd9c0mr8068514pzj.43.1688997566074; Mon, 10 Jul 2023 06:59:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688997566; cv=none; d=google.com; s=arc-20160816; b=1KIMEJMzamm48oQhLfCN6lh1Fl4JIpJVAX0xY4Q2s5TC/cWDaesPeHp38ou02+Y+wo 2YI/OjCBVKO1aclfl5JjlzOjs2i/EKkWhHZg3gAPBfxF5q5pb6PL3ztSzn9RT8yNS5P4 4CGzgoLZ1a3Z2ng7MbxGY89IQypXDSJbiuuLGc795hbPZcO0xmeKBZtyXUFQdrLSgAfG LViVh2sn4KOAg+YcPNwuW7/8yfA7Pgl1S6q0BFpc+gzJs0W7eXdmgcYmSD3ixVTD97Jr 9CKMcZKdbQs8YFTJydZY3hRUfycUZT4UUs6KG/gh0tCh/mqu/VsfCcz0/7YlxAjbkn0m SQng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=XsZWA8451BPr7/Ud83/6VPIROKIK25FqP0KDzoKAhWM=; fh=HVRBJStvoKWbFco6Jta18xe5UAVCwWVs9OvJstciom4=; b=lIsa0NrcBymKONxDyRBc+BG1Xx+nMLG5PRmwkfHFtJLv/RdS7E4bY+OUWVDNsbunlS SzPFQpD9SpNMH1UCoovaSZhGDkagd4cfz6A8ljocq7vp8tF57O9tt8FnnLRB8PFk0A5Q Dyb8+Apm4x6Dm1Hm9wtn6MEHyReyygOruzef1y9wY777bqHKhjU9Z956EgNfS5X73pTL BBFe2kGy/AicxjSAfAEOrqWrXXmARVknzXrpJ7kl0H6YyxaOzJ8V0Vxa1KcEYBD6/yWb Lg8GgdqY7AkJSD8/WpMbo71tHE3zjpnYebnq1Gjd/BQ4scvKxHf8jV6EKrXDOLyfTu5L 95vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="Mw3dc/a9"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k5-20020a056a00134500b006824e0fdcb0si9423328pfu.98.2023.07.10.06.59.12; Mon, 10 Jul 2023 06:59:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="Mw3dc/a9"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233034AbjGJNpj (ORCPT + 99 others); Mon, 10 Jul 2023 09:45:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232058AbjGJNpb (ORCPT ); Mon, 10 Jul 2023 09:45:31 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97D9CEB for ; Mon, 10 Jul 2023 06:45:29 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1688996728; 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=XsZWA8451BPr7/Ud83/6VPIROKIK25FqP0KDzoKAhWM=; b=Mw3dc/a9jAPsfBXa5qx/sQ5RoWbHUyxm3PcE/jk9l4Jo81VrtkX8XspuI6hcpszFAEY5IT uWaMvEh8eMn+5FyYnmuWegEPDM0S1yEO72QKpIg68GB5/MpCav+/158g+K8s4LCqh71bYm BM+8Xzl+2M/ir2jlCOGc1nCwz/YvZOT73up0J2r7Opkeloi4xQJn/AYMBzKyaA3z3ycdXg JiI0uQftmXA3T79fPU3qrC4zpi/2GOjsfc4ckoFXbfCKUkQq8fWj5ZJheGPmCM2zQK25wB Z8GzftlQYR46pfqzfPYmvChFata0f8Kmq0ccCZMYUUUGhIxWfktCuuZwJGneaw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1688996728; 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=XsZWA8451BPr7/Ud83/6VPIROKIK25FqP0KDzoKAhWM=; b=V0iW5iYy+XU5xZIBorpzPgtN6zAAFRNG4EASSrDUuRkWb1hfOTqfOQfkfXGyvTCLM8mU9h RriOhxkUWRIefXDQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 2/5] printk: Add NMI safety to console_flush_on_panic() and console_unblank() Date: Mon, 10 Jul 2023 15:51:21 +0206 Message-Id: <20230710134524.25232-3-john.ogness@linutronix.de> In-Reply-To: <20230710134524.25232-1-john.ogness@linutronix.de> References: <20230710134524.25232-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771042311923684122 X-GMAIL-MSGID: 1771042311923684122 The printk path is NMI safe because it only adds content to the buffer and then triggers the delayed output via irq_work. If the console is flushed or unblanked on panic (from NMI context) then it can deadlock in down_trylock_console_sem() because the semaphore is not NMI safe. Avoid taking the console lock when flushing in panic. To prevent other CPUs from taking the console lock while flushing, have console_lock() block and console_trylock() fail for non-panic CPUs during panic. Skip unblanking in panic if the current context is NMI. Signed-off-by: John Ogness --- kernel/printk/printk.c | 77 +++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 9644f6e5bf15..8a6c917dc081 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2583,6 +2583,25 @@ static int console_cpu_notify(unsigned int cpu) return 0; } +/* + * Return true when this CPU should unlock console_sem without pushing all + * messages to the console. This reduces the chance that the console is + * locked when the panic CPU tries to use it. + */ +static bool abandon_console_lock_in_panic(void) +{ + if (!panic_in_progress()) + return false; + + /* + * We can use raw_smp_processor_id() here because it is impossible for + * the task to be migrated to the panic_cpu, or away from it. If + * panic_cpu has already been set, and we're not currently executing on + * that CPU, then we never will be. + */ + return atomic_read(&panic_cpu) != raw_smp_processor_id(); +} + /** * console_lock - block the console subsystem from printing * @@ -2595,6 +2614,10 @@ void console_lock(void) { might_sleep(); + /* On panic, the console_lock must be left to the panic cpu. */ + while (abandon_console_lock_in_panic()) + msleep(1000); + down_console_sem(); if (console_suspended) return; @@ -2613,6 +2636,9 @@ EXPORT_SYMBOL(console_lock); */ int console_trylock(void) { + /* On panic, the console_lock must be left to the panic cpu. */ + if (abandon_console_lock_in_panic()) + return 0; if (down_trylock_console_sem()) return 0; if (console_suspended) { @@ -2631,25 +2657,6 @@ int is_console_locked(void) } EXPORT_SYMBOL(is_console_locked); -/* - * Return true when this CPU should unlock console_sem without pushing all - * messages to the console. This reduces the chance that the console is - * locked when the panic CPU tries to use it. - */ -static bool abandon_console_lock_in_panic(void) -{ - if (!panic_in_progress()) - return false; - - /* - * We can use raw_smp_processor_id() here because it is impossible for - * the task to be migrated to the panic_cpu, or away from it. If - * panic_cpu has already been set, and we're not currently executing on - * that CPU, then we never will be. - */ - return atomic_read(&panic_cpu) != raw_smp_processor_id(); -} - /* * Check if the given console is currently capable and allowed to print * records. @@ -3054,6 +3061,10 @@ void console_unblank(void) * In that case, attempt a trylock as best-effort. */ if (oops_in_progress) { + /* Semaphores are not NMI-safe. */ + if (in_nmi()) + return; + if (down_trylock_console_sem() != 0) return; } else @@ -3083,14 +3094,24 @@ void console_unblank(void) */ void console_flush_on_panic(enum con_flush_mode mode) { + bool handover; + u64 next_seq; + /* - * If someone else is holding the console lock, trylock will fail - * and may_schedule may be set. Ignore and proceed to unlock so - * that messages are flushed out. As this can be called from any - * context and we don't want to get preempted while flushing, - * ensure may_schedule is cleared. + * Ignore the console lock and flush out the messages. Attempting a + * trylock would not be useful because: + * + * - if it is contended, it must be ignored anyway + * - console_lock() and console_trylock() block and fail + * respectively in panic for non-panic CPUs + * - semaphores are not NMI-safe + */ + + /* + * If another context is holding the console lock, + * @console_may_schedule might be set. Clear it so that + * this context does not call cond_resched() while flushing. */ - console_trylock(); console_may_schedule = 0; if (mode == CONSOLE_REPLAY_ALL) { @@ -3103,15 +3124,15 @@ void console_flush_on_panic(enum con_flush_mode mode) cookie = console_srcu_read_lock(); for_each_console_srcu(c) { /* - * If the above console_trylock() failed, this is an - * unsynchronized assignment. But in that case, the + * This is an unsynchronized assignment, but the * kernel is in "hope and pray" mode anyway. */ c->seq = seq; } console_srcu_read_unlock(cookie); } - console_unlock(); + + console_flush_all(false, &next_seq, &handover); } /* From patchwork Mon Jul 10 13:45:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 117933 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp5049773vqx; Mon, 10 Jul 2023 07:06:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlG1Pz0o/mL7H72jeOChZicauhkWpQjneMVJeS66vMcUXOTib0uPfEG5FH5eBQIy1H3snj3F X-Received: by 2002:a17:903:504:b0:1b8:6b17:9093 with SMTP id jn4-20020a170903050400b001b86b179093mr9304577plb.1.1688997993957; Mon, 10 Jul 2023 07:06:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688997993; cv=none; d=google.com; s=arc-20160816; b=v3d7DMqK4hsqv19uMryw7yMO2BbB49Nkk6oV7MKyOgvaGpgdyuFnrzyrinkHS0vLs7 GOtt4pzZRNhve5qGunfIIMULTnaT3qunGhphKzosYCIWClcjIh1iN8Jz9wRaroiFDur1 bwtPVXyMzwxTR4dDhYXHb9k2MD3iTr1rIA7o+Ys3HhLJMy1saX3LpXLETmZw9RYLTiIf nK11JgjzfvOOZ+O3ohwpgo/y1X9KKP4QCoHrriL5bm/7GZwuliR3ya1Iv2aRcWosO63b 6ZdSsSVEvNDvIjh1DAyoQ25APM1PdwLodxSTTOcORblBsA+d6+y8jW4muuRz8wFDeE+L Ugwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=gNoZRjtYvz+muzS7qSrxZkmQzTEAXcTSx4NPxxauFRc=; fh=HVRBJStvoKWbFco6Jta18xe5UAVCwWVs9OvJstciom4=; b=EcgYbhqOCQgDiVbFaDW8ECGvUnfjW5zPpeeF6xLIXrffzOOINuTZGvqWUxMCyRCTRl 13AeUxQztVNLNFLbPIdqUZwsxPzrut2id6C9oPlEK1uk8EKrrw33umTsTIrpk8BQO2zg PYajTpJBKXjpZHQwfRIW99mHzkX/HduOGFb/656tW4t9slNYrbsxL/Q5McCPN9qsrNzC EYRHXFrbfh4BkubtgMnrnnRCA+PaQW0akYAEQYQ2glp74ikwxCmRC30I25AGLRZCdjLq A1lXzq1BorP6suX0ni5hIPWRRT9YV+jbzyOAubOMNQ4N1YFvMkrsABATWMRPn9ox6NQe 9DmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dmXuNtNq; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t13-20020a170902e84d00b001b9d2010c39si4429518plg.192.2023.07.10.07.06.20; Mon, 10 Jul 2023 07:06:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dmXuNtNq; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233019AbjGJNph (ORCPT + 99 others); Mon, 10 Jul 2023 09:45:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231382AbjGJNpb (ORCPT ); Mon, 10 Jul 2023 09:45:31 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CEF3FE for ; Mon, 10 Jul 2023 06:45:29 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1688996728; 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=gNoZRjtYvz+muzS7qSrxZkmQzTEAXcTSx4NPxxauFRc=; b=dmXuNtNql6F9emsQAi7+TV8RVDFsgs/MSWxH3vWrxR75nEc4ecMk3zgTO2CrhNzZEuwxeY 4xLtw9hxiqEjuxvOoNKLHl8ni1PIqh+tOv8g26LLOXl3CvkNk2KIZb0tBVfICSxz6TXR0I +xChvwdiuLZ8QGO+8VsCk7NbpB/YWqPhosAcBQlM8Z4Qojn40eIjiuUzz1dudqj39JEz2t q4npg8Scp2qOU+3tu24rQhIcOUP1B3ZG5Ldu+O3A1l5VfAr1qeQs104Gjsh4rh0o30htIk rnazfhrVUD2rQUgZrk1eYtFgRK8/VKp6tNC1GHduecHy/TOjqVSqWZeh6EFTmg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1688996728; 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=gNoZRjtYvz+muzS7qSrxZkmQzTEAXcTSx4NPxxauFRc=; b=MkXNNujyGh+shQ0/nLVDn/7Uxr5/7KEvPHgmKG2qVky0opg0FfV/QtypgOp4ZX6npSJzKH vacKBcLg34H2F7Cw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 3/5] printk: Consolidate console deferred printing Date: Mon, 10 Jul 2023 15:51:22 +0206 Message-Id: <20230710134524.25232-4-john.ogness@linutronix.de> In-Reply-To: <20230710134524.25232-1-john.ogness@linutronix.de> References: <20230710134524.25232-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771042760287005305 X-GMAIL-MSGID: 1771042760287005305 Printing to consoles can be deferred for several reasons: - explicitly with printk_deferred() - printk() in NMI context - recursive printk() calls The current implementation is not consistent. For printk_deferred(), irq work is scheduled twice. For NMI und recursive, panic CPU suppression and caller delays are not properly enforced. Correct these inconsistencies by consolidating the deferred printing code so that vprintk_deferred() is the top-level function for deferred printing and vprintk_emit() will perform whichever irq_work queueing is appropriate. Also add kerneldoc for wake_up_klogd() and defer_console_output() to clarify their differences and appropriate usage. Signed-off-by: John Ogness Reviewed-by: Sergey Senozhatsky Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 35 ++++++++++++++++++++++++++++------- kernel/printk/printk_safe.c | 9 ++------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 8a6c917dc081..e7632ed3b6fd 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2306,7 +2306,11 @@ asmlinkage int vprintk_emit(int facility, int level, preempt_enable(); } - wake_up_klogd(); + if (in_sched) + defer_console_output(); + else + wake_up_klogd(); + return printed_len; } EXPORT_SYMBOL(vprintk_emit); @@ -3817,11 +3821,33 @@ static void __wake_up_klogd(int val) preempt_enable(); } +/** + * wake_up_klogd - Wake kernel logging daemon + * + * Use this function when new records have been added to the ringbuffer + * and the console printing of those records has already occurred or is + * known to be handled by some other context. This function will only + * wake the logging daemon. + * + * Context: Any context. + */ void wake_up_klogd(void) { __wake_up_klogd(PRINTK_PENDING_WAKEUP); } +/** + * defer_console_output - Wake kernel logging daemon and trigger + * console printing in a deferred context + * + * Use this function when new records have been added to the ringbuffer, + * this context is responsible for console printing those records, but + * the current context is not allowed to perform the console printing. + * Trigger an irq_work context to perform the console printing. This + * function also wakes the logging daemon. + * + * Context: Any context. + */ void defer_console_output(void) { /* @@ -3838,12 +3864,7 @@ void printk_trigger_flush(void) int vprintk_deferred(const char *fmt, va_list args) { - int r; - - r = vprintk_emit(0, LOGLEVEL_SCHED, NULL, fmt, args); - defer_console_output(); - - return r; + return vprintk_emit(0, LOGLEVEL_SCHED, NULL, fmt, args); } int _printk_deferred(const char *fmt, ...) diff --git a/kernel/printk/printk_safe.c b/kernel/printk/printk_safe.c index ef0f9a2044da..6d10927a07d8 100644 --- a/kernel/printk/printk_safe.c +++ b/kernel/printk/printk_safe.c @@ -38,13 +38,8 @@ asmlinkage int vprintk(const char *fmt, va_list args) * Use the main logbuf even in NMI. But avoid calling console * drivers that might have their own locks. */ - if (this_cpu_read(printk_context) || in_nmi()) { - int len; - - len = vprintk_store(0, LOGLEVEL_DEFAULT, NULL, fmt, args); - defer_console_output(); - return len; - } + if (this_cpu_read(printk_context) || in_nmi()) + return vprintk_deferred(fmt, args); /* No obstacles. */ return vprintk_default(fmt, args); From patchwork Mon Jul 10 13:45:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 117936 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp5050247vqx; Mon, 10 Jul 2023 07:07:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlEKWOSTGVRvhmBdOcZB+Pbz9wlEHHPui6lE5eIDS2YjKg/iLo3gnas8a1KktKnNdupVHHIe X-Received: by 2002:a05:6a20:8e19:b0:130:45cc:71f9 with SMTP id y25-20020a056a208e1900b0013045cc71f9mr10108298pzj.18.1688998031768; Mon, 10 Jul 2023 07:07:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688998031; cv=none; d=google.com; s=arc-20160816; b=FgF2DG98KiYe3QVY23jfWnr5n5l8+ZwMcNHRKaa7oMZWfno44qAftqY6pcys2sf07i 5fr/bmFqgNSacY5GCkOSQh8NjstKh30x/5hjyAQsQDIrV3W3huQ/vSBMdSda4bP9Jvtp UEy4W3Z6X8E0Zeb7LR9lZ9bbBM6GuXRgWwCoyv2IK2J3TvzxKKohchv1tPgw4VJMHt68 Zk8QVRQTt4j9o64gq0fYAajbAs9bBxRJnFY15/i1S0eUErxRCAklM6FND7ErxRYd5ndg OzwCGcBHk1cYLEBDcoVO0CCCQfUeofvemFylRLG1suLoVMKFEeieXMSQWJtbWm6/6FpR PtnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=GgzMpaka03nOC0RkiorRFWglOjfyG1gZscYLSfQH6GY=; fh=I/6bvJz6sWq8p1xoNUgGjc7lme65GQ/wcdq821dg0a8=; b=GZ5VOhkHKDv4m2TVFxyUgJ9VxlnnhQTB0ioSu/L+MGRkwx2xFjs1eZyOhAtaUxznr8 JjhPnKZhx2jYMz4U0SwtVAjcVRwrdx80GHPQhUHffFh00NenW7ZJ0uF1hllVSx2cqUuA 3jJPMSTaEIQ/lv07zjc+h3g6e0Vh1lf8QJOa2lracFxHM5xmnZOlk0ZD37cXbdl6WzvH H20ojhYZWGx4adHep2VHS19ITbroz8c7gasaKGKPnL5asbU+SL9OFCgJL/C29W/WlReZ 3nX0G0VzLJZPf2+3dWJOsz7Zq4vgHpfDbNDCgN4V+0XWezCn4oAsheQIMKUPMcBpUd63 ZNYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="Nsws1/z0"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="/gmNMNbL"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bq24-20020a056a000e1800b0068188beefedsi8999727pfb.88.2023.07.10.07.06.58; Mon, 10 Jul 2023 07:07:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="Nsws1/z0"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="/gmNMNbL"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233062AbjGJNpn (ORCPT + 99 others); Mon, 10 Jul 2023 09:45:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232814AbjGJNpc (ORCPT ); Mon, 10 Jul 2023 09:45:32 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C220D2 for ; Mon, 10 Jul 2023 06:45:30 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1688996728; 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=GgzMpaka03nOC0RkiorRFWglOjfyG1gZscYLSfQH6GY=; b=Nsws1/z0h3MmFN9DTdi5BKGmy8Ha6ipy7aXoHrr4QSn0xsLwqM4qlb9UUzgyJfPYIsIygP qnb0FIkhu9c2TKTAiVVgzneEelkd0nIpcQluJ0EcZeucs0cYg1+Hl4XDxpi+1oxpqUc0VK iykqxiU0pyaJ7ieP6MrkME/2Faxm1ySQzJ/jJ0bOFYEVonLsW5Bc03NFE5B0RnkF9ByzOP Lf9Mu7TtnMTk3osRnIfB6/IVbzFCuzS1K9LxaOdT7qEIDJnSFsH8XeicL922g1L+tzis1K 2TrdIVCHAiIkMXaOjiI2UPQZeFzRYCtrTH6juZTfTftlt6aHy8oUiqfhIRf4ag== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1688996728; 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=GgzMpaka03nOC0RkiorRFWglOjfyG1gZscYLSfQH6GY=; b=/gmNMNbLltxNbfZ38zdL2+rsf17Gp0HvlWp6UNIaj6ykfvY8DcV8ih2K3LfuEZMrhnPuP/ enD9fplczXk4oABA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v2 4/5] printk: Add per-console suspended state Date: Mon, 10 Jul 2023 15:51:23 +0206 Message-Id: <20230710134524.25232-5-john.ogness@linutronix.de> In-Reply-To: <20230710134524.25232-1-john.ogness@linutronix.de> References: <20230710134524.25232-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771042800230303902 X-GMAIL-MSGID: 1771042800230303902 Currently the global @console_suspended is used to determine if consoles are in a suspended state. Its primary purpose is to allow usage of the console_lock when suspended without causing console printing. It is synchronized by the console_lock. Rather than relying on the console_lock to determine suspended state, make it an official per-console state that is set within console->flags. This allows the state to be queried via SRCU. Remove @console_suspended. Console printing will still be avoided when suspended because console_is_usable() returns false when the new suspended flag is set for that console. Signed-off-by: John Ogness Reviewed-by: Sergey Senozhatsky Reviewed-by: Petr Mladek --- include/linux/console.h | 3 ++ kernel/printk/printk.c | 74 ++++++++++++++++++++++++----------------- 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index d3195664baa5..7de11c763eb3 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -154,6 +154,8 @@ static inline int con_debug_leave(void) * receiving the printk spam for obvious reasons. * @CON_EXTENDED: The console supports the extended output format of * /dev/kmesg which requires a larger output buffer. + * @CON_SUSPENDED: Indicates if a console is suspended. If true, the + * printing callbacks must not be called. */ enum cons_flags { CON_PRINTBUFFER = BIT(0), @@ -163,6 +165,7 @@ enum cons_flags { CON_ANYTIME = BIT(4), CON_BRL = BIT(5), CON_EXTENDED = BIT(6), + CON_SUSPENDED = BIT(7), }; /** diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index e7632ed3b6fd..701908d389f4 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -86,7 +86,7 @@ EXPORT_SYMBOL(oops_in_progress); static DEFINE_MUTEX(console_mutex); /* - * console_sem protects updates to console->seq and console_suspended, + * console_sem protects updates to console->seq * and also provides serialization for console printing. */ static DEFINE_SEMAPHORE(console_sem); @@ -359,7 +359,7 @@ static bool panic_in_progress(void) * paths in the console code where we end up in places I want * locked without the console semaphore held). */ -static int console_locked, console_suspended; +static int console_locked; /* * Array of consoles built from command line options (console=) @@ -2549,22 +2549,46 @@ MODULE_PARM_DESC(console_no_auto_verbose, "Disable console loglevel raise to hig */ void suspend_console(void) { + struct console *con; + if (!console_suspend_enabled) return; pr_info("Suspending console(s) (use no_console_suspend to debug)\n"); pr_flush(1000, true); - console_lock(); - console_suspended = 1; - up_console_sem(); + + console_list_lock(); + for_each_console(con) + console_srcu_write_flags(con, con->flags | CON_SUSPENDED); + console_list_unlock(); + + /* + * Ensure that all SRCU list walks have completed. All printing + * contexts must be able to see that they are suspended so that it + * is guaranteed that all printing has stopped when this function + * completes. + */ + synchronize_srcu(&console_srcu); } void resume_console(void) { + struct console *con; + if (!console_suspend_enabled) return; - down_console_sem(); - console_suspended = 0; - console_unlock(); + + console_list_lock(); + for_each_console(con) + console_srcu_write_flags(con, con->flags & ~CON_SUSPENDED); + console_list_unlock(); + + /* + * Ensure that all SRCU list walks have completed. All printing + * contexts must be able to see they are no longer suspended so + * that they are guaranteed to wake up and resume printing. + */ + synchronize_srcu(&console_srcu); + pr_flush(1000, true); } @@ -2623,8 +2647,6 @@ void console_lock(void) msleep(1000); down_console_sem(); - if (console_suspended) - return; console_locked = 1; console_may_schedule = 1; } @@ -2645,10 +2667,6 @@ int console_trylock(void) return 0; if (down_trylock_console_sem()) return 0; - if (console_suspended) { - up_console_sem(); - return 0; - } console_locked = 1; console_may_schedule = 0; return 1; @@ -2674,6 +2692,9 @@ static inline bool console_is_usable(struct console *con) if (!(flags & CON_ENABLED)) return false; + if ((flags & CON_SUSPENDED)) + return false; + if (!con->write) return false; @@ -2992,11 +3013,6 @@ void console_unlock(void) bool flushed; u64 next_seq; - if (console_suspended) { - up_console_sem(); - return; - } - /* * Console drivers are called with interrupts disabled, so * @console_may_schedule should be cleared before; however, we may @@ -3702,8 +3718,7 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre /* * Hold the console_lock to guarantee safe access to - * console->seq and to prevent changes to @console_suspended - * until all consoles have been processed. + * console->seq. */ console_lock(); @@ -3711,6 +3726,11 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre for_each_console_srcu(c) { if (con && con != c) continue; + /* + * If consoles are not usable, it cannot be expected + * that they make forward progress, so only increment + * @diff for usable consoles. + */ if (!console_is_usable(c)) continue; printk_seq = c->seq; @@ -3719,18 +3739,12 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre } console_srcu_read_unlock(cookie); - /* - * If consoles are suspended, it cannot be expected that they - * make forward progress, so timeout immediately. @diff is - * still used to return a valid flush status. - */ - if (console_suspended) - remaining = 0; - else if (diff != last_diff && reset_on_progress) + if (diff != last_diff && reset_on_progress) remaining = timeout_ms; console_unlock(); + /* Note: @diff is 0 if there are no usable consoles. */ if (diff == 0 || remaining == 0) break; @@ -3764,7 +3778,7 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre * printer has been seen to make some forward progress. * * Context: Process context. May sleep while acquiring console lock. - * Return: true if all enabled printers are caught up. + * Return: true if all usable printers are caught up. */ static bool pr_flush(int timeout_ms, bool reset_on_progress) { From patchwork Mon Jul 10 13:45:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 117934 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp5049935vqx; Mon, 10 Jul 2023 07:06:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlERBP/3WDTdJXnliWH3Sz70tbpcC/mgeb72ZboRlDxnzuGEO6PQzjWmH6plJgdlwnKc6KEB X-Received: by 2002:a05:6a20:970a:b0:126:a80d:4960 with SMTP id hr10-20020a056a20970a00b00126a80d4960mr12261380pzc.30.1688998008075; Mon, 10 Jul 2023 07:06:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688998008; cv=none; d=google.com; s=arc-20160816; b=XzAUlYLca7pbU0WhqUEL2QU3TvZSNN+QiOrnxx1Cd5DiLNeU0lflxpgo31+E7kzkUc hc03ABEaTJf3YU907SzVTYt8HK8P8GVMcL5e+bG8JlyAG4q7ZP9whK61lyTN9saqyw0g jccAxD+OQq3uQg/BHZcZokLWfw2oDlqEDwCQX4w7Lgye6uCo/1JWyubQN834YHT4akgj a2hTnjdIobG59wnXs3cD+O3aurC5RYc2iY7SLE+stnYoEh+QMOaZmgB8JP1TB9ZqlSUI WLKVHGpLgIeVAvwT9NsEW4DrnxMXc3mWeJuLEpkR3Hvede4fZez3ri6pLvhl+EqHnR5a V4Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=2mOd9Z/Y7bd7pNGaxo//Z18/44l8G9zcu4FfGzkB3p4=; fh=HVRBJStvoKWbFco6Jta18xe5UAVCwWVs9OvJstciom4=; b=jxjPqWOe7DHWxrJvu6rvUVL61ZSwfNmEX4pDBY7YNl+J7yObdZ+ARHKMDYb6ldzjkI RPGQB7KhNCVrcw9u32VXIALkjemf4P6KnmytukznH1v/ZZIAn6CpAR7VoyPjH5obfoCU MYI3mkyyYdgiYdHyQXafsULKDz/Rxhcb4mJuu0eW1XiE4NCTFTDUWfktT3IzZcdQg72R XqT40UW/kHuLKUgzDDrd+pd+RNA6IhjtybiNpsNAq+0m6xVK00E9sqfclC5wlSaMC8Ho nIIM4eJcoQKk2kYKjl5/TBihj+2XvcZzS+Ugn7QreFtOcx/XRLA9OSYdKQSfZzM1H0Kk UDFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=XS44BxOg; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j11-20020a63230b000000b0055adfd71daesi1914615pgj.663.2023.07.10.07.06.34; Mon, 10 Jul 2023 07:06:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=XS44BxOg; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233074AbjGJNpq (ORCPT + 99 others); Mon, 10 Jul 2023 09:45:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233003AbjGJNpf (ORCPT ); Mon, 10 Jul 2023 09:45:35 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6710B11B for ; Mon, 10 Jul 2023 06:45:32 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1688996728; 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=2mOd9Z/Y7bd7pNGaxo//Z18/44l8G9zcu4FfGzkB3p4=; b=XS44BxOgMF+ntJ4i3SNvH+Xz4wYQeLdVjA9CMnPz4O56If1F5PDyBEoKsE+abaGraJ5NbP d+bf/knkAxY4xfhZbvcYUJ481mkTg0gzYped90BDsXO9J7OlyZCtcZ1hVe6X/P++hqIabm B1FaDt3A1UqFowdj00k/SyRhMuk5KLfSC/sLUoiIZ0yIVYus9SWAbaaHDwa3Y7vrpKrnak lBWpq2utIO/k+FPY2zLsBgoKf1jFo39flgPqYbjiJ2RK74aLWcGFlMBhjNyGDCBLsfIOd3 InX/xK5ZgtheFn5D4MM19iebg1LRKKz9VAToAFcLkmGNUsPsQTesvcrbuMpBgw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1688996728; 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=2mOd9Z/Y7bd7pNGaxo//Z18/44l8G9zcu4FfGzkB3p4=; b=SMgsQ96fW5dYutuP4iuvwQR9qSF+1IhBHPkLwxDrfLAyP/GKrGQvk9Af5UfpmjtW/U7aOv 63AnFfL8kKXxPVBg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 5/5] printk: Rename abandon_console_lock_in_panic() to other_cpu_in_panic() Date: Mon, 10 Jul 2023 15:51:24 +0206 Message-Id: <20230710134524.25232-6-john.ogness@linutronix.de> In-Reply-To: <20230710134524.25232-1-john.ogness@linutronix.de> References: <20230710134524.25232-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771042775059647408 X-GMAIL-MSGID: 1771042775059647408 Currently abandon_console_lock_in_panic() is only used to determine if the current CPU should immediately release the console lock because another CPU is in panic. However, later this function will be used by the CPU to immediately release other resources in this situation. Rename the function to other_cpu_in_panic(), which is a better description and does not assume it is related to the console lock. Signed-off-by: John Ogness Reviewed-by: Sergey Senozhatsky Reviewed-by: Petr Mladek --- kernel/printk/internal.h | 2 ++ kernel/printk/printk.c | 15 ++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index 2a17704136f1..7d4979d5c3ce 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -103,3 +103,5 @@ struct printk_message { u64 seq; unsigned long dropped; }; + +bool other_cpu_in_panic(void); diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 701908d389f4..529671aaec2d 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2612,11 +2612,12 @@ static int console_cpu_notify(unsigned int cpu) } /* - * Return true when this CPU should unlock console_sem without pushing all - * messages to the console. This reduces the chance that the console is - * locked when the panic CPU tries to use it. + * Return true if a panic is in progress on a remote CPU. + * + * On true, the local CPU should immediately release any printing resources + * that may be needed by the panic CPU. */ -static bool abandon_console_lock_in_panic(void) +bool other_cpu_in_panic(void) { if (!panic_in_progress()) return false; @@ -2643,7 +2644,7 @@ void console_lock(void) might_sleep(); /* On panic, the console_lock must be left to the panic cpu. */ - while (abandon_console_lock_in_panic()) + while (other_cpu_in_panic()) msleep(1000); down_console_sem(); @@ -2663,7 +2664,7 @@ EXPORT_SYMBOL(console_lock); int console_trylock(void) { /* On panic, the console_lock must be left to the panic cpu. */ - if (abandon_console_lock_in_panic()) + if (other_cpu_in_panic()) return 0; if (down_trylock_console_sem()) return 0; @@ -2978,7 +2979,7 @@ static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove any_progress = true; /* Allow panic_cpu to take over the consoles safely. */ - if (abandon_console_lock_in_panic()) + if (other_cpu_in_panic()) goto abandon; if (do_cond_resched)